Skip to contentSkip to conversation

XFS metadata dump feature added to xfs_db

PATCH New Barry Naujok 1 participant 1 message Feb 13, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 XFS metadata dump feature added to xfs_db

The attached patch adds a metadata dump and restore command to xfs_db. A script is also supplied called xfs_metadata to make it simpler to generate a metadump file from the command line.

The purpose of this feature is to allow a user with a corrupted and/or unrepairable filesystem to generate a compact metadata only image that is small and compressable that can easily be transferred to us for analysis.

The command also supports output to stdout, so can be used in the following fashion:

# xfs_metadump /dev/foo - | bzip2 > /tmp/foo.bz2

A man page update for xfs_db and a new man page for xfs_metadump will be created before this is checked in.

I will also investigate a "name obfuscation" option that works with the hash entries in directories and extended attributes. This would be a future enhancement that won't make this patch.

Regards,
Barry.

===========================================================================
xfsprogs/db/Makefile
===========================================================================

xfsprogs/db/Makefile +3 -2
@@ -11,11 +11,11 @@ HFILES = addr.h agf.h agfl.h agi.h attr.
 	bmapbt.h bmroot.h bnobt.h check.h cntbt.h command.h convert.h \
 	dbread.h debug.h dir.h dir2.h dir2sf.h dirshort.h dquot.h echo.h \
 	faddr.h field.h flist.h fprint.h frag.h freesp.h hash.h help.h \
-	init.h inobt.h inode.h input.h io.h malloc.h output.h \
+	init.h inobt.h inode.h input.h io.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
 CFILES = $(HFILES:.h=.c)
-LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh
+LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh xfs_metadump.sh
 LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG)
 LLDFLAGS += -static
@@ -40,4 +40,5 @@ install: default
 	$(INSTALL) -m 755 xfs_admin.sh $(PKG_BIN_DIR)/xfs_admin
 	$(INSTALL) -m 755 xfs_check.sh $(PKG_BIN_DIR)/xfs_check
 	$(INSTALL) -m 755 xfs_ncheck.sh $(PKG_BIN_DIR)/xfs_ncheck
+	$(INSTALL) -m 755 xfs_metadump.sh $(PKG_BIN_DIR)/xfs_metadump
 install-dev:

===========================================================================
xfsprogs/db/command.c
===========================================================================

xfsprogs/db/command.c +1 -0
@@ -131,6 +131,7 @@ init_commands(void)
 	inode_init();
 	input_init();
 	io_init();
+	metadump_init();
 	output_init();
 	print_init();
 	quit_init();

===========================================================================
xfsprogs/db/init.c
===========================================================================

xfsprogs/db/init.c +5 -5
@@ -107,8 +107,8 @@ init(
 	}
 
 	if (read_bbs(XFS_SB_DADDR, 1, &bufp, NULL)) {
-		dbprintf(_("%s: %s is invalid (cannot read first 512 bytes)\n"),
-			progname, fsdevice);
+		fprintf(stderr, _("%s: %s is invalid (cannot read first 512 "
+			"bytes)\n"), progname, fsdevice);
 		exit(1);
 	}
 
@@ -118,7 +118,7 @@ init(
 
 	sbp = &xmount.m_sb;
 	if (sbp->sb_magicnum != XFS_SB_MAGIC) {
-		dbprintf(_("%s: unexpected XFS SB magic number 0x%08x\n"),
+		fprintf(stderr, _("%s: unexpected XFS SB magic number 0x%08x\n"),
 			progname, sbp->sb_magicnum);
 	}
 
@@ -128,8 +128,8 @@ init(
 		mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev,
 				LIBXFS_MOUNT_DEBUGGER);
 		if (!mp) {
-			dbprintf(_("%s: device %s unusable (not an XFS filesystem?)\n"),
-			progname, fsdevice);
+			fprintf(stderr, _("%s: device %s unusable (not an XFS "
+				"filesystem?)\n"), progname, fsdevice);
 			exit(1);
 		}
 	}

===========================================================================
xfsprogs/db/metadump.c
===========================================================================

xfsprogs/db/metadump.c +1195 -0

1,195 lines not on this page · raw message

===========================================================================
xfsprogs/db/metadump.h
===========================================================================

xfsprogs/db/metadump.h +19 -0
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2007 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * 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.
+ *
+ * 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	metadump_init(void);

===========================================================================
xfsprogs/db/xfs_metadump.sh
===========================================================================

xfsprogs/db/xfs_metadump.sh +37 -0
@@ -0,0 +1,37 @@
+#!/bin/sh -f
+#
+# Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
+#
+
+OPTS=" "
+DBOPTS=" "
+USAGE="Usage: xfs_metadump [-efgwV] [-l logdev] source target"
+
+while getopts "efgl:wV" c
+do
+	case $c in
+	e)	OPTS=$OPTS"-e ";;
+	g)	OPTS=$OPTS"-g ";;
+	w)	OPTS=$OPTS"-w ";;
+	f)	DBOPTS=$DBOPTS" -f";;
+	l)	DBOPTS=$DBOPTS" -l "$OPTARG" ";;
+	V)	xfs_db -p xfs_metadump -V
+		status=$?
+		exit $status
+		;;
+	\?)	echo $USAGE 1>&2
+		exit 2
+		;;
+	esac
+done
+set -- extra $@
+shift $OPTIND
+case $# in
+	2)	xfs_db$DBOPTS -i -p xfs_metadump -c "metadump$OPTS $2" $1
+		status=$?
+		;;
+	*)	echo $USAGE 1>&2
+		exit 2
+		;;
+esac
+exit $status