VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
7336d0e654f7a (Thomas Gleixner     2019-05-31 01:09:56 -0700    1) // SPDX-License-Identifier: GPL-2.0-only
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000    2) /*
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000    3)  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
da6dd40d59fa9 (Bob Peterson        2007-12-11 18:49:21 -0600    4)  * Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000    5)  */
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000    6) 
d77d1b58aaf44 (Joe Perches         2014-03-06 12:10:45 -0800    7) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
d77d1b58aaf44 (Joe Perches         2014-03-06 12:10:45 -0800    8) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100    9) #include <linux/bio.h>
174cd4b1e5fbd (Ingo Molnar         2017-02-02 19:15:33 +0100   10) #include <linux/sched/signal.h>
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   11) #include <linux/slab.h>
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   12) #include <linux/spinlock.h>
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   13) #include <linux/completion.h>
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   14) #include <linux/buffer_head.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   15) #include <linux/statfs.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   16) #include <linux/seq_file.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   17) #include <linux/mount.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   18) #include <linux/kthread.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   19) #include <linux/delay.h>
5c676f6d359b0 (Steven Whitehouse   2006-02-27 17:23:27 -0500   20) #include <linux/gfs2_ondisk.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   21) #include <linux/crc32.h>
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   22) #include <linux/time.h>
e402746a945ce (Steven Whitehouse   2010-01-25 11:20:19 +0000   23) #include <linux/wait.h>
a9185b41a4f84 (Christoph Hellwig   2010-03-05 09:21:37 +0100   24) #include <linux/writeback.h>
4667a0ec32867 (Steven Whitehouse   2011-04-18 14:18:09 +0100   25) #include <linux/backing-dev.h>
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600   26) #include <linux/kernel.h>
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   27) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   28) #include "gfs2.h"
5c676f6d359b0 (Steven Whitehouse   2006-02-27 17:23:27 -0500   29) #include "incore.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   30) #include "bmap.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   31) #include "dir.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   32) #include "glock.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   33) #include "glops.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   34) #include "inode.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   35) #include "log.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   36) #include "meta_io.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   37) #include "quota.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   38) #include "recovery.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   39) #include "rgrp.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   40) #include "super.h"
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   41) #include "trans.h"
5c676f6d359b0 (Steven Whitehouse   2006-02-27 17:23:27 -0500   42) #include "util.h"
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   43) #include "sys.h"
307cf6e63cfa5 (Steven Whitehouse   2009-08-26 18:51:04 +0100   44) #include "xattr.h"
f4686c26ecc34 (Abhi Das            2019-05-02 14:17:40 -0500   45) #include "lops.h"
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100   46) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   47) enum dinode_demise {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   48) 	SHOULD_DELETE_DINODE,
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   49) 	SHOULD_NOT_DELETE_DINODE,
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   50) 	SHOULD_DEFER_EVICTION,
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   51) };
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500   52) 
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   53) /**
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   54)  * gfs2_jindex_free - Clear all the journal index information
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   55)  * @sdp: The GFS2 superblock
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   56)  *
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   57)  */
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   58) 
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   59) void gfs2_jindex_free(struct gfs2_sbd *sdp)
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   60) {
b50f227bddf11 (Steven Whitehouse   2014-03-03 13:35:57 +0000   61) 	struct list_head list;
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   62) 	struct gfs2_jdesc *jd;
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   63) 
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   64) 	spin_lock(&sdp->sd_jindex_spin);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   65) 	list_add(&list, &sdp->sd_jindex_list);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   66) 	list_del_init(&sdp->sd_jindex_list);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   67) 	sdp->sd_journals = 0;
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   68) 	spin_unlock(&sdp->sd_jindex_spin);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   69) 
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100   70) 	sdp->sd_jdesc = NULL;
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   71) 	while (!list_empty(&list)) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100   72) 		jd = list_first_entry(&list, struct gfs2_jdesc, jd_list);
b50f227bddf11 (Steven Whitehouse   2014-03-03 13:35:57 +0000   73) 		gfs2_free_journal_extents(jd);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   74) 		list_del(&jd->jd_list);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   75) 		iput(jd->jd_inode);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100   76) 		jd->jd_inode = NULL;
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   77) 		kfree(jd);
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   78) 	}
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   79) }
fefc03bfedeff (Steven Whitehouse   2008-12-19 15:32:06 +0000   80) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   81) static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   82) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   83) 	struct gfs2_jdesc *jd;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   84) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   85) 	list_for_each_entry(jd, head, jd_list) {
736b2f778f0a7 (Andreas Gruenbacher 2020-12-07 00:06:32 +0100   86) 		if (jd->jd_jid == jid)
736b2f778f0a7 (Andreas Gruenbacher 2020-12-07 00:06:32 +0100   87) 			return jd;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   88) 	}
736b2f778f0a7 (Andreas Gruenbacher 2020-12-07 00:06:32 +0100   89) 	return NULL;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   90) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   91) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   92) struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   93) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   94) 	struct gfs2_jdesc *jd;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   95) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   96) 	spin_lock(&sdp->sd_jindex_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   97) 	jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   98) 	spin_unlock(&sdp->sd_jindex_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000   99) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  100) 	return jd;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  101) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  102) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  103) int gfs2_jdesc_check(struct gfs2_jdesc *jd)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  104) {
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  105) 	struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  106) 	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
a2e0f79939e09 (Steven Whitehouse   2010-08-11 09:53:11 +0100  107) 	u64 size = i_size_read(jd->jd_inode);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  108) 
47a9a52794684 (Fabian Frederick    2016-08-02 12:05:27 -0500  109) 	if (gfs2_check_internal_file_size(jd->jd_inode, 8 << 20, BIT(30)))
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  110) 		return -EIO;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  111) 
a2e0f79939e09 (Steven Whitehouse   2010-08-11 09:53:11 +0100  112) 	jd->jd_blocks = size >> sdp->sd_sb.sb_bsize_shift;
a2e0f79939e09 (Steven Whitehouse   2010-08-11 09:53:11 +0100  113) 
a2e0f79939e09 (Steven Whitehouse   2010-08-11 09:53:11 +0100  114) 	if (gfs2_write_alloc_required(ip, 0, size)) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  115) 		gfs2_consist_inode(ip);
461cb419f074a (Bob Peterson        2010-06-24 19:21:20 -0400  116) 		return -EIO;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  117) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  118) 
461cb419f074a (Bob Peterson        2010-06-24 19:21:20 -0400  119) 	return 0;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  120) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  121) 
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  122) static int init_threads(struct gfs2_sbd *sdp)
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  123) {
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  124) 	struct task_struct *p;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  125) 	int error = 0;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  126) 
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  127) 	p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  128) 	if (IS_ERR(p)) {
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  129) 		error = PTR_ERR(p);
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  130) 		fs_err(sdp, "can't start logd thread: %d\n", error);
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  131) 		return error;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  132) 	}
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  133) 	sdp->sd_logd_process = p;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  134) 
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  135) 	p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  136) 	if (IS_ERR(p)) {
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  137) 		error = PTR_ERR(p);
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  138) 		fs_err(sdp, "can't start quotad thread: %d\n", error);
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  139) 		goto fail;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  140) 	}
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  141) 	sdp->sd_quotad_process = p;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  142) 	return 0;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  143) 
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  144) fail:
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  145) 	kthread_stop(sdp->sd_logd_process);
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  146) 	sdp->sd_logd_process = NULL;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  147) 	return error;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  148) }
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  149) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  150) /**
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  151)  * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  152)  * @sdp: the filesystem
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  153)  *
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  154)  * Returns: errno
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  155)  */
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  156) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  157) int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  158) {
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  159) 	struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
5c676f6d359b0 (Steven Whitehouse   2006-02-27 17:23:27 -0500  160) 	struct gfs2_glock *j_gl = ip->i_gl;
5516762261633 (Al Viro             2006-10-13 21:47:13 -0400  161) 	struct gfs2_log_header_host head;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  162) 	int error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  163) 
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  164) 	error = init_threads(sdp);
62dd0f98a0e56 (Andrew Price        2021-03-15 12:24:00 +0000  165) 	if (error) {
62dd0f98a0e56 (Andrew Price        2021-03-15 12:24:00 +0000  166) 		gfs2_withdraw_delayed(sdp);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  167) 		return error;
62dd0f98a0e56 (Andrew Price        2021-03-15 12:24:00 +0000  168) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  169) 
1a14d3a68f045 (Steven Whitehouse   2006-11-20 10:37:45 -0500  170) 	j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  171) 	if (gfs2_withdrawn(sdp)) {
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  172) 		error = -EIO;
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  173) 		goto fail;
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  174) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  175) 
f4686c26ecc34 (Abhi Das            2019-05-02 14:17:40 -0500  176) 	error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  177) 	if (error || gfs2_withdrawn(sdp))
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  178) 		goto fail;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  179) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  180) 	if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  181) 		gfs2_consist(sdp);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  182) 		error = -EIO;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  183) 		goto fail;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  184) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  185) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  186) 	/*  Initialize some head of the log stuff  */
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  187) 	sdp->sd_log_sequence = head.lh_sequence + 1;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  188) 	gfs2_log_pointers_init(sdp, head.lh_blkno);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  189) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  190) 	error = gfs2_quota_init(sdp);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  191) 	if (error || gfs2_withdrawn(sdp))
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  192) 		goto fail;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  193) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  194) 	set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  195) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  196) 	return 0;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  197) 
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  198) fail:
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  199) 	if (sdp->sd_quotad_process)
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  200) 		kthread_stop(sdp->sd_quotad_process);
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  201) 	sdp->sd_quotad_process = NULL;
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  202) 	if (sdp->sd_logd_process)
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  203) 		kthread_stop(sdp->sd_logd_process);
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  204) 	sdp->sd_logd_process = NULL;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  205) 	return error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  206) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  207) 
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  208) void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  209) {
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  210) 	const struct gfs2_statfs_change *str = buf;
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  211) 
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  212) 	sc->sc_total = be64_to_cpu(str->sc_total);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  213) 	sc->sc_free = be64_to_cpu(str->sc_free);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  214) 	sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  215) }
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  216) 
730926982d770 (Abhi Das            2020-10-20 15:58:03 -0500  217) void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  218) {
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  219) 	struct gfs2_statfs_change *str = buf;
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  220) 
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  221) 	str->sc_total = cpu_to_be64(sc->sc_total);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  222) 	str->sc_free = cpu_to_be64(sc->sc_free);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  223) 	str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  224) }
bb8d8a6f54c1c (Steven Whitehouse   2007-06-01 14:11:58 +0100  225) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  226) int gfs2_statfs_init(struct gfs2_sbd *sdp)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  227) {
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  228) 	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
bd209cc017f23 (Al Viro             2006-10-13 23:43:19 -0400  229) 	struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  230) 	struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
bd209cc017f23 (Al Viro             2006-10-13 23:43:19 -0400  231) 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  232) 	struct buffer_head *m_bh, *l_bh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  233) 	struct gfs2_holder gh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  234) 	int error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  235) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  236) 	error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  237) 				   &gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  238) 	if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  239) 		return error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  240) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  241) 	error = gfs2_meta_inode_buffer(m_ip, &m_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  242) 	if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  243) 		goto out;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  244) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  245) 	if (sdp->sd_args.ar_spectator) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  246) 		spin_lock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  247) 		gfs2_statfs_change_in(m_sc, m_bh->b_data +
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  248) 				      sizeof(struct gfs2_dinode));
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  249) 		spin_unlock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  250) 	} else {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  251) 		error = gfs2_meta_inode_buffer(l_ip, &l_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  252) 		if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  253) 			goto out_m_bh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  254) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  255) 		spin_lock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  256) 		gfs2_statfs_change_in(m_sc, m_bh->b_data +
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  257) 				      sizeof(struct gfs2_dinode));
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  258) 		gfs2_statfs_change_in(l_sc, l_bh->b_data +
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  259) 				      sizeof(struct gfs2_dinode));
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  260) 		spin_unlock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  261) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  262) 		brelse(l_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  263) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  264) 
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  265) out_m_bh:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  266) 	brelse(m_bh);
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  267) out:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  268) 	gfs2_glock_dq_uninit(&gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  269) 	return 0;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  270) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  271) 
cd915493fce91 (Steven Whitehouse   2006-09-04 12:49:07 -0400  272) void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
cd915493fce91 (Steven Whitehouse   2006-09-04 12:49:07 -0400  273) 			s64 dinodes)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  274) {
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  275) 	struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
bd209cc017f23 (Al Viro             2006-10-13 23:43:19 -0400  276) 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500  277) 	struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  278) 	struct buffer_head *l_bh;
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  279) 	s64 x, y;
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  280) 	int need_sync = 0;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  281) 	int error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  282) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  283) 	error = gfs2_meta_inode_buffer(l_ip, &l_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  284) 	if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  285) 		return;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  286) 
350a9b0a7269c (Steven Whitehouse   2012-12-14 12:36:02 +0000  287) 	gfs2_trans_add_meta(l_ip->i_gl, l_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  288) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  289) 	spin_lock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  290) 	l_sc->sc_total += total;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  291) 	l_sc->sc_free += free;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  292) 	l_sc->sc_dinodes += dinodes;
907b9bceb41fa (Steven Whitehouse   2006-09-25 09:26:04 -0400  293) 	gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode));
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  294) 	if (sdp->sd_args.ar_statfs_percent) {
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  295) 		x = 100 * l_sc->sc_free;
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  296) 		y = m_sc->sc_free * sdp->sd_args.ar_statfs_percent;
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  297) 		if (x >= y || x <= -y)
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  298) 			need_sync = 1;
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  299) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  300) 	spin_unlock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  301) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  302) 	brelse(l_bh);
c14f5735e724c (Benjamin Marzinski  2009-10-26 13:29:47 -0500  303) 	if (need_sync)
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500  304) 		gfs2_wake_up_statfs(sdp);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  305) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  306) 
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  307) void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh,
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  308) 		   struct buffer_head *l_bh)
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  309) {
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  310) 	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  311) 	struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  312) 	struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  313) 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  314) 
350a9b0a7269c (Steven Whitehouse   2012-12-14 12:36:02 +0000  315) 	gfs2_trans_add_meta(l_ip->i_gl, l_bh);
901c6c665b102 (Bob Peterson        2015-03-11 09:52:31 -0500  316) 	gfs2_trans_add_meta(m_ip->i_gl, m_bh);
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  317) 
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  318) 	spin_lock(&sdp->sd_statfs_spin);
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  319) 	m_sc->sc_total += l_sc->sc_total;
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  320) 	m_sc->sc_free += l_sc->sc_free;
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  321) 	m_sc->sc_dinodes += l_sc->sc_dinodes;
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  322) 	memset(l_sc, 0, sizeof(struct gfs2_statfs_change));
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  323) 	memset(l_bh->b_data + sizeof(struct gfs2_dinode),
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  324) 	       0, sizeof(struct gfs2_statfs_change));
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  325) 	gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode));
901c6c665b102 (Bob Peterson        2015-03-11 09:52:31 -0500  326) 	spin_unlock(&sdp->sd_statfs_spin);
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  327) }
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  328) 
8c42d637f6f28 (Steven Whitehouse   2009-09-11 14:36:44 +0100  329) int gfs2_statfs_sync(struct super_block *sb, int type)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  330) {
8c42d637f6f28 (Steven Whitehouse   2009-09-11 14:36:44 +0100  331) 	struct gfs2_sbd *sdp = sb->s_fs_info;
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  332) 	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  333) 	struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
bd209cc017f23 (Al Viro             2006-10-13 23:43:19 -0400  334) 	struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
bd209cc017f23 (Al Viro             2006-10-13 23:43:19 -0400  335) 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  336) 	struct gfs2_holder gh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  337) 	struct buffer_head *m_bh, *l_bh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  338) 	int error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  339) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  340) 	error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  341) 				   &gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  342) 	if (error)
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  343) 		goto out;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  344) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  345) 	error = gfs2_meta_inode_buffer(m_ip, &m_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  346) 	if (error)
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  347) 		goto out_unlock;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  348) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  349) 	spin_lock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  350) 	gfs2_statfs_change_in(m_sc, m_bh->b_data +
907b9bceb41fa (Steven Whitehouse   2006-09-25 09:26:04 -0400  351) 			      sizeof(struct gfs2_dinode));
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  352) 	if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  353) 		spin_unlock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  354) 		goto out_bh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  355) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  356) 	spin_unlock(&sdp->sd_statfs_spin);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  357) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  358) 	error = gfs2_meta_inode_buffer(l_ip, &l_bh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  359) 	if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  360) 		goto out_bh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  361) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  362) 	error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  363) 	if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  364) 		goto out_bh2;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  365) 
1946f70ab5e4e (Benjamin Marzinski  2009-06-25 15:09:51 -0500  366) 	update_statfs(sdp, m_bh, l_bh);
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500  367) 	sdp->sd_statfs_force_sync = 0;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  368) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  369) 	gfs2_trans_end(sdp);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  370) 
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  371) out_bh2:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  372) 	brelse(l_bh);
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  373) out_bh:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  374) 	brelse(m_bh);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  375) out_unlock:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  376) 	gfs2_glock_dq_uninit(&gh);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  377) out:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  378) 	return error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  379) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  380) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  381) struct lfcc {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  382) 	struct list_head list;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  383) 	struct gfs2_holder gh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  384) };
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  385) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  386) /**
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  387)  * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  388)  *                            journals are clean
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  389)  * @sdp: the file system
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  390)  *
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  391)  * Returns: errno
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  392)  */
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  393) 
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  394) static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  395) {
5c676f6d359b0 (Steven Whitehouse   2006-02-27 17:23:27 -0500  396) 	struct gfs2_inode *ip;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  397) 	struct gfs2_jdesc *jd;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  398) 	struct lfcc *lfcc;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  399) 	LIST_HEAD(list);
5516762261633 (Al Viro             2006-10-13 21:47:13 -0400  400) 	struct gfs2_log_header_host lh;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  401) 	int error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  402) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  403) 	list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  404) 		lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  405) 		if (!lfcc) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  406) 			error = -ENOMEM;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  407) 			goto out;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  408) 		}
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  409) 		ip = GFS2_I(jd->jd_inode);
feaa7bba026c1 (Steven Whitehouse   2006-06-14 15:32:57 -0400  410) 		error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  411) 		if (error) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  412) 			kfree(lfcc);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  413) 			goto out;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  414) 		}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  415) 		list_add(&lfcc->list, &list);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  416) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  417) 
24972557b12ce (Benjamin Marzinski  2014-05-01 22:26:55 -0500  418) 	error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_EXCLUSIVE,
c860f8ffbea89 (Bob Peterson        2020-06-25 14:42:17 -0500  419) 				   LM_FLAG_NOEXP, &sdp->sd_freeze_gh);
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  420) 	if (error)
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  421) 		goto out;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  422) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  423) 	list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  424) 		error = gfs2_jdesc_check(jd);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  425) 		if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  426) 			break;
f4686c26ecc34 (Abhi Das            2019-05-02 14:17:40 -0500  427) 		error = gfs2_find_jhead(jd, &lh, false);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  428) 		if (error)
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  429) 			break;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  430) 		if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  431) 			error = -EBUSY;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  432) 			break;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  433) 		}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  434) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  435) 
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  436) 	if (error)
c77b52c0a1379 (Bob Peterson        2020-12-22 14:43:27 -0600  437) 		gfs2_freeze_unlock(&sdp->sd_freeze_gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  438) 
a91ea69ffd3f8 (Steven Whitehouse   2006-09-04 12:04:26 -0400  439) out:
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  440) 	while (!list_empty(&list)) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100  441) 		lfcc = list_first_entry(&list, struct lfcc, list);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  442) 		list_del(&lfcc->list);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  443) 		gfs2_glock_dq_uninit(&lfcc->gh);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  444) 		kfree(lfcc);
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  445) 	}
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  446) 	return error;
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  447) }
b3b94faa5fe59 (David Teigland      2006-01-16 16:50:04 +0000  448) 
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  449) void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  450) {
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  451) 	struct gfs2_dinode *str = buf;
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  452) 
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  453) 	str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  454) 	str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  455) 	str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  456) 	str->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  457) 	str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  458) 	str->di_mode = cpu_to_be32(ip->i_inode.i_mode);
d0546426426ca (Eric W. Biederman   2013-01-31 22:08:10 -0800  459) 	str->di_uid = cpu_to_be32(i_uid_read(&ip->i_inode));
d0546426426ca (Eric W. Biederman   2013-01-31 22:08:10 -0800  460) 	str->di_gid = cpu_to_be32(i_gid_read(&ip->i_inode));
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  461) 	str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  462) 	str->di_size = cpu_to_be64(i_size_read(&ip->i_inode));
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  463) 	str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  464) 	str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  465) 	str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  466) 	str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  467) 
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  468) 	str->di_goal_meta = cpu_to_be64(ip->i_goal);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  469) 	str->di_goal_data = cpu_to_be64(ip->i_goal);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  470) 	str->di_generation = cpu_to_be64(ip->i_generation);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  471) 
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  472) 	str->di_flags = cpu_to_be32(ip->i_diskflags);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  473) 	str->di_height = cpu_to_be16(ip->i_height);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  474) 	str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) &&
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  475) 					     !(ip->i_diskflags & GFS2_DIF_EXHASH) ?
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  476) 					     GFS2_FORMAT_DE : 0);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  477) 	str->di_depth = cpu_to_be16(ip->i_depth);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  478) 	str->di_entries = cpu_to_be32(ip->i_entries);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  479) 
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  480) 	str->di_eattr = cpu_to_be64(ip->i_eattr);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  481) 	str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  482) 	str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  483) 	str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
9eed04cd99b0a (Steven Whitehouse   2011-05-09 14:11:40 +0100  484) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  485) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  486) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  487)  * gfs2_write_inode - Make sure the inode is stable on the disk
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  488)  * @inode: The inode
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  489)  * @wbc: The writeback control structure
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  490)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  491)  * Returns: errno
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  492)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  493) 
a9185b41a4f84 (Christoph Hellwig   2010-03-05 09:21:37 +0100  494) static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  495) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  496) 	struct gfs2_inode *ip = GFS2_I(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  497) 	struct gfs2_sbd *sdp = GFS2_SB(inode);
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  498) 	struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl);
de1414a654e66 (Christoph Hellwig   2015-01-14 10:42:36 +0100  499) 	struct backing_dev_info *bdi = inode_to_bdi(metamapping->host);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  500) 	int ret = 0;
adbc3ddf28ad9 (Bob Peterson        2017-10-11 16:22:07 +0200  501) 	bool flush_all = (wbc->sync_mode == WB_SYNC_ALL || gfs2_is_jdata(ip));
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  502) 
adbc3ddf28ad9 (Bob Peterson        2017-10-11 16:22:07 +0200  503) 	if (flush_all)
c1696fb85d331 (Bob Peterson        2018-01-17 00:01:33 +0100  504) 		gfs2_log_flush(GFS2_SB(inode), ip->i_gl,
805c090750a31 (Bob Peterson        2018-01-08 10:34:17 -0500  505) 			       GFS2_LOG_HEAD_FLUSH_NORMAL |
805c090750a31 (Bob Peterson        2018-01-08 10:34:17 -0500  506) 			       GFS2_LFC_WRITE_INODE);
a88a341a73be4 (Tejun Heo           2015-05-22 17:13:28 -0400  507) 	if (bdi->wb.dirty_exceeded)
4667a0ec32867 (Steven Whitehouse   2011-04-18 14:18:09 +0100  508) 		gfs2_ail1_flush(sdp, wbc);
1d4ec642d9f00 (Steven Whitehouse   2011-08-02 13:13:20 +0100  509) 	else
1d4ec642d9f00 (Steven Whitehouse   2011-08-02 13:13:20 +0100  510) 		filemap_fdatawrite(metamapping);
adbc3ddf28ad9 (Bob Peterson        2017-10-11 16:22:07 +0200  511) 	if (flush_all)
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  512) 		ret = filemap_fdatawait(metamapping);
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  513) 	if (ret)
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  514) 		mark_inode_dirty_sync(inode);
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  515) 	else {
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  516) 		spin_lock(&inode->i_lock);
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  517) 		if (!(inode->i_flags & I_DIRTY))
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  518) 			gfs2_ordered_del_inode(ip);
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  519) 		spin_unlock(&inode->i_lock);
957a7acd46e64 (Abhi Das            2018-01-30 10:00:09 -0700  520) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  521) 	return ret;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  522) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  523) 
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  524) /**
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  525)  * gfs2_dirty_inode - check for atime updates
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  526)  * @inode: The inode in question
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  527)  * @flags: The type of dirty
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  528)  *
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  529)  * Unfortunately it can be called under any combination of inode
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  530)  * glock and transaction lock, so we have to check carefully.
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  531)  *
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  532)  * At the moment this deals only with atime - it should be possible
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  533)  * to expand that role in future, once a review of the locking has
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  534)  * been carried out.
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  535)  */
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  536) 
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  537) static void gfs2_dirty_inode(struct inode *inode, int flags)
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  538) {
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  539) 	struct gfs2_inode *ip = GFS2_I(inode);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  540) 	struct gfs2_sbd *sdp = GFS2_SB(inode);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  541) 	struct buffer_head *bh;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  542) 	struct gfs2_holder gh;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  543) 	int need_unlock = 0;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  544) 	int need_endtrans = 0;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  545) 	int ret;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  546) 
eb43e660c0940 (Bob Peterson        2019-11-14 09:52:15 -0500  547) 	if (unlikely(gfs2_withdrawn(sdp)))
0d1c7ae9d849b (Bob Peterson        2017-03-03 12:37:14 -0500  548) 		return;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  549) 	if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  550) 		ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  551) 		if (ret) {
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  552) 			fs_err(sdp, "dirty_inode: glock %d\n", ret);
e28c02b94f9e0 (Bob Peterson        2020-07-30 12:31:38 -0500  553) 			gfs2_dump_glock(NULL, ip->i_gl, true);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  554) 			return;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  555) 		}
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  556) 		need_unlock = 1;
3d1626889a64b (Benjamin Marzinski  2012-11-06 00:49:28 -0600  557) 	} else if (WARN_ON_ONCE(ip->i_gl->gl_state != LM_ST_EXCLUSIVE))
3d1626889a64b (Benjamin Marzinski  2012-11-06 00:49:28 -0600  558) 		return;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  559) 
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  560) 	if (current->journal_info == NULL) {
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  561) 		ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  562) 		if (ret) {
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  563) 			fs_err(sdp, "dirty_inode: gfs2_trans_begin %d\n", ret);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  564) 			goto out;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  565) 		}
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  566) 		need_endtrans = 1;
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  567) 	}
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  568) 
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  569) 	ret = gfs2_meta_inode_buffer(ip, &bh);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  570) 	if (ret == 0) {
350a9b0a7269c (Steven Whitehouse   2012-12-14 12:36:02 +0000  571) 		gfs2_trans_add_meta(ip->i_gl, bh);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  572) 		gfs2_dinode_out(ip, bh->b_data);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  573) 		brelse(bh);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  574) 	}
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  575) 
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  576) 	if (need_endtrans)
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  577) 		gfs2_trans_end(sdp);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  578) out:
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  579) 	if (need_unlock)
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  580) 		gfs2_glock_dq_uninit(&gh);
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  581) }
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100  582) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  583) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  584)  * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  585)  * @sdp: the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  586)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  587)  * Returns: errno
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  588)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  589) 
eb602521f4387 (Yang Li             2021-03-04 09:28:57 -0500  590) void gfs2_make_fs_ro(struct gfs2_sbd *sdp)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  591) {
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  592) 	int log_write_allowed = test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  593) 
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100  594) 	gfs2_flush_delete_work(sdp);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  595) 	if (!log_write_allowed && current == sdp->sd_quotad_process)
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  596) 		fs_warn(sdp, "The quotad daemon is withdrawing.\n");
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  597) 	else if (sdp->sd_quotad_process)
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  598) 		kthread_stop(sdp->sd_quotad_process);
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  599) 	sdp->sd_quotad_process = NULL;
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  600) 
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  601) 	if (!log_write_allowed && current == sdp->sd_logd_process)
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  602) 		fs_warn(sdp, "The logd daemon is withdrawing.\n");
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  603) 	else if (sdp->sd_logd_process)
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  604) 		kthread_stop(sdp->sd_logd_process);
5b3a9f348bc58 (Bob Peterson        2019-04-26 08:11:27 -0600  605) 	sdp->sd_logd_process = NULL;
8ad151c2ac9aa (Steven Whitehouse   2013-12-12 11:34:09 +0000  606) 
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  607) 	if (log_write_allowed) {
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  608) 		gfs2_quota_sync(sdp->sd_vfs, 0);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  609) 		gfs2_statfs_sync(sdp->sd_vfs, 0);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  610) 
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  611) 		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SHUTDOWN |
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  612) 			       GFS2_LFC_MAKE_FS_RO);
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  613) 		wait_event_timeout(sdp->sd_log_waitq,
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  614) 				   gfs2_log_is_empty(sdp),
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  615) 				   HZ * 5);
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  616) 		gfs2_assert_warn(sdp, gfs2_log_is_empty(sdp));
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  617) 	} else {
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  618) 		wait_event_timeout(sdp->sd_log_waitq,
f3708fb59f6c2 (Andreas Gruenbacher 2020-12-13 09:21:34 +0100  619) 				   gfs2_log_is_empty(sdp),
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  620) 				   HZ * 5);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  621) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  622) 	gfs2_quota_cleanup(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  623) 
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  624) 	if (!log_write_allowed)
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  625) 		sdp->sd_vfs->s_flags |= SB_RDONLY;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  626) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  627) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  628) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  629)  * gfs2_put_super - Unmount the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  630)  * @sb: The VFS superblock
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  631)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  632)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  633) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  634) static void gfs2_put_super(struct super_block *sb)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  635) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  636) 	struct gfs2_sbd *sdp = sb->s_fs_info;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  637) 	struct gfs2_jdesc *jd;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  638) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  639) 	/* No more recovery requests */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  640) 	set_bit(SDF_NORECOVERY, &sdp->sd_flags);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  641) 	smp_mb();
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  642) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  643) 	/* Wait on outstanding recovery */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  644) restart:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  645) 	spin_lock(&sdp->sd_jindex_spin);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  646) 	list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  647) 		if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  648) 			continue;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  649) 		spin_unlock(&sdp->sd_jindex_spin);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  650) 		wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
743162013d40c (NeilBrown           2014-07-07 15:16:04 +1000  651) 			    TASK_UNINTERRUPTIBLE);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  652) 		goto restart;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  653) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  654) 	spin_unlock(&sdp->sd_jindex_spin);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  655) 
bc98a42c1f7d0 (David Howells       2017-07-17 08:45:34 +0100  656) 	if (!sb_rdonly(sb)) {
eb602521f4387 (Yang Li             2021-03-04 09:28:57 -0500  657) 		gfs2_make_fs_ro(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  658) 	}
5a61ae1402f15 (Andreas Gruenbacher 2020-08-28 23:44:36 +0200  659) 	WARN_ON(gfs2_withdrawing(sdp));
5a61ae1402f15 (Andreas Gruenbacher 2020-08-28 23:44:36 +0200  660) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  661) 	/*  At this point, we're through modifying the disk  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  662) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  663) 	/*  Release stuff  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  664) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  665) 	iput(sdp->sd_jindex);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  666) 	iput(sdp->sd_statfs_inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  667) 	iput(sdp->sd_rindex);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  668) 	iput(sdp->sd_quota_inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  669) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  670) 	gfs2_glock_put(sdp->sd_rename_gl);
24972557b12ce (Benjamin Marzinski  2014-05-01 22:26:55 -0500  671) 	gfs2_glock_put(sdp->sd_freeze_gl);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  672) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  673) 	if (!sdp->sd_args.ar_spectator) {
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  674) 		if (gfs2_holder_initialized(&sdp->sd_journal_gh))
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  675) 			gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  676) 		if (gfs2_holder_initialized(&sdp->sd_jinode_gh))
601ef0d52e961 (Bob Peterson        2020-01-28 20:23:45 +0100  677) 			gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  678) 		gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  679) 		gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500  680) 		free_local_statfs_inodes(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  681) 		iput(sdp->sd_qc_inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  682) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  683) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  684) 	gfs2_glock_dq_uninit(&sdp->sd_live_gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  685) 	gfs2_clear_rgrpd(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  686) 	gfs2_jindex_free(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  687) 	/*  Take apart glock structures and buffer lists  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  688) 	gfs2_gl_hash_clear(sdp);
a9dd945ccef07 (Bob Peterson        2020-10-27 10:10:02 -0500  689) 	truncate_inode_pages_final(&sdp->sd_aspace);
b2fb7dab7f193 (Bob Peterson        2017-07-28 07:22:55 -0500  690) 	gfs2_delete_debugfs_file(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  691) 	/*  Unmount the locking protocol  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  692) 	gfs2_lm_unmount(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  693) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  694) 	/*  At this point, we're through participating in the lockspace  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  695) 	gfs2_sys_fs_del(sdp);
c2a04b02c060c (Jamie Iles          2020-10-12 14:13:09 +0100  696) 	free_sbd(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  697) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  698) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  699) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  700)  * gfs2_sync_fs - sync the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  701)  * @sb: the superblock
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100  702)  * @wait: true to wait for completion
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  703)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  704)  * Flushes the log to disk.
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  705)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  706) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  707) static int gfs2_sync_fs(struct super_block *sb, int wait)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  708) {
1027efaa238e1 (Steven Whitehouse   2011-03-30 16:13:25 +0100  709) 	struct gfs2_sbd *sdp = sb->s_fs_info;
a1177825719cc (Jan Kara            2012-07-03 16:45:29 +0200  710) 
a1177825719cc (Jan Kara            2012-07-03 16:45:29 +0200  711) 	gfs2_quota_sync(sb, -1);
942b0cddfbf66 (Bob Peterson        2017-08-16 11:30:06 -0500  712) 	if (wait)
805c090750a31 (Bob Peterson        2018-01-08 10:34:17 -0500  713) 		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL |
805c090750a31 (Bob Peterson        2018-01-08 10:34:17 -0500  714) 			       GFS2_LFC_SYNC_FS);
942b0cddfbf66 (Bob Peterson        2017-08-16 11:30:06 -0500  715) 	return sdp->sd_log_error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  716) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  717) 
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  718) void gfs2_freeze_func(struct work_struct *work)
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  719) {
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  720) 	int error;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  721) 	struct gfs2_holder freeze_gh;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  722) 	struct gfs2_sbd *sdp = container_of(work, struct gfs2_sbd, sd_freeze_work);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  723) 	struct super_block *sb = sdp->sd_vfs;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  724) 
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  725) 	atomic_inc(&sb->s_active);
c77b52c0a1379 (Bob Peterson        2020-12-22 14:43:27 -0600  726) 	error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  727) 	if (error) {
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  728) 		gfs2_assert_withdraw(sdp, 0);
8f91821990fd6 (Abhi Das            2019-04-30 16:53:47 -0500  729) 	} else {
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  730) 		atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  731) 		error = thaw_super(sb);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  732) 		if (error) {
f29e62eed261f (Bob Peterson        2019-05-13 09:42:18 -0500  733) 			fs_info(sdp, "GFS2: couldn't thaw filesystem: %d\n",
f29e62eed261f (Bob Peterson        2019-05-13 09:42:18 -0500  734) 				error);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  735) 			gfs2_assert_withdraw(sdp, 0);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  736) 		}
c77b52c0a1379 (Bob Peterson        2020-12-22 14:43:27 -0600  737) 		gfs2_freeze_unlock(&freeze_gh);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  738) 	}
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  739) 	deactivate_super(sb);
8f91821990fd6 (Abhi Das            2019-04-30 16:53:47 -0500  740) 	clear_bit_unlock(SDF_FS_FROZEN, &sdp->sd_flags);
8f91821990fd6 (Abhi Das            2019-04-30 16:53:47 -0500  741) 	wake_up_bit(&sdp->sd_flags, SDF_FS_FROZEN);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  742) 	return;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  743) }
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  744) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  745) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  746)  * gfs2_freeze - prevent further writes to the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  747)  * @sb: the VFS structure for the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  748)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  749)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  750) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  751) static int gfs2_freeze(struct super_block *sb)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  752) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  753) 	struct gfs2_sbd *sdp = sb->s_fs_info;
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  754) 	int error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  755) 
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  756) 	mutex_lock(&sdp->sd_freeze_mutex);
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  757) 	if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN) {
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  758) 		error = -EBUSY;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  759) 		goto out;
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  760) 	}
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  761) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  762) 	for (;;) {
60528afa78667 (Bob Peterson        2019-11-14 09:53:36 -0500  763) 		if (gfs2_withdrawn(sdp)) {
60528afa78667 (Bob Peterson        2019-11-14 09:53:36 -0500  764) 			error = -EINVAL;
60528afa78667 (Bob Peterson        2019-11-14 09:53:36 -0500  765) 			goto out;
60528afa78667 (Bob Peterson        2019-11-14 09:53:36 -0500  766) 		}
60528afa78667 (Bob Peterson        2019-11-14 09:53:36 -0500  767) 
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  768) 		error = gfs2_lock_fs_check_clean(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  769) 		if (!error)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  770) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  771) 
55317f5b00f0d (Bob Peterson        2019-04-29 09:36:23 -0600  772) 		if (error == -EBUSY)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  773) 			fs_err(sdp, "waiting for recovery before freeze\n");
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  774) 		else if (error == -EIO) {
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  775) 			fs_err(sdp, "Fatal IO error: cannot freeze gfs2 due "
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  776) 			       "to recovery error.\n");
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  777) 			goto out;
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  778) 		} else {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  779) 			fs_err(sdp, "error freezing FS: %d\n", error);
52b1cdcb7a84a (Bob Peterson        2019-11-15 09:42:46 -0500  780) 		}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  781) 		fs_err(sdp, "retrying...\n");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  782) 		msleep(1000);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  783) 	}
8f91821990fd6 (Abhi Das            2019-04-30 16:53:47 -0500  784) 	set_bit(SDF_FS_FROZEN, &sdp->sd_flags);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  785) out:
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  786) 	mutex_unlock(&sdp->sd_freeze_mutex);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  787) 	return error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  788) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  789) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  790) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  791)  * gfs2_unfreeze - reallow writes to the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  792)  * @sb: the VFS structure for the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  793)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  794)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  795) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  796) static int gfs2_unfreeze(struct super_block *sb)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  797) {
d564053f07463 (Steven Whitehouse   2013-01-11 10:49:34 +0000  798) 	struct gfs2_sbd *sdp = sb->s_fs_info;
d564053f07463 (Steven Whitehouse   2013-01-11 10:49:34 +0000  799) 
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  800) 	mutex_lock(&sdp->sd_freeze_mutex);
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  801) 	if (atomic_read(&sdp->sd_freeze_state) != SFS_FROZEN ||
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  802) 	    !gfs2_holder_initialized(&sdp->sd_freeze_gh)) {
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  803) 		mutex_unlock(&sdp->sd_freeze_mutex);
ff132c5f93c06 (Bob Peterson        2021-03-25 08:51:13 -0400  804) 		return -EINVAL;
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  805) 	}
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  806) 
c77b52c0a1379 (Bob Peterson        2020-12-22 14:43:27 -0600  807) 	gfs2_freeze_unlock(&sdp->sd_freeze_gh);
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600  808) 	mutex_unlock(&sdp->sd_freeze_mutex);
8f91821990fd6 (Abhi Das            2019-04-30 16:53:47 -0500  809) 	return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN, TASK_INTERRUPTIBLE);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  810) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  811) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  812) /**
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100  813)  * statfs_slow_fill - fill in the sg for a given RG
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  814)  * @rgd: the RG
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  815)  * @sc: the sc structure
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  816)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  817)  * Returns: 0 on success, -ESTALE if the LVB is invalid
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  818)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  819) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  820) static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  821) 			    struct gfs2_statfs_change_host *sc)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  822) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  823) 	gfs2_rgrp_verify(rgd);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  824) 	sc->sc_total += rgd->rd_data;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  825) 	sc->sc_free += rgd->rd_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  826) 	sc->sc_dinodes += rgd->rd_dinodes;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  827) 	return 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  828) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  829) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  830) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  831)  * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  832)  * @sdp: the filesystem
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  833)  * @sc: the sc info that will be returned
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  834)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  835)  * Any error (other than a signal) will cause this routine to fall back
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  836)  * to the synchronous version.
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  837)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  838)  * FIXME: This really shouldn't busy wait like this.
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  839)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  840)  * Returns: errno
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  841)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  842) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  843) static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  844) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  845) 	struct gfs2_rgrpd *rgd_next;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  846) 	struct gfs2_holder *gha, *gh;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  847) 	unsigned int slots = 64;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  848) 	unsigned int x;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  849) 	int done;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  850) 	int error = 0, err;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  851) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  852) 	memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
6da2ec56059c3 (Kees Cook           2018-06-12 13:55:00 -0700  853) 	gha = kmalloc_array(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  854) 	if (!gha)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  855) 		return -ENOMEM;
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  856) 	for (x = 0; x < slots; x++)
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  857) 		gfs2_holder_mark_uninitialized(gha + x);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  858) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  859) 	rgd_next = gfs2_rgrpd_get_first(sdp);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  860) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  861) 	for (;;) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  862) 		done = 1;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  863) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  864) 		for (x = 0; x < slots; x++) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  865) 			gh = gha + x;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  866) 
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  867) 			if (gfs2_holder_initialized(gh) && gfs2_glock_poll(gh)) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  868) 				err = gfs2_glock_wait(gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  869) 				if (err) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  870) 					gfs2_holder_uninit(gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  871) 					error = err;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  872) 				} else {
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  873) 					if (!error) {
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  874) 						struct gfs2_rgrpd *rgd =
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  875) 							gfs2_glock2rgrp(gh->gh_gl);
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  876) 
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  877) 						error = statfs_slow_fill(rgd, sc);
6f6597baae206 (Andreas Gruenbacher 2017-06-30 07:55:08 -0500  878) 					}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  879) 					gfs2_glock_dq_uninit(gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  880) 				}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  881) 			}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  882) 
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  883) 			if (gfs2_holder_initialized(gh))
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  884) 				done = 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  885) 			else if (rgd_next && !error) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  886) 				error = gfs2_glock_nq_init(rgd_next->rd_gl,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  887) 							   LM_ST_SHARED,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  888) 							   GL_ASYNC,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  889) 							   gh);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  890) 				rgd_next = gfs2_rgrpd_get_next(rgd_next);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  891) 				done = 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  892) 			}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  893) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  894) 			if (signal_pending(current))
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  895) 				error = -ERESTARTSYS;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  896) 		}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  897) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  898) 		if (done)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  899) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  900) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  901) 		yield();
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  902) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  903) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  904) 	kfree(gha);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  905) 	return error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  906) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  907) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  908) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  909)  * gfs2_statfs_i - Do a statfs
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  910)  * @sdp: the filesystem
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100  911)  * @sc: the sc structure
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  912)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  913)  * Returns: errno
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  914)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  915) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  916) static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  917) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  918) 	struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  919) 	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  920) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  921) 	spin_lock(&sdp->sd_statfs_spin);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  922) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  923) 	*sc = *m_sc;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  924) 	sc->sc_total += l_sc->sc_total;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  925) 	sc->sc_free += l_sc->sc_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  926) 	sc->sc_dinodes += l_sc->sc_dinodes;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  927) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  928) 	spin_unlock(&sdp->sd_statfs_spin);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  929) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  930) 	if (sc->sc_free < 0)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  931) 		sc->sc_free = 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  932) 	if (sc->sc_free > sc->sc_total)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  933) 		sc->sc_free = sc->sc_total;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  934) 	if (sc->sc_dinodes < 0)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  935) 		sc->sc_dinodes = 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  936) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  937) 	return 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  938) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  939) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  940) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  941)  * gfs2_statfs - Gather and return stats about the filesystem
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100  942)  * @dentry: The name of the link
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100  943)  * @buf: The buffer
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  944)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  945)  * Returns: 0 on success or error code
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  946)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  947) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  948) static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  949) {
fc64005c93090 (Al Viro             2016-04-10 01:33:30 -0400  950) 	struct super_block *sb = dentry->d_sb;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  951) 	struct gfs2_sbd *sdp = sb->s_fs_info;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  952) 	struct gfs2_statfs_change_host sc;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  953) 	int error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  954) 
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100  955) 	error = gfs2_rindex_update(sdp);
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100  956) 	if (error)
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100  957) 		return error;
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100  958) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  959) 	if (gfs2_tune_get(sdp, gt_statfs_slow))
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  960) 		error = gfs2_statfs_slow(sdp, &sc);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  961) 	else
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  962) 		error = gfs2_statfs_i(sdp, &sc);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  963) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  964) 	if (error)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  965) 		return error;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  966) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  967) 	buf->f_type = GFS2_MAGIC;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  968) 	buf->f_bsize = sdp->sd_sb.sb_bsize;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  969) 	buf->f_blocks = sc.sc_total;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  970) 	buf->f_bfree = sc.sc_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  971) 	buf->f_bavail = sc.sc_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  972) 	buf->f_files = sc.sc_dinodes + sc.sc_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  973) 	buf->f_ffree = sc.sc_free;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  974) 	buf->f_namelen = GFS2_FNAMESIZE;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  975) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  976) 	return 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  977) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  978) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  979) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  980)  * gfs2_drop_inode - Drop an inode (test for remote unlink)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  981)  * @inode: The inode to drop
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  982)  *
61b91cfdc6c0c (Andreas Gruenbacher 2017-08-01 09:54:33 -0500  983)  * If we've received a callback on an iopen lock then it's because a
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  984)  * remote node tried to deallocate the inode but failed due to this node
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  985)  * still having the inode open. Here we mark the link count zero
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  986)  * since we know that it must have reached zero if the GLF_DEMOTE flag
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  987)  * is set on the iopen glock. If we didn't do a disk read since the
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  988)  * remote node removed the final link then we might otherwise miss
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  989)  * this event. This check ensures that this node will deallocate the
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  990)  * inode's blocks, or alternatively pass the baton on to another
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  991)  * node for later deallocation.
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  992)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  993) 
45321ac54316e (Al Viro             2010-06-07 13:43:19 -0400  994) static int gfs2_drop_inode(struct inode *inode)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  995) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  996) 	struct gfs2_inode *ip = GFS2_I(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100  997) 
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  998) 	if (!test_bit(GIF_FREE_VFS_INODE, &ip->i_flags) &&
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500  999) 	    inode->i_nlink &&
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500 1000) 	    gfs2_holder_initialized(&ip->i_iopen_gh)) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1001) 		struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500 1002) 		if (test_bit(GLF_DEMOTE, &gl->gl_flags))
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1003) 			clear_nlink(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1004) 	}
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1005) 
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1006) 	/*
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1007) 	 * When under memory pressure when an inode's link count has dropped to
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1008) 	 * zero, defer deleting the inode to the delete workqueue.  This avoids
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1009) 	 * calling into DLM under memory pressure, which can deadlock.
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1010) 	 */
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1011) 	if (!inode->i_nlink &&
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1012) 	    unlikely(current->flags & PF_MEMALLOC) &&
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1013) 	    gfs2_holder_initialized(&ip->i_iopen_gh)) {
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1014) 		struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1015) 
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1016) 		gfs2_glock_hold(gl);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1017) 		if (!gfs2_queue_delete_work(gl, 0))
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1018) 			gfs2_glock_queue_put(gl);
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1019) 		return false;
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1020) 	}
6a1c8f6dcf815 (Andreas Gruenbacher 2017-08-01 11:49:42 -0500 1021) 
45321ac54316e (Al Viro             2010-06-07 13:43:19 -0400 1022) 	return generic_drop_inode(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1023) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1024) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1025) static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1026) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1027) 	do {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1028) 		if (d1 == d2)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1029) 			return 1;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1030) 		d1 = d1->d_parent;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1031) 	} while (!IS_ROOT(d1));
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1032) 	return 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1033) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1034) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1035) /**
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1036)  * gfs2_show_options - Show mount options for /proc/mounts
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1037)  * @s: seq_file structure
34c80b1d93e6e (Al Viro             2011-12-08 21:32:45 -0500 1038)  * @root: root of this (sub)tree
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1039)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1040)  * Returns: 0 on success or error code
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1041)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1042) 
34c80b1d93e6e (Al Viro             2011-12-08 21:32:45 -0500 1043) static int gfs2_show_options(struct seq_file *s, struct dentry *root)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1044) {
34c80b1d93e6e (Al Viro             2011-12-08 21:32:45 -0500 1045) 	struct gfs2_sbd *sdp = root->d_sb->s_fs_info;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1046) 	struct gfs2_args *args = &sdp->sd_args;
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1047) 	int val;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1048) 
34c80b1d93e6e (Al Viro             2011-12-08 21:32:45 -0500 1049) 	if (is_ancestor(root, sdp->sd_master_dir))
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1050) 		seq_puts(s, ",meta");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1051) 	if (args->ar_lockproto[0])
a068acf2ee776 (Kees Cook           2015-09-04 15:44:57 -0700 1052) 		seq_show_option(s, "lockproto", args->ar_lockproto);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1053) 	if (args->ar_locktable[0])
a068acf2ee776 (Kees Cook           2015-09-04 15:44:57 -0700 1054) 		seq_show_option(s, "locktable", args->ar_locktable);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1055) 	if (args->ar_hostdata[0])
a068acf2ee776 (Kees Cook           2015-09-04 15:44:57 -0700 1056) 		seq_show_option(s, "hostdata", args->ar_hostdata);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1057) 	if (args->ar_spectator)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1058) 		seq_puts(s, ",spectator");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1059) 	if (args->ar_localflocks)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1060) 		seq_puts(s, ",localflocks");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1061) 	if (args->ar_debug)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1062) 		seq_puts(s, ",debug");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1063) 	if (args->ar_posix_acl)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1064) 		seq_puts(s, ",acl");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1065) 	if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1066) 		char *state;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1067) 		switch (args->ar_quota) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1068) 		case GFS2_QUOTA_OFF:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1069) 			state = "off";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1070) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1071) 		case GFS2_QUOTA_ACCOUNT:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1072) 			state = "account";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1073) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1074) 		case GFS2_QUOTA_ON:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1075) 			state = "on";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1076) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1077) 		default:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1078) 			state = "unknown";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1079) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1080) 		}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1081) 		seq_printf(s, ",quota=%s", state);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1082) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1083) 	if (args->ar_suiddir)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1084) 		seq_puts(s, ",suiddir");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1085) 	if (args->ar_data != GFS2_DATA_DEFAULT) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1086) 		char *state;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1087) 		switch (args->ar_data) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1088) 		case GFS2_DATA_WRITEBACK:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1089) 			state = "writeback";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1090) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1091) 		case GFS2_DATA_ORDERED:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1092) 			state = "ordered";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1093) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1094) 		default:
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1095) 			state = "unknown";
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1096) 			break;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1097) 		}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1098) 		seq_printf(s, ",data=%s", state);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1099) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1100) 	if (args->ar_discard)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1101) 		seq_puts(s, ",discard");
5e687eac1bd31 (Benjamin Marzinski  2010-05-04 14:29:16 -0500 1102) 	val = sdp->sd_tune.gt_logd_secs;
5e687eac1bd31 (Benjamin Marzinski  2010-05-04 14:29:16 -0500 1103) 	if (val != 30)
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1104) 		seq_printf(s, ",commit=%d", val);
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1105) 	val = sdp->sd_tune.gt_statfs_quantum;
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1106) 	if (val != 30)
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1107) 		seq_printf(s, ",statfs_quantum=%d", val);
2b9731e8bb1bd (Steven Whitehouse   2012-08-20 17:07:49 +0100 1108) 	else if (sdp->sd_tune.gt_statfs_slow)
2b9731e8bb1bd (Steven Whitehouse   2012-08-20 17:07:49 +0100 1109) 		seq_puts(s, ",statfs_quantum=0");
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1110) 	val = sdp->sd_tune.gt_quota_quantum;
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1111) 	if (val != 60)
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1112) 		seq_printf(s, ",quota_quantum=%d", val);
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1113) 	if (args->ar_statfs_percent)
3d3c10f2ce80d (Benjamin Marzinski  2009-10-20 02:39:44 -0500 1114) 		seq_printf(s, ",statfs_percent=%d", args->ar_statfs_percent);
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1115) 	if (args->ar_errors != GFS2_ERRORS_DEFAULT) {
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1116) 		const char *state;
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1117) 
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1118) 		switch (args->ar_errors) {
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1119) 		case GFS2_ERRORS_WITHDRAW:
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1120) 			state = "withdraw";
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1121) 			break;
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1122) 		case GFS2_ERRORS_PANIC:
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1123) 			state = "panic";
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1124) 			break;
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1125) 		default:
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1126) 			state = "unknown";
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1127) 			break;
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1128) 		}
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1129) 		seq_printf(s, ",errors=%s", state);
d34843d0c4a20 (Bob Peterson        2009-08-24 10:44:18 +0100 1130) 	}
cdcfde62dac64 (Steven Whitehouse   2009-10-30 10:48:53 +0000 1131) 	if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags))
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1132) 		seq_puts(s, ",nobarrier");
913a71d250803 (Steven Whitehouse   2010-05-06 11:03:29 +0100 1133) 	if (test_bit(SDF_DEMOTE, &sdp->sd_flags))
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1134) 		seq_puts(s, ",demote_interface_used");
90306c41dc3d8 (Benjamin Marzinski  2012-05-29 23:01:09 -0500 1135) 	if (args->ar_rgrplvb)
eaebdedc61ac7 (Fabian Frederick    2014-07-02 22:08:46 +0200 1136) 		seq_puts(s, ",rgrplvb");
471f3db2786bc (Benjamin Marzinski  2015-12-01 08:46:55 -0600 1137) 	if (args->ar_loccookie)
471f3db2786bc (Benjamin Marzinski  2015-12-01 08:46:55 -0600 1138) 		seq_puts(s, ",loccookie");
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1139) 	return 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1140) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1141) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1142) static void gfs2_final_release_pages(struct gfs2_inode *ip)
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1143) {
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1144) 	struct inode *inode = &ip->i_inode;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1145) 	struct gfs2_glock *gl = ip->i_gl;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1146) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1147) 	truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1148) 	truncate_inode_pages(&inode->i_data, 0);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1149) 
638803d456812 (Bob Peterson        2019-06-06 07:33:38 -0500 1150) 	if (atomic_read(&gl->gl_revokes) == 0) {
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1151) 		clear_bit(GLF_LFLUSH, &gl->gl_flags);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1152) 		clear_bit(GLF_DIRTY, &gl->gl_flags);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1153) 	}
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1154) }
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1155) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1156) static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1157) {
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1158) 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1159) 	struct gfs2_rgrpd *rgd;
564e12b115721 (Bob Peterson        2011-11-21 13:36:17 -0500 1160) 	struct gfs2_holder gh;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1161) 	int error;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1162) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1163) 	if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
94fb763b1a76a (Steven Whitehouse   2011-05-09 13:36:10 +0100 1164) 		gfs2_consist_inode(ip);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1165) 		return -EIO;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1166) 	}
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1167) 
8e2e00473598d (Bob Peterson        2012-07-19 08:12:40 -0400 1168) 	error = gfs2_rindex_update(sdp);
8e2e00473598d (Bob Peterson        2012-07-19 08:12:40 -0400 1169) 	if (error)
8e2e00473598d (Bob Peterson        2012-07-19 08:12:40 -0400 1170) 		return error;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1171) 
f4108a607f75b (Eric W. Biederman   2013-01-31 17:49:26 -0800 1172) 	error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1173) 	if (error)
5407e24229408 (Bob Peterson        2012-05-18 09:28:23 -0400 1174) 		return error;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1175) 
66fc061bda352 (Steven Whitehouse   2012-02-08 12:58:32 +0000 1176) 	rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1177) 	if (!rgd) {
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1178) 		gfs2_consist_inode(ip);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1179) 		error = -EIO;
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100 1180) 		goto out_qs;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1181) 	}
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1182) 
4fc7ec31c3c44 (Bob Peterson        2018-04-24 10:35:02 -0700 1183) 	error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
4fc7ec31c3c44 (Bob Peterson        2018-04-24 10:35:02 -0700 1184) 				   LM_FLAG_NODE_SCOPE, &gh);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1185) 	if (error)
8339ee543ece6 (Steven Whitehouse   2011-08-31 16:38:29 +0100 1186) 		goto out_qs;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1187) 
4667a0ec32867 (Steven Whitehouse   2011-04-18 14:18:09 +0100 1188) 	error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA,
4667a0ec32867 (Steven Whitehouse   2011-04-18 14:18:09 +0100 1189) 				 sdp->sd_jdesc->jd_blocks);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1190) 	if (error)
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1191) 		goto out_rg_gunlock;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1192) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1193) 	gfs2_free_di(rgd, ip);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1194) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1195) 	gfs2_final_release_pages(ip);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1196) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1197) 	gfs2_trans_end(sdp);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1198) 
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1199) out_rg_gunlock:
564e12b115721 (Bob Peterson        2011-11-21 13:36:17 -0500 1200) 	gfs2_glock_dq_uninit(&gh);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1201) out_qs:
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1202) 	gfs2_quota_unhold(ip);
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1203) 	return error;
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1204) }
f42ab0852946c (Steven Whitehouse   2011-04-14 16:50:31 +0100 1205) 
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1206) /**
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1207)  * gfs2_glock_put_eventually
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1208)  * @gl:	The glock to put
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1209)  *
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1210)  * When under memory pressure, trigger a deferred glock put to make sure we
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1211)  * won't call into DLM and deadlock.  Otherwise, put the glock directly.
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1212)  */
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1213) 
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1214) static void gfs2_glock_put_eventually(struct gfs2_glock *gl)
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1215) {
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1216) 	if (current->flags & PF_MEMALLOC)
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1217) 		gfs2_glock_queue_put(gl);
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1218) 	else
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1219) 		gfs2_glock_put(gl);
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1220) }
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1221) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1222) static bool gfs2_upgrade_iopen_glock(struct inode *inode)
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1223) {
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1224) 	struct gfs2_inode *ip = GFS2_I(inode);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1225) 	struct gfs2_sbd *sdp = GFS2_SB(inode);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1226) 	struct gfs2_holder *gh = &ip->i_iopen_gh;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1227) 	long timeout = 5 * HZ;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1228) 	int error;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1229) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1230) 	gh->gh_flags |= GL_NOCACHE;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1231) 	gfs2_glock_dq_wait(gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1232) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1233) 	/*
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1234) 	 * If there are no other lock holders, we'll get the lock immediately.
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1235) 	 * Otherwise, the other nodes holding the lock will be notified about
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1236) 	 * our locking request.  If they don't have the inode open, they'll
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1237) 	 * evict the cached inode and release the lock.  Otherwise, if they
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1238) 	 * poke the inode glock, we'll take this as an indication that they
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1239) 	 * still need the iopen glock and that they'll take care of deleting
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1240) 	 * the inode when they're done.  As a last resort, if another node
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1241) 	 * keeps holding the iopen glock without showing any activity on the
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1242) 	 * inode glock, we'll eventually time out.
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1243) 	 *
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1244) 	 * Note that we're passing the LM_FLAG_TRY_1CB flag to the first
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1245) 	 * locking request as an optimization to notify lock holders as soon as
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1246) 	 * possible.  Without that flag, they'd be notified implicitly by the
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1247) 	 * second locking request.
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1248) 	 */
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1249) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1250) 	gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1251) 	error = gfs2_glock_nq(gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1252) 	if (error != GLR_TRYFAILED)
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1253) 		return !error;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1254) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1255) 	gfs2_holder_reinit(LM_ST_EXCLUSIVE, GL_ASYNC | GL_NOCACHE, gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1256) 	error = gfs2_glock_nq(gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1257) 	if (error)
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1258) 		return false;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1259) 
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1260) 	timeout = wait_event_interruptible_timeout(sdp->sd_async_glock_wait,
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1261) 		!test_bit(HIF_WAIT, &gh->gh_iflags) ||
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 1262) 		test_bit(GLF_DEMOTE, &ip->i_gl->gl_flags),
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1263) 		timeout);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1264) 	if (!test_bit(HIF_HOLDER, &gh->gh_iflags)) {
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1265) 		gfs2_glock_dq(gh);
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1266) 		return false;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1267) 	}
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1268) 	return true;
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1269) }
9e73330f298ac (Andreas Gruenbacher 2020-01-14 14:59:08 +0100 1270) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1271) /**
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1272)  * evict_should_delete - determine whether the inode is eligible for deletion
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1273)  * @inode: The inode to evict
c551f66c5dfef (Lee Jones           2021-03-30 17:44:29 +0100 1274)  * @gh: The glock holder structure
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1275)  *
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1276)  * This function determines whether the evicted inode is eligible to be deleted
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1277)  * and locks the inode glock.
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1278)  *
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1279)  * Returns: the fate of the dinode
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1280)  */
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1281) static enum dinode_demise evict_should_delete(struct inode *inode,
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1282) 					      struct gfs2_holder *gh)
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1283) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1284) 	struct gfs2_inode *ip = GFS2_I(inode);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1285) 	struct super_block *sb = inode->i_sb;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1286) 	struct gfs2_sbd *sdp = sb->s_fs_info;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1287) 	int ret;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1288) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1289) 	if (test_bit(GIF_ALLOC_FAILED, &ip->i_flags)) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1290) 		BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1291) 		goto should_delete;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1292) 	}
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1293) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1294) 	if (test_bit(GIF_DEFERRED_DELETE, &ip->i_flags))
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1295) 		return SHOULD_DEFER_EVICTION;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1296) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1297) 	/* Deletes should never happen under memory pressure anymore.  */
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1298) 	if (WARN_ON_ONCE(current->flags & PF_MEMALLOC))
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1299) 		return SHOULD_DEFER_EVICTION;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1300) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1301) 	/* Must not read inode block until block type has been verified */
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1302) 	ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, gh);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1303) 	if (unlikely(ret)) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1304) 		glock_clear_object(ip->i_iopen_gh.gh_gl, ip);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1305) 		ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1306) 		gfs2_glock_dq_uninit(&ip->i_iopen_gh);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1307) 		return SHOULD_DEFER_EVICTION;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1308) 	}
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1309) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1310) 	if (gfs2_inode_already_deleted(ip->i_gl, ip->i_no_formal_ino))
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1311) 		return SHOULD_NOT_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1312) 	ret = gfs2_check_blk_type(sdp, ip->i_no_addr, GFS2_BLKST_UNLINKED);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1313) 	if (ret)
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1314) 		return SHOULD_NOT_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1315) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1316) 	if (test_bit(GIF_INVALID, &ip->i_flags)) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1317) 		ret = gfs2_inode_refresh(ip);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1318) 		if (ret)
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1319) 			return SHOULD_NOT_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1320) 	}
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1321) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1322) 	/*
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1323) 	 * The inode may have been recreated in the meantime.
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1324) 	 */
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1325) 	if (inode->i_nlink)
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1326) 		return SHOULD_NOT_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1327) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1328) should_delete:
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1329) 	if (gfs2_holder_initialized(&ip->i_iopen_gh) &&
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1330) 	    test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1331) 		if (!gfs2_upgrade_iopen_glock(inode)) {
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1332) 			gfs2_holder_uninit(&ip->i_iopen_gh);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1333) 			return SHOULD_NOT_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1334) 		}
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1335) 	}
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1336) 	return SHOULD_DELETE_DINODE;
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1337) }
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1338) 
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1339) /**
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1340)  * evict_unlinked_inode - delete the pieces of an unlinked evicted inode
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1341)  * @inode: The inode to evict
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1342)  */
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1343) static int evict_unlinked_inode(struct inode *inode)
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1344) {
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1345) 	struct gfs2_inode *ip = GFS2_I(inode);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1346) 	int ret;
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1347) 
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1348) 	if (S_ISDIR(inode->i_mode) &&
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1349) 	    (ip->i_diskflags & GFS2_DIF_EXHASH)) {
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1350) 		ret = gfs2_dir_exhash_dealloc(ip);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1351) 		if (ret)
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1352) 			goto out;
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1353) 	}
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1354) 
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1355) 	if (ip->i_eattr) {
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1356) 		ret = gfs2_ea_dealloc(ip);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1357) 		if (ret)
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1358) 			goto out;
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1359) 	}
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1360) 
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1361) 	if (!gfs2_is_stuffed(ip)) {
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1362) 		ret = gfs2_file_dealloc(ip);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1363) 		if (ret)
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1364) 			goto out;
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1365) 	}
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1366) 
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1367) 	/* We're about to clear the bitmap for the dinode, but as soon as we
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1368) 	   do, gfs2_create_inode can create another inode at the same block
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1369) 	   location and try to set gl_object again. We clear gl_object here so
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1370) 	   that subsequent inode creates don't see an old gl_object. */
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1371) 	glock_clear_object(ip->i_gl, ip);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1372) 	ret = gfs2_dinode_dealloc(ip);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1373) 	gfs2_inode_remember_delete(ip->i_gl, ip->i_no_formal_ino);
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1374) out:
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1375) 	return ret;
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1376) }
6e7e9a505571d (Bob Peterson        2020-09-11 09:29:25 -0500 1377) 
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1378) /*
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1379)  * evict_linked_inode - evict an inode whose dinode has not been unlinked
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1380)  * @inode: The inode to evict
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1381)  */
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1382) static int evict_linked_inode(struct inode *inode)
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1383) {
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1384) 	struct super_block *sb = inode->i_sb;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1385) 	struct gfs2_sbd *sdp = sb->s_fs_info;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1386) 	struct gfs2_inode *ip = GFS2_I(inode);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1387) 	struct address_space *metamapping;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1388) 	int ret;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1389) 
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1390) 	gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL |
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1391) 		       GFS2_LFC_EVICT_INODE);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1392) 	metamapping = gfs2_glock2aspace(ip->i_gl);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1393) 	if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) {
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1394) 		filemap_fdatawrite(metamapping);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1395) 		filemap_fdatawait(metamapping);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1396) 	}
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1397) 	write_inode_now(inode, 1);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1398) 	gfs2_ail_flush(ip->i_gl, 0);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1399) 
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1400) 	ret = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1401) 	if (ret)
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1402) 		return ret;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1403) 
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1404) 	/* Needs to be done before glock release & also in a transaction */
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1405) 	truncate_inode_pages(&inode->i_data, 0);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1406) 	truncate_inode_pages(metamapping, 0);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1407) 	gfs2_trans_end(sdp);
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1408) 	return 0;
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1409) }
d90be6ab9ad76 (Bob Peterson        2020-09-11 14:53:52 -0500 1410) 
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1411) /**
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1412)  * gfs2_evict_inode - Remove an inode from cache
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1413)  * @inode: The inode to evict
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1414)  *
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1415)  * There are three cases to consider:
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1416)  * 1. i_nlink == 0, we are final opener (and must deallocate)
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1417)  * 2. i_nlink == 0, we are not the final opener (and cannot deallocate)
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1418)  * 3. i_nlink > 0
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1419)  *
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1420)  * If the fs is read only, then we have to treat all cases as per #3
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1421)  * since we are unable to do any deallocation. The inode will be
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1422)  * deallocated by the next read/write node to attempt an allocation
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1423)  * in the same resource group
380f7c65a7eb3 (Steven Whitehouse   2011-07-14 08:59:44 +0100 1424)  *
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1425)  * We have to (at the moment) hold the inodes main lock to cover
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1426)  * the gap between unlocking the shared lock on the iopen lock and
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1427)  * taking the exclusive lock. I'd rather do a shared -> exclusive
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1428)  * conversion on the iopen lock, but we can change that later. This
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1429)  * is safe, just less efficient.
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1430)  */
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1431) 
d5c1515cf3749 (Al Viro             2010-06-07 11:05:19 -0400 1432) static void gfs2_evict_inode(struct inode *inode)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1433) {
001e8e8df4283 (Steven Whitehouse   2011-03-30 14:17:51 +0100 1434) 	struct super_block *sb = inode->i_sb;
001e8e8df4283 (Steven Whitehouse   2011-03-30 14:17:51 +0100 1435) 	struct gfs2_sbd *sdp = sb->s_fs_info;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1436) 	struct gfs2_inode *ip = GFS2_I(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1437) 	struct gfs2_holder gh;
23d828fc3f1e3 (Bob Peterson        2020-09-11 10:56:31 -0500 1438) 	int ret;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1439) 
059788039f1e6 (Abhi Das            2014-03-31 10:33:17 -0500 1440) 	if (test_bit(GIF_FREE_VFS_INODE, &ip->i_flags)) {
059788039f1e6 (Abhi Das            2014-03-31 10:33:17 -0500 1441) 		clear_inode(inode);
059788039f1e6 (Abhi Das            2014-03-31 10:33:17 -0500 1442) 		return;
059788039f1e6 (Abhi Das            2014-03-31 10:33:17 -0500 1443) 	}
059788039f1e6 (Abhi Das            2014-03-31 10:33:17 -0500 1444) 
bc98a42c1f7d0 (David Howells       2017-07-17 08:45:34 +0100 1445) 	if (inode->i_nlink || sb_rdonly(sb))
d5c1515cf3749 (Al Viro             2010-06-07 11:05:19 -0400 1446) 		goto out;
d5c1515cf3749 (Al Viro             2010-06-07 11:05:19 -0400 1447) 
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1448) 	gfs2_holder_mark_uninitialized(&gh);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1449) 	ret = evict_should_delete(inode, &gh);
53dbc27eb1899 (Bob Peterson        2020-09-11 10:30:26 -0500 1450) 	if (ret == SHOULD_DEFER_EVICTION)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 1451) 		goto out;
0a0d9f55c211d (Bob Peterson        2020-09-16 08:50:44 -0500 1452) 	if (ret == SHOULD_DELETE_DINODE)
0a0d9f55c211d (Bob Peterson        2020-09-16 08:50:44 -0500 1453) 		ret = evict_unlinked_inode(inode);
0a0d9f55c211d (Bob Peterson        2020-09-16 08:50:44 -0500 1454) 	else
0a0d9f55c211d (Bob Peterson        2020-09-16 08:50:44 -0500 1455) 		ret = evict_linked_inode(inode);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1456) 
a097dc7e24cba (Bob Peterson        2015-07-16 08:28:04 -0500 1457) 	if (gfs2_rs_active(&ip->i_res))
a097dc7e24cba (Bob Peterson        2015-07-16 08:28:04 -0500 1458) 		gfs2_rs_deltree(&ip->i_res);
8e2e00473598d (Bob Peterson        2012-07-19 08:12:40 -0400 1459) 
240c6235dfe4f (Bob Peterson        2017-07-18 12:36:01 -0500 1460) 	if (gfs2_holder_initialized(&gh)) {
240c6235dfe4f (Bob Peterson        2017-07-18 12:36:01 -0500 1461) 		glock_clear_object(ip->i_gl, ip);
e0b62e21b71bb (Andreas Gruenbacher 2017-06-30 08:16:46 -0500 1462) 		gfs2_glock_dq_uninit(&gh);
240c6235dfe4f (Bob Peterson        2017-07-18 12:36:01 -0500 1463) 	}
23d828fc3f1e3 (Bob Peterson        2020-09-11 10:56:31 -0500 1464) 	if (ret && ret != GLR_TRYFAILED && ret != -EROFS)
23d828fc3f1e3 (Bob Peterson        2020-09-11 10:56:31 -0500 1465) 		fs_warn(sdp, "gfs2_evict_inode: %d\n", ret);
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1466) out:
91b0abe36a7b2 (Johannes Weiner     2014-04-03 14:47:49 -0700 1467) 	truncate_inode_pages_final(&inode->i_data);
2fba46a04c383 (Bob Peterson        2020-02-27 12:47:53 -0600 1468) 	if (ip->i_qadata)
2fba46a04c383 (Bob Peterson        2020-02-27 12:47:53 -0600 1469) 		gfs2_assert_warn(sdp, ip->i_qadata->qa_ref == 0);
1595548fe72ca (Andreas Gruenbacher 2020-03-06 10:32:35 -0600 1470) 	gfs2_rs_delete(ip, NULL);
4513899092b32 (Steven Whitehouse   2013-01-28 09:30:07 +0000 1471) 	gfs2_ordered_del_inode(ip);
dbd5768f87ff6 (Jan Kara            2012-05-03 14:48:02 +0200 1472) 	clear_inode(inode);
17d539f0499fa (Steven Whitehouse   2011-06-15 10:29:37 +0100 1473) 	gfs2_dir_hash_inval(ip);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1474) 	if (ip->i_gl) {
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1475) 		glock_clear_object(ip->i_gl, ip);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1476) 		wait_on_bit_io(&ip->i_flags, GIF_GLOP_PENDING, TASK_UNINTERRUPTIBLE);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1477) 		gfs2_glock_add_to_lru(ip->i_gl);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1478) 		gfs2_glock_put_eventually(ip->i_gl);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1479) 		ip->i_gl = NULL;
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1480) 	}
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500 1481) 	if (gfs2_holder_initialized(&ip->i_iopen_gh)) {
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1482) 		struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1483) 
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1484) 		glock_clear_object(gl, ip);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1485) 		if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1486) 			ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1487) 			gfs2_glock_dq(&ip->i_iopen_gh);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1488) 		}
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1489) 		gfs2_glock_hold(gl);
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1490) 		gfs2_holder_uninit(&ip->i_iopen_gh);
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 1491) 		gfs2_glock_put_eventually(gl);
d5c1515cf3749 (Al Viro             2010-06-07 11:05:19 -0400 1492) 	}
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1493) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1494) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1495) static struct inode *gfs2_alloc_inode(struct super_block *sb)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1496) {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1497) 	struct gfs2_inode *ip;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1498) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1499) 	ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1500) 	if (!ip)
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1501) 		return NULL;
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1502) 	ip->i_flags = 0;
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1503) 	ip->i_gl = NULL;
40e7e86ef1655 (Andreas Gruenbacher 2020-01-24 14:14:46 +0100 1504) 	gfs2_holder_mark_uninitialized(&ip->i_iopen_gh);
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1505) 	memset(&ip->i_res, 0, sizeof(ip->i_res));
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1506) 	RB_CLEAR_NODE(&ip->i_res.rs_node);
d40312598d534 (Andreas Gruenbacher 2019-07-24 13:05:38 +0200 1507) 	ip->i_rahead = 0;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1508) 	return &ip->i_inode;
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1509) }
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1510) 
784494e1d7596 (Al Viro             2019-04-15 19:45:26 -0400 1511) static void gfs2_free_inode(struct inode *inode)
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1512) {
784494e1d7596 (Al Viro             2019-04-15 19:45:26 -0400 1513) 	kmem_cache_free(gfs2_inode_cachep, GFS2_I(inode));
fa0d7e3de6d6f (Nicholas Piggin     2011-01-07 17:49:49 +1100 1514) }
fa0d7e3de6d6f (Nicholas Piggin     2011-01-07 17:49:49 +1100 1515) 
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1516) extern void free_local_statfs_inodes(struct gfs2_sbd *sdp)
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1517) {
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1518) 	struct local_statfs_inode *lsi, *safe;
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1519) 
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1520) 	/* Run through the statfs inodes list to iput and free memory */
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1521) 	list_for_each_entry_safe(lsi, safe, &sdp->sd_sc_inodes_list, si_list) {
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1522) 		if (lsi->si_jid == sdp->sd_jdesc->jd_jid)
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1523) 			sdp->sd_sc_inode = NULL; /* belongs to this node */
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1524) 		if (lsi->si_sc_inode)
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1525) 			iput(lsi->si_sc_inode);
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1526) 		list_del(&lsi->si_list);
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1527) 		kfree(lsi);
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1528) 	}
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1529) }
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1530) 
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1531) extern struct inode *find_local_statfs_inode(struct gfs2_sbd *sdp,
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1532) 					     unsigned int index)
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1533) {
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1534) 	struct local_statfs_inode *lsi;
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1535) 
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1536) 	/* Return the local (per node) statfs inode in the
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1537) 	 * sdp->sd_sc_inodes_list corresponding to the 'index'. */
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1538) 	list_for_each_entry(lsi, &sdp->sd_sc_inodes_list, si_list) {
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1539) 		if (lsi->si_jid == index)
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1540) 			return lsi->si_sc_inode;
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1541) 	}
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1542) 	return NULL;
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1543) }
97fd734ba17e3 (Abhi Das            2020-10-20 15:58:04 -0500 1544) 
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1545) const struct super_operations gfs2_super_ops = {
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1546) 	.alloc_inode		= gfs2_alloc_inode,
784494e1d7596 (Al Viro             2019-04-15 19:45:26 -0400 1547) 	.free_inode		= gfs2_free_inode,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1548) 	.write_inode		= gfs2_write_inode,
ab9bbda0204df (Steven Whitehouse   2011-08-15 14:20:36 +0100 1549) 	.dirty_inode		= gfs2_dirty_inode,
d5c1515cf3749 (Al Viro             2010-06-07 11:05:19 -0400 1550) 	.evict_inode		= gfs2_evict_inode,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1551) 	.put_super		= gfs2_put_super,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1552) 	.sync_fs		= gfs2_sync_fs,
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600 1553) 	.freeze_super		= gfs2_freeze,
2e60d7683c8d2 (Benjamin Marzinski  2014-11-13 20:42:04 -0600 1554) 	.thaw_super		= gfs2_unfreeze,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1555) 	.statfs			= gfs2_statfs,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1556) 	.drop_inode		= gfs2_drop_inode,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1557) 	.show_options		= gfs2_show_options,
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1558) };
9e6e0a128bca0 (Steven Whitehouse   2009-05-22 10:36:01 +0100 1559)