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

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