Skip to contentSkip to conversation

xfsdump: use the full 32-bit generation number

PATCH In review Bill Kendall 2 participants 4 messages Feb 9, 2012 – Feb 13, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfsdump: use the full 32-bit generation number

xfsdump historically has truncated the inode generation number to the low 12 bits when writing out directory entries. This makes it possible for xfsrestore to mistakingly think 2 directory entries refer to the same inode when dealing with incremental or resumed dumps. A message such as this is an indication of this problem:

WARNING: unable to unlink current file prior to restore

This patch changes xfsdump to use the full 32-bit inode generation number. A change to part of the dump format (direnthdr_t) was required, so the dump format version has been bumped to 3. xfsdump also required changes to its inode-to-generation cache. This map is not persistent though, so no compatibility or version changes were required there.

xfsdump can still generate a format 2 dump using the new -K option. This is useful when moving a filesystem to a system with an older version of xfsrestore.

xfsrestore has been changed to support the old and new dump formats. This required a change to its persistent data structures (for cumulative restores), so the housekeeping version number was bumped as well.

When restoring a series of incremental/resumed dumps, if the oldest restore used 12-bit generation numbers then they will be used throughout the restore series to avoid mass confusion.

In the rare case that a cumulative restore is done using a format 3 dump followed by a format 2 dump, the user must specifically tell xfsrestore to use format 2 generation numbers throughout the restore series by using the -K option on the first restore.

It's recommended that users do a level 0 backup of their filesystems with the new xfsdump so that future incremental restores can take advantage of the full 32-bit generation number.

This patch also fixes a couple of instances where the dump format was being displayed with an incorrect value.

---
Changes in v2:
* add -K option to xfsdump and restore for compatibility with format 2 dumps. xfsdump -K generates format 2 dumps. xfsrestore -K forces the use of format 2 (truncated) generation numbers.
* show correct current dump format when displaying version information.
* detect cases where xfsrestore -K is required.
* validate checksums of a format 2 direnthdr_v1_t before it's converted to a direnthdr_t.

I have a few xfstests to cover these changes. I'll submit them once this has been reviewed in case they need to be tweaked.

 common/arch_xlate.c    |   54 ++++++++++++++++++++++++++--
 common/arch_xlate.h    |    5 +++
 common/content_inode.h |   20 +++++++++--
 common/global.c        |    5 +++
 common/global.h        |    7 ++--
 common/main.c          |   16 +++-----
 dump/content.c         |   82 +++++++++++++++++++++++++++++++-----------
 dump/getopt.h          |    4 +-
 dump/inomap.c          |   45 +++++-------------------
 dump/inomap.h          |    2 +-
 man/man8/xfsdump.8     |    7 ++++
 man/man8/xfsrestore.8  |    9 +++++
 restore/content.c      |   88 +++++++++++++++++++++++++++++++++++++---------
 restore/getopt.h       |    4 +-
 restore/tree.c         |   91 +++++++++++++++++++++++++++++++++++++++--------
 restore/tree.h         |   16 +++++++--
 16 files changed, 335 insertions(+), 120 deletions(-)
common/arch_xlate.c +50 -4
index 1c7e880..c156313 100644
@@ -438,8 +438,8 @@ xlate_direnthdr(direnthdr_t *dh1, direnthdr_t *dh2, int dir)
 
 	IXLATE(dh1, dh2, dh_ino);
 	IXLATE(dh1, dh2, dh_gen);
-	IXLATE(dh1, dh2, dh_sz);
 	IXLATE(dh1, dh2, dh_checksum);
+	IXLATE(dh1, dh2, dh_sz);
 
 	if (dir < 0) {
 		ptr1 = dh2;
@@ -450,7 +450,53 @@ xlate_direnthdr(direnthdr_t *dh1, direnthdr_t *dh2, int dir)
 
 	mlog(MLOG_NITTY, "xlate_direnthdr: pre-xlate\n"
 	     "\tdh_ino %llu\n"
-	     "\tdh_gen %d\n"
+	     "\tdh_gen %u\n"
+	     "\tdh_checksum %d\n"
+	     "\tdh_sz %d\n"
+	     "\tdh_name %.8s\n",
+	     ptr1->dh_ino,
+	     ptr1->dh_gen,
+	     ptr1->dh_checksum,
+	     ptr1->dh_sz,
+	     ptr1->dh_name );
+
+	mlog(MLOG_NITTY, "xlate_direnthdr: post-xlate\n"
+	     "\tdh_ino %llu\n"
+	     "\tdh_gen %u\n"
+	     "\tdh_checksum %d\n"
+	     "\tdh_sz %d\n"
+	     "\tdh_name %.8s\n",
+	     ptr2->dh_ino,
+	     ptr2->dh_gen,
+	     ptr2->dh_checksum,
+	     ptr2->dh_sz,
+	     ptr2->dh_name );
+}
+
+/*
+ * xlate_direnthdr_v1 - endian convert struct direnthdr_v1
+ */
+void
+xlate_direnthdr_v1(direnthdr_v1_t *dh1, direnthdr_v1_t *dh2, int dir)
+{
+	direnthdr_v1_t *ptr1 = dh1;
+	direnthdr_v1_t *ptr2 = dh2;
+
+	IXLATE(dh1, dh2, dh_ino);
+	IXLATE(dh1, dh2, dh_gen);
+	IXLATE(dh1, dh2, dh_sz);
+	IXLATE(dh1, dh2, dh_checksum);
+
+	if (dir < 0) {
+		ptr1 = dh2;
+		ptr2 = dh1;
+	}
+
+	BXLATE(dh_name);
+
+	mlog(MLOG_NITTY, "xlate_direnthdr_v1: pre-xlate\n"
+	     "\tdh_ino %llu\n"
+	     "\tdh_gen %u\n"
 	     "\tdh_sz %d\n"
 	     "\tdh_checksum %d\n"
 	     "\tdh_name %.8s\n",
@@ -460,9 +506,9 @@ xlate_direnthdr(direnthdr_t *dh1, direnthdr_t *dh2, int dir)
 	     ptr1->dh_checksum,
 	     ptr1->dh_name );
 
-	mlog(MLOG_NITTY, "xlate_direnthdr: post-xlate\n"
+	mlog(MLOG_NITTY, "xlate_direnthdr_v1: post-xlate\n"
 	     "\tdh_ino %llu\n"
-	     "\tdh_gen %d\n"
+	     "\tdh_gen %u\n"
 	     "\tdh_sz %d\n"
 	     "\tdh_checksum %d\n"
 	     "\tdh_name %.8s\n",
common/arch_xlate.h +5 -0
index 3ad3c97..35333c6 100644
@@ -98,6 +98,11 @@ void xlate_extenthdr(extenthdr_t *eh1, extenthdr_t *eh2, int dir);
 void xlate_direnthdr(direnthdr_t *dh1, direnthdr_t *dh2, int dir);
 
 /*
+ * xlate_direnthdr_v1 - endian convert struct direnthdr_v1
+ */
+void xlate_direnthdr_v1(direnthdr_v1_t *dh1, direnthdr_v1_t *dh2, int dir);
+
+/*
  * xlate_extattrhdr - endian convert struct extattrhdr
  */
 void xlate_extattrhdr(extattrhdr_t *eh1, extattrhdr_t *eh2, int dir);
common/content_inode.h +17 -3
index 67c4f6d..a25b66e 100644
@@ -284,26 +284,40 @@ typedef struct extenthdr extenthdr_t;
  * a sequence of directory entries is always terminated with a null direnthdr_t.
  * this is detected by looking for a zero ino.
  */
+typedef u_int32_t gen_t;
+
 #define DIRENTHDR_ALIGN	8
 
 #define DIRENTHDR_SZ	24
 
 struct direnthdr {
 	xfs_ino_t dh_ino;
+	gen_t dh_gen;
+	u_int32_t dh_checksum;
+	u_int16_t dh_sz; /* overall size of record */
+	char dh_name[ 6 ];
+};
+
+typedef struct direnthdr direnthdr_t;
+
+/* the old direnthdr truncated the inode generation number
+ * to the low 12 bits.
+ */
+
+struct direnthdr_v1 {
+	xfs_ino_t dh_ino;
 	u_int16_t dh_gen; /* generation count & DENTGENMASK of ref'ed inode */
 	u_int16_t dh_sz; /* overall size of record */
 	u_int32_t dh_checksum;
 	char dh_name[ 8 ];
 };
 
-typedef struct direnthdr direnthdr_t;
+typedef struct direnthdr_v1 direnthdr_v1_t;
 
 /* truncated generation count
  */
 #define DENTGENSZ		12	/* leave 4 bits for future flags */
 #define DENTGENMASK		(( 1 << DENTGENSZ ) - 1 )
-typedef u_int16_t gen_t;
-#define GEN_NULL		( ( gen_t )UINT16MAX )
 #define BIGGEN2GEN( bg )	( ( gen_t )( bg & DENTGENMASK ))
 
 
common/global.c +5 -0
index 737b731..8e49d8b 100644
@@ -191,6 +191,10 @@ global_hdr_alloc( intgen_t argc, char *argv[ ] )
 			}
 			ghdrp->gh_timestamp = statb.st_mtime;
 			break;
+
+		case GETOPT_FMT2COMPAT:
+			ghdrp->gh_version = GLOBAL_HDR_VERSION_2;
+			break;
 #endif /* DUMP */
 		}
 	}
@@ -276,6 +280,7 @@ global_version_check( u_int32_t version )
 		case GLOBAL_HDR_VERSION_0:
 		case GLOBAL_HDR_VERSION_1:
 		case GLOBAL_HDR_VERSION_2:
+		case GLOBAL_HDR_VERSION_3:
 			return BOOL_TRUE;
 		default:
 			return BOOL_FALSE;
common/global.h +4 -3
index ea2b732..6556a68 100644
@@ -27,13 +27,14 @@
 #define GLOBAL_HDR_VERSION_0	0
 #define GLOBAL_HDR_VERSION_1	1
 #define GLOBAL_HDR_VERSION_2	2
-	/* version 2 adds encoding of holes and a change to on-tape inventory format.
+#define GLOBAL_HDR_VERSION_3	3
+	/* version 3 uses the full 32-bit inode generation number in direnthdr_t.
+	 * version 2 adds encoding of holes and a change to on-tape inventory format.
 	 * version 1 adds extended file attribute dumping.
 	 * version 0 xfsrestore can't handle media produced
 	 * by version 1 xfsdump. 
 	 */
-#define GLOBAL_HDR_VERSION	GLOBAL_HDR_VERSION_2
-#define GLOBAL_HDR_VERSION_PREV	1
+#define GLOBAL_HDR_VERSION	GLOBAL_HDR_VERSION_3
 
 #define GLOBAL_HDR_STRING_SZ	0x100
 #define GLOBAL_HDR_TIME_SZ	4
common/main.c +6 -10
index 5880723..a01b02a 100644
@@ -103,8 +103,6 @@ static char *strpbrkquotes( char *p, const char *sep );
 
 /* definition of locally defined global variables ****************************/
 
-intgen_t version = 3;
-intgen_t subversion = 0;
 char *progname = 0;			/* used in all error output */
 char *homedir = 0;			/* directory invoked from */
 bool_t pipeline = BOOL_FALSE;
@@ -400,10 +398,8 @@ main( int argc, char *argv[] )
 	 */
 	if ( infoonly ) {
 		mlog( MLOG_NORMAL,
-		      _("version %s (dump format %d.%d)\n"),
-		      VERSION,
-		      version,
-		      subversion );
+		      _("version %s (dump format %d.0)\n"),
+		      VERSION, GLOBAL_HDR_VERSION );
 		usage( );
 		return mlog_exit(EXIT_NORMAL, RV_OK); /* normal termination */
 	}
@@ -475,10 +471,8 @@ main( int argc, char *argv[] )
 	 */
 	sistr = sigintstr( );
 	mlog( MLOG_VERBOSE,
-	      _("version %s (dump format %d.%d)"),
-	      VERSION,
-	      version,
-	      subversion );
+	      _("version %s (dump format %d.0)"),
+	      VERSION, GLOBAL_HDR_VERSION );
 	if ( ! pipeline && ! stdoutpiped && sistr && dlog_allowed( )) {
 		mlog( MLOG_VERBOSE | MLOG_BARE, _(
 		      " - "
@@ -930,6 +924,7 @@ usage( void )
 #endif /* REVEAL */
 	ULO(_("(display dump inventory)"),		GETOPT_INVPRINT );
 	ULO(_("(inhibit inventory update)"),		GETOPT_NOINVUPDATE );
+	ULO(_("(generate format 2 dump)"),		GETOPT_FMT2COMPAT );
 	ULO(_("<session label>"),			GETOPT_DUMPLABEL );
 	ULO(_("<media label> ..."),			GETOPT_MEDIALABEL );
 #ifdef REVEAL
@@ -978,6 +973,7 @@ usage( void )
 	ULO(_("(don't prompt)"),			GETOPT_FORCE );
 	ULO(_("(display dump inventory)"),		GETOPT_INVPRINT );
 	ULO(_("(inhibit inventory update)"),		GETOPT_NOINVUPDATE );
+	ULO(_("(force use of format 2 generation numbers)"),GETOPT_FMT2COMPAT );
 	ULO(_("<session label>"),			GETOPT_DUMPLABEL );
 #ifdef REVEAL
 	ULO(_("(timestamp messages)"),			GETOPT_TIMESTAMP );
dump/content.c +60 -22

147 lines not on this page · raw message

dump/getopt.h +2 -2
index ba26c93..3bab87a 100644
@@ -27,7 +27,7 @@
  * facilitating easy changes.
  */
 
-#define GETOPT_CMDSTRING	"ab:c:d:ef:hl:mop:qs:t:v:z:AB:CDEFG:H:I:JL:M:NO:PRSTUVWY:"
+#define GETOPT_CMDSTRING	"ab:c:d:ef:hl:mop:qs:t:v:z:AB:CDEFG:H:I:JKL:M:NO:PRSTUVWY:"
 
 #define GETOPT_DUMPASOFFLINE	'a'	/* dump DMF dualstate files as offline */
 #define	GETOPT_BLOCKSIZE	'b'	/* blocksize for rmt */
@@ -65,7 +65,7 @@
 #define GETOPT_MAXSTACKSZ	'H'	/* maximum stack size (bytes) */
 #define GETOPT_INVPRINT         'I'     /* just display the inventory */
 #define	GETOPT_NOINVUPDATE	'J'	/* do not update the dump inventory */
-/*				'K'	*/
+#define GETOPT_FMT2COMPAT	'K'	/* use dump format 2 for compat with old restore */
 #define	GETOPT_DUMPLABEL	'L'	/* dump session label (global.c) */
 #define	GETOPT_MEDIALABEL	'M'	/* media object label (media.c) */
 #define	GETOPT_TIMESTAMP	'N'	/* show timestamps in log msgs */
dump/inomap.c +9 -36

78 lines not on this page · raw message

dump/inomap.h +1 -1
index 16f2efb..7d1db1f 100644
@@ -132,7 +132,7 @@ extern void *inomap_alloc_context( void );
 extern void inomap_reset_context( void *contextp );
 extern void inomap_free_context( void *contextp );
 extern intgen_t inomap_get_state( void *contextp, xfs_ino_t ino );
-extern gen_t inomap_get_gen( void *contextp, xfs_ino_t ino );
+extern intgen_t inomap_get_gen( void *contextp, xfs_ino_t ino, gen_t *gen );
 
 
 /* generators returning the next dir or non-dir ino selected in this dump.
man/man8/xfsdump.8 +7 -0
index fb47f7b..7d261ed 100644
@@ -333,6 +333,13 @@ Inhibits the normal update of the inventory.
 This is useful when the media being dumped to
 will be discarded or overwritten.
 .TP 5
+.B \-K
+Generate a format 2 dump instead of the current format. This is useful
+if the dump will be restored on a system with an older
+.I xfsrestore
+which does not understand the current dump format. Use of this option
+is otherwise not recommended.
+.TP 5
 \f3\-L\f1 \f2session_label\f1
 Specifies a label for the dump session.
 It can be any arbitrary string up to 255 characters long.
man/man8/xfsrestore.8 +9 -0
index aad97fa..60e4309 100644
@@ -339,6 +339,15 @@ when it encounters an on-media session inventory,
 but only if run with an effective user id of root
 and only if this option is not given.
 .TP 5
+.B \-K
+Force
+.I xfsrestore
+to use dump format 2 generation numbers. Normally the need for this is
+determined automatically, but this option is required on the first
+.I xfsrestore
+invocation in the rare case that a cumulative restore begins
+with a format 3 (or newer) dump and will be followed by a format 2 dump.
+.TP 5
 \f3\-L\f1 \f2session_label\f1
 Specifies the label
 of the dump session to be restored.
restore/content.c +70 -18

178 lines not on this page · raw message

restore/getopt.h +2 -2
index 63568de..361bc61 100644
@@ -26,7 +26,7 @@
  * purpose is to contain that command string.
  */
 
-#define GETOPT_CMDSTRING	"a:b:c:def:himn:op:qrs:tv:wABCDEFG:H:I:JL:M:NO:PQRS:TUVWX:Y:"
+#define GETOPT_CMDSTRING	"a:b:c:def:himn:op:qrs:tv:wABCDEFG:H:I:JKL:M:NO:PQRS:TUVWX:Y:"
 
 #define GETOPT_WORKSPACE	'a'	/* workspace dir (content.c) */
 #define GETOPT_BLOCKSIZE        'b'     /* blocksize for rmt */
@@ -64,7 +64,7 @@
 #define GETOPT_MAXSTACKSZ	'H'	/* maximum stack size (bytes) */
 #define GETOPT_INVPRINT         'I'     /* just display the inventory */
 #define	GETOPT_NOINVUPDATE	'J'	/* do not update the dump inventory */
-/*				'K' */
+#define GETOPT_FMT2COMPAT	'K'	/* force use format 2 gen numbers */
 #define	GETOPT_DUMPLABEL	'L'	/* dump session label (global.c) */
 #define	GETOPT_MEDIALABEL	'M'	/* media object label (media.c) */
 #define	GETOPT_TIMESTAMP	'N'	/* show timestamps in log msgs */
restore/tree.c +75 -16

204 lines not on this page · raw message

restore/tree.h +13 -3
index 93621c7..7b1a76a 100644
@@ -32,7 +32,9 @@ extern bool_t tree_init( char *hkdir,
 			 size64_t vmsz,
 			 bool_t fullpr,
 			 bool_t restoredmpr,
-			 bool_t dstdirisxfspr );
+			 bool_t dstdirisxfspr,
+			 u_int32_t dumpformat,
+			 bool_t truncategenpr );
 
 /* tree_sync - synchronizes with an existing tree abstraction
  */
@@ -42,6 +44,14 @@ extern bool_t tree_sync( char *hkdir,
 			 bool_t fullpr,
 			 bool_t dstdirisxfspr );
 
+/* tree_check_dump_format - detect the rare case where a
+ * cumulative restore begins with a format 3 (or newer)
+ * dump, and a later restore in the series encounters
+ * a format 2 dump. the restore will fail unless the
+ * original restore was told to use format 2 gen numbers.
+ */
+extern bool_t tree_check_dump_format( u_int32_t dumpformat );
+
 
 /* tree_begindir - begins application of dumped directory to tree.
  * returns handle to dir node. returns by reference the dirattr
@@ -53,7 +63,7 @@ extern nh_t tree_begindir( filehdr_t *fhdrp, dah_t *dahp );
  */
 extern rv_t tree_addent( nh_t dirh,
 			 xfs_ino_t ino,
-			 size_t gen,
+			 gen_t gen,
 			 char *name,
 			 size_t namelen );
 
@@ -84,7 +94,7 @@ extern bool_t tree_subtree_parse( bool_t sensepr, char *path );
 extern bool_t tree_post( char *path1, char *path2 );
 
 extern rv_t tree_cb_links( xfs_ino_t ino,
-			   u_int32_t biggen,
+			   gen_t gen,
 			   int32_t ctime,
 			   int32_t mtime,
 			   bool_t ( * funcp )( void *contextp,
Signature · 6 lines
1.7.0.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
Quoted 3 lines · Christoph Hellwig

Looks generally good to me, but is there any good reason to not make the -K argument extensible by requiring a version argument, even if that one currently only supports 2 and 3 as valid values?

I thought about doing that, but given the low frequency of format changes decided it could wait until there's more than one old format to support. -K without an argument could be treated as "generate the previous media format", or with an argument it could generate a specific format. I'm okay with requiring a version argument though, being explicit is better.

FWIW, the way things have always worked is that xfsrestore provides backwards compatibility for all dump formats. xfsdump has, until now, always generated the current format. It's nice to provide the ability to generate old formats during a transition period, but long-term I don't see xfsdump retaining support for generating all old formats.

Bill

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 12 lines · Bill Kendall
Quoted 3 lines · Christoph Hellwig

Looks generally good to me, but is there any good reason to not make the -K argument extensible by requiring a version argument, even if that one currently only supports 2 and 3 as valid values?

I thought about doing that, but given the low frequency of format changes decided it could wait until there's more than one old format to support. -K without an argument could be treated as "generate the previous media format", or with an argument it could generate a specific format. I'm okay with requiring a version argument though, being explicit is better.

Quoted 6 lines

FWIW, the way things have always worked is that xfsrestore provides backwards compatibility for all dump formats. xfsdump has, until now, always generated the current format. It's nice to provide the ability to generate old formats during a transition period, but long-term I don't see xfsdump retaining support for generating all old formats.

Ok, sounds fine. I'll put it into the repository and after that we should aim for an xfsdump 3.1.0 release ASAP.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs