Skip to contentSkip to conversation

gfs2: local statfs improvements

PATCH New Abhi Das 1 participant 4 messages Oct 20, 2020 GFS2 file system

lore
Share & tools
lore

Abhi Das

author
#0 lore raw

v3 cover gfs2: local statfs improvements

This patchset allows gfs2 to sync statfs info from the journal to the master statfs file during a log flush or during recovery. We still write to the local statfs file to allow older versions to recover the statfs info of newer kernels with this patchset.

This version addresses the bug Andreas found with xfstests:generic/034. Turns out we weren't looking up the statfs inodes early enough in the mount process. I also added some comments in the code.

Abhi Das (3):
gfs2: Add fields for statfs info in struct gfs2_log_header_host
gfs2: lookup local statfs inodes prior to journal recovery
gfs2: Recover statfs info in journal head

 fs/gfs2/incore.h     |  12 ++++
 fs/gfs2/lops.c       |   2 +-
 fs/gfs2/lops.h       |   1 +
 fs/gfs2/ops_fstype.c | 133 +++++++++++++++++++++++++++++++------------
 fs/gfs2/recovery.c   | 108 +++++++++++++++++++++++++++++++++++
 fs/gfs2/super.c      |  33 ++++++++++-
 fs/gfs2/super.h      |   5 ++
 7 files changed, 256 insertions(+), 38 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v3 1/3 gfs2: Add fields for statfs info in struct gfs2_log_header_host

And read these in __get_log_header() from the log header. Also make gfs2_statfs_change_out() non-static so it can be used outside of super.c

---
 fs/gfs2/incore.h   | 4 ++++
 fs/gfs2/recovery.c | 4 ++++
 fs/gfs2/super.c    | 2 +-
 fs/gfs2/super.h    | 2 ++
 4 files changed, 11 insertions(+), 1 deletion(-)
fs/gfs2/incore.h +4 -0
index c3ca9b8382ec..e34183e02a9e 100644
@@ -41,6 +41,10 @@ struct gfs2_log_header_host {
 	u32 lh_flags;		/* GFS2_LOG_HEAD_... */
 	u32 lh_tail;		/* Block number of log tail */
 	u32 lh_blkno;
+
+	s64 lh_local_total;
+	s64 lh_local_free;
+	s64 lh_local_dinodes;
 };
 
 /*
fs/gfs2/recovery.c +4 -0
index 390ea79d682c..a8bb17e355b8 100644
@@ -144,6 +144,10 @@ int __get_log_header(struct gfs2_sbd *sdp, const struct gfs2_log_header *lh,
 	head->lh_tail = be32_to_cpu(lh->lh_tail);
 	head->lh_blkno = be32_to_cpu(lh->lh_blkno);
 
+	head->lh_local_total = be64_to_cpu(lh->lh_local_total);
+	head->lh_local_free = be64_to_cpu(lh->lh_local_free);
+	head->lh_local_dinodes = be64_to_cpu(lh->lh_local_dinodes);
+
 	return 0;
 }
 /**
fs/gfs2/super.c +1 -1
index 8e250ec42e91..e17961ea994d 100644
@@ -230,7 +230,7 @@ void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
 	sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
 }
 
-static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
+void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
 {
 	struct gfs2_statfs_change *str = buf;
 
fs/gfs2/super.h +2 -0
index 51900554ed81..ed4f5cb29074 100644
@@ -37,6 +37,8 @@ extern void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
 			       s64 dinodes);
 extern void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc,
 				  const void *buf);
+extern void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc,
+				   void *buf);
 extern void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh,
 			  struct buffer_head *l_bh);
 extern int gfs2_statfs_sync(struct super_block *sb, int type);
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH v3 2/3 gfs2: lookup local statfs inodes prior to journal recovery

In reply to Abhi Das

We need to lookup the master statfs inode and the local statfs inodes earlier in the mount process (in init_journal) so journal recovery can use them when it attempts to recover the statfs info. We lookup all the local statfs inodes and store them in a linked list to allow a node to recover statfs info for other nodes in the cluster.

---
 fs/gfs2/incore.h     |   8 +++
 fs/gfs2/ops_fstype.c | 133 +++++++++++++++++++++++++++++++------------
 fs/gfs2/super.c      |  31 +++++++++-
 fs/gfs2/super.h      |   3 +
 4 files changed, 139 insertions(+), 36 deletions(-)
fs/gfs2/incore.h +8 -0
index e34183e02a9e..0220f2b1d5bf 100644
@@ -697,6 +697,13 @@ struct gfs2_pcpu_lkstats {
 	struct gfs2_lkstats lkstats[10];
 };
 
+/* List of local (per node) statfs inodes */
+struct lcl_statfs_inode {
+	struct list_head si_list;
+	struct inode *si_sc_inode;
+	unsigned int si_jid; /* journal id this statfs inode corresponds to */
+};
+
 struct gfs2_sbd {
 	struct super_block *sd_vfs;
 	struct gfs2_pcpu_lkstats __percpu *sd_lkstats;
@@ -748,6 +755,7 @@ struct gfs2_sbd {
 	struct inode *sd_jindex;
 	struct inode *sd_statfs_inode;
 	struct inode *sd_sc_inode;
+	struct list_head sd_sc_inodes_list;
 	struct inode *sd_qc_inode;
 	struct inode *sd_rindex;
 	struct inode *sd_quota_inode;
fs/gfs2/ops_fstype.c +98 -35

218 lines not on this page · raw message

fs/gfs2/super.c +30 -1
index e17961ea994d..823d10e7263a 100644
@@ -729,7 +729,7 @@ static void gfs2_put_super(struct super_block *sb)
 			gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
 		gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
 		gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
-		iput(sdp->sd_sc_inode);
+		free_lcl_statfs_inodes(sdp);
 		iput(sdp->sd_qc_inode);
 	}
 
@@ -1561,6 +1561,35 @@ static void gfs2_free_inode(struct inode *inode)
 	kmem_cache_free(gfs2_inode_cachep, GFS2_I(inode));
 }
 
+extern void free_lcl_statfs_inodes(struct gfs2_sbd *sdp)
+{
+	struct lcl_statfs_inode *lsi, *safe;
+
+	/* Run through the statfs inodes list to iput and free memory */
+	list_for_each_entry_safe(lsi, safe, &sdp->sd_sc_inodes_list, si_list) {
+		if (lsi->si_jid == sdp->sd_jdesc->jd_jid)
+			sdp->sd_sc_inode = NULL; /* belongs to this node */
+		if (lsi->si_sc_inode)
+			iput(lsi->si_sc_inode);
+		list_del(&lsi->si_list);
+		kfree(lsi);
+	}
+}
+
+extern struct inode *find_lcl_statfs_inode(struct gfs2_sbd *sdp,
+                                           unsigned int index)
+{
+	struct lcl_statfs_inode *lsi;
+
+	/* Return the local (per node) statfs inode in the
+	 * sdp->sd_sc_inodes_list corresponding to the 'index'. */
+	list_for_each_entry(lsi, &sdp->sd_sc_inodes_list, si_list) {
+		if (lsi->si_jid == index)
+			return lsi->si_sc_inode;
+	}
+	return NULL;
+}
+
 const struct super_operations gfs2_super_ops = {
 	.alloc_inode		= gfs2_alloc_inode,
 	.free_inode		= gfs2_free_inode,
fs/gfs2/super.h +3 -0
index ed4f5cb29074..55f2b51824f4 100644
@@ -44,6 +44,9 @@ extern void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh,
 extern int gfs2_statfs_sync(struct super_block *sb, int type);
 extern void gfs2_freeze_func(struct work_struct *work);
 
+extern void free_lcl_statfs_inodes(struct gfs2_sbd *sdp);
+extern struct inode *find_lcl_statfs_inode(struct gfs2_sbd *sdp,
+                                           unsigned int index);
 extern void free_sbd(struct gfs2_sbd *sdp);
 
 extern struct file_system_type gfs2_fs_type;
Signature · 1 line
2.20.1
author
#3 lore raw

PATCH v3 3/3 gfs2: Recover statfs info in journal head

In reply to Abhi Das

Apply the outstanding statfs changes in the journal head to the master statfs file. Zero out the local statfs file for good measure.

Previously, statfs updates would be read in from the local statfs inode and synced to the master statfs inode during recovery.

We now use the statfs updates in the journal head to update the master statfs inode instead of reading in from the local statfs inode. To preserve backward compatibility with kernels that can't do this, we still need to keep the local statfs inode up to date by writing changes to it. At some point in the future, we can do away with the local statfs inodes altogether and keep the statfs changes solely in the journal.

---
 fs/gfs2/lops.c     |   2 +-
 fs/gfs2/lops.h     |   1 +
 fs/gfs2/recovery.c | 104 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 1 deletion(-)
fs/gfs2/lops.c +1 -1
index ed1da4323967..ed69298dd824 100644
@@ -823,7 +823,7 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
  *
  */
 
-static void gfs2_meta_sync(struct gfs2_glock *gl)
+void gfs2_meta_sync(struct gfs2_glock *gl)
 {
 	struct address_space *mapping = gfs2_glock2aspace(gl);
 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
fs/gfs2/lops.h +1 -0
index 9c5e4e491e03..4a3d8aecdf82 100644
@@ -27,6 +27,7 @@ extern void gfs2_log_submit_bio(struct bio **biop, int opf);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
 			   struct gfs2_log_header_host *head, bool keep_cache);
+extern void gfs2_meta_sync(struct gfs2_glock *gl);
 
 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
 {
fs/gfs2/recovery.c +104 -0

116 lines not on this page · raw message

Signature · 1 line
2.20.1