Skip to contentSkip to conversation

xfs_logprint: Fix super block buffer interpretation issue

PATCH In review Chi Zhiling 2 participants 2 messages Jan 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 xfs_logprint: Fix super block buffer interpretation issue

From: Chi Zhiling <[email protected]>

When using xfs_logprint to interpret the buffer of the super block, the icount will always be 6360863066640355328 (0x5846534200001000). This is because the offset of icount is incorrect, causing xfs_logprint to misinterpret the MAGIC number as icount.
This patch fixes the offset value of the SB counters in xfs_logprint.

Before this patch:
icount: 6360863066640355328 ifree: 5242880 fdblks: 0 frext: 0

After this patch:
icount: 10240 ifree: 4906 fdblks: 37 frext: 0

---
 logprint/log_misc.c      | 17 +++++------------
 logprint/log_print_all.c | 22 ++++++++++------------
 2 files changed, 15 insertions(+), 24 deletions(-)
logprint/log_misc.c +5 -12
index 8e86ac34..973bc90c 100644
@@ -282,22 +282,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 		if (be32_to_cpu(head->oh_len) < 4*8) {
 			printf(_("Out of space\n"));
 		} else {
-			__be64		 a, b;
+			struct xfs_dsb	*dsb = (struct xfs_dsb *) *ptr;
 
 			printf("\n");
-			/*
-			 * memmove because *ptr may not be 8-byte aligned
-			 */
-			memmove(&a, *ptr, sizeof(__be64));
-			memmove(&b, *ptr+8, sizeof(__be64));
 			printf(_("icount: %llu  ifree: %llu  "),
-			       (unsigned long long) be64_to_cpu(a),
-			       (unsigned long long) be64_to_cpu(b));
-			memmove(&a, *ptr+16, sizeof(__be64));
-			memmove(&b, *ptr+24, sizeof(__be64));
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_icount),
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_ifree));
 			printf(_("fdblks: %llu  frext: %llu\n"),
-			       (unsigned long long) be64_to_cpu(a),
-			       (unsigned long long) be64_to_cpu(b));
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_fdblocks),
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_frextents));
 		}
 		super_block = 0;
 	} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
logprint/log_print_all.c +10 -12
index a4a5e41f..cd5fccce 100644
@@ -91,22 +91,20 @@ xlog_recover_print_buffer(
 		len = item->ri_buf[i].i_len;
 		i++;
 		if (blkno == 0) { /* super block */
+			struct xfs_dsb  *dsb = (struct xfs_dsb *)p;
+
 			printf(_("	SUPER Block Buffer:\n"));
 			if (!print_buffer)
 				continue;
-		       printf(_("              icount:%llu ifree:%llu  "),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p)),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+8)));
-		       printf(_("fdblks:%llu  frext:%llu\n"),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+16)),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+24)));
+			printf(_("              icount:%llu ifree:%llu  "),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_icount),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_ifree));
+			printf(_("fdblks:%llu  frext:%llu\n"),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_fdblocks),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_frextents));
 			printf(_("		sunit:%u  swidth:%u\n"),
-			       be32_to_cpu(*(__be32 *)(p+56)),
-			       be32_to_cpu(*(__be32 *)(p+60)));
+				get_unaligned_be32(&dsb->sb_unit),
+				get_unaligned_be32(&dsb->sb_width));
 		} else if (be32_to_cpu(*(__be32 *)p) == XFS_AGI_MAGIC) {
 			int bucket, buckets;
 			agi = (xfs_agi_t *)p;
Signature · 1 line
2.43.0
Reviewed-by on v5 1/1
#1 lore raw
Quoted 11 lines · Chi Zhiling

From: Chi Zhiling <[email protected]>

When using xfs_logprint to interpret the buffer of the super block, the icount will always be 6360863066640355328 (0x5846534200001000). This is because the offset of icount is incorrect, causing xfs_logprint to misinterpret the MAGIC number as icount.
This patch fixes the offset value of the SB counters in xfs_logprint.

Before this patch:
icount: 6360863066640355328 ifree: 5242880 fdblks: 0 frext: 0

Quoted 6 lines

After this patch:
icount: 10240 ifree: 4906 fdblks: 37 frext: 0

I think this looks ok now, though my unaligned-access fu has become weak since the end of my personal sparc era...

--D

Quoted 78 lines
---
 logprint/log_misc.c      | 17 +++++------------
 logprint/log_print_all.c | 22 ++++++++++------------
 2 files changed, 15 insertions(+), 24 deletions(-)
logprint/log_misc.c +5 -12
index 8e86ac34..973bc90c 100644
@@ -282,22 +282,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 		if (be32_to_cpu(head->oh_len) < 4*8) {
 			printf(_("Out of space\n"));
 		} else {
-			__be64		 a, b;
+			struct xfs_dsb	*dsb = (struct xfs_dsb *) *ptr;
 
 			printf("\n");
-			/*
-			 * memmove because *ptr may not be 8-byte aligned
-			 */
-			memmove(&a, *ptr, sizeof(__be64));
-			memmove(&b, *ptr+8, sizeof(__be64));
 			printf(_("icount: %llu  ifree: %llu  "),
-			       (unsigned long long) be64_to_cpu(a),
-			       (unsigned long long) be64_to_cpu(b));
-			memmove(&a, *ptr+16, sizeof(__be64));
-			memmove(&b, *ptr+24, sizeof(__be64));
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_icount),
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_ifree));
 			printf(_("fdblks: %llu  frext: %llu\n"),
-			       (unsigned long long) be64_to_cpu(a),
-			       (unsigned long long) be64_to_cpu(b));
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_fdblocks),
+			       (unsigned long long) get_unaligned_be64(&dsb->sb_frextents));
 		}
 		super_block = 0;
 	} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
logprint/log_print_all.c +10 -12
index a4a5e41f..cd5fccce 100644
@@ -91,22 +91,20 @@ xlog_recover_print_buffer(
 		len = item->ri_buf[i].i_len;
 		i++;
 		if (blkno == 0) { /* super block */
+			struct xfs_dsb  *dsb = (struct xfs_dsb *)p;
+
 			printf(_("	SUPER Block Buffer:\n"));
 			if (!print_buffer)
 				continue;
-		       printf(_("              icount:%llu ifree:%llu  "),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p)),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+8)));
-		       printf(_("fdblks:%llu  frext:%llu\n"),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+16)),
-			       (unsigned long long)
-				       be64_to_cpu(*(__be64 *)(p+24)));
+			printf(_("              icount:%llu ifree:%llu  "),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_icount),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_ifree));
+			printf(_("fdblks:%llu  frext:%llu\n"),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_fdblocks),
+				(unsigned long long) get_unaligned_be64(&dsb->sb_frextents));
 			printf(_("		sunit:%u  swidth:%u\n"),
-			       be32_to_cpu(*(__be32 *)(p+56)),
-			       be32_to_cpu(*(__be32 *)(p+60)));
+				get_unaligned_be32(&dsb->sb_unit),
+				get_unaligned_be32(&dsb->sb_width));
 		} else if (be32_to_cpu(*(__be32 *)p) == XFS_AGI_MAGIC) {
 			int bucket, buckets;
 			agi = (xfs_agi_t *)p;
Signature · 1 line
2.43.0