Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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