Blame SOURCES/xfsprogs-4.12.0-xfs_db-update-buffer-size-when-new-type-is-set.patch

9bf599
From 55f224baf83d71b3d2cc24e6387d9f1f6a5a1eda Mon Sep 17 00:00:00 2001
9bf599
From: Bill O'Donnell <billodo@redhat.com>
9bf599
Date: Thu, 29 Jun 2017 13:05:00 -0500
9bf599
Subject: [PATCH] xfs_db: update buffer size when new type is set
9bf599
9bf599
xfs_db doesn't take sector size into account when setting type.
9bf599
This can result in an errant crc. For example, with a sector size
9bf599
of 4096:
9bf599
9bf599
xfs_db> agi 0
9bf599
xfs_db> p crc
9bf599
crc = 0xab85043e (correct)
9bf599
xfs_db> daddr
9bf599
current daddr is 16
9bf599
xfs_db> daddr 42
9bf599
xfs_db> daddr 16
9bf599
xfs_db> type agi
9bf599
Metadata CRC error detected at xfs_agi block 0x10/0x200
9bf599
xfs_db> p crc
9bf599
crc = 0xab85043e (bad)
9bf599
9bf599
When xfs_db sets the new daddr in daddr_f, it does so with one
9bf599
BBSIZE sector (512). Changing the type doesn't change the size
9bf599
of the current buffer in iocur_top, so the checksum is calculated
9bf599
on the wrong length for the type (when the actual sector size > BBSIZE (512).
9bf599
9bf599
For types with fields, reread the buffer to pick up the correct size for
9bf599
the new type when it gets set. Facilitate the reread by setting the cursor
9bf599
with set_cur().
9bf599
9bf599
Signed-off-by: Bill O'Donnell <billodo@redhat.com>
9bf599
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
9bf599
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
9bf599
[sandeen: fix up long line, clarify subject & comments]
9bf599
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
9bf599
---
9bf599
 db/io.c | 8 ++++++++
9bf599
 1 file changed, 8 insertions(+)
9bf599
9bf599
Index: xfsprogs-rhel7.5/db/io.c
9bf599
===================================================================
9bf599
--- xfsprogs-rhel7.5.orig/db/io.c
9bf599
+++ xfsprogs-rhel7.5/db/io.c
9bf599
@@ -27,6 +27,7 @@
9bf599
 #include "output.h"
9bf599
 #include "init.h"
9bf599
 #include "malloc.h"
9bf599
+#include "bit.h"
9bf599
 
9bf599
 static int	pop_f(int argc, char **argv);
9bf599
 static void     pop_help(void);
9bf599
@@ -567,6 +568,13 @@ set_iocur_type(
9bf599
 {
9bf599
 	struct xfs_buf	*bp = iocur_top->bp;
9bf599
 
9bf599
+	/* adjust buffer size for types with fields & hence fsize() */
9bf599
+	if (t->fields) {
9bf599
+		int bb_count;	/* type's size in basic blocks */
9bf599
+
9bf599
+		bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));
9bf599
+		set_cur(t, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
9bf599
+	}
9bf599
 	iocur_top->typ = t;
9bf599
 
9bf599
 	/* verify the buffer if the type has one. */