All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] xfs_db misc. btree dumping improvements
@ 2017-04-10 22:47 Darrick J. Wong
  2017-04-10 22:47 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:47 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

Hi all,

Here are a bunch of patches improving various aspects of btree dumping
in xfs_db.  The first few patches fix up numerous crashes that occur
when the user navigates to a btree block with an unknown magic number.
Instead of blowing up, now we can display the (corrupt) contents for
further analysis.

The last patch in this patchset adds a 'btdump' command, which dumps
whatever metadata subtree is rooted at the current iocursor location.
(For inodes it will default to the data for bmbt if there is one.)  This
makes it much easier to display all records of any btree for debugging
or forensic analysis, because the user no longer has to navigate the
btree manually.

Questions?  Comments?

--D

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer
  2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
@ 2017-04-10 22:47 ` Darrick J. Wong
  2017-04-26 17:12   ` Eric Sandeen
  2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:47 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Before printing an array, clamp the array count against the size of the
buffer so that we don't print random heap contents.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/print.c |   11 +++++++++++
 1 file changed, 11 insertions(+)


diff --git a/db/print.c b/db/print.c
index e31372f..0caad8f 100644
--- a/db/print.c
+++ b/db/print.c
@@ -144,6 +144,17 @@ print_flist_1(
 			if (fl->flags & FL_OKHIGH)
 				count = min(count, fl->high - low + 1);
 			if (fa->prfunc) {
+				int	fsz;
+				int	bitlen;
+
+				/* Don't read an array off the end of the buffer */
+				fsz = fsize(f, iocur_top->data, parentoff, 0);
+				bitlen = iocur_top->len * NBBY;
+				if ((f->flags & FLD_ARRAY) &&
+				    fl->offset + (count * fsz) > bitlen) {
+					count = (bitlen - fl->offset) / fsz;
+				}
+
 				neednl = fa->prfunc(iocur_top->data, fl->offset,
 					count, fa->fmtstr,
 					fsize(f, iocur_top->data, parentoff, 0),


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
  2017-04-10 22:47 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
@ 2017-04-10 22:47 ` Darrick J. Wong
  2017-04-11  0:03   ` Dave Chinner
  2017-04-11  0:20   ` [PATCH v2 " Darrick J. Wong
  2017-04-10 22:47 ` [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics Darrick J. Wong
  2017-04-10 22:48 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
  3 siblings, 2 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:47 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

The function block_to_bt plays an integral role in determining the btree
geometry of a block that we want to manipulate with the debugger.
Normally we use the block magic to find the geometry profile, but if the
magic is bad we'll never find it and return NULL.  The callers of this
function do not check for NULL and crash.

Therefore, if we can't find a geometry profile matching the magic
number, use the iocursor type to guess the profile and scowl about that
to stdout.  This makes it so that even with a corrupt magic we can try
to print the fields instead of crashing the debugger.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: be less macro-happy and only evaluate hascrc once
---
 db/btblock.c |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 8 deletions(-)


diff --git a/db/btblock.c b/db/btblock.c
index 835a5f0..e494f3e 100644
--- a/db/btblock.c
+++ b/db/btblock.c
@@ -25,6 +25,8 @@
 #include "print.h"
 #include "bit.h"
 #include "init.h"
+#include "io.h"
+#include "output.h"
 
 /*
  * Definition of the possible btree block layouts.
@@ -122,13 +124,50 @@ static struct xfs_db_btree *
 block_to_bt(
 	struct xfs_btree_block	*bb)
 {
-	struct xfs_db_btree *btp = &btrees[0];
+	struct xfs_db_btree	*btp;
+	uint32_t		magic;
+	bool			crc;
+
+	magic = be32_to_cpu((bb)->bb_magic);
+	for (btp = &btrees[0]; btp->magic != 0; btp++)
+		if (magic == btp->magic)
+			return btp;
 
-	do {
-		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
+	crc = xfs_sb_version_hascrc(&mp->m_sb);
+	switch (iocur_top->typ->typnm) {
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
+		break;
+	case TYP_BNOBT:
+		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
+		break;
+	case TYP_CNTBT:
+		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
+		break;
+	case TYP_INOBT:
+		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
+		break;
+	case TYP_FINOBT:
+		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
+		break;
+	case TYP_RMAPBT:
+		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
+		break;
+	case TYP_REFCBT:
+		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
+		break;
+	default:
+		ASSERT(0);
+	}
+
+	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
+		be32_to_cpu((bb)->bb_magic),
+		iocur_top->typ->name);
+
+	for (btp = &btrees[0]; btp->magic != 0; btp++)
+		if (magic == btp->magic)
 			return btp;
-		btp++;
-	} while (btp->magic != 0);
 
 	return NULL;
 }
@@ -193,7 +232,6 @@ btblock_key_offset(
 	int			offset;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level != 0);
 
 	offset = bt->block_len + (idx - 1) * bt->key_len;
 	return bitize(offset);
@@ -214,7 +252,6 @@ btblock_ptr_offset(
 	int			maxrecs;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level != 0);
 
 	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
 	offset = bt->block_len +
@@ -238,7 +275,6 @@ btblock_rec_offset(
 	int			offset;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level == 0);
 
 	offset = bt->block_len + (idx - 1) * bt->rec_len;
 	return bitize(offset);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics
  2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
  2017-04-10 22:47 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
  2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
@ 2017-04-10 22:47 ` Darrick J. Wong
  2017-04-11 21:42   ` Darrick J. Wong
  2017-04-10 22:48 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
  3 siblings, 1 reply; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:47 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

The directory and attribute manipulation code also use the block's magic
number to figure out the real type of the block we're analyzing.  If the
magic doesn't match any of the known magics, we end up with the field
type set to the raw attr3/dir3 type and no child type to descend into.
Since there's no print function, we trip over the assertion about
FTARG_OKEMPTY and crash.  Instead provide a print function that
complains about the bad magic number.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/attr.c  |   21 +++++++++++++++++++++
 db/attr.h  |    3 +++
 db/dir2.c  |   21 +++++++++++++++++++++
 db/dir2.h  |    3 +++
 db/field.c |   16 ++++++++--------
 5 files changed, 56 insertions(+), 8 deletions(-)


diff --git a/db/attr.c b/db/attr.c
index e26ac67..68a3116 100644
--- a/db/attr.c
+++ b/db/attr.c
@@ -574,3 +574,24 @@ const struct xfs_buf_ops xfs_attr3_db_buf_ops = {
 	.verify_read = xfs_attr3_db_read_verify,
 	.verify_write = xfs_attr3_db_write_verify,
 };
+
+int
+attr_print_func(
+	void		*obj,
+	int		bit,
+	int		count,
+	char		*fmtstr,
+	int		size,
+	int		arg,
+	int		base,
+	int		array)
+{
+	__be32			magic32;
+	__be16			magic16;
+
+	magic32 = *(__be32 *)obj;
+	magic16 = ((struct xfs_da_blkinfo *)obj)->magic;
+	dbprintf(_("Unknown attribute buffer magic (0x%x:0x%x)!\n"),
+		magic32, magic16);
+	return 0;
+}
diff --git a/db/attr.h b/db/attr.h
index bc3431f..525b144 100644
--- a/db/attr.h
+++ b/db/attr.h
@@ -35,3 +35,6 @@ extern int	attr_leaf_name_size(void *obj, int startoff, int idx);
 extern int	attr_size(void *obj, int startoff, int idx);
 
 extern const struct xfs_buf_ops xfs_attr3_db_buf_ops;
+
+extern int	attr_print_func(void *obj, int bit, int count, char *fmtstr,
+		int size, int arg, int base, int array);
diff --git a/db/dir2.c b/db/dir2.c
index 533f705..3b89330 100644
--- a/db/dir2.c
+++ b/db/dir2.c
@@ -1041,3 +1041,24 @@ const struct xfs_buf_ops xfs_dir3_db_buf_ops = {
 	.verify_read = xfs_dir3_db_read_verify,
 	.verify_write = xfs_dir3_db_write_verify,
 };
+
+int
+dir2_print_func(
+	void		*obj,
+	int		bit,
+	int		count,
+	char		*fmtstr,
+	int		size,
+	int		arg,
+	int		base,
+	int		array)
+{
+	__be32			magic32;
+	__be16			magic16;
+
+	magic32 = *(__be32 *)obj;
+	magic16 = ((struct xfs_da_blkinfo *)obj)->magic;
+	dbprintf(_("Unknown directory buffer magic (0x%x:0x%x)!\n"),
+		magic32, magic16);
+	return 0;
+}
diff --git a/db/dir2.h b/db/dir2.h
index 0c2a62e..6d12cc1 100644
--- a/db/dir2.h
+++ b/db/dir2.h
@@ -62,3 +62,6 @@ extern int	dir2_data_union_size(void *obj, int startoff, int idx);
 extern int	dir2_size(void *obj, int startoff, int idx);
 
 extern const struct xfs_buf_ops xfs_dir3_db_buf_ops;
+
+extern int	dir2_print_func(void *obj, int bit, int count, char *fmtstr,
+		int size, int arg, int base, int array);
diff --git a/db/field.c b/db/field.c
index 1968dd5..5496789 100644
--- a/db/field.c
+++ b/db/field.c
@@ -59,8 +59,8 @@ const ftattr_t	ftattrtab[] = {
 	  FTARG_DONULL, NULL, NULL },
 
 /* attr fields */
-	{ FLDT_ATTR, "attr", NULL, (char *)attr_flds, attr_size, FTARG_SIZE,
-	  NULL, attr_flds },
+	{ FLDT_ATTR, "attr", attr_print_func, (char *)attr_flds, attr_size,
+	  FTARG_SIZE, NULL, attr_flds },
 	{ FLDT_ATTR_BLKINFO, "attr_blkinfo", NULL, (char *)attr_blkinfo_flds,
 	  SI(bitsz(struct xfs_da_blkinfo)), 0, NULL, attr_blkinfo_flds },
 	{ FLDT_ATTR_LEAF_ENTRY, "attr_leaf_entry", fp_sarray,
@@ -89,8 +89,8 @@ const ftattr_t	ftattrtab[] = {
 	  attrshort_size, FTARG_SIZE, NULL, attr_shortform_flds },
 
 /* attr3 specific fields */
-	{ FLDT_ATTR3, "attr3", NULL, (char *)attr3_flds, attr_size, FTARG_SIZE,
-	  NULL, attr3_flds },
+	{ FLDT_ATTR3, "attr3", attr_print_func, (char *)attr3_flds, attr_size,
+	  FTARG_SIZE, NULL, attr3_flds },
 	{ FLDT_ATTR3_LEAF_HDR, "attr3_leaf_hdr", NULL,
 	  (char *)attr3_leaf_hdr_flds, SI(bitsz(struct xfs_attr3_leaf_hdr)),
 	  0, NULL, attr3_leaf_hdr_flds },
@@ -219,8 +219,8 @@ const ftattr_t	ftattrtab[] = {
 	  SI(bitsz(xfs_dinode_t)), 0, NULL, inode_v3_flds },
 
 /* dir v2 fields */
-	{ FLDT_DIR2, "dir2", NULL, (char *)dir2_flds, dir2_size, FTARG_SIZE,
-	  NULL, dir2_flds },
+	{ FLDT_DIR2, "dir2", dir2_print_func, (char *)dir2_flds, dir2_size,
+	  FTARG_SIZE, NULL, dir2_flds },
 	{ FLDT_DIR2_BLOCK_TAIL, "dir2_block_tail", NULL,
 	  (char *)dir2_block_tail_flds, SI(bitsz(xfs_dir2_block_tail_t)), 0,
 	  NULL, dir2_block_tail_flds },
@@ -262,8 +262,8 @@ const ftattr_t	ftattrtab[] = {
 	  FTARG_SIZE, NULL, dir2sf_flds },
 
 /* dir v3 fields */
-	{ FLDT_DIR3, "dir3", NULL, (char *)dir3_flds, dir2_size, FTARG_SIZE,
-	  NULL, dir3_flds },
+	{ FLDT_DIR3, "dir3", dir2_print_func, (char *)dir3_flds, dir2_size,
+	  FTARG_SIZE, NULL, dir3_flds },
 	{ FLDT_DIR3_BLKHDR, "dir3_blk_hdr", NULL, (char *)dir3_blkhdr_flds,
 	  SI(bitsz(struct xfs_dir3_blk_hdr)), 0, NULL, dir3_blkhdr_flds },
 	{ FLDT_DIR3_DATA_HDR, "dir3_data_hdr", NULL, (char *)dir3_data_hdr_flds,


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
                   ` (2 preceding siblings ...)
  2017-04-10 22:47 ` [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics Darrick J. Wong
@ 2017-04-10 22:48 ` Darrick J. Wong
  2017-04-26 19:50   ` Eric Sandeen
  2017-04-26 20:36   ` [PATCH v2 " Darrick J. Wong
  3 siblings, 2 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:48 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Introduce a new 'btdump' command that can print the contents of all
blocks of any metadata subtree in the filesystem.  This enables
developers and forensic analyst to view a metadata structure without
having to navigate the btree manually.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: put the btdump_init declaration in command.h to avoid lots of silly
little header files
---
 db/Makefile  |    2 
 db/btdump.c  |  271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 db/command.c |    1 
 db/command.h |    2 
 4 files changed, 275 insertions(+), 1 deletion(-)
 create mode 100644 db/btdump.c


diff --git a/db/Makefile b/db/Makefile
index cdc0b99..2c7679c 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs
 LTCOMMAND = xfs_db
 
 HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
-	btblock.h bmroot.h check.h command.h convert.h crc.h debug.h \
+	btblock.h btdump.c bmroot.h check.h command.h convert.h crc.h debug.h \
 	dir2.h dir2sf.h dquot.h echo.h faddr.h field.h \
 	flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
diff --git a/db/btdump.c b/db/btdump.c
new file mode 100644
index 0000000..9b9fc2c
--- /dev/null
+++ b/db/btdump.c
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 2017 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "output.h"
+#include "init.h"
+#include "io.h"
+#include "type.h"
+#include "input.h"
+
+static void
+btdump_help(void)
+{
+	dbprintf(_(
+"\n"
+" 'btdump' dumps the btree rooted at the current io cursor location.\n"
+" In the case of an inode, the data fork bmbt is displayed.\n"
+" Options:\n"
+"   -a -- Display the extended attribute bmbt.\n"
+"   -i -- Print internal btree nodes.\n"
+"\n"
+));
+
+}
+
+static int
+eval(
+	const char	*fmt, ...)
+{
+	va_list		ap;
+	char		buf[PATH_MAX];
+	char		**v;
+	int		c;
+	int		ret;
+
+	va_start(ap, fmt);
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	va_end(ap);
+
+	v = breakline(buf, &c);
+	ret = command(c, v);
+	free(v);
+	return ret;
+}
+
+static bool
+btblock_has_rightsib(
+	struct xfs_btree_block	*block,
+	bool			long_format)
+{
+	if (long_format)
+		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
+	return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
+}
+
+static int
+dump_btlevel(
+	int			level,
+	bool			long_format)
+{
+	xfs_daddr_t		orig_daddr = iocur_top->bb;
+	xfs_daddr_t		last_daddr;
+	unsigned int		nr;
+	int			ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	nr = 1;
+	do {
+		last_daddr = iocur_top->bb;
+		dbprintf(_("%s level %u block %u daddr %llu\n"),
+			 iocur_top->typ->name, level, nr, last_daddr);
+		if (level > 0) {
+			ret = eval("print keys");
+			if (ret)
+				goto err;
+			ret = eval("print ptrs");
+		} else {
+			ret = eval("print recs");
+		}
+		if (ret)
+			goto err;
+		if (btblock_has_rightsib(iocur_top->data, long_format)) {
+			ret = eval("addr rightsib");
+			if (ret)
+				goto err;
+		}
+		nr++;
+	} while (iocur_top->bb != orig_daddr && iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+dump_btree(
+	bool		dump_node_blocks,
+	bool		long_format)
+{
+	xfs_daddr_t	orig_daddr = iocur_top->bb;
+	xfs_daddr_t	last_daddr;
+	int		level;
+	int		ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	cur_agno = XFS_FSB_TO_AGNO(mp, XFS_DADDR_TO_FSB(mp, iocur_top->bb));
+	level = xfs_btree_get_level(iocur_top->data);
+	do {
+		last_daddr = iocur_top->bb;
+		if (level > 0) {
+			if (dump_node_blocks) {
+				ret = dump_btlevel(level, long_format);
+				if (ret)
+					goto err;
+			}
+			ret = eval("addr ptrs[1]");
+		} else {
+			ret = dump_btlevel(level, long_format);
+		}
+		if (ret)
+			goto err;
+		level--;
+	} while (level >= 0 &&
+		 iocur_top->bb != orig_daddr &&
+		 iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+dump_inode(
+	bool			dump_node_blocks,
+	bool			attrfork)
+{
+	char			*prefix;
+	struct xfs_dinode	*dip;
+	int			ret;
+
+	if (attrfork)
+		prefix = "a.bmbt";
+	else if (xfs_sb_version_hascrc(&mp->m_sb))
+		prefix = "u3.bmbt";
+	else
+		prefix = "u.bmbt";
+
+	dip = iocur_top->data;
+	if (attrfork) {
+		if (!dip->di_anextents ||
+		    dip->di_aformat != XFS_DINODE_FMT_BTREE)
+			return 0;
+	} else {
+		if (!dip->di_nextents ||
+		    dip->di_format != XFS_DINODE_FMT_BTREE)
+			return 0;
+	}
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	if (dump_node_blocks) {
+		ret = eval("print %s.keys", prefix);
+		if (ret)
+			goto err;
+		ret = eval("print %s.ptrs", prefix);
+		if (ret)
+			goto err;
+	}
+
+	ret = eval("addr %s.ptrs[1]", prefix);
+	if (ret)
+		goto err;
+
+	ret = dump_btree(dump_node_blocks, true);
+	if (ret)
+		goto err;
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+btdump_f(
+	int		argc,
+	char		**argv)
+{
+	bool		aflag = false;
+	bool		iflag = false;
+	int		c;
+
+	if (cur_typ == NULL) {
+		dbprintf(_("no current type\n"));
+		return 0;
+	}
+	while ((c = getopt(argc, argv, "ai")) != EOF) {
+		switch (c) {
+		case 'a':
+			aflag = true;
+			break;
+		case 'i':
+			iflag = true;
+			break;
+		default:
+			dbprintf(_("bad option for btdump command\n"));
+			return 0;
+		}
+	}
+	if (aflag && cur_typ->typnm != TYP_INODE) {
+		dbprintf(_("attrfork flag doesn't apply here\n"));
+		return 0;
+	}
+	switch (cur_typ->typnm) {
+	case TYP_BNOBT:
+	case TYP_CNTBT:
+	case TYP_INOBT:
+	case TYP_FINOBT:
+	case TYP_RMAPBT:
+	case TYP_REFCBT:
+		return dump_btree(iflag, false);
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		return dump_btree(iflag, true);
+	case TYP_INODE:
+		return dump_inode(iflag, aflag);
+	default:
+		dbprintf(_("Not a btree.\n"));
+		return 0;
+	}
+}
+
+static const cmdinfo_t btdump_cmd =
+	{ "btdump", "b", btdump_f, 0, 1, 0, "",
+	  N_("dump btree"), btdump_help };
+
+void
+btdump_init(void)
+{
+	add_command(&btdump_cmd);
+}
diff --git a/db/command.c b/db/command.c
index 3d7cfd7..c90c85c 100644
--- a/db/command.c
+++ b/db/command.c
@@ -124,6 +124,7 @@ init_commands(void)
 	attrset_init();
 	block_init();
 	bmap_init();
+	btdump_init();
 	check_init();
 	convert_init();
 	crc_init();
diff --git a/db/command.h b/db/command.h
index 4d4807d..9b4ed2d 100644
--- a/db/command.h
+++ b/db/command.h
@@ -39,3 +39,5 @@ extern void		add_command(const cmdinfo_t *ci);
 extern int		command(int argc, char **argv);
 extern const cmdinfo_t	*find_command(const char *cmd);
 extern void		init_commands(void);
+
+extern void		btdump_init(void);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
@ 2017-04-11  0:03   ` Dave Chinner
  2017-04-11  0:19     ` Darrick J. Wong
  2017-04-11  0:20   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 23+ messages in thread
From: Dave Chinner @ 2017-04-11  0:03 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Apr 10, 2017 at 03:47:53PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> The function block_to_bt plays an integral role in determining the btree
> geometry of a block that we want to manipulate with the debugger.
> Normally we use the block magic to find the geometry profile, but if the
> magic is bad we'll never find it and return NULL.  The callers of this
> function do not check for NULL and crash.
> 
> Therefore, if we can't find a geometry profile matching the magic
> number, use the iocursor type to guess the profile and scowl about that
> to stdout.  This makes it so that even with a corrupt magic we can try
> to print the fields instead of crashing the debugger.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v2: be less macro-happy and only evaluate hascrc once
> ---
>  db/btblock.c |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 44 insertions(+), 8 deletions(-)
> 
> 
> diff --git a/db/btblock.c b/db/btblock.c
> index 835a5f0..e494f3e 100644
> --- a/db/btblock.c
> +++ b/db/btblock.c
> @@ -25,6 +25,8 @@
>  #include "print.h"
>  #include "bit.h"
>  #include "init.h"
> +#include "io.h"
> +#include "output.h"
>  
>  /*
>   * Definition of the possible btree block layouts.
> @@ -122,13 +124,50 @@ static struct xfs_db_btree *
>  block_to_bt(
>  	struct xfs_btree_block	*bb)
>  {
> -	struct xfs_db_btree *btp = &btrees[0];
> +	struct xfs_db_btree	*btp;
> +	uint32_t		magic;
> +	bool			crc;
> +
> +	magic = be32_to_cpu((bb)->bb_magic);
> +	for (btp = &btrees[0]; btp->magic != 0; btp++)
> +		if (magic == btp->magic)
> +			return btp;

{}

-Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-11  0:03   ` Dave Chinner
@ 2017-04-11  0:19     ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-11  0:19 UTC (permalink / raw)
  To: Dave Chinner; +Cc: sandeen, linux-xfs

On Tue, Apr 11, 2017 at 10:03:32AM +1000, Dave Chinner wrote:
> On Mon, Apr 10, 2017 at 03:47:53PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > The function block_to_bt plays an integral role in determining the btree
> > geometry of a block that we want to manipulate with the debugger.
> > Normally we use the block magic to find the geometry profile, but if the
> > magic is bad we'll never find it and return NULL.  The callers of this
> > function do not check for NULL and crash.
> > 
> > Therefore, if we can't find a geometry profile matching the magic
> > number, use the iocursor type to guess the profile and scowl about that
> > to stdout.  This makes it so that even with a corrupt magic we can try
> > to print the fields instead of crashing the debugger.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > v2: be less macro-happy and only evaluate hascrc once
> > ---
> >  db/btblock.c |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
> >  1 file changed, 44 insertions(+), 8 deletions(-)
> > 
> > 
> > diff --git a/db/btblock.c b/db/btblock.c
> > index 835a5f0..e494f3e 100644
> > --- a/db/btblock.c
> > +++ b/db/btblock.c
> > @@ -25,6 +25,8 @@
> >  #include "print.h"
> >  #include "bit.h"
> >  #include "init.h"
> > +#include "io.h"
> > +#include "output.h"
> >  
> >  /*
> >   * Definition of the possible btree block layouts.
> > @@ -122,13 +124,50 @@ static struct xfs_db_btree *
> >  block_to_bt(
> >  	struct xfs_btree_block	*bb)
> >  {
> > -	struct xfs_db_btree *btp = &btrees[0];
> > +	struct xfs_db_btree	*btp;
> > +	uint32_t		magic;
> > +	bool			crc;
> > +
> > +	magic = be32_to_cpu((bb)->bb_magic);
> > +	for (btp = &btrees[0]; btp->magic != 0; btp++)
> > +		if (magic == btp->magic)
> > +			return btp;
> 
> {}

Sure.

--D

> 
> -Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
  2017-04-11  0:03   ` Dave Chinner
@ 2017-04-11  0:20   ` Darrick J. Wong
  2017-04-26 17:48     ` Eric Sandeen
  2017-04-26 18:47     ` [PATCH v3 " Eric Sandeen
  1 sibling, 2 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-11  0:20 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

The function block_to_bt plays an integral role in determining the btree
geometry of a block that we want to manipulate with the debugger.
Normally we use the block magic to find the geometry profile, but if the
magic is bad we'll never find it and return NULL.  The callers of this
function do not check for NULL and crash.

Therefore, if we can't find a geometry profile matching the magic
number, use the iocursor type to guess the profile and scowl about that
to stdout.  This makes it so that even with a corrupt magic we can try
to print the fields instead of crashing the debugger.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: be less macro-happy and only evaluate hascrc once
v3: braces around the for loop body
---
 db/btblock.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/db/btblock.c b/db/btblock.c
index 835a5f0..b819fa5 100644
--- a/db/btblock.c
+++ b/db/btblock.c
@@ -25,6 +25,8 @@
 #include "print.h"
 #include "bit.h"
 #include "init.h"
+#include "io.h"
+#include "output.h"
 
 /*
  * Definition of the possible btree block layouts.
@@ -122,13 +124,52 @@ static struct xfs_db_btree *
 block_to_bt(
 	struct xfs_btree_block	*bb)
 {
-	struct xfs_db_btree *btp = &btrees[0];
+	struct xfs_db_btree	*btp;
+	uint32_t		magic;
+	bool			crc;
 
-	do {
-		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
+	magic = be32_to_cpu((bb)->bb_magic);
+	for (btp = &btrees[0]; btp->magic != 0; btp++) {
+		if (magic == btp->magic)
+			return btp;
+	}
+
+	crc = xfs_sb_version_hascrc(&mp->m_sb);
+	switch (iocur_top->typ->typnm) {
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
+		break;
+	case TYP_BNOBT:
+		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
+		break;
+	case TYP_CNTBT:
+		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
+		break;
+	case TYP_INOBT:
+		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
+		break;
+	case TYP_FINOBT:
+		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
+		break;
+	case TYP_RMAPBT:
+		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
+		break;
+	case TYP_REFCBT:
+		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
+		break;
+	default:
+		ASSERT(0);
+	}
+
+	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
+		be32_to_cpu((bb)->bb_magic),
+		iocur_top->typ->name);
+
+	for (btp = &btrees[0]; btp->magic != 0; btp++) {
+		if (magic == btp->magic)
 			return btp;
-		btp++;
-	} while (btp->magic != 0);
+	}
 
 	return NULL;
 }
@@ -193,7 +234,6 @@ btblock_key_offset(
 	int			offset;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level != 0);
 
 	offset = bt->block_len + (idx - 1) * bt->key_len;
 	return bitize(offset);
@@ -214,7 +254,6 @@ btblock_ptr_offset(
 	int			maxrecs;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level != 0);
 
 	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
 	offset = bt->block_len +
@@ -238,7 +277,6 @@ btblock_rec_offset(
 	int			offset;
 
 	ASSERT(startoff == 0);
-	ASSERT(block->bb_level == 0);
 
 	offset = bt->block_len + (idx - 1) * bt->rec_len;
 	return bitize(offset);

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics
  2017-04-10 22:47 ` [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics Darrick J. Wong
@ 2017-04-11 21:42   ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-11 21:42 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

On Mon, Apr 10, 2017 at 03:47:59PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> The directory and attribute manipulation code also use the block's magic
> number to figure out the real type of the block we're analyzing.  If the
> magic doesn't match any of the known magics, we end up with the field
> type set to the raw attr3/dir3 type and no child type to descend into.
> Since there's no print function, we trip over the assertion about
> FTARG_OKEMPTY and crash.  Instead provide a print function that
> complains about the bad magic number.

NAK, this patch breaks directory block dumping.

--D

> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  db/attr.c  |   21 +++++++++++++++++++++
>  db/attr.h  |    3 +++
>  db/dir2.c  |   21 +++++++++++++++++++++
>  db/dir2.h  |    3 +++
>  db/field.c |   16 ++++++++--------
>  5 files changed, 56 insertions(+), 8 deletions(-)
> 
> 
> diff --git a/db/attr.c b/db/attr.c
> index e26ac67..68a3116 100644
> --- a/db/attr.c
> +++ b/db/attr.c
> @@ -574,3 +574,24 @@ const struct xfs_buf_ops xfs_attr3_db_buf_ops = {
>  	.verify_read = xfs_attr3_db_read_verify,
>  	.verify_write = xfs_attr3_db_write_verify,
>  };
> +
> +int
> +attr_print_func(
> +	void		*obj,
> +	int		bit,
> +	int		count,
> +	char		*fmtstr,
> +	int		size,
> +	int		arg,
> +	int		base,
> +	int		array)
> +{
> +	__be32			magic32;
> +	__be16			magic16;
> +
> +	magic32 = *(__be32 *)obj;
> +	magic16 = ((struct xfs_da_blkinfo *)obj)->magic;
> +	dbprintf(_("Unknown attribute buffer magic (0x%x:0x%x)!\n"),
> +		magic32, magic16);
> +	return 0;
> +}
> diff --git a/db/attr.h b/db/attr.h
> index bc3431f..525b144 100644
> --- a/db/attr.h
> +++ b/db/attr.h
> @@ -35,3 +35,6 @@ extern int	attr_leaf_name_size(void *obj, int startoff, int idx);
>  extern int	attr_size(void *obj, int startoff, int idx);
>  
>  extern const struct xfs_buf_ops xfs_attr3_db_buf_ops;
> +
> +extern int	attr_print_func(void *obj, int bit, int count, char *fmtstr,
> +		int size, int arg, int base, int array);
> diff --git a/db/dir2.c b/db/dir2.c
> index 533f705..3b89330 100644
> --- a/db/dir2.c
> +++ b/db/dir2.c
> @@ -1041,3 +1041,24 @@ const struct xfs_buf_ops xfs_dir3_db_buf_ops = {
>  	.verify_read = xfs_dir3_db_read_verify,
>  	.verify_write = xfs_dir3_db_write_verify,
>  };
> +
> +int
> +dir2_print_func(
> +	void		*obj,
> +	int		bit,
> +	int		count,
> +	char		*fmtstr,
> +	int		size,
> +	int		arg,
> +	int		base,
> +	int		array)
> +{
> +	__be32			magic32;
> +	__be16			magic16;
> +
> +	magic32 = *(__be32 *)obj;
> +	magic16 = ((struct xfs_da_blkinfo *)obj)->magic;
> +	dbprintf(_("Unknown directory buffer magic (0x%x:0x%x)!\n"),
> +		magic32, magic16);
> +	return 0;
> +}
> diff --git a/db/dir2.h b/db/dir2.h
> index 0c2a62e..6d12cc1 100644
> --- a/db/dir2.h
> +++ b/db/dir2.h
> @@ -62,3 +62,6 @@ extern int	dir2_data_union_size(void *obj, int startoff, int idx);
>  extern int	dir2_size(void *obj, int startoff, int idx);
>  
>  extern const struct xfs_buf_ops xfs_dir3_db_buf_ops;
> +
> +extern int	dir2_print_func(void *obj, int bit, int count, char *fmtstr,
> +		int size, int arg, int base, int array);
> diff --git a/db/field.c b/db/field.c
> index 1968dd5..5496789 100644
> --- a/db/field.c
> +++ b/db/field.c
> @@ -59,8 +59,8 @@ const ftattr_t	ftattrtab[] = {
>  	  FTARG_DONULL, NULL, NULL },
>  
>  /* attr fields */
> -	{ FLDT_ATTR, "attr", NULL, (char *)attr_flds, attr_size, FTARG_SIZE,
> -	  NULL, attr_flds },
> +	{ FLDT_ATTR, "attr", attr_print_func, (char *)attr_flds, attr_size,
> +	  FTARG_SIZE, NULL, attr_flds },
>  	{ FLDT_ATTR_BLKINFO, "attr_blkinfo", NULL, (char *)attr_blkinfo_flds,
>  	  SI(bitsz(struct xfs_da_blkinfo)), 0, NULL, attr_blkinfo_flds },
>  	{ FLDT_ATTR_LEAF_ENTRY, "attr_leaf_entry", fp_sarray,
> @@ -89,8 +89,8 @@ const ftattr_t	ftattrtab[] = {
>  	  attrshort_size, FTARG_SIZE, NULL, attr_shortform_flds },
>  
>  /* attr3 specific fields */
> -	{ FLDT_ATTR3, "attr3", NULL, (char *)attr3_flds, attr_size, FTARG_SIZE,
> -	  NULL, attr3_flds },
> +	{ FLDT_ATTR3, "attr3", attr_print_func, (char *)attr3_flds, attr_size,
> +	  FTARG_SIZE, NULL, attr3_flds },
>  	{ FLDT_ATTR3_LEAF_HDR, "attr3_leaf_hdr", NULL,
>  	  (char *)attr3_leaf_hdr_flds, SI(bitsz(struct xfs_attr3_leaf_hdr)),
>  	  0, NULL, attr3_leaf_hdr_flds },
> @@ -219,8 +219,8 @@ const ftattr_t	ftattrtab[] = {
>  	  SI(bitsz(xfs_dinode_t)), 0, NULL, inode_v3_flds },
>  
>  /* dir v2 fields */
> -	{ FLDT_DIR2, "dir2", NULL, (char *)dir2_flds, dir2_size, FTARG_SIZE,
> -	  NULL, dir2_flds },
> +	{ FLDT_DIR2, "dir2", dir2_print_func, (char *)dir2_flds, dir2_size,
> +	  FTARG_SIZE, NULL, dir2_flds },
>  	{ FLDT_DIR2_BLOCK_TAIL, "dir2_block_tail", NULL,
>  	  (char *)dir2_block_tail_flds, SI(bitsz(xfs_dir2_block_tail_t)), 0,
>  	  NULL, dir2_block_tail_flds },
> @@ -262,8 +262,8 @@ const ftattr_t	ftattrtab[] = {
>  	  FTARG_SIZE, NULL, dir2sf_flds },
>  
>  /* dir v3 fields */
> -	{ FLDT_DIR3, "dir3", NULL, (char *)dir3_flds, dir2_size, FTARG_SIZE,
> -	  NULL, dir3_flds },
> +	{ FLDT_DIR3, "dir3", dir2_print_func, (char *)dir3_flds, dir2_size,
> +	  FTARG_SIZE, NULL, dir3_flds },
>  	{ FLDT_DIR3_BLKHDR, "dir3_blk_hdr", NULL, (char *)dir3_blkhdr_flds,
>  	  SI(bitsz(struct xfs_dir3_blk_hdr)), 0, NULL, dir3_blkhdr_flds },
>  	{ FLDT_DIR3_DATA_HDR, "dir3_data_hdr", NULL, (char *)dir3_data_hdr_flds,
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer
  2017-04-10 22:47 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
@ 2017-04-26 17:12   ` Eric Sandeen
  2017-04-26 17:45     ` Darrick J. Wong
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 17:12 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/10/17 5:47 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Before printing an array, clamp the array count against the size of the
> buffer so that we don't print random heap contents.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  db/print.c |   11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> 
> diff --git a/db/print.c b/db/print.c
> index e31372f..0caad8f 100644
> --- a/db/print.c
> +++ b/db/print.c
> @@ -144,6 +144,17 @@ print_flist_1(
>  			if (fl->flags & FL_OKHIGH)
>  				count = min(count, fl->high - low + 1);
>  			if (fa->prfunc) {
> +				int	fsz;
> +				int	bitlen;
> +
> +				/* Don't read an array off the end of the buffer */
> +				fsz = fsize(f, iocur_top->data, parentoff, 0);
> +				bitlen = iocur_top->len * NBBY;
> +				if ((f->flags & FLD_ARRAY) &&
> +				    fl->offset + (count * fsz) > bitlen) {
> +					count = (bitlen - fl->offset) / fsz;
> +				}
> +
>  				neednl = fa->prfunc(iocur_top->data, fl->offset,
>  					count, fa->fmtstr,
>  					fsize(f, iocur_top->data, parentoff, 0),

can we just re-use fsz here in the prfunc call?

Otherwise seems fine, and I could do that on commit.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer
  2017-04-26 17:12   ` Eric Sandeen
@ 2017-04-26 17:45     ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 17:45 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Wed, Apr 26, 2017 at 12:12:38PM -0500, Eric Sandeen wrote:
> On 4/10/17 5:47 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Before printing an array, clamp the array count against the size of the
> > buffer so that we don't print random heap contents.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  db/print.c |   11 +++++++++++
> >  1 file changed, 11 insertions(+)
> > 
> > 
> > diff --git a/db/print.c b/db/print.c
> > index e31372f..0caad8f 100644
> > --- a/db/print.c
> > +++ b/db/print.c
> > @@ -144,6 +144,17 @@ print_flist_1(
> >  			if (fl->flags & FL_OKHIGH)
> >  				count = min(count, fl->high - low + 1);
> >  			if (fa->prfunc) {
> > +				int	fsz;
> > +				int	bitlen;
> > +
> > +				/* Don't read an array off the end of the buffer */
> > +				fsz = fsize(f, iocur_top->data, parentoff, 0);
> > +				bitlen = iocur_top->len * NBBY;
> > +				if ((f->flags & FLD_ARRAY) &&
> > +				    fl->offset + (count * fsz) > bitlen) {
> > +					count = (bitlen - fl->offset) / fsz;
> > +				}
> > +
> >  				neednl = fa->prfunc(iocur_top->data, fl->offset,
> >  					count, fa->fmtstr,
> >  					fsize(f, iocur_top->data, parentoff, 0),
> 
> can we just re-use fsz here in the prfunc call?

Yeah, we could reuse it.

--D

> 
> Otherwise seems fine, and I could do that on commit.
> 
> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-11  0:20   ` [PATCH v2 " Darrick J. Wong
@ 2017-04-26 17:48     ` Eric Sandeen
  2017-04-26 18:25       ` Darrick J. Wong
  2017-04-26 18:47     ` [PATCH v3 " Eric Sandeen
  1 sibling, 1 reply; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 17:48 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/10/17 7:20 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> The function block_to_bt plays an integral role in determining the btree
> geometry of a block that we want to manipulate with the debugger.
> Normally we use the block magic to find the geometry profile, but if the
> magic is bad we'll never find it and return NULL.  The callers of this
> function do not check for NULL and crash.
> 
> Therefore, if we can't find a geometry profile matching the magic
> number, use the iocursor type to guess the profile and scowl about that
> to stdout.  This makes it so that even with a corrupt magic we can try
> to print the fields instead of crashing the debugger.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Makes sense generally, minor things below.

> ---
> v2: be less macro-happy and only evaluate hascrc once
> v3: braces around the for loop body
> ---
>  db/btblock.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 46 insertions(+), 8 deletions(-)
> 
> diff --git a/db/btblock.c b/db/btblock.c
> index 835a5f0..b819fa5 100644
> --- a/db/btblock.c
> +++ b/db/btblock.c
> @@ -25,6 +25,8 @@
>  #include "print.h"
>  #include "bit.h"
>  #include "init.h"
> +#include "io.h"
> +#include "output.h"
>  
>  /*
>   * Definition of the possible btree block layouts.
> @@ -122,13 +124,52 @@ static struct xfs_db_btree *

urgh:

/*
 * Find the right block defintion for a given ondisk block.
 *
 * We use the least significant bit of the magic number as index into
 * the array of block defintions.

(nope, we don't, I can remove that on commit...)

 */
static struct xfs_db_btree *

>  block_to_bt(
>  	struct xfs_btree_block	*bb)
>  {
> -	struct xfs_db_btree *btp = &btrees[0];
> +	struct xfs_db_btree	*btp;
> +	uint32_t		magic;
> +	bool			crc;
>  
> -	do {
> -		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
> +	magic = be32_to_cpu((bb)->bb_magic);

maybe -

again:

> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> +		if (magic == btp->magic)
> +			return btp;
> +	}

	/* Magic is invalid/unknown.  Guess based on iocur type */

> +	crc = xfs_sb_version_hascrc(&mp->m_sb);

Bah, wish we could use something like:

	magic = xfs_magics[crc][btnum];

but that's static to libxfs/xfs_btree.c and I guess btnum != typnm.
Because of course.

(btnum = xfs_typnm_to_btnum[iocur_top->typ->typnm]; ? :) Ok I'll
drop it...)

> +	switch (iocur_top->typ->typnm) {
> +	case TYP_BMAPBTA:
> +	case TYP_BMAPBTD:
> +		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
> +		break;
> +	case TYP_BNOBT:
> +		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
> +		break;
> +	case TYP_CNTBT:
> +		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
> +		break;
> +	case TYP_INOBT:
> +		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
> +		break;
> +	case TYP_FINOBT:
> +		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
> +		break;
> +	case TYP_RMAPBT:
> +		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
> +		break;
> +	case TYP_REFCBT:
> +		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
> +		break;
> +	default:
> +		ASSERT(0);
> +	}

	ASSERT(magic);

we'd better have that by now, yes?  Or could we hit the RMAP/REFC
types w/o crc set?  I guess then the caller ASSERTs anyway?

> +
> +	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
> +		be32_to_cpu((bb)->bb_magic),
> +		iocur_top->typ->name);


	goto again;

to avoid the cut & paste of the loop below?  But maybe that's uglier.

> +
> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> +		if (magic == btp->magic)
>  			return btp;
> -		btp++;
> -	} while (btp->magic != 0);
> +	}
>  
>  	return NULL;
>  }
> @@ -193,7 +234,6 @@ btblock_key_offset(
>  	int			offset;
>  
>  	ASSERT(startoff == 0);
> -	ASSERT(block->bb_level != 0);

Help me out, why are these now removed?

-Eric

>  
>  	offset = bt->block_len + (idx - 1) * bt->key_len;
>  	return bitize(offset);
> @@ -214,7 +254,6 @@ btblock_ptr_offset(
>  	int			maxrecs;
>  
>  	ASSERT(startoff == 0);
> -	ASSERT(block->bb_level != 0);
>  
>  	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
>  	offset = bt->block_len +
> @@ -238,7 +277,6 @@ btblock_rec_offset(
>  	int			offset;
>  
>  	ASSERT(startoff == 0);
> -	ASSERT(block->bb_level == 0);
>  
>  	offset = bt->block_len + (idx - 1) * bt->rec_len;
>  	return bitize(offset);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-26 17:48     ` Eric Sandeen
@ 2017-04-26 18:25       ` Darrick J. Wong
  2017-04-26 18:41         ` Eric Sandeen
  0 siblings, 1 reply; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 18:25 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Wed, Apr 26, 2017 at 12:48:48PM -0500, Eric Sandeen wrote:
> On 4/10/17 7:20 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > The function block_to_bt plays an integral role in determining the btree
> > geometry of a block that we want to manipulate with the debugger.
> > Normally we use the block magic to find the geometry profile, but if the
> > magic is bad we'll never find it and return NULL.  The callers of this
> > function do not check for NULL and crash.
> > 
> > Therefore, if we can't find a geometry profile matching the magic
> > number, use the iocursor type to guess the profile and scowl about that
> > to stdout.  This makes it so that even with a corrupt magic we can try
> > to print the fields instead of crashing the debugger.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Makes sense generally, minor things below.
> 
> > ---
> > v2: be less macro-happy and only evaluate hascrc once
> > v3: braces around the for loop body
> > ---
> >  db/btblock.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
> >  1 file changed, 46 insertions(+), 8 deletions(-)
> > 
> > diff --git a/db/btblock.c b/db/btblock.c
> > index 835a5f0..b819fa5 100644
> > --- a/db/btblock.c
> > +++ b/db/btblock.c
> > @@ -25,6 +25,8 @@
> >  #include "print.h"
> >  #include "bit.h"
> >  #include "init.h"
> > +#include "io.h"
> > +#include "output.h"
> >  
> >  /*
> >   * Definition of the possible btree block layouts.
> > @@ -122,13 +124,52 @@ static struct xfs_db_btree *
> 
> urgh:
> 
> /*
>  * Find the right block defintion for a given ondisk block.
>  *
>  * We use the least significant bit of the magic number as index into
>  * the array of block defintions.
> 
> (nope, we don't, I can remove that on commit...)

Oops.  Should've nuked that comment from the start.

>  */
> static struct xfs_db_btree *
> 
> >  block_to_bt(
> >  	struct xfs_btree_block	*bb)
> >  {
> > -	struct xfs_db_btree *btp = &btrees[0];
> > +	struct xfs_db_btree	*btp;
> > +	uint32_t		magic;
> > +	bool			crc;
> >  
> > -	do {
> > -		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
> > +	magic = be32_to_cpu((bb)->bb_magic);
> 
> maybe -
> 
> again:

Eww, backwards jumping gotos :)

I guess that works so long as you're sure we can't accidentally jump
backwards with an unrecognized magic and thus end up in an infinite
loop.

> > +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> > +		if (magic == btp->magic)
> > +			return btp;
> > +	}
> 
> 	/* Magic is invalid/unknown.  Guess based on iocur type */
> 
> > +	crc = xfs_sb_version_hascrc(&mp->m_sb);
> 
> Bah, wish we could use something like:
> 
> 	magic = xfs_magics[crc][btnum];
> 
> but that's static to libxfs/xfs_btree.c and I guess btnum != typnm.
> Because of course.
> 
> (btnum = xfs_typnm_to_btnum[iocur_top->typ->typnm]; ? :) Ok I'll
> drop it...)

:D

> > +	switch (iocur_top->typ->typnm) {
> > +	case TYP_BMAPBTA:
> > +	case TYP_BMAPBTD:
> > +		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
> > +		break;
> > +	case TYP_BNOBT:
> > +		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
> > +		break;
> > +	case TYP_CNTBT:
> > +		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
> > +		break;
> > +	case TYP_INOBT:
> > +		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
> > +		break;
> > +	case TYP_FINOBT:
> > +		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
> > +		break;
> > +	case TYP_RMAPBT:
> > +		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
> > +		break;
> > +	case TYP_REFCBT:
> > +		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
> > +		break;
> > +	default:
> > +		ASSERT(0);
> > +	}
> 
> 	ASSERT(magic);
> 
> we'd better have that by now, yes?

Yes.

> Or could we hit the RMAP/REFC types w/o crc set?

In theory, no, because xfs_db sets up a different type profile for the
!crc case, and that type profile excludes TYP_RMAPBT/TYP_REFCBT.

>  I guess then the caller ASSERTs anyway?

<shrug>

> > +
> > +	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
> > +		be32_to_cpu((bb)->bb_magic),
> > +		iocur_top->typ->name);
> 
> 
> 	goto again;
> 
> to avoid the cut & paste of the loop below?  But maybe that's uglier.

Mostly a matter of taste, I think.  If the machinery was more complex
I'd argue for a backwards goto to avoid having to maintain two identical
loops, but this is pretty simple.

> > +
> > +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> > +		if (magic == btp->magic)
> >  			return btp;
> > -		btp++;
> > -	} while (btp->magic != 0);
> > +	}
> >  
> >  	return NULL;
> >  }
> > @@ -193,7 +234,6 @@ btblock_key_offset(
> >  	int			offset;
> >  
> >  	ASSERT(startoff == 0);
> > -	ASSERT(block->bb_level != 0);
> 
> Help me out, why are these now removed?

/me doesn't remember, maybe they should just go away.

> -Eric
> 
> >  
> >  	offset = bt->block_len + (idx - 1) * bt->key_len;
> >  	return bitize(offset);
> > @@ -214,7 +254,6 @@ btblock_ptr_offset(
> >  	int			maxrecs;
> >  
> >  	ASSERT(startoff == 0);
> > -	ASSERT(block->bb_level != 0);
> >  
> >  	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
> >  	offset = bt->block_len +
> > @@ -238,7 +277,6 @@ btblock_rec_offset(
> >  	int			offset;
> >  
> >  	ASSERT(startoff == 0);
> > -	ASSERT(block->bb_level == 0);
> >  
> >  	offset = bt->block_len + (idx - 1) * bt->rec_len;
> >  	return bitize(offset);
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-26 18:25       ` Darrick J. Wong
@ 2017-04-26 18:41         ` Eric Sandeen
  2017-04-26 18:43           ` Darrick J. Wong
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 18:41 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On 4/26/17 1:25 PM, Darrick J. Wong wrote:
> On Wed, Apr 26, 2017 at 12:48:48PM -0500, Eric Sandeen wrote:
>> On 4/10/17 7:20 PM, Darrick J. Wong wrote:
>>> From: Darrick J. Wong <darrick.wong@oracle.com>
>>>
>>> The function block_to_bt plays an integral role in determining the btree
>>> geometry of a block that we want to manipulate with the debugger.
>>> Normally we use the block magic to find the geometry profile, but if the
>>> magic is bad we'll never find it and return NULL.  The callers of this
>>> function do not check for NULL and crash.
>>>
>>> Therefore, if we can't find a geometry profile matching the magic
>>> number, use the iocursor type to guess the profile and scowl about that
>>> to stdout.  This makes it so that even with a corrupt magic we can try
>>> to print the fields instead of crashing the debugger.
>>>
>>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
>>
>> Makes sense generally, minor things below.
>>
>>> ---
>>> v2: be less macro-happy and only evaluate hascrc once
>>> v3: braces around the for loop body
>>> ---
>>>  db/btblock.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
>>>  1 file changed, 46 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/db/btblock.c b/db/btblock.c
>>> index 835a5f0..b819fa5 100644
>>> --- a/db/btblock.c
>>> +++ b/db/btblock.c
>>> @@ -25,6 +25,8 @@
>>>  #include "print.h"
>>>  #include "bit.h"
>>>  #include "init.h"
>>> +#include "io.h"
>>> +#include "output.h"
>>>  
>>>  /*
>>>   * Definition of the possible btree block layouts.
>>> @@ -122,13 +124,52 @@ static struct xfs_db_btree *
>>
>> urgh:
>>
>> /*
>>  * Find the right block defintion for a given ondisk block.
>>  *
>>  * We use the least significant bit of the magic number as index into
>>  * the array of block defintions.
>>
>> (nope, we don't, I can remove that on commit...)
> 
> Oops.  Should've nuked that comment from the start.

Ok, thanks for the replies.

I'll:

1) Fix up comments
2) /Not/ do backwards-jumping-gotos, fair point.
3) add the magic ASSERT
4) nuke the other ASSERTs

on commit? or do you want to resend ;)

> 
>>  */
>> static struct xfs_db_btree *
>>
>>>  block_to_bt(
>>>  	struct xfs_btree_block	*bb)
>>>  {
>>> -	struct xfs_db_btree *btp = &btrees[0];
>>> +	struct xfs_db_btree	*btp;
>>> +	uint32_t		magic;
>>> +	bool			crc;
>>>  
>>> -	do {
>>> -		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
>>> +	magic = be32_to_cpu((bb)->bb_magic);
>>
>> maybe -
>>
>> again:
> 
> Eww, backwards jumping gotos :)
> 
> I guess that works so long as you're sure we can't accidentally jump
> backwards with an unrecognized magic and thus end up in an infinite
> loop.
> 
>>> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
>>> +		if (magic == btp->magic)
>>> +			return btp;
>>> +	}
>>
>> 	/* Magic is invalid/unknown.  Guess based on iocur type */
>>
>>> +	crc = xfs_sb_version_hascrc(&mp->m_sb);
>>
>> Bah, wish we could use something like:
>>
>> 	magic = xfs_magics[crc][btnum];
>>
>> but that's static to libxfs/xfs_btree.c and I guess btnum != typnm.
>> Because of course.
>>
>> (btnum = xfs_typnm_to_btnum[iocur_top->typ->typnm]; ? :) Ok I'll
>> drop it...)
> 
> :D
> 
>>> +	switch (iocur_top->typ->typnm) {
>>> +	case TYP_BMAPBTA:
>>> +	case TYP_BMAPBTD:
>>> +		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
>>> +		break;
>>> +	case TYP_BNOBT:
>>> +		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
>>> +		break;
>>> +	case TYP_CNTBT:
>>> +		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
>>> +		break;
>>> +	case TYP_INOBT:
>>> +		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
>>> +		break;
>>> +	case TYP_FINOBT:
>>> +		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
>>> +		break;
>>> +	case TYP_RMAPBT:
>>> +		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
>>> +		break;
>>> +	case TYP_REFCBT:
>>> +		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
>>> +		break;
>>> +	default:
>>> +		ASSERT(0);
>>> +	}
>>
>> 	ASSERT(magic);
>>
>> we'd better have that by now, yes?
> 
> Yes.
> 
>> Or could we hit the RMAP/REFC types w/o crc set?
> 
> In theory, no, because xfs_db sets up a different type profile for the
> !crc case, and that type profile excludes TYP_RMAPBT/TYP_REFCBT.
> 
>>  I guess then the caller ASSERTs anyway?
> 
> <shrug>
> 
>>> +
>>> +	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
>>> +		be32_to_cpu((bb)->bb_magic),
>>> +		iocur_top->typ->name);
>>
>>
>> 	goto again;
>>
>> to avoid the cut & paste of the loop below?  But maybe that's uglier.
> 
> Mostly a matter of taste, I think.  If the machinery was more complex
> I'd argue for a backwards goto to avoid having to maintain two identical
> loops, but this is pretty simple.
> 
>>> +
>>> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
>>> +		if (magic == btp->magic)
>>>  			return btp;
>>> -		btp++;
>>> -	} while (btp->magic != 0);
>>> +	}
>>>  
>>>  	return NULL;
>>>  }
>>> @@ -193,7 +234,6 @@ btblock_key_offset(
>>>  	int			offset;
>>>  
>>>  	ASSERT(startoff == 0);
>>> -	ASSERT(block->bb_level != 0);
>>
>> Help me out, why are these now removed?
> 
> /me doesn't remember, maybe they should just go away.
> 
>> -Eric
>>
>>>  
>>>  	offset = bt->block_len + (idx - 1) * bt->key_len;
>>>  	return bitize(offset);
>>> @@ -214,7 +254,6 @@ btblock_ptr_offset(
>>>  	int			maxrecs;
>>>  
>>>  	ASSERT(startoff == 0);
>>> -	ASSERT(block->bb_level != 0);
>>>  
>>>  	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
>>>  	offset = bt->block_len +
>>> @@ -238,7 +277,6 @@ btblock_rec_offset(
>>>  	int			offset;
>>>  
>>>  	ASSERT(startoff == 0);
>>> -	ASSERT(block->bb_level == 0);
>>>  
>>>  	offset = bt->block_len + (idx - 1) * bt->rec_len;
>>>  	return bitize(offset);
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-26 18:41         ` Eric Sandeen
@ 2017-04-26 18:43           ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 18:43 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Wed, Apr 26, 2017 at 01:41:26PM -0500, Eric Sandeen wrote:
> On 4/26/17 1:25 PM, Darrick J. Wong wrote:
> > On Wed, Apr 26, 2017 at 12:48:48PM -0500, Eric Sandeen wrote:
> >> On 4/10/17 7:20 PM, Darrick J. Wong wrote:
> >>> From: Darrick J. Wong <darrick.wong@oracle.com>
> >>>
> >>> The function block_to_bt plays an integral role in determining the btree
> >>> geometry of a block that we want to manipulate with the debugger.
> >>> Normally we use the block magic to find the geometry profile, but if the
> >>> magic is bad we'll never find it and return NULL.  The callers of this
> >>> function do not check for NULL and crash.
> >>>
> >>> Therefore, if we can't find a geometry profile matching the magic
> >>> number, use the iocursor type to guess the profile and scowl about that
> >>> to stdout.  This makes it so that even with a corrupt magic we can try
> >>> to print the fields instead of crashing the debugger.
> >>>
> >>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> >>
> >> Makes sense generally, minor things below.
> >>
> >>> ---
> >>> v2: be less macro-happy and only evaluate hascrc once
> >>> v3: braces around the for loop body
> >>> ---
> >>>  db/btblock.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
> >>>  1 file changed, 46 insertions(+), 8 deletions(-)
> >>>
> >>> diff --git a/db/btblock.c b/db/btblock.c
> >>> index 835a5f0..b819fa5 100644
> >>> --- a/db/btblock.c
> >>> +++ b/db/btblock.c
> >>> @@ -25,6 +25,8 @@
> >>>  #include "print.h"
> >>>  #include "bit.h"
> >>>  #include "init.h"
> >>> +#include "io.h"
> >>> +#include "output.h"
> >>>  
> >>>  /*
> >>>   * Definition of the possible btree block layouts.
> >>> @@ -122,13 +124,52 @@ static struct xfs_db_btree *
> >>
> >> urgh:
> >>
> >> /*
> >>  * Find the right block defintion for a given ondisk block.
> >>  *
> >>  * We use the least significant bit of the magic number as index into
> >>  * the array of block defintions.
> >>
> >> (nope, we don't, I can remove that on commit...)
> > 
> > Oops.  Should've nuked that comment from the start.
> 
> Ok, thanks for the replies.
> 
> I'll:
> 
> 1) Fix up comments
> 2) /Not/ do backwards-jumping-gotos, fair point.
> 3) add the magic ASSERT
> 4) nuke the other ASSERTs
> 
> on commit? or do you want to resend ;)

Fix it up, send it out one more time to the list?

--D

> 
> > 
> >>  */
> >> static struct xfs_db_btree *
> >>
> >>>  block_to_bt(
> >>>  	struct xfs_btree_block	*bb)
> >>>  {
> >>> -	struct xfs_db_btree *btp = &btrees[0];
> >>> +	struct xfs_db_btree	*btp;
> >>> +	uint32_t		magic;
> >>> +	bool			crc;
> >>>  
> >>> -	do {
> >>> -		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
> >>> +	magic = be32_to_cpu((bb)->bb_magic);
> >>
> >> maybe -
> >>
> >> again:
> > 
> > Eww, backwards jumping gotos :)
> > 
> > I guess that works so long as you're sure we can't accidentally jump
> > backwards with an unrecognized magic and thus end up in an infinite
> > loop.
> > 
> >>> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> >>> +		if (magic == btp->magic)
> >>> +			return btp;
> >>> +	}
> >>
> >> 	/* Magic is invalid/unknown.  Guess based on iocur type */
> >>
> >>> +	crc = xfs_sb_version_hascrc(&mp->m_sb);
> >>
> >> Bah, wish we could use something like:
> >>
> >> 	magic = xfs_magics[crc][btnum];
> >>
> >> but that's static to libxfs/xfs_btree.c and I guess btnum != typnm.
> >> Because of course.
> >>
> >> (btnum = xfs_typnm_to_btnum[iocur_top->typ->typnm]; ? :) Ok I'll
> >> drop it...)
> > 
> > :D
> > 
> >>> +	switch (iocur_top->typ->typnm) {
> >>> +	case TYP_BMAPBTA:
> >>> +	case TYP_BMAPBTD:
> >>> +		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
> >>> +		break;
> >>> +	case TYP_BNOBT:
> >>> +		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
> >>> +		break;
> >>> +	case TYP_CNTBT:
> >>> +		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
> >>> +		break;
> >>> +	case TYP_INOBT:
> >>> +		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
> >>> +		break;
> >>> +	case TYP_FINOBT:
> >>> +		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
> >>> +		break;
> >>> +	case TYP_RMAPBT:
> >>> +		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
> >>> +		break;
> >>> +	case TYP_REFCBT:
> >>> +		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
> >>> +		break;
> >>> +	default:
> >>> +		ASSERT(0);
> >>> +	}
> >>
> >> 	ASSERT(magic);
> >>
> >> we'd better have that by now, yes?
> > 
> > Yes.
> > 
> >> Or could we hit the RMAP/REFC types w/o crc set?
> > 
> > In theory, no, because xfs_db sets up a different type profile for the
> > !crc case, and that type profile excludes TYP_RMAPBT/TYP_REFCBT.
> > 
> >>  I guess then the caller ASSERTs anyway?
> > 
> > <shrug>
> > 
> >>> +
> >>> +	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
> >>> +		be32_to_cpu((bb)->bb_magic),
> >>> +		iocur_top->typ->name);
> >>
> >>
> >> 	goto again;
> >>
> >> to avoid the cut & paste of the loop below?  But maybe that's uglier.
> > 
> > Mostly a matter of taste, I think.  If the machinery was more complex
> > I'd argue for a backwards goto to avoid having to maintain two identical
> > loops, but this is pretty simple.
> > 
> >>> +
> >>> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> >>> +		if (magic == btp->magic)
> >>>  			return btp;
> >>> -		btp++;
> >>> -	} while (btp->magic != 0);
> >>> +	}
> >>>  
> >>>  	return NULL;
> >>>  }
> >>> @@ -193,7 +234,6 @@ btblock_key_offset(
> >>>  	int			offset;
> >>>  
> >>>  	ASSERT(startoff == 0);
> >>> -	ASSERT(block->bb_level != 0);
> >>
> >> Help me out, why are these now removed?
> > 
> > /me doesn't remember, maybe they should just go away.
> > 
> >> -Eric
> >>
> >>>  
> >>>  	offset = bt->block_len + (idx - 1) * bt->key_len;
> >>>  	return bitize(offset);
> >>> @@ -214,7 +254,6 @@ btblock_ptr_offset(
> >>>  	int			maxrecs;
> >>>  
> >>>  	ASSERT(startoff == 0);
> >>> -	ASSERT(block->bb_level != 0);
> >>>  
> >>>  	maxrecs = btblock_maxrecs(bt, mp->m_sb.sb_blocksize);
> >>>  	offset = bt->block_len +
> >>> @@ -238,7 +277,6 @@ btblock_rec_offset(
> >>>  	int			offset;
> >>>  
> >>>  	ASSERT(startoff == 0);
> >>> -	ASSERT(block->bb_level == 0);
> >>>  
> >>>  	offset = bt->block_len + (idx - 1) * bt->rec_len;
> >>>  	return bitize(offset);
> >>> --
> >>> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> >>> the body of a message to majordomo@vger.kernel.org
> >>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >>>
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> >> the body of a message to majordomo@vger.kernel.org
> >> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v3 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-11  0:20   ` [PATCH v2 " Darrick J. Wong
  2017-04-26 17:48     ` Eric Sandeen
@ 2017-04-26 18:47     ` Eric Sandeen
  2017-04-26 19:11       ` Darrick J. Wong
  1 sibling, 1 reply; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 18:47 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

The function block_to_bt plays an integral role in determining the btree
geometry of a block that we want to manipulate with the debugger.
Normally we use the block magic to find the geometry profile, but if the
magic is bad we'll never find it and return NULL.  The callers of this
function do not check for NULL and crash.

Therefore, if we can't find a geometry profile matching the magic
number, use the iocursor type to guess the profile and scowl about that
to stdout.  This makes it so that even with a corrupt magic we can try
to print the fields instead of crashing the debugger.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: be less macro-happy and only evaluate hascrc once
v3: braces around the for loop body
v4: proposed maintainer changes from eric:
    fix comments, add magic assert, keep other asserts which
    were removed for unknown reasons...
---

diff --git a/db/btblock.c b/db/btblock.c
index 835a5f0..b7eacb5 100644
--- a/db/btblock.c
+++ b/db/btblock.c
@@ -25,6 +25,8 @@
 #include "print.h"
 #include "bit.h"
 #include "init.h"
+#include "io.h"
+#include "output.h"
 
 /*
  * Definition of the possible btree block layouts.
@@ -113,22 +115,60 @@ struct xfs_db_btree {
 };
 
 /*
- * Find the right block defintion for a given ondisk block.
- *
- * We use the least significant bit of the magic number as index into
- * the array of block defintions.
+ * Find the right block definition for a given ondisk block.
  */
 static struct xfs_db_btree *
 block_to_bt(
 	struct xfs_btree_block	*bb)
 {
-	struct xfs_db_btree *btp = &btrees[0];
+	struct xfs_db_btree	*btp;
+	uint32_t		magic;
+	bool			crc;
 
-	do {
-		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
+	magic = be32_to_cpu((bb)->bb_magic);
+	for (btp = &btrees[0]; btp->magic != 0; btp++) {
+		if (magic == btp->magic)
+			return btp;
+	}
+
+	/* Magic is invalid/unknown.  Guess based on iocur type */
+	crc = xfs_sb_version_hascrc(&mp->m_sb);
+	switch (iocur_top->typ->typnm) {
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
+		break;
+	case TYP_BNOBT:
+		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
+		break;
+	case TYP_CNTBT:
+		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
+		break;
+	case TYP_INOBT:
+		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
+		break;
+	case TYP_FINOBT:
+		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
+		break;
+	case TYP_RMAPBT:
+		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
+		break;
+	case TYP_REFCBT:
+		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
+		break;
+	default:
+		ASSERT(0);
+	}
+
+	ASSERT(magic);
+	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
+		be32_to_cpu((bb)->bb_magic),
+		iocur_top->typ->name);
+
+	for (btp = &btrees[0]; btp->magic != 0; btp++) {
+		if (magic == btp->magic)
 			return btp;
-		btp++;
-	} while (btp->magic != 0);
+	}
 
 	return NULL;
 }


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v3 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
  2017-04-26 18:47     ` [PATCH v3 " Eric Sandeen
@ 2017-04-26 19:11       ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 19:11 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Wed, Apr 26, 2017 at 01:47:47PM -0500, Eric Sandeen wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> The function block_to_bt plays an integral role in determining the btree
> geometry of a block that we want to manipulate with the debugger.
> Normally we use the block magic to find the geometry profile, but if the
> magic is bad we'll never find it and return NULL.  The callers of this
> function do not check for NULL and crash.
> 
> Therefore, if we can't find a geometry profile matching the magic
> number, use the iocursor type to guess the profile and scowl about that
> to stdout.  This makes it so that even with a corrupt magic we can try
> to print the fields instead of crashing the debugger.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v2: be less macro-happy and only evaluate hascrc once
> v3: braces around the for loop body
> v4: proposed maintainer changes from eric:
>     fix comments, add magic assert, keep other asserts which
>     were removed for unknown reasons...

Needs a S-o-b: Eric Sandeen for the changes you made, but otherwise,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
> 
> diff --git a/db/btblock.c b/db/btblock.c
> index 835a5f0..b7eacb5 100644
> --- a/db/btblock.c
> +++ b/db/btblock.c
> @@ -25,6 +25,8 @@
>  #include "print.h"
>  #include "bit.h"
>  #include "init.h"
> +#include "io.h"
> +#include "output.h"
>  
>  /*
>   * Definition of the possible btree block layouts.
> @@ -113,22 +115,60 @@ struct xfs_db_btree {
>  };
>  
>  /*
> - * Find the right block defintion for a given ondisk block.
> - *
> - * We use the least significant bit of the magic number as index into
> - * the array of block defintions.
> + * Find the right block definition for a given ondisk block.
>   */
>  static struct xfs_db_btree *
>  block_to_bt(
>  	struct xfs_btree_block	*bb)
>  {
> -	struct xfs_db_btree *btp = &btrees[0];
> +	struct xfs_db_btree	*btp;
> +	uint32_t		magic;
> +	bool			crc;
>  
> -	do {
> -		if (be32_to_cpu((bb)->bb_magic) == btp->magic)
> +	magic = be32_to_cpu((bb)->bb_magic);
> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> +		if (magic == btp->magic)
> +			return btp;
> +	}
> +
> +	/* Magic is invalid/unknown.  Guess based on iocur type */
> +	crc = xfs_sb_version_hascrc(&mp->m_sb);
> +	switch (iocur_top->typ->typnm) {
> +	case TYP_BMAPBTA:
> +	case TYP_BMAPBTD:
> +		magic = crc ? XFS_BMAP_CRC_MAGIC : XFS_BMAP_MAGIC;
> +		break;
> +	case TYP_BNOBT:
> +		magic = crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
> +		break;
> +	case TYP_CNTBT:
> +		magic = crc ? XFS_ABTC_CRC_MAGIC : XFS_ABTC_MAGIC;
> +		break;
> +	case TYP_INOBT:
> +		magic = crc ? XFS_IBT_CRC_MAGIC : XFS_IBT_MAGIC;
> +		break;
> +	case TYP_FINOBT:
> +		magic = crc ? XFS_FIBT_CRC_MAGIC : XFS_FIBT_MAGIC;
> +		break;
> +	case TYP_RMAPBT:
> +		magic = crc ? XFS_RMAP_CRC_MAGIC : 0;
> +		break;
> +	case TYP_REFCBT:
> +		magic = crc ? XFS_REFC_CRC_MAGIC : 0;
> +		break;
> +	default:
> +		ASSERT(0);
> +	}
> +
> +	ASSERT(magic);
> +	dbprintf(_("Bad btree magic 0x%x; coercing to %s.\n"),
> +		be32_to_cpu((bb)->bb_magic),
> +		iocur_top->typ->name);
> +
> +	for (btp = &btrees[0]; btp->magic != 0; btp++) {
> +		if (magic == btp->magic)
>  			return btp;
> -		btp++;
> -	} while (btp->magic != 0);
> +	}
>  
>  	return NULL;
>  }
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-10 22:48 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
@ 2017-04-26 19:50   ` Eric Sandeen
  2017-04-26 20:27     ` Darrick J. Wong
  2017-04-26 20:36   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 19:50 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/10/17 5:48 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Introduce a new 'btdump' command that can print the contents of all
> blocks of any metadata subtree in the filesystem.  This enables
> developers and forensic analyst to view a metadata structure without
> having to navigate the btree manually.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v2: put the btdump_init declaration in command.h to avoid lots of silly
> little header files
> ---
>  db/Makefile  |    2 
>  db/btdump.c  |  271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  db/command.c |    1 
>  db/command.h |    2 

man/man8/xfs_db.8 ?

>  4 files changed, 275 insertions(+), 1 deletion(-)
>  create mode 100644 db/btdump.c
> 
> 
> diff --git a/db/Makefile b/db/Makefile
> index cdc0b99..2c7679c 100644
> --- a/db/Makefile
> +++ b/db/Makefile
> @@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs
>  LTCOMMAND = xfs_db
>  
>  HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
> -	btblock.h bmroot.h check.h command.h convert.h crc.h debug.h \
> +	btblock.h btdump.c bmroot.h check.h command.h convert.h crc.h debug.h \
                  ^^^^^^^^

That's ... not an HFILE :)

>  	dir2.h dir2sf.h dquot.h echo.h faddr.h field.h \
>  	flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \
>  	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \

...

CFILES = $(HFILES:.h=.c)

Oh.  Urgh.  Yuk.  o_O  /o\

How about:

CFILES = btdump.c $(HFILES:.h=.c)

maybe?

(I have another patch to remove all the other silly little headers, so maybe
we can start going in that direction for new functions)


> diff --git a/db/btdump.c b/db/btdump.c
> new file mode 100644
> index 0000000..9b9fc2c
> --- /dev/null
> +++ b/db/btdump.c
> @@ -0,0 +1,271 @@
> +/*
> + * Copyright (C) 2017 Oracle.  All Rights Reserved.
> + *
> + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> + */
> +#include "libxfs.h"
> +#include "command.h"
> +#include "output.h"
> +#include "init.h"
> +#include "io.h"
> +#include "type.h"
> +#include "input.h"
> +
> +static void
> +btdump_help(void)
> +{
> +	dbprintf(_(
> +"\n"
> +" 'btdump' dumps the btree rooted at the current io cursor location.\n"

Note that the current type must be set to the proper btree?
(I know a guy who forgot to do that) Or could/should it be automagic?

> +" In the case of an inode, the data fork bmbt is displayed.\n"

"In the case of an inode, the data fork btree root is automatically
selected, unless the attribute btree root is selected with -a."

> +" Options:\n"
> +"   -a -- Display the extended attribute bmbt.\n"

-a -- Display an inode's extended attribute btree.

> +"   -i -- Print internal btree nodes.\n"
> +"\n"
> +));
> +
> +}
> +
> +static int
> +eval(
> +	const char	*fmt, ...)
> +{
> +	va_list		ap;
> +	char		buf[PATH_MAX];
> +	char		**v;
> +	int		c;
> +	int		ret;
> +
> +	va_start(ap, fmt);
> +	vsnprintf(buf, sizeof(buf), fmt, ap);
> +	va_end(ap);
> +
> +	v = breakline(buf, &c);
> +	ret = command(c, v);
> +	free(v);
> +	return ret;
> +}

w00t

> +
> +static bool
> +btblock_has_rightsib(
> +	struct xfs_btree_block	*block,
> +	bool			long_format)
> +{
> +	if (long_format)
> +		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
> +	return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
> +}
> +
> +static int
> +dump_btlevel(
> +	int			level,
> +	bool			long_format)
> +{
> +	xfs_daddr_t		orig_daddr = iocur_top->bb;
> +	xfs_daddr_t		last_daddr;
> +	unsigned int		nr;
> +	int			ret;
> +
> +	ret = eval("push");
> +	if (ret)
> +		return ret;
> +
> +	nr = 1;
> +	do {
> +		last_daddr = iocur_top->bb;
> +		dbprintf(_("%s level %u block %u daddr %llu\n"),
> +			 iocur_top->typ->name, level, nr, last_daddr);
> +		if (level > 0) {
> +			ret = eval("print keys");
> +			if (ret)
> +				goto err;
> +			ret = eval("print ptrs");
> +		} else {
> +			ret = eval("print recs");
> +		}
> +		if (ret)
> +			goto err;
> +		if (btblock_has_rightsib(iocur_top->data, long_format)) {
> +			ret = eval("addr rightsib");
> +			if (ret)
> +				goto err;
> +		}
> +		nr++;
> +	} while (iocur_top->bb != orig_daddr && iocur_top->bb != last_daddr);
> +
> +	ret = eval("pop");
> +	return ret;
> +err:
> +	eval("pop");
> +	return ret;
> +}
> +
> +static int
> +dump_btree(
> +	bool		dump_node_blocks,
> +	bool		long_format)
> +{
> +	xfs_daddr_t	orig_daddr = iocur_top->bb;
> +	xfs_daddr_t	last_daddr;
> +	int		level;
> +	int		ret;
> +
> +	ret = eval("push");
> +	if (ret)
> +		return ret;
> +
> +	cur_agno = XFS_FSB_TO_AGNO(mp, XFS_DADDR_TO_FSB(mp, iocur_top->bb));
> +	level = xfs_btree_get_level(iocur_top->data);
> +	do {
> +		last_daddr = iocur_top->bb;
> +		if (level > 0) {
> +			if (dump_node_blocks) {
> +				ret = dump_btlevel(level, long_format);
> +				if (ret)
> +					goto err;
> +			}
> +			ret = eval("addr ptrs[1]");
> +		} else {
> +			ret = dump_btlevel(level, long_format);
> +		}
> +		if (ret)
> +			goto err;
> +		level--;
> +	} while (level >= 0 &&
> +		 iocur_top->bb != orig_daddr &&
> +		 iocur_top->bb != last_daddr);
> +
> +	ret = eval("pop");
> +	return ret;
> +err:
> +	eval("pop");
> +	return ret;
> +}
> +
> +static int
> +dump_inode(
> +	bool			dump_node_blocks,
> +	bool			attrfork)
> +{
> +	char			*prefix;
> +	struct xfs_dinode	*dip;
> +	int			ret;
> +
> +	if (attrfork)
> +		prefix = "a.bmbt";
> +	else if (xfs_sb_version_hascrc(&mp->m_sb))
> +		prefix = "u3.bmbt";
> +	else
> +		prefix = "u.bmbt";
> +
> +	dip = iocur_top->data;
> +	if (attrfork) {
> +		if (!dip->di_anextents ||
> +		    dip->di_aformat != XFS_DINODE_FMT_BTREE)

			dbprintf(_("attr fork not in btree format\n"));

> +			return 0;
> +	} else {
> +		if (!dip->di_nextents ||
> +		    dip->di_format != XFS_DINODE_FMT_BTREE)

			dbprintf(_("data fork not in btree format\n"));

> +			return 0;
> +	}
> +
> +	ret = eval("push");
> +	if (ret)
> +		return ret;
> +
> +	if (dump_node_blocks) {
> +		ret = eval("print %s.keys", prefix);
> +		if (ret)
> +			goto err;
> +		ret = eval("print %s.ptrs", prefix);
> +		if (ret)
> +			goto err;
> +	}
> +
> +	ret = eval("addr %s.ptrs[1]", prefix);
> +	if (ret)
> +		goto err;
> +
> +	ret = dump_btree(dump_node_blocks, true);

not a huge fan of the magic "true / false" options in callers for
dump_btree, though it's not a dealbreaker.

> +	if (ret)
> +		goto err;
> +
> +	ret = eval("pop");
> +	return ret;
> +err:
> +	eval("pop");
> +	return ret;
> +}
> +
> +static int
> +btdump_f(
> +	int		argc,
> +	char		**argv)
> +{
> +	bool		aflag = false;
> +	bool		iflag = false;
> +	int		c;
> +
> +	if (cur_typ == NULL) {
> +		dbprintf(_("no current type\n"));
> +		return 0;
> +	}
> +	while ((c = getopt(argc, argv, "ai")) != EOF) {
> +		switch (c) {
> +		case 'a':
> +			aflag = true;
> +			break;
> +		case 'i':
> +			iflag = true;
> +			break;
> +		default:
> +			dbprintf(_("bad option for btdump command\n"));
> +			return 0;
> +		}
> +	}

		if (optind != argc) {
			dbprintf(_("bad options for btdump command\n"));
			return 0;
		}

(this catches "btdump foo")

> +	if (aflag && cur_typ->typnm != TYP_INODE) {
> +		dbprintf(_("attrfork flag doesn't apply here\n"));
> +		return 0;
> +	}
> +	switch (cur_typ->typnm) {
> +	case TYP_BNOBT:
> +	case TYP_CNTBT:
> +	case TYP_INOBT:
> +	case TYP_FINOBT:
> +	case TYP_RMAPBT:
> +	case TYP_REFCBT:
> +		return dump_btree(iflag, false);
> +	case TYP_BMAPBTA:
> +	case TYP_BMAPBTD:
> +		return dump_btree(iflag, true);
> +	case TYP_INODE:
> +		return dump_inode(iflag, aflag);
> +	default:
> +		dbprintf(_("Not a btree.\n"));

dbprintf(_("Type \"%s\" is not a btree type.\n"), cur_typ->name);

?

> +		return 0;
> +	}
> +}
> +
> +static const cmdinfo_t btdump_cmd =
> +	{ "btdump", "b", btdump_f, 0, 1, 0, "",
> +	  N_("dump btree"), btdump_help };

args (not "") here please, so that bare "xfs_db> help" gives you the
proper synopsis as do other commands:

xfs_db> help
...
blockuse [-n] [-c blockcount] -- print usage for current block(s)
bmap [-ad] [block [len]] -- show block map for current file
btdump  -- dump btree
...

and arg max is wrong, so we can't:

xfs_db> btdump -i -a
bad argument count 2 to btdump, expected between 0 and 1 arguments

but we can:

xfs_db> btdump -ia
xfs_db> 

(named structure members ala db/logformat.c would be nice, but
I guess most other db commands don't use that today...)

> +
> +void
> +btdump_init(void)
> +{
> +	add_command(&btdump_cmd);
> +}
> diff --git a/db/command.c b/db/command.c
> index 3d7cfd7..c90c85c 100644
> --- a/db/command.c
> +++ b/db/command.c
> @@ -124,6 +124,7 @@ init_commands(void)
>  	attrset_init();
>  	block_init();
>  	bmap_init();
> +	btdump_init();
>  	check_init();
>  	convert_init();
>  	crc_init();
> diff --git a/db/command.h b/db/command.h
> index 4d4807d..9b4ed2d 100644
> --- a/db/command.h
> +++ b/db/command.h
> @@ -39,3 +39,5 @@ extern void		add_command(const cmdinfo_t *ci);
>  extern int		command(int argc, char **argv);
>  extern const cmdinfo_t	*find_command(const char *cmd);
>  extern void		init_commands(void);
> +
> +extern void		btdump_init(void);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-26 19:50   ` Eric Sandeen
@ 2017-04-26 20:27     ` Darrick J. Wong
  0 siblings, 0 replies; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 20:27 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Wed, Apr 26, 2017 at 02:50:45PM -0500, Eric Sandeen wrote:
> On 4/10/17 5:48 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Introduce a new 'btdump' command that can print the contents of all
> > blocks of any metadata subtree in the filesystem.  This enables
> > developers and forensic analyst to view a metadata structure without
> > having to navigate the btree manually.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > v2: put the btdump_init declaration in command.h to avoid lots of silly
> > little header files
> > ---
> >  db/Makefile  |    2 
> >  db/btdump.c  |  271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  db/command.c |    1 
> >  db/command.h |    2 
> 
> man/man8/xfs_db.8 ?

Oops, forgot that.

> >  4 files changed, 275 insertions(+), 1 deletion(-)
> >  create mode 100644 db/btdump.c
> > 
> > 
> > diff --git a/db/Makefile b/db/Makefile
> > index cdc0b99..2c7679c 100644
> > --- a/db/Makefile
> > +++ b/db/Makefile
> > @@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs
> >  LTCOMMAND = xfs_db
> >  
> >  HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
> > -	btblock.h bmroot.h check.h command.h convert.h crc.h debug.h \
> > +	btblock.h btdump.c bmroot.h check.h command.h convert.h crc.h debug.h \
>                   ^^^^^^^^
> 
> That's ... not an HFILE :)
> 
> >  	dir2.h dir2sf.h dquot.h echo.h faddr.h field.h \
> >  	flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \
> >  	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
> 
> ...
> 
> CFILES = $(HFILES:.h=.c)
> 
> Oh.  Urgh.  Yuk.  o_O  /o\
> 
> How about:
> 
> CFILES = btdump.c $(HFILES:.h=.c)
> 
> maybe?

Ok, ok. :)

> (I have another patch to remove all the other silly little headers, so maybe
> we can start going in that direction for new functions)
> 
> 
> > diff --git a/db/btdump.c b/db/btdump.c
> > new file mode 100644
> > index 0000000..9b9fc2c
> > --- /dev/null
> > +++ b/db/btdump.c
> > @@ -0,0 +1,271 @@
> > +/*
> > + * Copyright (C) 2017 Oracle.  All Rights Reserved.
> > + *
> > + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * as published by the Free Software Foundation; either version 2
> > + * of the License, or (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it would be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write the Free Software Foundation,
> > + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> > + */
> > +#include "libxfs.h"
> > +#include "command.h"
> > +#include "output.h"
> > +#include "init.h"
> > +#include "io.h"
> > +#include "type.h"
> > +#include "input.h"
> > +
> > +static void
> > +btdump_help(void)
> > +{
> > +	dbprintf(_(
> > +"\n"
> > +" 'btdump' dumps the btree rooted at the current io cursor location.\n"
> 
> Note that the current type must be set to the proper btree?
> (I know a guy who forgot to do that) Or could/should it be automagic?
> 
> > +" In the case of an inode, the data fork bmbt is displayed.\n"
> 
> "In the case of an inode, the data fork btree root is automatically
> selected, unless the attribute btree root is selected with -a."
> 
> > +" Options:\n"
> > +"   -a -- Display the extended attribute bmbt.\n"
> 
> -a -- Display an inode's extended attribute btree.

"...extended attribute fork btree.", because the xattr key/value store
is itself a btree.

"If the cursor points to a btree block, 'btdump' dumps the btree
downward from that block.  If the cursor points to an inode, the data
fork btree root is selected by default.

Options:
  -a -- Display an inode's extended attribute fork btree.
  -i -- Print internal btree nodes."

(Note that if the cursor points at an intermediate node, btdump prints
the subtree rooted at that node.)

> > +"   -i -- Print internal btree nodes.\n"
> > +"\n"
> > +));
> > +
> > +}
> > +
> > +static int
> > +eval(
> > +	const char	*fmt, ...)
> > +{
> > +	va_list		ap;
> > +	char		buf[PATH_MAX];
> > +	char		**v;
> > +	int		c;
> > +	int		ret;
> > +
> > +	va_start(ap, fmt);
> > +	vsnprintf(buf, sizeof(buf), fmt, ap);
> > +	va_end(ap);
> > +
> > +	v = breakline(buf, &c);
> > +	ret = command(c, v);
> > +	free(v);
> > +	return ret;
> > +}
> 
> w00t
> 
> > +
> > +static bool
> > +btblock_has_rightsib(
> > +	struct xfs_btree_block	*block,
> > +	bool			long_format)
> > +{
> > +	if (long_format)
> > +		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
> > +	return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
> > +}
> > +
> > +static int
> > +dump_btlevel(
> > +	int			level,
> > +	bool			long_format)
> > +{
> > +	xfs_daddr_t		orig_daddr = iocur_top->bb;
> > +	xfs_daddr_t		last_daddr;
> > +	unsigned int		nr;
> > +	int			ret;
> > +
> > +	ret = eval("push");
> > +	if (ret)
> > +		return ret;
> > +
> > +	nr = 1;
> > +	do {
> > +		last_daddr = iocur_top->bb;
> > +		dbprintf(_("%s level %u block %u daddr %llu\n"),
> > +			 iocur_top->typ->name, level, nr, last_daddr);
> > +		if (level > 0) {
> > +			ret = eval("print keys");
> > +			if (ret)
> > +				goto err;
> > +			ret = eval("print ptrs");
> > +		} else {
> > +			ret = eval("print recs");
> > +		}
> > +		if (ret)
> > +			goto err;
> > +		if (btblock_has_rightsib(iocur_top->data, long_format)) {
> > +			ret = eval("addr rightsib");
> > +			if (ret)
> > +				goto err;
> > +		}
> > +		nr++;
> > +	} while (iocur_top->bb != orig_daddr && iocur_top->bb != last_daddr);
> > +
> > +	ret = eval("pop");
> > +	return ret;
> > +err:
> > +	eval("pop");
> > +	return ret;
> > +}
> > +
> > +static int
> > +dump_btree(
> > +	bool		dump_node_blocks,
> > +	bool		long_format)
> > +{
> > +	xfs_daddr_t	orig_daddr = iocur_top->bb;
> > +	xfs_daddr_t	last_daddr;
> > +	int		level;
> > +	int		ret;
> > +
> > +	ret = eval("push");
> > +	if (ret)
> > +		return ret;
> > +
> > +	cur_agno = XFS_FSB_TO_AGNO(mp, XFS_DADDR_TO_FSB(mp, iocur_top->bb));
> > +	level = xfs_btree_get_level(iocur_top->data);
> > +	do {
> > +		last_daddr = iocur_top->bb;
> > +		if (level > 0) {
> > +			if (dump_node_blocks) {
> > +				ret = dump_btlevel(level, long_format);
> > +				if (ret)
> > +					goto err;
> > +			}
> > +			ret = eval("addr ptrs[1]");
> > +		} else {
> > +			ret = dump_btlevel(level, long_format);
> > +		}
> > +		if (ret)
> > +			goto err;
> > +		level--;
> > +	} while (level >= 0 &&
> > +		 iocur_top->bb != orig_daddr &&
> > +		 iocur_top->bb != last_daddr);
> > +
> > +	ret = eval("pop");
> > +	return ret;
> > +err:
> > +	eval("pop");
> > +	return ret;
> > +}
> > +
> > +static int
> > +dump_inode(
> > +	bool			dump_node_blocks,
> > +	bool			attrfork)
> > +{
> > +	char			*prefix;
> > +	struct xfs_dinode	*dip;
> > +	int			ret;
> > +
> > +	if (attrfork)
> > +		prefix = "a.bmbt";
> > +	else if (xfs_sb_version_hascrc(&mp->m_sb))
> > +		prefix = "u3.bmbt";
> > +	else
> > +		prefix = "u.bmbt";
> > +
> > +	dip = iocur_top->data;
> > +	if (attrfork) {
> > +		if (!dip->di_anextents ||
> > +		    dip->di_aformat != XFS_DINODE_FMT_BTREE)
> 
> 			dbprintf(_("attr fork not in btree format\n"));

OK.

> > +			return 0;
> > +	} else {
> > +		if (!dip->di_nextents ||
> > +		    dip->di_format != XFS_DINODE_FMT_BTREE)
> 
> 			dbprintf(_("data fork not in btree format\n"));

Ok.

> > +			return 0;
> > +	}
> > +
> > +	ret = eval("push");
> > +	if (ret)
> > +		return ret;
> > +
> > +	if (dump_node_blocks) {
> > +		ret = eval("print %s.keys", prefix);
> > +		if (ret)
> > +			goto err;
> > +		ret = eval("print %s.ptrs", prefix);
> > +		if (ret)
> > +			goto err;
> > +	}
> > +
> > +	ret = eval("addr %s.ptrs[1]", prefix);
> > +	if (ret)
> > +		goto err;
> > +
> > +	ret = dump_btree(dump_node_blocks, true);
> 
> not a huge fan of the magic "true / false" options in callers for
> dump_btree, though it's not a dealbreaker.

So long as I'm reworking it I might as well just introduce
dump_btree_{short,long} so it's clearer what we're doing.

> 
> > +	if (ret)
> > +		goto err;
> > +
> > +	ret = eval("pop");
> > +	return ret;
> > +err:
> > +	eval("pop");
> > +	return ret;
> > +}
> > +
> > +static int
> > +btdump_f(
> > +	int		argc,
> > +	char		**argv)
> > +{
> > +	bool		aflag = false;
> > +	bool		iflag = false;
> > +	int		c;
> > +
> > +	if (cur_typ == NULL) {
> > +		dbprintf(_("no current type\n"));
> > +		return 0;
> > +	}
> > +	while ((c = getopt(argc, argv, "ai")) != EOF) {
> > +		switch (c) {
> > +		case 'a':
> > +			aflag = true;
> > +			break;
> > +		case 'i':
> > +			iflag = true;
> > +			break;
> > +		default:
> > +			dbprintf(_("bad option for btdump command\n"));
> > +			return 0;
> > +		}
> > +	}
> 
> 		if (optind != argc) {
> 			dbprintf(_("bad options for btdump command\n"));
> 			return 0;
> 		}
> 
> (this catches "btdump foo")

Ok.

> 
> > +	if (aflag && cur_typ->typnm != TYP_INODE) {
> > +		dbprintf(_("attrfork flag doesn't apply here\n"));
> > +		return 0;
> > +	}
> > +	switch (cur_typ->typnm) {
> > +	case TYP_BNOBT:
> > +	case TYP_CNTBT:
> > +	case TYP_INOBT:
> > +	case TYP_FINOBT:
> > +	case TYP_RMAPBT:
> > +	case TYP_REFCBT:
> > +		return dump_btree(iflag, false);
> > +	case TYP_BMAPBTA:
> > +	case TYP_BMAPBTD:
> > +		return dump_btree(iflag, true);
> > +	case TYP_INODE:
> > +		return dump_inode(iflag, aflag);
> > +	default:
> > +		dbprintf(_("Not a btree.\n"));
> 
> dbprintf(_("Type \"%s\" is not a btree type.\n"), cur_typ->name);

"...not a btree type or inode"

> 
> ?
> 
> > +		return 0;
> > +	}
> > +}
> > +
> > +static const cmdinfo_t btdump_cmd =
> > +	{ "btdump", "b", btdump_f, 0, 1, 0, "",
> > +	  N_("dump btree"), btdump_help };
> 
> args (not "") here please, so that bare "xfs_db> help" gives you the
> proper synopsis as do other commands:
> 
> xfs_db> help
> ...
> blockuse [-n] [-c blockcount] -- print usage for current block(s)
> bmap [-ad] [block [len]] -- show block map for current file
> btdump  -- dump btree

Ok, fixed.

> ...
> 
> and arg max is wrong, so we can't:
> 
> xfs_db> btdump -i -a
> bad argument count 2 to btdump, expected between 0 and 1 arguments

Fixed.

> but we can:
> 
> xfs_db> btdump -ia
> xfs_db> 
> 
> (named structure members ala db/logformat.c would be nice, but
> I guess most other db commands don't use that today...)

Yep.

--D
> 
> > +
> > +void
> > +btdump_init(void)
> > +{
> > +	add_command(&btdump_cmd);
> > +}
> > diff --git a/db/command.c b/db/command.c
> > index 3d7cfd7..c90c85c 100644
> > --- a/db/command.c
> > +++ b/db/command.c
> > @@ -124,6 +124,7 @@ init_commands(void)
> >  	attrset_init();
> >  	block_init();
> >  	bmap_init();
> > +	btdump_init();
> >  	check_init();
> >  	convert_init();
> >  	crc_init();
> > diff --git a/db/command.h b/db/command.h
> > index 4d4807d..9b4ed2d 100644
> > --- a/db/command.h
> > +++ b/db/command.h
> > @@ -39,3 +39,5 @@ extern void		add_command(const cmdinfo_t *ci);
> >  extern int		command(int argc, char **argv);
> >  extern const cmdinfo_t	*find_command(const char *cmd);
> >  extern void		init_commands(void);
> > +
> > +extern void		btdump_init(void);
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-10 22:48 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
  2017-04-26 19:50   ` Eric Sandeen
@ 2017-04-26 20:36   ` Darrick J. Wong
  2017-04-26 21:35     ` Eric Sandeen
  1 sibling, 1 reply; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-26 20:36 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

Introduce a new 'btdump' command that can print the contents of all
blocks of any metadata subtree in the filesystem.  This enables
developers and forensic analyst to view a metadata structure without
having to navigate the btree manually.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: various documentation and error message fixes
---
 db/Makefile       |    2 
 db/btdump.c       |  294 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 db/command.c      |    1 
 db/command.h      |    2 
 man/man8/xfs_db.8 |   13 ++
 5 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 db/btdump.c

diff --git a/db/Makefile b/db/Makefile
index cdc0b99..6618bff 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -13,7 +13,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
 	flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
 	 sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h
-CFILES = $(HFILES:.h=.c)
+CFILES = $(HFILES:.h=.c) btdump.c
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
 
 LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
diff --git a/db/btdump.c b/db/btdump.c
new file mode 100644
index 0000000..3b76e17
--- /dev/null
+++ b/db/btdump.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2017 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "output.h"
+#include "init.h"
+#include "io.h"
+#include "type.h"
+#include "input.h"
+
+static void
+btdump_help(void)
+{
+	dbprintf(_(
+"\n"
+" If the cursor points to a btree block, 'btdump' dumps the btree\n"
+" downward from that block.  If the cursor points to an inode,\n"
+" the data fork btree root is selected by default.\n"
+"\n"
+" Options:\n"
+"   -a -- Display an inode's extended attribute fork btree.\n"
+"   -i -- Print internal btree nodes.\n"
+"\n"
+));
+
+}
+
+static int
+eval(
+	const char	*fmt, ...)
+{
+	va_list		ap;
+	char		buf[PATH_MAX];
+	char		**v;
+	int		c;
+	int		ret;
+
+	va_start(ap, fmt);
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	va_end(ap);
+
+	v = breakline(buf, &c);
+	ret = command(c, v);
+	free(v);
+	return ret;
+}
+
+static bool
+btblock_has_rightsib(
+	struct xfs_btree_block	*block,
+	bool			long_format)
+{
+	if (long_format)
+		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
+	return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
+}
+
+static int
+dump_btlevel(
+	int			level,
+	bool			long_format)
+{
+	xfs_daddr_t		orig_daddr = iocur_top->bb;
+	xfs_daddr_t		last_daddr;
+	unsigned int		nr;
+	int			ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	nr = 1;
+	do {
+		last_daddr = iocur_top->bb;
+		dbprintf(_("%s level %u block %u daddr %llu\n"),
+			 iocur_top->typ->name, level, nr, last_daddr);
+		if (level > 0) {
+			ret = eval("print keys");
+			if (ret)
+				goto err;
+			ret = eval("print ptrs");
+		} else {
+			ret = eval("print recs");
+		}
+		if (ret)
+			goto err;
+		if (btblock_has_rightsib(iocur_top->data, long_format)) {
+			ret = eval("addr rightsib");
+			if (ret)
+				goto err;
+		}
+		nr++;
+	} while (iocur_top->bb != orig_daddr && iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+dump_btree(
+	bool		dump_node_blocks,
+	bool		long_format)
+{
+	xfs_daddr_t	orig_daddr = iocur_top->bb;
+	xfs_daddr_t	last_daddr;
+	int		level;
+	int		ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	cur_agno = XFS_FSB_TO_AGNO(mp, XFS_DADDR_TO_FSB(mp, iocur_top->bb));
+	level = xfs_btree_get_level(iocur_top->data);
+	do {
+		last_daddr = iocur_top->bb;
+		if (level > 0) {
+			if (dump_node_blocks) {
+				ret = dump_btlevel(level, long_format);
+				if (ret)
+					goto err;
+			}
+			ret = eval("addr ptrs[1]");
+		} else {
+			ret = dump_btlevel(level, long_format);
+		}
+		if (ret)
+			goto err;
+		level--;
+	} while (level >= 0 &&
+		 iocur_top->bb != orig_daddr &&
+		 iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static inline int dump_btree_short(bool dump_node_blocks)
+{
+	return dump_btree(dump_node_blocks, false);
+}
+
+static inline int dump_btree_long(bool dump_node_blocks)
+{
+	return dump_btree(dump_node_blocks, true);
+}
+
+static int
+dump_inode(
+	bool			dump_node_blocks,
+	bool			attrfork)
+{
+	char			*prefix;
+	struct xfs_dinode	*dip;
+	int			ret;
+
+	if (attrfork)
+		prefix = "a.bmbt";
+	else if (xfs_sb_version_hascrc(&mp->m_sb))
+		prefix = "u3.bmbt";
+	else
+		prefix = "u.bmbt";
+
+	dip = iocur_top->data;
+	if (attrfork) {
+		if (!dip->di_anextents ||
+		    dip->di_aformat != XFS_DINODE_FMT_BTREE) {
+			dbprintf(_("attr fork not in btree format\n"));
+			return 0;
+		}
+	} else {
+		if (!dip->di_nextents ||
+		    dip->di_format != XFS_DINODE_FMT_BTREE) {
+			dbprintf(_("data fork not in btree format\n"));
+			return 0;
+		}
+	}
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	if (dump_node_blocks) {
+		ret = eval("print %s.keys", prefix);
+		if (ret)
+			goto err;
+		ret = eval("print %s.ptrs", prefix);
+		if (ret)
+			goto err;
+	}
+
+	ret = eval("addr %s.ptrs[1]", prefix);
+	if (ret)
+		goto err;
+
+	ret = dump_btree_long(dump_node_blocks);
+	if (ret)
+		goto err;
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+btdump_f(
+	int		argc,
+	char		**argv)
+{
+	bool		aflag = false;
+	bool		iflag = false;
+	int		c;
+
+	if (cur_typ == NULL) {
+		dbprintf(_("no current type\n"));
+		return 0;
+	}
+	while ((c = getopt(argc, argv, "ai")) != EOF) {
+		switch (c) {
+		case 'a':
+			aflag = true;
+			break;
+		case 'i':
+			iflag = true;
+			break;
+		default:
+			dbprintf(_("bad option for btdump command\n"));
+			return 0;
+		}
+	}
+
+	if (optind != argc) {
+		dbprintf(_("bad options for btdump command\n"));
+		return 0;
+	}
+	if (aflag && cur_typ->typnm != TYP_INODE) {
+		dbprintf(_("attrfork flag doesn't apply here\n"));
+		return 0;
+	}
+
+	switch (cur_typ->typnm) {
+	case TYP_BNOBT:
+	case TYP_CNTBT:
+	case TYP_INOBT:
+	case TYP_FINOBT:
+	case TYP_RMAPBT:
+	case TYP_REFCBT:
+		return dump_btree_short(iflag);
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		return dump_btree_long(iflag);
+	case TYP_INODE:
+		return dump_inode(iflag, aflag);
+	default:
+		dbprintf(_("type \"%s\" is not a btree type or inode\n"),
+				cur_typ->name);
+		return 0;
+	}
+}
+
+static const cmdinfo_t btdump_cmd =
+	{ "btdump", "b", btdump_f, 0, 2, 0, "[-a] [-i]",
+	  N_("dump btree"), btdump_help };
+
+void
+btdump_init(void)
+{
+	add_command(&btdump_cmd);
+}
diff --git a/db/command.c b/db/command.c
index 3d7cfd7..c90c85c 100644
--- a/db/command.c
+++ b/db/command.c
@@ -124,6 +124,7 @@ init_commands(void)
 	attrset_init();
 	block_init();
 	bmap_init();
+	btdump_init();
 	check_init();
 	convert_init();
 	crc_init();
diff --git a/db/command.h b/db/command.h
index 4d4807d..9b4ed2d 100644
--- a/db/command.h
+++ b/db/command.h
@@ -39,3 +39,5 @@ extern void		add_command(const cmdinfo_t *ci);
 extern int		command(int argc, char **argv);
 extern const cmdinfo_t	*find_command(const char *cmd);
 extern void		init_commands(void);
+
+extern void		btdump_init(void);
diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
index b1c341d..eafb602 100644
--- a/man/man8/xfs_db.8
+++ b/man/man8/xfs_db.8
@@ -332,6 +332,19 @@ and
 options are used to select the attribute or data
 area of the inode, if neither option is given then both areas are shown.
 .TP
+.B btdump [-a] [-i]
+If the cursor points to a btree node, dump the btree from that block downward.
+If instead the cursor points to an inode, dump the data fork block mapping btree if there is one.
+By default, only records stored in the btree are dumped.
+.RS 1.0i
+.TP 0.4i
+.B \-a
+If the cursor points at an inode, dump the extended attribute block mapping btree, if present.
+.TP
+.B \-i
+Dump all keys and pointers in intermediate btree nodes, and all records in leaf btree nodes.
+.RE
+.TP
 .B check
 See the
 .B blockget

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-26 20:36   ` [PATCH v2 " Darrick J. Wong
@ 2017-04-26 21:35     ` Eric Sandeen
  0 siblings, 0 replies; 23+ messages in thread
From: Eric Sandeen @ 2017-04-26 21:35 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/26/17 3:36 PM, Darrick J. Wong wrote:
> Introduce a new 'btdump' command that can print the contents of all
> blocks of any metadata subtree in the filesystem.  This enables
> developers and forensic analyst to view a metadata structure without
> having to navigate the btree manually.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good to me, thanks.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-08  3:04 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
@ 2017-04-08 23:11   ` Dave Chinner
  0 siblings, 0 replies; 23+ messages in thread
From: Dave Chinner @ 2017-04-08 23:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Fri, Apr 07, 2017 at 08:04:07PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Introduce a new 'btdump' command that can print the contents of all
> blocks of any metadata subtree in the filesystem.  This enables
> developers and forensic analyst to view a metadata structure without
> having to navigate the btree manually.
....

Something I've noticed recently:

> --- /dev/null
> +++ b/db/btdump.h
> @@ -0,0 +1,20 @@
> +/*
> + * Copyright (C) 2017 Oracle.  All Rights Reserved.
> + *
> + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> + */
> +extern void	btdump_init(void);

Adding a new header file just for an extern init function
declarationi is a pretty silly pattern. Just consolidate all the
init function declarations db/init.h, and get rid of all the
one-line headers...

We should really do the same for xfs_io, too...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump'
  2017-04-08  3:03 [RFC PATCH v1 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
@ 2017-04-08  3:04 ` Darrick J. Wong
  2017-04-08 23:11   ` Dave Chinner
  0 siblings, 1 reply; 23+ messages in thread
From: Darrick J. Wong @ 2017-04-08  3:04 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Introduce a new 'btdump' command that can print the contents of all
blocks of any metadata subtree in the filesystem.  This enables
developers and forensic analyst to view a metadata structure without
having to navigate the btree manually.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/Makefile  |    2 
 db/btdump.c  |  272 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 db/btdump.h  |   20 ++++
 db/command.c |    2 
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 db/btdump.c
 create mode 100644 db/btdump.h


diff --git a/db/Makefile b/db/Makefile
index cdc0b99..97dd898 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs
 LTCOMMAND = xfs_db
 
 HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
-	btblock.h bmroot.h check.h command.h convert.h crc.h debug.h \
+	btblock.h btdump.h bmroot.h check.h command.h convert.h crc.h debug.h \
 	dir2.h dir2sf.h dquot.h echo.h faddr.h field.h \
 	flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
diff --git a/db/btdump.c b/db/btdump.c
new file mode 100644
index 0000000..7824c33
--- /dev/null
+++ b/db/btdump.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2017 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "output.h"
+#include "init.h"
+#include "io.h"
+#include "type.h"
+#include "btdump.h"
+#include "input.h"
+
+static void
+btdump_help(void)
+{
+	dbprintf(_(
+"\n"
+" 'btdump' dumps the btree rooted at the current io cursor location.\n"
+" In the case of an inode, the data fork bmbt is displayed.\n"
+" Options:\n"
+"   -a -- Display the extended attribute bmbt.\n"
+"   -i -- Print internal btree nodes.\n"
+"\n"
+));
+
+}
+
+static int
+eval(
+	const char	*fmt, ...)
+{
+	va_list		ap;
+	char		buf[PATH_MAX];
+	char		**v;
+	int		c;
+	int		ret;
+
+	va_start(ap, fmt);
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	va_end(ap);
+
+	v = breakline(buf, &c);
+	ret = command(c, v);
+	free(v);
+	return ret;
+}
+
+static bool
+btblock_has_rightsib(
+	struct xfs_btree_block	*block,
+	bool			long_format)
+{
+	if (long_format)
+		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
+	return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
+}
+
+static int
+dump_btlevel(
+	int			level,
+	bool			long_format)
+{
+	xfs_daddr_t		orig_daddr = iocur_top->bb;
+	xfs_daddr_t		last_daddr;
+	unsigned int		nr;
+	int			ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	nr = 1;
+	do {
+		last_daddr = iocur_top->bb;
+		dbprintf(_("%s level %u block %u daddr %llu\n"),
+			 iocur_top->typ->name, level, nr, last_daddr);
+		if (level > 0) {
+			ret = eval("print keys");
+			if (ret)
+				goto err;
+			ret = eval("print ptrs");
+		} else {
+			ret = eval("print recs");
+		}
+		if (ret)
+			goto err;
+		if (btblock_has_rightsib(iocur_top->data, long_format)) {
+			ret = eval("addr rightsib");
+			if (ret)
+				goto err;
+		}
+		nr++;
+	} while (iocur_top->bb != orig_daddr && iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+dump_btree(
+	bool		dump_node_blocks,
+	bool		long_format)
+{
+	xfs_daddr_t	orig_daddr = iocur_top->bb;
+	xfs_daddr_t	last_daddr;
+	int		level;
+	int		ret;
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	cur_agno = XFS_FSB_TO_AGNO(mp, XFS_DADDR_TO_FSB(mp, iocur_top->bb));
+	level = xfs_btree_get_level(iocur_top->data);
+	do {
+		last_daddr = iocur_top->bb;
+		if (level > 0) {
+			if (dump_node_blocks) {
+				ret = dump_btlevel(level, long_format);
+				if (ret)
+					goto err;
+			}
+			ret = eval("addr ptrs[1]");
+		} else {
+			ret = dump_btlevel(level, long_format);
+		}
+		if (ret)
+			goto err;
+		level--;
+	} while (level >= 0 &&
+		 iocur_top->bb != orig_daddr &&
+		 iocur_top->bb != last_daddr);
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+dump_inode(
+	bool			dump_node_blocks,
+	bool			attrfork)
+{
+	char			*prefix;
+	struct xfs_dinode	*dip;
+	int			ret;
+
+	if (attrfork)
+		prefix = "a.bmbt";
+	else if (xfs_sb_version_hascrc(&mp->m_sb))
+		prefix = "u3.bmbt";
+	else
+		prefix = "u.bmbt";
+
+	dip = iocur_top->data;
+	if (attrfork) {
+		if (!dip->di_anextents ||
+		    dip->di_aformat != XFS_DINODE_FMT_BTREE)
+			return 0;
+	} else {
+		if (!dip->di_nextents ||
+		    dip->di_format != XFS_DINODE_FMT_BTREE)
+			return 0;
+	}
+
+	ret = eval("push");
+	if (ret)
+		return ret;
+
+	if (dump_node_blocks) {
+		ret = eval("print %s.keys", prefix);
+		if (ret)
+			goto err;
+		ret = eval("print %s.ptrs", prefix);
+		if (ret)
+			goto err;
+	}
+
+	ret = eval("addr %s.ptrs[1]", prefix);
+	if (ret)
+		goto err;
+
+	ret = dump_btree(dump_node_blocks, true);
+	if (ret)
+		goto err;
+
+	ret = eval("pop");
+	return ret;
+err:
+	eval("pop");
+	return ret;
+}
+
+static int
+btdump_f(
+	int		argc,
+	char		**argv)
+{
+	bool		aflag = false;
+	bool		iflag = false;
+	int		c;
+
+	if (cur_typ == NULL) {
+		dbprintf(_("no current type\n"));
+		return 0;
+	}
+	while ((c = getopt(argc, argv, "ai")) != EOF) {
+		switch (c) {
+		case 'a':
+			aflag = true;
+			break;
+		case 'i':
+			iflag = true;
+			break;
+		default:
+			dbprintf(_("bad option for btdump command\n"));
+			return 0;
+		}
+	}
+	if (aflag && cur_typ->typnm != TYP_INODE) {
+		dbprintf(_("attrfork flag doesn't apply here\n"));
+		return 0;
+	}
+	switch (cur_typ->typnm) {
+	case TYP_BNOBT:
+	case TYP_CNTBT:
+	case TYP_INOBT:
+	case TYP_FINOBT:
+	case TYP_RMAPBT:
+	case TYP_REFCBT:
+		return dump_btree(iflag, false);
+	case TYP_BMAPBTA:
+	case TYP_BMAPBTD:
+		return dump_btree(iflag, true);
+	case TYP_INODE:
+		return dump_inode(iflag, aflag);
+	default:
+		dbprintf(_("Not a btree.\n"));
+		return 0;
+	}
+}
+
+static const cmdinfo_t btdump_cmd =
+	{ "btdump", "b", btdump_f, 0, 1, 0, "",
+	  N_("dump btree"), btdump_help };
+
+void
+btdump_init(void)
+{
+	add_command(&btdump_cmd);
+}
diff --git a/db/btdump.h b/db/btdump.h
new file mode 100644
index 0000000..45a65aa
--- /dev/null
+++ b/db/btdump.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2017 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+extern void	btdump_init(void);
diff --git a/db/command.c b/db/command.c
index 3d7cfd7..c2ed7b4 100644
--- a/db/command.c
+++ b/db/command.c
@@ -51,6 +51,7 @@
 #include "dquot.h"
 #include "fsmap.h"
 #include "crc.h"
+#include "btdump.h"
 
 cmdinfo_t	*cmdtab;
 int		ncmds;
@@ -124,6 +125,7 @@ init_commands(void)
 	attrset_init();
 	block_init();
 	bmap_init();
+	btdump_init();
 	check_init();
 	convert_init();
 	crc_init();


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2017-04-26 21:35 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
2017-04-10 22:47 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
2017-04-26 17:12   ` Eric Sandeen
2017-04-26 17:45     ` Darrick J. Wong
2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
2017-04-11  0:03   ` Dave Chinner
2017-04-11  0:19     ` Darrick J. Wong
2017-04-11  0:20   ` [PATCH v2 " Darrick J. Wong
2017-04-26 17:48     ` Eric Sandeen
2017-04-26 18:25       ` Darrick J. Wong
2017-04-26 18:41         ` Eric Sandeen
2017-04-26 18:43           ` Darrick J. Wong
2017-04-26 18:47     ` [PATCH v3 " Eric Sandeen
2017-04-26 19:11       ` Darrick J. Wong
2017-04-10 22:47 ` [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics Darrick J. Wong
2017-04-11 21:42   ` Darrick J. Wong
2017-04-10 22:48 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
2017-04-26 19:50   ` Eric Sandeen
2017-04-26 20:27     ` Darrick J. Wong
2017-04-26 20:36   ` [PATCH v2 " Darrick J. Wong
2017-04-26 21:35     ` Eric Sandeen
  -- strict thread matches above, loose matches on Subject: below --
2017-04-08  3:03 [RFC PATCH v1 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
2017-04-08  3:04 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
2017-04-08 23:11   ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.