Skip to contentSkip to conversation

GFS2: Introduce new gfs2_log_header_v2

PATCH Superseded Bob Peterson 2 participants 7 messages Dec 22, 2017 – Jan 4, 2018 1 message not in the archive GFS2 file system

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/1 GFS2: Introduce new gfs2_log_header_v2

In reply to a message not in the archive

Hi,

Here is version 2 of this patch, which has been heavily revised based on comments from the initial patch. I'm still planning to do a third patch which saves a new debug field for log header origin.

Bob
---
This patch adds a new structure called gfs2_log_header_v2 which is used to store expanded fields into previously unused areas of the log headers. Some of these are used for debug purposes so we can backtrack when problems occur. Others are reserved for future expansion.

This is based on a prototype patch from Steve Whitehouse.

In addition to Steve's original code, we also replace the log flush types (NORMAL_FLUSH, SYNC_FLUSH, etc.) with new log header flags (GFS2_LOG_HEAD_*). This way the log flush type be automatically saved in the log header (as the UNMOUNT flag is now). A few extra flags are also defined so we can distinguish whether the log header was written by recovery, user space (gfs2-utils), or one of the log flush operations.

---
 fs/gfs2/aops.c                   |  2 +-
 fs/gfs2/file.c                   |  3 ++-
 fs/gfs2/glops.c                  | 13 ++++++-----
 fs/gfs2/log.c                    | 50 ++++++++++++++++++++++++++++------------
 fs/gfs2/log.h                    |  8 +------
 fs/gfs2/lops.c                   | 30 ++++++++++++++++++++----
 fs/gfs2/lops.h                   |  2 ++
 fs/gfs2/ops_fstype.c             |  2 +-
 fs/gfs2/quota.c                  |  3 ++-
 fs/gfs2/recovery.c               |  4 ++--
 fs/gfs2/rgrp.c                   |  2 +-
 fs/gfs2/super.c                  |  9 ++++----
 fs/gfs2/trans.c                  |  2 +-
 include/uapi/linux/gfs2_ondisk.h | 26 ++++++++++++++++++++-
 14 files changed, 111 insertions(+), 45 deletions(-)
fs/gfs2/aops.c +1 -1
index 658ca027cab9..7c64925735d3 100644
@@ -445,7 +445,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,
 
 	ret = gfs2_write_cache_jdata(mapping, wbc);
 	if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
-		gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 		ret = gfs2_write_cache_jdata(mapping, wbc);
 	}
 	return ret;
fs/gfs2/file.c +2 -1
index 58705ef8643a..475c601ef4d8 100644
@@ -246,7 +246,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
 	}
 	if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
 		if (new_flags & GFS2_DIF_JDATA)
-			gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, ip->i_gl,
+				       GFS2_LOG_HEAD_FLUSH_NORMAL);
 		error = filemap_fdatawrite(inode->i_mapping);
 		if (error)
 			goto out;
fs/gfs2/glops.c +7 -6
index cdd1c5f06f45..2daab13a9e0b 100644
@@ -107,7 +107,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
 	__gfs2_ail_flush(gl, 0, tr.tr_revokes);
 
 	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 }
 
 void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
@@ -128,7 +128,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
 		return;
 	__gfs2_ail_flush(gl, fsync, max_revokes);
 	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 }
 
 /**
@@ -157,7 +157,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
 		return;
 	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(sdp, gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
 	error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
 	mapping_set_error(mapping, error);
@@ -252,7 +252,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
 
 	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
+	gfs2_log_flush(gl->gl_name.ln_sbd, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	filemap_fdatawrite(metamapping);
 	if (isreg) {
 		struct address_space *mapping = ip->i_inode.i_mapping;
@@ -303,7 +303,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
 	}
 
 	if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
-		gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(gl->gl_name.ln_sbd, NULL,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
 		gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
 	}
 	if (ip && S_ISREG(ip->i_inode.i_mode))
@@ -495,7 +496,7 @@ static void freeze_go_sync(struct gfs2_glock *gl)
 			gfs2_assert_withdraw(sdp, 0);
 		}
 		queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
-		gfs2_log_flush(sdp, NULL, FREEZE_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE);
 	}
 }
 
fs/gfs2/log.c +35 -15

130 lines not on this page · raw message

fs/gfs2/log.h +1 -7
index 619de9a1ff4f..e5089ee688ca 100644
@@ -65,16 +65,10 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
 
 extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
 extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
-enum gfs2_flush_type {
-	NORMAL_FLUSH = 0,
-	SYNC_FLUSH,
-	SHUTDOWN_FLUSH,
-	FREEZE_FLUSH
-};
 extern void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
 				  u32 flags, int op_flags);
 extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
-			   enum gfs2_flush_type type);
+			   u32 type);
 extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
 extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
 extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc);
fs/gfs2/lops.c +26 -4
index c8ff7b7954f0..124fa68c38a3 100644
@@ -18,6 +18,7 @@
 #include <linux/fs.h>
 #include <linux/list_sort.h>
 
+#include "dir.h"
 #include "gfs2.h"
 #include "incore.h"
 #include "inode.h"
@@ -306,6 +307,25 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
 	return gfs2_log_alloc_bio(sdp, blkno);
 }
 
+/**
+ * gfs2_set_log_csum - Set a whole-block checksum for a page
+ * @sb: The superblock
+ * @page: The page to write
+ * @blkno: The device block number we want to write to
+ * 
+ * Set the location of the block to be written and then checksum the block
+ * before writing it.
+ */
+static void gfs2_set_log_csum(struct super_block *sb, struct page *page,
+			      u64 blkno)
+{
+	struct gfs2_log_header_v2 *lh = page_address(page);
+	u32 hash;
+
+	lh->lh_addr = cpu_to_be64(blkno);
+	hash = gfs2_disk_hash(page_address(page), sb->s_blocksize);
+	lh->lh_crc = cpu_to_be32(hash);
+}
 
 /**
  * gfs2_log_write - write to log
@@ -319,8 +339,8 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
  * then add the page segment to that.
  */
 
-static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
-			   unsigned size, unsigned offset)
+void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+		    unsigned size, unsigned offset, bool is_hdr)
 {
 	u64 blkno = gfs2_log_bmap(sdp);
 	struct bio *bio;
@@ -334,6 +354,8 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 		ret = bio_add_page(bio, page, size, offset);
 		WARN_ON(ret == 0);
 	}
+	if (is_hdr)
+		gfs2_set_log_csum(sdp->sd_vfs, page, blkno);
 }
 
 /**
@@ -348,7 +370,7 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 
 static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
 {
-	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh));
+	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh), false);
 }
 
 /**
@@ -365,7 +387,7 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
 void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
 {
 	struct super_block *sb = sdp->sd_vfs;
-	gfs2_log_write(sdp, page, sb->s_blocksize, 0);
+	gfs2_log_write(sdp, page, sb->s_blocksize, 0, false);
 }
 
 static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
fs/gfs2/lops.h +2 -0
index e529f536c117..f31a5ff470f4 100644
@@ -26,6 +26,8 @@ extern const struct gfs2_log_operations gfs2_revoke_lops;
 extern const struct gfs2_log_operations gfs2_databuf_lops;
 
 extern const struct gfs2_log_operations *gfs2_log_ops[];
+extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+			   unsigned size, unsigned offset, bool is_hdr);
 extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
 extern void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int op, int op_flags);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
fs/gfs2/ops_fstype.c +1 -1
index a3711f543405..d80c1e433f87 100644
@@ -1382,7 +1382,7 @@ static void gfs2_kill_sb(struct super_block *sb)
 		return;
 	}
 
-	gfs2_log_flush(sdp, NULL, SYNC_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SYNC);
 	dput(sdp->sd_root_dir);
 	dput(sdp->sd_master_dir);
 	sdp->sd_root_dir = NULL;
fs/gfs2/quota.c +2 -1
index e700fb162664..2092df19e433 100644
@@ -955,7 +955,8 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
 		gfs2_glock_dq_uninit(&ghs[qx]);
 	inode_unlock(&ip->i_inode);
 	kfree(ghs);
-	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl,
+		       GFS2_LOG_HEAD_FLUSH_NORMAL);
 	return error;
 }
 
fs/gfs2/recovery.c +2 -2
index 5d3431219425..587171740c9d 100644
@@ -385,8 +385,8 @@ static void clean_journal(struct gfs2_jdesc *jd,
 	sdp->sd_log_flush_head = head->lh_blkno;
 	gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head);
 	gfs2_write_log_header(sdp, head->lh_sequence + 1, 0,
-			      GFS2_LOG_HEAD_UNMOUNT, REQ_PREFLUSH |
-			      REQ_FUA | REQ_META | REQ_SYNC);
+			      GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
+			      REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC);
 }
 
 
fs/gfs2/rgrp.c +1 -1
index e8aba6fa1472..44879546613f 100644
@@ -2086,7 +2086,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap)
 		}
 		/* Flushing the log may release space */
 		if (loops == 2)
-			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	}
 
 	return -ENOSPC;
fs/gfs2/super.c +5 -4
index 9cb5c9a97d69..d57d29c32523 100644
@@ -757,7 +757,8 @@ static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
 	bool flush_all = (wbc->sync_mode == WB_SYNC_ALL || gfs2_is_jdata(ip));
 
 	if (flush_all)
-		gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(GFS2_SB(inode), ip->i_gl,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
 	if (bdi->wb.dirty_exceeded)
 		gfs2_ail1_flush(sdp, wbc);
 	else
@@ -853,7 +854,7 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
 	gfs2_quota_sync(sdp->sd_vfs, 0);
 	gfs2_statfs_sync(sdp->sd_vfs, 0);
 
-	gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SHUTDOWN);
 	wait_event(sdp->sd_reserving_log_wait, atomic_read(&sdp->sd_reserving_log) == 0);
 	gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
 
@@ -946,7 +947,7 @@ static int gfs2_sync_fs(struct super_block *sb, int wait)
 
 	gfs2_quota_sync(sb, -1);
 	if (wait)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	return sdp->sd_log_error;
 }
 
@@ -1650,7 +1651,7 @@ static void gfs2_evict_inode(struct inode *inode)
 	goto out_unlock;
 
 out_truncate:
-	gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	metamapping = gfs2_glock2aspace(ip->i_gl);
 	if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) {
 		filemap_fdatawrite(metamapping);
fs/gfs2/trans.c +1 -1
index a85ca8b2c9ba..5ab1bf69c788 100644
@@ -118,7 +118,7 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
 	up_read(&sdp->sd_log_flush_lock);
 
 	if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	if (alloced)
 		sb_end_intwrite(sdp->sd_vfs);
 }
include/uapi/linux/gfs2_ondisk.h +25 -1
index 09f0920f07e9..e68789a27ff1 100644
@@ -403,7 +403,13 @@ struct gfs2_ea_header {
  * Log header structure
  */
 
-#define GFS2_LOG_HEAD_UNMOUNT	0x00000001	/* log is clean */
+#define GFS2_LOG_HEAD_UNMOUNT		0x00000001 /* log is clean */
+#define GFS2_LOG_HEAD_FLUSH_NORMAL	0x00000002 /* normal log flush */
+#define GFS2_LOG_HEAD_FLUSH_SYNC	0x00000004 /* Sync log flush */
+#define GFS2_LOG_HEAD_FLUSH_SHUTDOWN	0x00000008 /* Shutdown log flush */
+#define GFS2_LOG_HEAD_FLUSH_FREEZE	0x00000010 /* Freeze flush */
+#define GFS2_LOG_HEAD_RECOVERY		0x00000020 /* Journal recovery */
+#define GFS2_LOG_HEAD_USERSPACE		0x80000000 /* Written by gfs2-utils */
 
 struct gfs2_log_header {
 	struct gfs2_meta_header lh_header;
@@ -415,6 +421,24 @@ struct gfs2_log_header {
 	__be32 lh_hash;
 };
 
+struct gfs2_log_header_v2 {
+	struct gfs2_log_header lhv1;
+
+	__be32 lh_crc;		/* crc32 of whole block with this field 0 */
+	__be32 lh_nsec;		/* Nano second time stamp */
+	__be64 lh_sec;		/* Second based time stamp */
+	__be64 lh_addr;		/* Block number of this log header (absolute) */
+	__be64 lh_jinode;	/* Journal inode number */
+	__be64 lh_statfs_addr;	/* Local statfs inode number */
+	__be64 lh_quota_addr;	/* Local quota change inode number */
+
+	/* Statfs local changes (i.e. diff from global statfs) */
+	__be64 lh_local_total;
+	__be64 lh_local_free;
+	__be64 lh_local_dinodes;
+	__be32 lh_log_origin;	/* The origin of this log header */
+};
+
 /*
  * Log type descriptor
  */
#2 lore raw

PATCH v2 1/1 GFS2: Introduce new gfs2_log_header_v2

Hi,

Quoted 171 lines · Bob Peterson

Hi,

Here is version 2 of this patch, which has been heavily revised based on comments from the initial patch. I'm still planning to do a third patch which saves a new debug field for log header origin.

Bob
---
This patch adds a new structure called gfs2_log_header_v2 which is used to store expanded fields into previously unused areas of the log headers. Some of these are used for debug purposes so we can backtrack when problems occur. Others are reserved for future expansion.

This is based on a prototype patch from Steve Whitehouse.

In addition to Steve's original code, we also replace the log flush types (NORMAL_FLUSH, SYNC_FLUSH, etc.) with new log header flags (GFS2_LOG_HEAD_*). This way the log flush type be automatically saved in the log header (as the UNMOUNT flag is now). A few extra flags are also defined so we can distinguish whether the log header was written by recovery, user space (gfs2-utils), or one of the log flush operations.

---
  fs/gfs2/aops.c                   |  2 +-
  fs/gfs2/file.c                   |  3 ++-
  fs/gfs2/glops.c                  | 13 ++++++-----
  fs/gfs2/log.c                    | 50 ++++++++++++++++++++++++++++------------
  fs/gfs2/log.h                    |  8 +------
  fs/gfs2/lops.c                   | 30 ++++++++++++++++++++----
  fs/gfs2/lops.h                   |  2 ++
  fs/gfs2/ops_fstype.c             |  2 +-
  fs/gfs2/quota.c                  |  3 ++-
  fs/gfs2/recovery.c               |  4 ++--
  fs/gfs2/rgrp.c                   |  2 +-
  fs/gfs2/super.c                  |  9 ++++----
  fs/gfs2/trans.c                  |  2 +-
  include/uapi/linux/gfs2_ondisk.h | 26 ++++++++++++++++++++-
  14 files changed, 111 insertions(+), 45 deletions(-)
fs/gfs2/aops.c +1 -1
index 658ca027cab9..7c64925735d3 100644
@@ -445,7 +445,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,
 
  	ret = gfs2_write_cache_jdata(mapping, wbc);
  	if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
-		gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  		ret = gfs2_write_cache_jdata(mapping, wbc);
  	}
  	return ret;
fs/gfs2/file.c +2 -1
index 58705ef8643a..475c601ef4d8 100644
@@ -246,7 +246,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
  	}
  	if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
  		if (new_flags & GFS2_DIF_JDATA)
-			gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, ip->i_gl,
+				       GFS2_LOG_HEAD_FLUSH_NORMAL);
  		error = filemap_fdatawrite(inode->i_mapping);
  		if (error)
  			goto out;
fs/gfs2/glops.c +7 -6
index cdd1c5f06f45..2daab13a9e0b 100644
@@ -107,7 +107,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
  	__gfs2_ail_flush(gl, 0, tr.tr_revokes);
 
  	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  }
 
  void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
@@ -128,7 +128,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
  		return;
  	__gfs2_ail_flush(gl, fsync, max_revokes);
  	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  }
 
  /**
@@ -157,7 +157,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
  		return;
  	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(sdp, gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  	error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  	mapping_set_error(mapping, error);
@@ -252,7 +252,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
 
  	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
+	gfs2_log_flush(gl->gl_name.ln_sbd, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	filemap_fdatawrite(metamapping);
  	if (isreg) {
  		struct address_space *mapping = ip->i_inode.i_mapping;
@@ -303,7 +303,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
  	}
 
  	if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
-		gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(gl->gl_name.ln_sbd, NULL,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
  		gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
  	}
  	if (ip && S_ISREG(ip->i_inode.i_mode))
@@ -495,7 +496,7 @@ static void freeze_go_sync(struct gfs2_glock *gl)
  			gfs2_assert_withdraw(sdp, 0);
  		}
  		queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
-		gfs2_log_flush(sdp, NULL, FREEZE_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE);
  	}
  }
 
fs/gfs2/log.c +11 -4
index 27e97d3de1e0..2cc00d28e907 100644
@@ -652,7 +652,7 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp)
   * @sdp: The GFS2 superblock
   * @seq: sequence number
   * @tail: tail of the log
- * @flags: log header flags
+ * @flags: log header flags GFS2_LOG_HEAD_*
   * @op_flags: flags to pass to the bio
   *
   * Returns: the initialized log buffer descriptor
@@ -661,13 +661,18 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp)
  void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
  			   u32 flags, int op_flags)
  {
+	struct gfs2_log_header_v2 *lh2;
  	struct gfs2_log_header *lh;
  	u32 hash;
  	struct page *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
+	struct timespec64 tv;
+	struct super_block *sb = sdp->sd_vfs;
 
-	lh = page_address(page);
-	clear_page(lh);
+	lh2 = page_address(page);
+	clear_page(lh2);
 
+	lh = &lh2->lhv1;
  	lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
  	lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
  	lh->lh_header.__pad0 = cpu_to_be64(0);
@@ -680,7 +685,20 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
  	hash = gfs2_disk_hash(page_address(page), sizeof(struct gfs2_log_header));
  	lh->lh_hash = cpu_to_be32(hash);
 
-	gfs2_log_write_page(sdp, page);
+	tv = current_kernel_time64();
+	lh2->lh_nsec = cpu_to_be32(tv.tv_nsec);
+	lh2->lh_sec = cpu_to_be64(tv.tv_sec);

fs/gfs2/log.c void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail, · line 700

Quoted 10 lines
fs/gfs2/log.c +10 -0
+	lh2->lh_jinode = cpu_to_be64(GFS2_I(sdp->sd_jdesc->jd_inode)->i_no_addr);
+	lh2->lh_statfs_addr = cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr);
+	lh2->lh_quota_addr = cpu_to_be64(GFS2_I(sdp->sd_qc_inode)->i_no_addr);
+
+	spin_lock(&sdp->sd_statfs_spin);
+	lh2->lh_local_total = cpu_to_be64(l_sc->sc_total);
+	lh2->lh_local_free = cpu_to_be64(l_sc->sc_free);
+	lh2->lh_local_dinodes = cpu_to_be64(l_sc->sc_dinodes);
+	spin_unlock(&sdp->sd_statfs_spin);
+

Bear in mind, that now this function writes the recovery log headers too, it must avoid writing the local node's statfs info into the log that has just been recovered (for another node). Likewise the other local inode info needs to match that for the node/log that has been recovered. Otherwise though, the patch looks good,

Steve.

#3 lore raw

PATCH v3 1/1 GFS2: Introduce new gfs2_log_header_v2

----- Original Message -----

| Bear in mind, that now this function writes the recovery log headers
| too, it must avoid writing the local node's statfs info into the log
| that has just been recovered (for another node). Likewise the other
| local inode info needs to match that for the node/log that has been
| recovered. Otherwise though, the patch looks good,
| 
| Steve.

Good catch. Here is a revised patch that hopefully takes this into account.

Regards,

Bob Peterson
---
This patch adds a new structure called gfs2_log_header_v2 which is used to store expanded fields into previously unused areas of the log headers. Some of these are used for debug purposes so we can backtrack when problems occur. Others are reserved for future expansion.

This is based on a prototype patch from Steve Whitehouse.

In addition to Steve's original code, we also replace the log flush types (NORMAL_FLUSH, SYNC_FLUSH, etc.) with new log header flags (GFS2_LOG_HEAD_*). This way the log flush type be automatically saved in the log header (as the UNMOUNT flag is now). A few extra flags are also defined so we can distinguish whether the log header was written by recovery, user space (gfs2-utils), or one of the log flush operations.

---
 fs/gfs2/aops.c                   |  2 +-
 fs/gfs2/file.c                   |  3 +-
 fs/gfs2/glops.c                  | 13 +++++----
 fs/gfs2/log.c                    | 62 +++++++++++++++++++++++++++++-----------
 fs/gfs2/log.h                    | 10 ++-----
 fs/gfs2/lops.c                   | 30 ++++++++++++++++---
 fs/gfs2/lops.h                   |  2 ++
 fs/gfs2/ops_fstype.c             |  2 +-
 fs/gfs2/quota.c                  |  3 +-
 fs/gfs2/recovery.c               |  5 ++--
 fs/gfs2/rgrp.c                   |  2 +-
 fs/gfs2/super.c                  |  9 +++---
 fs/gfs2/trans.c                  |  2 +-
 include/uapi/linux/gfs2_ondisk.h | 26 ++++++++++++++++-
 14 files changed, 123 insertions(+), 48 deletions(-)
fs/gfs2/aops.c +1 -1
index 658ca027cab9..7c64925735d3 100644
@@ -445,7 +445,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,
 
 	ret = gfs2_write_cache_jdata(mapping, wbc);
 	if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
-		gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 		ret = gfs2_write_cache_jdata(mapping, wbc);
 	}
 	return ret;
fs/gfs2/file.c +2 -1
index 58705ef8643a..475c601ef4d8 100644
@@ -246,7 +246,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
 	}
 	if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
 		if (new_flags & GFS2_DIF_JDATA)
-			gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, ip->i_gl,
+				       GFS2_LOG_HEAD_FLUSH_NORMAL);
 		error = filemap_fdatawrite(inode->i_mapping);
 		if (error)
 			goto out;
fs/gfs2/glops.c +7 -6
index cdd1c5f06f45..2daab13a9e0b 100644
@@ -107,7 +107,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
 	__gfs2_ail_flush(gl, 0, tr.tr_revokes);
 
 	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 }
 
 void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
@@ -128,7 +128,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
 		return;
 	__gfs2_ail_flush(gl, fsync, max_revokes);
 	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 }
 
 /**
@@ -157,7 +157,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
 		return;
 	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(sdp, gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
 	error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
 	mapping_set_error(mapping, error);
@@ -252,7 +252,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
 
 	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
+	gfs2_log_flush(gl->gl_name.ln_sbd, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	filemap_fdatawrite(metamapping);
 	if (isreg) {
 		struct address_space *mapping = ip->i_inode.i_mapping;
@@ -303,7 +303,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
 	}
 
 	if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
-		gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(gl->gl_name.ln_sbd, NULL,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
 		gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
 	}
 	if (ip && S_ISREG(ip->i_inode.i_mode))
@@ -495,7 +496,7 @@ static void freeze_go_sync(struct gfs2_glock *gl)
 			gfs2_assert_withdraw(sdp, 0);
 		}
 		queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
-		gfs2_log_flush(sdp, NULL, FREEZE_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE);
 	}
 }
 
fs/gfs2/log.c +45 -17

149 lines not on this page · raw message

fs/gfs2/log.h +2 -8
index 619de9a1ff4f..83b790672f2d 100644
@@ -65,16 +65,10 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
 
 extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
 extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
-enum gfs2_flush_type {
-	NORMAL_FLUSH = 0,
-	SYNC_FLUSH,
-	SHUTDOWN_FLUSH,
-	FREEZE_FLUSH
-};
 extern void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
-				  u32 flags, int op_flags);
+				  u32 flags, int op_flags, unsigned int jid);
 extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
-			   enum gfs2_flush_type type);
+			   u32 type);
 extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
 extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
 extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc);
fs/gfs2/lops.c +26 -4
index c8ff7b7954f0..124fa68c38a3 100644
@@ -18,6 +18,7 @@
 #include <linux/fs.h>
 #include <linux/list_sort.h>
 
+#include "dir.h"
 #include "gfs2.h"
 #include "incore.h"
 #include "inode.h"
@@ -306,6 +307,25 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
 	return gfs2_log_alloc_bio(sdp, blkno);
 }
 
+/**
+ * gfs2_set_log_csum - Set a whole-block checksum for a page
+ * @sb: The superblock
+ * @page: The page to write
+ * @blkno: The device block number we want to write to
+ * 
+ * Set the location of the block to be written and then checksum the block
+ * before writing it.
+ */
+static void gfs2_set_log_csum(struct super_block *sb, struct page *page,
+			      u64 blkno)
+{
+	struct gfs2_log_header_v2 *lh = page_address(page);
+	u32 hash;
+
+	lh->lh_addr = cpu_to_be64(blkno);
+	hash = gfs2_disk_hash(page_address(page), sb->s_blocksize);
+	lh->lh_crc = cpu_to_be32(hash);
+}
 
 /**
  * gfs2_log_write - write to log
@@ -319,8 +339,8 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
  * then add the page segment to that.
  */
 
-static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
-			   unsigned size, unsigned offset)
+void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+		    unsigned size, unsigned offset, bool is_hdr)
 {
 	u64 blkno = gfs2_log_bmap(sdp);
 	struct bio *bio;
@@ -334,6 +354,8 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 		ret = bio_add_page(bio, page, size, offset);
 		WARN_ON(ret == 0);
 	}
+	if (is_hdr)
+		gfs2_set_log_csum(sdp->sd_vfs, page, blkno);
 }
 
 /**
@@ -348,7 +370,7 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 
 static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
 {
-	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh));
+	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh), false);
 }
 
 /**
@@ -365,7 +387,7 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
 void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
 {
 	struct super_block *sb = sdp->sd_vfs;
-	gfs2_log_write(sdp, page, sb->s_blocksize, 0);
+	gfs2_log_write(sdp, page, sb->s_blocksize, 0, false);
 }
 
 static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
fs/gfs2/lops.h +2 -0
index e529f536c117..f31a5ff470f4 100644
@@ -26,6 +26,8 @@ extern const struct gfs2_log_operations gfs2_revoke_lops;
 extern const struct gfs2_log_operations gfs2_databuf_lops;
 
 extern const struct gfs2_log_operations *gfs2_log_ops[];
+extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+			   unsigned size, unsigned offset, bool is_hdr);
 extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
 extern void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int op, int op_flags);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
fs/gfs2/ops_fstype.c +1 -1
index a3711f543405..d80c1e433f87 100644
@@ -1382,7 +1382,7 @@ static void gfs2_kill_sb(struct super_block *sb)
 		return;
 	}
 
-	gfs2_log_flush(sdp, NULL, SYNC_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SYNC);
 	dput(sdp->sd_root_dir);
 	dput(sdp->sd_master_dir);
 	sdp->sd_root_dir = NULL;
fs/gfs2/quota.c +2 -1
index e700fb162664..2092df19e433 100644
@@ -955,7 +955,8 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
 		gfs2_glock_dq_uninit(&ghs[qx]);
 	inode_unlock(&ip->i_inode);
 	kfree(ghs);
-	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl,
+		       GFS2_LOG_HEAD_FLUSH_NORMAL);
 	return error;
 }
 
fs/gfs2/recovery.c +3 -2
index 5d3431219425..fb1b84db3037 100644
@@ -385,8 +385,9 @@ static void clean_journal(struct gfs2_jdesc *jd,
 	sdp->sd_log_flush_head = head->lh_blkno;
 	gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head);
 	gfs2_write_log_header(sdp, head->lh_sequence + 1, 0,
-			      GFS2_LOG_HEAD_UNMOUNT, REQ_PREFLUSH |
-			      REQ_FUA | REQ_META | REQ_SYNC);
+			      GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
+			      REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC,
+			      jd->jd_jid);
 }
 
 
fs/gfs2/rgrp.c +1 -1
index e8aba6fa1472..44879546613f 100644
@@ -2086,7 +2086,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap)
 		}
 		/* Flushing the log may release space */
 		if (loops == 2)
-			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	}
 
 	return -ENOSPC;
fs/gfs2/super.c +5 -4
index 9cb5c9a97d69..d57d29c32523 100644
@@ -757,7 +757,8 @@ static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
 	bool flush_all = (wbc->sync_mode == WB_SYNC_ALL || gfs2_is_jdata(ip));
 
 	if (flush_all)
-		gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(GFS2_SB(inode), ip->i_gl,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
 	if (bdi->wb.dirty_exceeded)
 		gfs2_ail1_flush(sdp, wbc);
 	else
@@ -853,7 +854,7 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
 	gfs2_quota_sync(sdp->sd_vfs, 0);
 	gfs2_statfs_sync(sdp->sd_vfs, 0);
 
-	gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SHUTDOWN);
 	wait_event(sdp->sd_reserving_log_wait, atomic_read(&sdp->sd_reserving_log) == 0);
 	gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
 
@@ -946,7 +947,7 @@ static int gfs2_sync_fs(struct super_block *sb, int wait)
 
 	gfs2_quota_sync(sb, -1);
 	if (wait)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	return sdp->sd_log_error;
 }
 
@@ -1650,7 +1651,7 @@ static void gfs2_evict_inode(struct inode *inode)
 	goto out_unlock;
 
 out_truncate:
-	gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	metamapping = gfs2_glock2aspace(ip->i_gl);
 	if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) {
 		filemap_fdatawrite(metamapping);
fs/gfs2/trans.c +1 -1
index a85ca8b2c9ba..5ab1bf69c788 100644
@@ -118,7 +118,7 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
 	up_read(&sdp->sd_log_flush_lock);
 
 	if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
 	if (alloced)
 		sb_end_intwrite(sdp->sd_vfs);
 }
include/uapi/linux/gfs2_ondisk.h +25 -1
index 09f0920f07e9..e68789a27ff1 100644
@@ -403,7 +403,13 @@ struct gfs2_ea_header {
  * Log header structure
  */
 
-#define GFS2_LOG_HEAD_UNMOUNT	0x00000001	/* log is clean */
+#define GFS2_LOG_HEAD_UNMOUNT		0x00000001 /* log is clean */
+#define GFS2_LOG_HEAD_FLUSH_NORMAL	0x00000002 /* normal log flush */
+#define GFS2_LOG_HEAD_FLUSH_SYNC	0x00000004 /* Sync log flush */
+#define GFS2_LOG_HEAD_FLUSH_SHUTDOWN	0x00000008 /* Shutdown log flush */
+#define GFS2_LOG_HEAD_FLUSH_FREEZE	0x00000010 /* Freeze flush */
+#define GFS2_LOG_HEAD_RECOVERY		0x00000020 /* Journal recovery */
+#define GFS2_LOG_HEAD_USERSPACE		0x80000000 /* Written by gfs2-utils */
 
 struct gfs2_log_header {
 	struct gfs2_meta_header lh_header;
@@ -415,6 +421,24 @@ struct gfs2_log_header {
 	__be32 lh_hash;
 };
 
+struct gfs2_log_header_v2 {
+	struct gfs2_log_header lhv1;
+
+	__be32 lh_crc;		/* crc32 of whole block with this field 0 */
+	__be32 lh_nsec;		/* Nano second time stamp */
+	__be64 lh_sec;		/* Second based time stamp */
+	__be64 lh_addr;		/* Block number of this log header (absolute) */
+	__be64 lh_jinode;	/* Journal inode number */
+	__be64 lh_statfs_addr;	/* Local statfs inode number */
+	__be64 lh_quota_addr;	/* Local quota change inode number */
+
+	/* Statfs local changes (i.e. diff from global statfs) */
+	__be64 lh_local_total;
+	__be64 lh_local_free;
+	__be64 lh_local_dinodes;
+	__be32 lh_log_origin;	/* The origin of this log header */
+};
+
 /*
  * Log type descriptor
  */
#4 lore raw

PATCH v3 1/1 GFS2: Introduce new gfs2_log_header_v2

Hi,

Quoted 173 lines · Bob Peterson

----- Original Message -----

| Bear in mind, that now this function writes the recovery log headers
| too, it must avoid writing the local node's statfs info into the log
| that has just been recovered (for another node). Likewise the other
| local inode info needs to match that for the node/log that has been
| recovered. Otherwise though, the patch looks good,
|
| Steve.

Good catch. Here is a revised patch that hopefully takes this into account.

Regards,

Bob Peterson
---
This patch adds a new structure called gfs2_log_header_v2 which is used to store expanded fields into previously unused areas of the log headers. Some of these are used for debug purposes so we can backtrack when problems occur. Others are reserved for future expansion.

This is based on a prototype patch from Steve Whitehouse.

In addition to Steve's original code, we also replace the log flush types (NORMAL_FLUSH, SYNC_FLUSH, etc.) with new log header flags (GFS2_LOG_HEAD_*). This way the log flush type be automatically saved in the log header (as the UNMOUNT flag is now). A few extra flags are also defined so we can distinguish whether the log header was written by recovery, user space (gfs2-utils), or one of the log flush operations.

---
  fs/gfs2/aops.c                   |  2 +-
  fs/gfs2/file.c                   |  3 +-
  fs/gfs2/glops.c                  | 13 +++++----
  fs/gfs2/log.c                    | 62 +++++++++++++++++++++++++++++-----------
  fs/gfs2/log.h                    | 10 ++-----
  fs/gfs2/lops.c                   | 30 ++++++++++++++++---
  fs/gfs2/lops.h                   |  2 ++
  fs/gfs2/ops_fstype.c             |  2 +-
  fs/gfs2/quota.c                  |  3 +-
  fs/gfs2/recovery.c               |  5 ++--
  fs/gfs2/rgrp.c                   |  2 +-
  fs/gfs2/super.c                  |  9 +++---
  fs/gfs2/trans.c                  |  2 +-
  include/uapi/linux/gfs2_ondisk.h | 26 ++++++++++++++++-
  14 files changed, 123 insertions(+), 48 deletions(-)
fs/gfs2/aops.c +1 -1
index 658ca027cab9..7c64925735d3 100644
@@ -445,7 +445,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,
 
  	ret = gfs2_write_cache_jdata(mapping, wbc);
  	if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
-		gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  		ret = gfs2_write_cache_jdata(mapping, wbc);
  	}
  	return ret;
fs/gfs2/file.c +2 -1
index 58705ef8643a..475c601ef4d8 100644
@@ -246,7 +246,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
  	}
  	if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
  		if (new_flags & GFS2_DIF_JDATA)
-			gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, ip->i_gl,
+				       GFS2_LOG_HEAD_FLUSH_NORMAL);
  		error = filemap_fdatawrite(inode->i_mapping);
  		if (error)
  			goto out;
fs/gfs2/glops.c +7 -6
index cdd1c5f06f45..2daab13a9e0b 100644
@@ -107,7 +107,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
  	__gfs2_ail_flush(gl, 0, tr.tr_revokes);
 
  	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  }
 
  void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
@@ -128,7 +128,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
  		return;
  	__gfs2_ail_flush(gl, fsync, max_revokes);
  	gfs2_trans_end(sdp);
-	gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  }
 
  /**
@@ -157,7 +157,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
  		return;
  	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(sdp, gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  	error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
  	mapping_set_error(mapping, error);
@@ -252,7 +252,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
 
  	GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
 
-	gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
+	gfs2_log_flush(gl->gl_name.ln_sbd, gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	filemap_fdatawrite(metamapping);
  	if (isreg) {
  		struct address_space *mapping = ip->i_inode.i_mapping;
@@ -303,7 +303,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
  	}
 
  	if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
-		gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(gl->gl_name.ln_sbd, NULL,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
  		gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
  	}
  	if (ip && S_ISREG(ip->i_inode.i_mode))
@@ -495,7 +496,7 @@ static void freeze_go_sync(struct gfs2_glock *gl)
  			gfs2_assert_withdraw(sdp, 0);
  		}
  		queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
-		gfs2_log_flush(sdp, NULL, FREEZE_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE);
  	}
  }
 
fs/gfs2/log.c +10 -4
index b9889ae5fd7c..fcea549732ab 100644
@@ -655,22 +655,28 @@ void gfs2_write_revokes(struct gfs2_sbd *sdp)
   * @sdp: The GFS2 superblock
   * @seq: sequence number
   * @tail: tail of the log
- * @flags: log header flags
+ * @flags: log header flags GFS2_LOG_HEAD_*
   * @op_flags: flags to pass to the bio
+ * @jid: journal id of the journal to which we are writing
   *
   * Returns: the initialized log buffer descriptor
   */
 
  void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
-			   u32 flags, int op_flags)
+			   u32 flags, int op_flags, unsigned int jid)
  {
+	struct gfs2_log_header_v2 *lh2;
  	struct gfs2_log_header *lh;
  	u32 hash;
  	struct page *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+	struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
+	struct timespec64 tv;
+	struct super_block *sb = sdp->sd_vfs;
 
-	lh = page_address(page);
-	clear_page(lh);
+	lh2 = page_address(page);
+	clear_page(lh2);
 
+	lh = &lh2->lhv1;
  	lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
  	lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
  	lh->lh_header.__pad0 = cpu_to_be64(0);

fs/gfs2/log.c void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail, · line 695

Quoted 8 lines
fs/gfs2/log.c +4 -1
@@ -683,7 +689,27 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
  	hash = gfs2_disk_hash(page_address(page), sizeof(struct gfs2_log_header));
  	lh->lh_hash = cpu_to_be32(hash);
 
-	gfs2_log_write_page(sdp, page);
+	tv = current_kernel_time64();
+	lh2->lh_nsec = cpu_to_be32(tv.tv_nsec);
+	lh2->lh_sec = cpu_to_be64(tv.tv_sec);
+	lh2->lh_jinode = cpu_to_be64(GFS2_I(sdp->sd_jdesc->jd_inode)->i_no_addr);

This is still writing the wrong inode number for recovery headers. Please check that all the fields are correct in both the local and remote journal cases. It would probably make more sense to pass the relevant gfs2_jdesc to this function in order to avoid this kind of mistake in the future,

Steve.

Quoted 384 lines
fs/gfs2/log.c +31 -12
+	/* We may only write local statfs, quota, etc., when writing to our
+	   own journal. The values are left 0 when recovering a journal
+	   different from our own. */
+	if (sdp->sd_jdesc->jd_jid == jid) {
+		lh2->lh_statfs_addr =
+			cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr);
+		lh2->lh_quota_addr =
+			cpu_to_be64(GFS2_I(sdp->sd_qc_inode)->i_no_addr);
+
+		spin_lock(&sdp->sd_statfs_spin);
+		lh2->lh_local_total = cpu_to_be64(l_sc->sc_total);
+		lh2->lh_local_free = cpu_to_be64(l_sc->sc_free);
+		lh2->lh_local_dinodes = cpu_to_be64(l_sc->sc_dinodes);
+		spin_unlock(&sdp->sd_statfs_spin);
+	}
+
+	gfs2_log_write(sdp, page, sb->s_blocksize, 0, true);
  	gfs2_log_flush_bio(sdp, REQ_OP_WRITE, op_flags);
  	log_flush_wait(sdp);
  }
@@ -691,6 +717,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
  /**
   * log_write_header - Get and initialize a journal header buffer
   * @sdp: The GFS2 superblock
+ * @flags: The log header flags, including log header origin
   *
   * Returns: the initialized log buffer descriptor
   */
@@ -711,7 +738,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
  	}
  	sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
  	gfs2_write_log_header(sdp, sdp->sd_log_sequence++, tail, flags,
-			      op_flags);
+			      op_flags, sdp->sd_jdesc->jd_jid);
 
  	if (sdp->sd_log_tail != tail)
  		log_pull_tail(sdp, tail);
@@ -721,11 +748,11 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
   * gfs2_log_flush - flush incore transaction(s)
   * @sdp: the filesystem
   * @gl: The glock structure to flush.  If NULL, flush the whole incore log
+ * @flags: The log header flags: GFS2_LOG_HEAD_FLUSH_*
   *
   */
 
-void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
-		    enum gfs2_flush_type type)
+void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
  {
  	struct gfs2_trans *tr;
  	enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
@@ -739,7 +766,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
  	}
  	trace_gfs2_log_flush(sdp, 1);
 
-	if (type == SHUTDOWN_FLUSH)
+	if (flags & GFS2_LOG_HEAD_FLUSH_SHUTDOWN)
  		clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
 
  	sdp->sd_log_flush_head = sdp->sd_log_head;
@@ -764,11 +791,11 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
 
  	if (sdp->sd_log_head != sdp->sd_log_flush_head) {
  		log_flush_wait(sdp);
-		log_write_header(sdp, 0);
+		log_write_header(sdp, flags);
  	} else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
  		atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
  		trace_gfs2_log_blocks(sdp, -1);
-		log_write_header(sdp, 0);
+		log_write_header(sdp, flags);
  	}
  	lops_after_commit(sdp, tr);
 
@@ -785,7 +812,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
  	spin_unlock(&sdp->sd_ail_lock);
  	gfs2_log_unlock(sdp);
 
-	if (type != NORMAL_FLUSH) {
+	if (!(flags & GFS2_LOG_HEAD_FLUSH_NORMAL)) {
  		if (!sdp->sd_log_idle) {
  			for (;;) {
  				gfs2_ail1_start(sdp);
@@ -795,12 +822,13 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
  			}
  			atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
  			trace_gfs2_log_blocks(sdp, -1);
-			log_write_header(sdp, 0);
+			log_write_header(sdp, flags);
  			sdp->sd_log_head = sdp->sd_log_flush_head;
  		}
-		if (type == SHUTDOWN_FLUSH || type == FREEZE_FLUSH)
+		if (flags & (GFS2_LOG_HEAD_FLUSH_SHUTDOWN |
+			     GFS2_LOG_HEAD_FLUSH_FREEZE))
  			gfs2_log_shutdown(sdp);
-		if (type == FREEZE_FLUSH)
+		if (flags & GFS2_LOG_HEAD_FLUSH_FREEZE)
  			atomic_set(&sdp->sd_freeze_state, SFS_FROZEN);
  	}
 
@@ -956,7 +984,7 @@ int gfs2_logd(void *data)
  		did_flush = false;
  		if (gfs2_jrnl_flush_reqd(sdp) || t == 0) {
  			gfs2_ail1_empty(sdp);
-			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  			did_flush = true;
  		}
 
@@ -964,7 +992,7 @@ int gfs2_logd(void *data)
  			gfs2_ail1_start(sdp);
  			gfs2_ail1_wait(sdp);
  			gfs2_ail1_empty(sdp);
-			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  			did_flush = true;
  		}
 
fs/gfs2/log.h +2 -8
index 619de9a1ff4f..83b790672f2d 100644
@@ -65,16 +65,10 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
 
  extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
  extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
-enum gfs2_flush_type {
-	NORMAL_FLUSH = 0,
-	SYNC_FLUSH,
-	SHUTDOWN_FLUSH,
-	FREEZE_FLUSH
-};
  extern void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
-				  u32 flags, int op_flags);
+				  u32 flags, int op_flags, unsigned int jid);
  extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
-			   enum gfs2_flush_type type);
+			   u32 type);
  extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
  extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
  extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc);
fs/gfs2/lops.c +26 -4
index c8ff7b7954f0..124fa68c38a3 100644
@@ -18,6 +18,7 @@
  #include <linux/fs.h>
  #include <linux/list_sort.h>
 
+#include "dir.h"
  #include "gfs2.h"
  #include "incore.h"
  #include "inode.h"
@@ -306,6 +307,25 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
  	return gfs2_log_alloc_bio(sdp, blkno);
  }
 
+/**
+ * gfs2_set_log_csum - Set a whole-block checksum for a page
+ * @sb: The superblock
+ * @page: The page to write
+ * @blkno: The device block number we want to write to
+ *
+ * Set the location of the block to be written and then checksum the block
+ * before writing it.
+ */
+static void gfs2_set_log_csum(struct super_block *sb, struct page *page,
+			      u64 blkno)
+{
+	struct gfs2_log_header_v2 *lh = page_address(page);
+	u32 hash;
+
+	lh->lh_addr = cpu_to_be64(blkno);
+	hash = gfs2_disk_hash(page_address(page), sb->s_blocksize);
+	lh->lh_crc = cpu_to_be32(hash);
+}
 
  /**
   * gfs2_log_write - write to log
@@ -319,8 +339,8 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno)
   * then add the page segment to that.
   */
 
-static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
-			   unsigned size, unsigned offset)
+void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+		    unsigned size, unsigned offset, bool is_hdr)
  {
  	u64 blkno = gfs2_log_bmap(sdp);
  	struct bio *bio;
@@ -334,6 +354,8 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
  		ret = bio_add_page(bio, page, size, offset);
  		WARN_ON(ret == 0);
  	}
+	if (is_hdr)
+		gfs2_set_log_csum(sdp->sd_vfs, page, blkno);
  }
 
  /**
@@ -348,7 +370,7 @@ static void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
 
  static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
  {
-	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh));
+	gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh), false);
  }
 
  /**
@@ -365,7 +387,7 @@ static void gfs2_log_write_bh(struct gfs2_sbd *sdp, struct buffer_head *bh)
  void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
  {
  	struct super_block *sb = sdp->sd_vfs;
-	gfs2_log_write(sdp, page, sb->s_blocksize, 0);
+	gfs2_log_write(sdp, page, sb->s_blocksize, 0, false);
  }
 
  static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
fs/gfs2/lops.h +2 -0
index e529f536c117..f31a5ff470f4 100644
@@ -26,6 +26,8 @@ extern const struct gfs2_log_operations gfs2_revoke_lops;
  extern const struct gfs2_log_operations gfs2_databuf_lops;
 
  extern const struct gfs2_log_operations *gfs2_log_ops[];
+extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
+			   unsigned size, unsigned offset, bool is_hdr);
  extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
  extern void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int op, int op_flags);
  extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
fs/gfs2/ops_fstype.c +1 -1
index a3711f543405..d80c1e433f87 100644
@@ -1382,7 +1382,7 @@ static void gfs2_kill_sb(struct super_block *sb)
  		return;
  	}
 
-	gfs2_log_flush(sdp, NULL, SYNC_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SYNC);
  	dput(sdp->sd_root_dir);
  	dput(sdp->sd_master_dir);
  	sdp->sd_root_dir = NULL;
fs/gfs2/quota.c +2 -1
index e700fb162664..2092df19e433 100644
@@ -955,7 +955,8 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
  		gfs2_glock_dq_uninit(&ghs[qx]);
  	inode_unlock(&ip->i_inode);
  	kfree(ghs);
-	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl,
+		       GFS2_LOG_HEAD_FLUSH_NORMAL);
  	return error;
  }
 
fs/gfs2/recovery.c +3 -2
index 5d3431219425..fb1b84db3037 100644
@@ -385,8 +385,9 @@ static void clean_journal(struct gfs2_jdesc *jd,
  	sdp->sd_log_flush_head = head->lh_blkno;
  	gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head);
  	gfs2_write_log_header(sdp, head->lh_sequence + 1, 0,
-			      GFS2_LOG_HEAD_UNMOUNT, REQ_PREFLUSH |
-			      REQ_FUA | REQ_META | REQ_SYNC);
+			      GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
+			      REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC,
+			      jd->jd_jid);
  }
 
 
fs/gfs2/rgrp.c +1 -1
index e8aba6fa1472..44879546613f 100644
@@ -2086,7 +2086,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap)
  		}
  		/* Flushing the log may release space */
  		if (loops == 2)
-			gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+			gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	}
 
  	return -ENOSPC;
fs/gfs2/super.c +5 -4
index 9cb5c9a97d69..d57d29c32523 100644
@@ -757,7 +757,8 @@ static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
  	bool flush_all = (wbc->sync_mode == WB_SYNC_ALL || gfs2_is_jdata(ip));
 
  	if (flush_all)
-		gfs2_log_flush(GFS2_SB(inode), ip->i_gl, NORMAL_FLUSH);
+		gfs2_log_flush(GFS2_SB(inode), ip->i_gl,
+			       GFS2_LOG_HEAD_FLUSH_NORMAL);
  	if (bdi->wb.dirty_exceeded)
  		gfs2_ail1_flush(sdp, wbc);
  	else
@@ -853,7 +854,7 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
  	gfs2_quota_sync(sdp->sd_vfs, 0);
  	gfs2_statfs_sync(sdp->sd_vfs, 0);
 
-	gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH);
+	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SHUTDOWN);
  	wait_event(sdp->sd_reserving_log_wait, atomic_read(&sdp->sd_reserving_log) == 0);
  	gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
 
@@ -946,7 +947,7 @@ static int gfs2_sync_fs(struct super_block *sb, int wait)
 
  	gfs2_quota_sync(sb, -1);
  	if (wait)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	return sdp->sd_log_error;
  }
 
@@ -1650,7 +1651,7 @@ static void gfs2_evict_inode(struct inode *inode)
  	goto out_unlock;
 
  out_truncate:
-	gfs2_log_flush(sdp, ip->i_gl, NORMAL_FLUSH);
+	gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	metamapping = gfs2_glock2aspace(ip->i_gl);
  	if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) {
  		filemap_fdatawrite(metamapping);
fs/gfs2/trans.c +1 -1
index a85ca8b2c9ba..5ab1bf69c788 100644
@@ -118,7 +118,7 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
  	up_read(&sdp->sd_log_flush_lock);
 
  	if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
-		gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
+		gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL);
  	if (alloced)
  		sb_end_intwrite(sdp->sd_vfs);
  }
include/uapi/linux/gfs2_ondisk.h +25 -1
index 09f0920f07e9..e68789a27ff1 100644
@@ -403,7 +403,13 @@ struct gfs2_ea_header {
   * Log header structure
   */
 
-#define GFS2_LOG_HEAD_UNMOUNT	0x00000001	/* log is clean */
+#define GFS2_LOG_HEAD_UNMOUNT		0x00000001 /* log is clean */
+#define GFS2_LOG_HEAD_FLUSH_NORMAL	0x00000002 /* normal log flush */
+#define GFS2_LOG_HEAD_FLUSH_SYNC	0x00000004 /* Sync log flush */
+#define GFS2_LOG_HEAD_FLUSH_SHUTDOWN	0x00000008 /* Shutdown log flush */
+#define GFS2_LOG_HEAD_FLUSH_FREEZE	0x00000010 /* Freeze flush */
+#define GFS2_LOG_HEAD_RECOVERY		0x00000020 /* Journal recovery */
+#define GFS2_LOG_HEAD_USERSPACE		0x80000000 /* Written by gfs2-utils */
 
  struct gfs2_log_header {
  	struct gfs2_meta_header lh_header;
@@ -415,6 +421,24 @@ struct gfs2_log_header {
  	__be32 lh_hash;
  };
 
+struct gfs2_log_header_v2 {
+	struct gfs2_log_header lhv1;
+
+	__be32 lh_crc;		/* crc32 of whole block with this field 0 */
+	__be32 lh_nsec;		/* Nano second time stamp */
+	__be64 lh_sec;		/* Second based time stamp */
+	__be64 lh_addr;		/* Block number of this log header (absolute) */
+	__be64 lh_jinode;	/* Journal inode number */
+	__be64 lh_statfs_addr;	/* Local statfs inode number */
+	__be64 lh_quota_addr;	/* Local quota change inode number */
+
+	/* Statfs local changes (i.e. diff from global statfs) */
+	__be64 lh_local_total;
+	__be64 lh_local_free;
+	__be64 lh_local_dinodes;
+	__be32 lh_log_origin;	/* The origin of this log header */
+};
+
  /*
   * Log type descriptor
   */
#5 lore raw

PATCH v3 1/1 GFS2: Introduce new gfs2_log_header_v2

----- Original Message -----

| > +	lh2->lh_jinode = cpu_to_be64(GFS2_I(sdp->sd_jdesc->jd_inode)->i_no_addr);
| This is still writing the wrong inode number for recovery headers.
| Please check that all the fields are correct in both the local and
| remote journal cases. It would probably make more sense to pass the
| relevant gfs2_jdesc to this function in order to avoid this kind of
| mistake in the future,
| 
| Steve.

Hi,

Actually, I did this intentionally. I suppose it depends on the intent and whether we consider this debug info, recovery hints, or hints for fsck. Right now it's just debug info, and I thought it would be more useful to put the journal inode of the node performing the recovery.

In other words, a bread crumb, a smoking gun, or "who dunnit." IOW, which node was responsible for writing the log header. But since GFS2 doesn't typically know its own node number in the cluster, but it does know which journal is assigned for its general use, and that's always written into the dmesg, syslog, etc., I thought it would be more useful for file system forensics.

The patch already saves the absolute block address of the log header, from which we can deduce the journal's inode address based on the inode's mapping. But what was the original intent?

I suppose we could keep both, since all nodes look up the inode of every journal. Thoughts?

Bob Peterson

#6 lore raw

PATCH v3 1/1 GFS2: Introduce new gfs2_log_header_v2

Hi,

Quoted 24 lines · Bob Peterson

----- Original Message -----

| > +	lh2->lh_jinode = cpu_to_be64(GFS2_I(sdp->sd_jdesc->jd_inode)->i_no_addr);
| This is still writing the wrong inode number for recovery headers.
| Please check that all the fields are correct in both the local and
| remote journal cases. It would probably make more sense to pass the
| relevant gfs2_jdesc to this function in order to avoid this kind of
| mistake in the future,
|
| Steve.

Hi,

Actually, I did this intentionally. I suppose it depends on the intent and whether we consider this debug info, recovery hints, or hints for fsck. Right now it's just debug info, and I thought it would be more useful to put the journal inode of the node performing the recovery.

In other words, a bread crumb, a smoking gun, or "who dunnit." IOW, which node was responsible for writing the log header. But since GFS2 doesn't typically know its own node number in the cluster, but it does know which journal is assigned for its general use, and that's always written into the dmesg, syslog, etc., I thought it would be more useful for file system forensics.

Quoted 8 lines

The patch already saves the absolute block address of the log header, from which we can deduce the journal's inode address based on the inode's mapping. But what was the original intent?

I suppose we could keep both, since all nodes look up the inode of every journal. Thoughts?

Bob Peterson

Apologies if it was not clear. The intent was that the inode address should follow the inode which the header belongs to. The idea was to make it easier to reconstruct journals in fsck. We have the journal id of the writer of the journal header anyway, so that should be enough to figure out which node wrote the header in the first place,

Steve.

#7 lore raw

PATCH v3 1/1 GFS2: Introduce new gfs2_log_header_v2

In reply to Steven Whitehouse

Hi,

Quoted 4 lines · Steven Whitehouse

Hi,

On 02/01/18 17:01, Bob Peterson wrote:

[snip]

Quoted 37 lines
Quoted 37 lines
include/uapi/linux/gfs2_ondisk.h +0 -0
index 09f0920f07e9..e68789a27ff1 100644
@@ -403,7 +403,13 @@ struct gfs2_ea_header {

?? * Log header structure
?? */
? -#define GFS2_LOG_HEAD_UNMOUNT??? 0x00000001??? /* log is clean */

include/uapi/linux/gfs2_ondisk.h +4 -0
+#define GFS2_LOG_HEAD_UNMOUNT??????? 0x00000001 /* log is clean */
+#define GFS2_LOG_HEAD_FLUSH_NORMAL??? 0x00000002 /* normal log flush */
+#define GFS2_LOG_HEAD_FLUSH_SYNC??? 0x00000004 /* Sync log flush */
+#define GFS2_LOG_HEAD_FLUSH_SHUTDOWN??? 0x00000008 /* Shutdown log 

flush */

include/uapi/linux/gfs2_ondisk.h +3 -0
+#define GFS2_LOG_HEAD_FLUSH_FREEZE??? 0x00000010 /* Freeze flush */
+#define GFS2_LOG_HEAD_RECOVERY??????? 0x00000020 /* Journal recovery */
+#define GFS2_LOG_HEAD_USERSPACE??????? 0x80000000 /* Written by 

gfs2-utils */
? ? struct gfs2_log_header {
????? struct gfs2_meta_header lh_header;

include/uapi/linux/gfs2_ondisk.h +6 -0
@@ -415,6 +421,24 @@ struct gfs2_log_header {
 ????? __be32 lh_hash;
 ? };
 ? +struct gfs2_log_header_v2 {
+??? struct gfs2_log_header lhv1;
+
+??? __be32 lh_crc;??????? /* crc32 of whole block with this field 0 */
+??? __be32 lh_nsec;??????? /* Nano second time stamp */
+??? __be64 lh_sec;??????? /* Second based time stamp */
+??? __be64 lh_addr;??????? /* Block number of this log header 

(absolute) */
+??? __be64 lh_jinode;??? /* Journal inode number */ +??? __be64 lh_statfs_addr;??? /* Local statfs inode number */ +??? __be64 lh_quota_addr;??? /* Local quota change inode number */ +
+??? /* Statfs local changes (i.e. diff from global statfs) */ +??? __be64 lh_local_total;

Quoted 9 lines
Quoted 8 lines

+??? __be64 lh_local_free;
+??? __be64 lh_local_dinodes;
+??? __be32 lh_log_origin;??? /* The origin of this log header */

include/uapi/linux/gfs2_ondisk.h +2 -0
+};
+

? /*
?? * Log type descriptor
?? */

Also, I've just noticed that we don't need a v2 structure here. We should just be able to add the new fields in to the existing structure without any problems. There is nothing that comes after the header in the journal header blocks, so we are free to extend the structure as much as we want to with the only constraint being that sizeof(struct gfs2_log_header) <= 512, unlike the other metadata structures. That should simplify the code a bit, and avoid the need for structure versions here,

Steve.