Skip to contentSkip to conversation

xfsdump: use the full 32-bit generation number

PATCH Superseded Bill Kendall 3 participants 7 messages Jan 6, 2012 – Feb 7, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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:

xfsrestore: 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.

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 that 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. 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.

---
 common/arch_xlate.c    |   54 +++++++++++++++++++++++++++++++++++---
 common/arch_xlate.h    |    5 +++
 common/content_inode.h |   20 ++++++++++++--
 common/global.c        |    1 +
 common/global.h        |    7 +++--
 dump/content.c         |   11 +++----
 dump/inomap.c          |   45 ++++++-------------------------
 dump/inomap.h          |    2 +-
 restore/content.c      |   27 +++++++++++++++---
 restore/tree.c         |   68 ++++++++++++++++++++++++++++++++++++-----------
 restore/tree.h         |    7 +++--
 11 files changed, 170 insertions(+), 77 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 +1 -0
index 737b731..baa13fe 100644
@@ -276,6 +276,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
dump/content.c +5 -6
index 3a7f508..20d6497 100644
@@ -290,7 +290,7 @@ static rv_t dump_dirent( drive_t *drivep,
 			 context_t *contextp,
 			 xfs_bstat_t *,
 			 xfs_ino_t,
-			 u_int32_t,
+			 gen_t,
 			 char *,
 			 size_t );
 static rv_t init_extent_group_context( jdm_fshandle_t *,
@@ -2902,7 +2902,7 @@ dump_dir( ix_t strmix,
 	struct dirent *gdp = ( struct dirent *)contextp->cc_getdentsbufp;
 	size_t gdsz = contextp->cc_getdentsbufsz;
 	intgen_t gdcnt;
-	u_int32_t gen;
+	gen_t gen;
 	rv_t rv;
 
 	/* no way this can be non-dir, but check anyway
@@ -3073,8 +3073,7 @@ dump_dir( ix_t strmix,
 			/* lookup the gen number in the ino-to-gen map.
 			 * if it's not there, we have to get it the slow way.
 			 */
-			gen = inomap_get_gen( NULL, p->d_ino );
-			if (gen == GEN_NULL) {
+			if ( inomap_get_gen( NULL, p->d_ino, &gen) ) {
 				xfs_bstat_t statbuf;
 				intgen_t scrval;
 				
@@ -5045,7 +5044,7 @@ dump_dirent( drive_t *drivep,
 	     context_t *contextp,
 	     xfs_bstat_t *statp,
 	     xfs_ino_t ino,
-	     u_int32_t gen,
+	     gen_t gen,
 	     char *name,
 	     size_t namelen )
 {
@@ -5083,8 +5082,8 @@ dump_dirent( drive_t *drivep,
 
 	memset( ( void * )dhdrp, 0, sz );
 	dhdrp->dh_ino = ino;
+	dhdrp->dh_gen = gen;
 	dhdrp->dh_sz = ( u_int16_t )sz;
-	dhdrp->dh_gen = ( u_int16_t )( gen & DENTGENMASK );
 
 	if ( name ) {
 		strcpy( dhdrp->dh_name, name );
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.
restore/content.c +22 -5
index a9e0b20..b2a3071 100644
@@ -73,8 +73,10 @@
 #define HOUSEKEEPING_MAGIC	0x686b6d61
 	/* "hkma" - see the housekeeping_magic field of pers_t below.
 	 */
-#define HOUSEKEEPING_VERSION	1
+#define HOUSEKEEPING_VERSION	2
 	/* see the housekeeping_version field of pers_t below.
+	 * version 2 changed the size of a gen_t, which caused node_t
+	 * to change in size. also p_truncategenpr was added to treepers_t.
 	 */
 
 #define WRITE_TRIES_MAX	3
@@ -2328,7 +2330,8 @@ content_stream_restore( ix_t thrdix )
 					tranp->t_vmsz,
 					fullpr,
 					persp->a.restoredmpr,
-					persp->a.dstdirisxfspr );
+					persp->a.dstdirisxfspr,
+					grhdrp->gh_version );
 			if ( ! ok ) {
 				Media_end( Mediap );
 				return mlog_exit(EXIT_ERROR, RV_ERROR);
@@ -3071,7 +3074,7 @@ applydirdump( drive_t *drivep,
 				 */
 				rv = tree_addent( dirh,
 					     dhdrp->dh_ino,
-					     ( size_t )dhdrp->dh_gen,
+					     dhdrp->dh_gen,
 					     dhdrp->dh_name,
 					     namelen );
 				if ( rv != RV_OK ) {
@@ -8109,11 +8112,13 @@ read_dirent( drive_t *drivep,
 	     size_t direntbufsz,
 	     bool_t dhcs )
 {
+	global_hdr_t *grhdrp = drivep->d_greadhdrp;
 	drive_ops_t *dop = drivep->d_opsp;
 	/* REFERENCED */
 	intgen_t nread;
 	intgen_t rval;
 	direnthdr_t tmpdh;
+	char *namep;    // beginning of name following the direnthdr_t
 
 	/* read the head of the dirent
 	 */
@@ -8124,7 +8129,19 @@ read_dirent( drive_t *drivep,
 			  ( rrbfp_t )
 			  dop->do_return_read_buf,
 			  &rval );
-	xlate_direnthdr(&tmpdh, dhdrp, 1);
+	if ( grhdrp->gh_version >= GLOBAL_HDR_VERSION_3 ) {
+		xlate_direnthdr(&tmpdh, dhdrp, 1);
+		namep = dhdrp->dh_name + sizeof(dhdrp->dh_name);
+	} else {
+		direnthdr_v1_t dhdr_v1;
+		xlate_direnthdr_v1((direnthdr_v1_t *)&tmpdh, &dhdr_v1, 1);
+		dhdrp->dh_ino = dhdr_v1.dh_ino;
+		dhdrp->dh_gen = BIGGEN2GEN(dhdr_v1.dh_gen);
+		dhdrp->dh_checksum = dhdr_v1.dh_checksum;
+		dhdrp->dh_sz = dhdr_v1.dh_sz;
+		memcpy(dhdrp->dh_name, dhdr_v1.dh_name, sizeof(dhdr_v1.dh_name));
+		namep = dhdrp->dh_name + sizeof(dhdr_v1.dh_name);
+	}
 
 	switch( rval ) {
 	case 0:
@@ -8177,7 +8194,7 @@ read_dirent( drive_t *drivep,
 	ASSERT( ! ( ( size_t )dhdrp->dh_sz & ( DIRENTHDR_ALIGN - 1 )));
 	if ( ( size_t )dhdrp->dh_sz > sizeof( direnthdr_t )) {
 		size_t remsz = ( size_t )dhdrp->dh_sz - sizeof( direnthdr_t );
-		nread = read_buf( ( char * )( dhdrp + 1 ),
+		nread = read_buf( namep,
 				  remsz,
 				  ( void * )drivep,
 				  ( rfp_t )dop->do_read,
restore/tree.c +52 -16

175 lines not on this page · raw message

restore/tree.h +4 -3
index 93621c7..29d1033 100644
@@ -32,7 +32,8 @@ 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 );
 
 /* tree_sync - synchronizes with an existing tree abstraction
  */
@@ -53,7 +54,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 +85,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
#1 lore raw
Quoted 5 lines · Bill Kendall

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.

I suspect that this does fix the problem. Since the fix is in the dump, not just restore, I guess I'll just have to start with a fresh level 0 and see if the failure ever happens again upon restore.

Thanks,
David

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

#2 lore raw
Quoted 10 lines · David Brown
Quoted 7 lines · Bill Kendall

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.

Quoted 3 lines

I suspect that this does fix the problem. Since the fix is in the dump, not just restore, I guess I'll just have to start with a fresh level 0 and see if the failure ever happens again upon restore.

That's right. If you need to recover files from the backup that has issues, try applying only your level 1 backup and select just the files that failed to restore.

Bill

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

#3 lore raw
In reply to Bill Kendall
Quoted 3 lines · Bill Kendall

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.

Shouldn't the be an option to still generate the old format for compatibility reasons?

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

#4 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Bill Kendall

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.

Shouldn't the be an option to still generate the old format for compatibility reasons?

The new format contains more information than the old. The new xfsrestore can drop back to using 12-bit generation numbers even if the dump used 32 bits. It will do this automatically when applying a series of restores if the oldest dump used only 12 bits.

It's possible that a site would revert to an old xfsdump in the middle of a series of incremental backups, allowing for the oldest backup to use 32-bit generation numbers and a newer backup to use only 12 bits. xfsrestore won't get this right, so a case could be made for having a "force 12-bit generation numbers" option on xfsrestore.

You were referring to an xfsdump option. What use case did you have in mind? Compatibility with an old restore?

Thanks,
Bill

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

#6 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Bill Kendall

You were referring to an xfsdump option. What use case did you have in mind? Compatibility with an old restore?

Yes.

Ok, I can see the value in that if a filesystem is being moved to another system which has an older xfsrestore.

I'll repost with that change as well as with an option for xfsrestore to truncate all generation numbers down to 12-bits as mentioned in my last mail.

Bill

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