Skip to contentSkip to conversation

repair: fix the variable-width nlink array

PATCH In review Christoph Hellwig 4 participants 8 messages Feb 28, 2012 – Mar 27, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 repair: fix the variable-width nlink array

It looks like we currently never grow the variable-width nlink array if only the on-disk nlink size overflows 8 bits. This leads to a major mess in nlink counting, and eventually an assert in phase7.

Replace the indirect all mess with a union that allows doing proper array arithmetics while we're at it.

repair/incore.h +14 -47
index fdb7742..8a578b5 100644
@@ -268,11 +268,17 @@ typedef struct parent_list  {
 #endif
 } parent_list_t;
 
+union ino_nlink {
+	__uint8_t	*un8;
+	__uint16_t	*un16;
+	__uint32_t	*un32;
+};
+
 typedef struct ino_ex_data  {
 	__uint64_t		ino_reached;	/* bit == 1 if reached */
 	__uint64_t		ino_processed;	/* reference checked bit mask */
 	parent_list_t		*parents;
-	__uint8_t		*counted_nlinks;/* counted nlinks in P6 */
+	union ino_nlink		counted_nlinks;/* counted nlinks in P6 */
 } ino_ex_data_t;
 
 typedef struct ino_tree_node  {
@@ -281,8 +287,8 @@ typedef struct ino_tree_node  {
 	xfs_inofree_t		ir_free;	/* inode free bit mask */
 	__uint64_t		ino_confirmed;	/* confirmed bitmask */
 	__uint64_t		ino_isa_dir;	/* bit == 1 if a directory */
-	struct nlink_ops	*nlinkops;	/* pointer to current nlink ops */
-	__uint8_t		*disk_nlinks;	/* on-disk nlinks, set in P3 */
+	__uint8_t		nlink_size;
+	union ino_nlink		disk_nlinks;	/* on-disk nlinks, set in P3 */
 	union  {
 		ino_ex_data_t	*ex_data;	/* phases 6,7 */
 		parent_list_t	*plist;		/* phases 2-5 */
@@ -292,16 +298,6 @@ typedef struct ino_tree_node  {
 #define INOS_PER_IREC	(sizeof(__uint64_t) * NBBY)
 #define	IREC_MASK(i)	((__uint64_t)1 << (i))
 
-typedef struct nlink_ops {
-	const int	nlink_size;
-	void		(*disk_nlink_set)(ino_tree_node_t *, int, __uint32_t);
-	__uint32_t	(*disk_nlink_get)(ino_tree_node_t *, int);
-	__uint32_t	(*counted_nlink_get)(ino_tree_node_t *, int);
-	__uint32_t	(*counted_nlink_inc)(ino_tree_node_t *, int);
-	__uint32_t	(*counted_nlink_dec)(ino_tree_node_t *, int);
-} nlink_ops_t;
-
-
 void		add_ino_ex_data(xfs_mount_t *mp);
 
 /*
@@ -460,29 +456,12 @@ static inline int is_inode_free(struct ino_tree_node *irec, int offset)
  * detected and drop_inode_ref() is called every time a link to
  * an inode that we've counted is removed.
  */
+void add_inode_ref(struct ino_tree_node *irec, int offset);
+void drop_inode_ref(struct ino_tree_node *irec, int offset);
+__uint32_t num_inode_references(struct ino_tree_node *irec, int offset);
 
-static inline void add_inode_ref(struct ino_tree_node *irec, int offset)
-{
-	ASSERT(irec->ino_un.ex_data != NULL);
-
-	irec->nlinkops->counted_nlink_inc(irec, offset);
-}
-
-static inline void drop_inode_ref(struct ino_tree_node *irec, int offset)
-{
-	ASSERT(irec->ino_un.ex_data != NULL);
-
-	if (irec->nlinkops->counted_nlink_dec(irec, offset) == 0)
-		irec->ino_un.ex_data->ino_reached &= ~IREC_MASK(offset);
-}
-
-static inline __uint32_t num_inode_references(struct ino_tree_node *irec,
-		int offset)
-{
-	ASSERT(irec->ino_un.ex_data != NULL);
-
-	return irec->nlinkops->counted_nlink_get(irec, offset);
-}
+void set_inode_disk_nlinks(struct ino_tree_node *irec, int offset, __uint32_t nlinks);
+__uint32_t get_inode_disk_nlinks(struct ino_tree_node *irec, int offset);
 
 static inline int is_inode_reached(struct ino_tree_node *irec, int offset)
 {
@@ -496,18 +475,6 @@ static inline void add_inode_reached(struct ino_tree_node *irec, int offset)
 	irec->ino_un.ex_data->ino_reached |= IREC_MASK(offset);
 }
 
-static inline void set_inode_disk_nlinks(struct ino_tree_node *irec, int offset,
-		__uint32_t nlinks)
-{
-	irec->nlinkops->disk_nlink_set(irec, offset, nlinks);
-}
-
-static inline __uint32_t get_inode_disk_nlinks(struct ino_tree_node *irec,
-		int offset)
-{
-	return irec->nlinkops->disk_nlink_get(irec, offset);
-}
-
 /*
  * set/get inode number of parent -- works for directory inodes only
  */
repair/incore_ino.c +170 -153

394 lines not on this page · raw message

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

#1 lore raw

PATCH 2/2 repair: fix messages from set_nlinks

Link counts are unsigned and need to be printed as such. Also only print the varning about upgrading the inode version if the inode was version 1 before.

repair/phase7.c +5 -4
Index: xfsprogs-dev/repair/phase7.c
===================================================================
@@ -40,19 +40,20 @@ set_nlinks(
 
 	if (!no_modify) {
 		*dirty = 1;
-		do_warn(_("resetting inode %" PRIu64 " nlinks from %d to %d\n"),
+		do_warn(_("resetting inode %" PRIu64 " nlinks from %u to %u\n"),
 			ino, dinoc->di_nlink, nrefs);
 
-		if (nrefs > XFS_MAXLINK_1)  {
+		if (dinoc->di_version == 1 && nrefs > XFS_MAXLINK_1)  {
 			ASSERT(fs_inode_nlink);
 			do_warn(
-_("nlinks %d will overflow v1 ino, ino %" PRIu64 " will be converted to version 2\n"),
+_("nlinks %u will overflow v1 ino, ino %" PRIu64 " will be converted to version 2\n"),
 				nrefs, ino);
 
 		}
 		dinoc->di_nlink = nrefs;
 	} else  {
-		do_warn(_("would have reset inode %" PRIu64 " nlinks from %d to %d\n"),
+		do_warn(
+_("would have reset inode %" PRIu64 " nlinks from %u to %u\n"),
 			ino, dinoc->di_nlink, nrefs);
 	}
 }

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

Reviewed-by on v1 1/2
#3 lore raw
In reply to Christoph Hellwig

Hey Christoph,

Quoted 8 lines · Christoph Hellwig

It looks like we currently never grow the variable-width nlink array if only the on-disk nlink size overflows 8 bits. This leads to a major mess in nlink counting, and eventually an assert in phase7.

Replace the indirect all mess with a union that allows doing proper array arithmetics while we're at it.

This looks good to me. I enjoyed the fallthrus in set_inode_disk_nlinks and add_inode_ref.

I haven't tested with this many links though... Are there any xfstests that would exercise this?

On my machine test 030 has regressed. It passed on 3.1.7.

-Ben

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

#4 lore raw
Quoted 10 lines · Ben Myers

Hey Christoph,

Quoted 7 lines · Christoph Hellwig

It looks like we currently never grow the variable-width nlink array if only the on-disk nlink size overflows 8 bits. This leads to a major mess in nlink counting, and eventually an assert in phase7.

Replace the indirect all mess with a union that allows doing proper array arithmetics while we're at it.

Quoted 7 lines
Quoted 1 line

This looks good to me. I enjoyed the fallthrus in set_inode_disk_nlinks and add_inode_ref.

I haven't tested with this many links though... Are there any xfstests that would exercise this?

There is none yet. I've tested it with Arekm's test metadump, which I've added to my nasty images collection. I'll create a testcase reproducing this artifically.

Quoted 1 line

On my machine test 030 has regressed. It passed on 3.1.7.

That's an older change. I have a fix in my local tree, but it needs polishing so that it still works with older repair versions.

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

Reviewed-by on v1 1/2
#7 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

It looks like we currently never grow the variable-width nlink array if only the on-disk nlink size overflows 8 bits. This leads to a major mess in nlink counting, and eventually an assert in phase7.

Replace the indirect all mess with a union that allows doing proper array arithmetics while we're at it.

Looks fairly sane to me. I can't see any obvious problems with the change, though it might be worth adding an overflow warning to the code:

Quoted 10 lines
repair/incore_ino.c +6 -3
+	switch (irec->nlink_size) {
+	case sizeof(__uint8_t):
+		if (irec->ino_un.ex_data->counted_nlinks.un8[ino_offset] < 0xff) {
+			irec->ino_un.ex_data->counted_nlinks.un8[ino_offset]++;
+			break;
+		}
 		nlink_grow_8_to_16(irec);
-		disk_nlink_16_set(irec, ino_offset, nlinks);
-	} else
-		irec->disk_nlinks[ino_offset] = nlinks;

repair/incore_ino.c static avltree_desc_t **inode_uncertain_tree_ptrs; · line 122

Quoted 10 lines
repair/incore_ino.c +10 -0
+		/*FALLTHRU*/
+	case sizeof(__uint16_t):
+		if (irec->ino_un.ex_data->counted_nlinks.un16[ino_offset] < 0xffff) {
+			irec->ino_un.ex_data->counted_nlinks.un16[ino_offset]++;
+			break;
+		}
+		nlink_grow_16_to_32(irec);
+		/*FALLTHRU*/
+	case sizeof(__uint32_t):
+		irec->ino_un.ex_data->counted_nlinks.un32[ino_offset]++;

To check for UINT_MAX before the increment....

Quoted 5 lines
repair/incore_ino.c +5 -0
+	switch (irec->nlink_size) {
+	case sizeof(__uint8_t):
+		ASSERT(irec->ino_un.ex_data->counted_nlinks.un8[ino_offset] > 0);
+		refs = --irec->ino_un.ex_data->counted_nlinks.un8[ino_offset];
+		break;

repair/incore_ino.c static avltree_desc_t **inode_uncertain_tree_ptrs; · line 149

Quoted 10 lines
repair/incore_ino.c +10 -0
+	case sizeof(__uint16_t):
+		ASSERT(irec->ino_un.ex_data->counted_nlinks.un16[ino_offset] > 0);
+		refs = --irec->ino_un.ex_data->counted_nlinks.un16[ino_offset];
+		break;
+	case sizeof(__uint32_t):
+		ASSERT(irec->ino_un.ex_data->counted_nlinks.un32[ino_offset] > 0);
+		refs = --irec->ino_un.ex_data->counted_nlinks.un32[ino_offset];
+		break;
+	default:
+		ASSERT(0);

Similar to the underflow checks here.

Otherwise:

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] repair: fix messages from set_nlinks

In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

Link counts are unsigned and need to be printed as such. Also only print the varning about upgrading the inode version if the inode was

warning

Quoted 3 lines

version 1 before.

Well you got reviews for the hard part, 1/2 :)

Quoted 31 lines

Index: xfsprogs-dev/repair/phase7.c
===================================================================

repair/phase7.c +5 -4
@@ -40,19 +40,20 @@ set_nlinks(
 
 	if (!no_modify) {
 		*dirty = 1;
-		do_warn(_("resetting inode %" PRIu64 " nlinks from %d to %d\n"),
+		do_warn(_("resetting inode %" PRIu64 " nlinks from %u to %u\n"),
 			ino, dinoc->di_nlink, nrefs);
 
-		if (nrefs > XFS_MAXLINK_1)  {
+		if (dinoc->di_version == 1 && nrefs > XFS_MAXLINK_1)  {
 			ASSERT(fs_inode_nlink);
 			do_warn(
-_("nlinks %d will overflow v1 ino, ino %" PRIu64 " will be converted to version 2\n"),
+_("nlinks %u will overflow v1 ino, ino %" PRIu64 " will be converted to version 2\n"),
 				nrefs, ino);
 
 		}
 		dinoc->di_nlink = nrefs;
 	} else  {
-		do_warn(_("would have reset inode %" PRIu64 " nlinks from %d to %d\n"),
+		do_warn(
+_("would have reset inode %" PRIu64 " nlinks from %u to %u\n"),
 			ino, dinoc->di_nlink, nrefs);
 	}
 }
Quoted 5 lines

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

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

#5 lore raw
In reply to Christoph Hellwig

Hey Christoph,

Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Ben Myers

On my machine test 030 has regressed. It passed on 3.1.7.

That's an older change. I have a fix in my local tree, but it needs polishing so that it still works with older repair versions.

Have you had a chance to work on your fix for 030?

Thanks,
Ben

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

#6 lore raw
Quoted 10 lines · Ben Myers

Hey Christoph,

Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Ben Myers

On my machine test 030 has regressed. It passed on 3.1.7.

That's an older change. I have a fix in my local tree, but it needs polishing so that it still works with older repair versions.

Have you had a chance to work on your fix for 030?

Sorry, I still haven't managed to get back to speed on xfstests, we are still missing tons of external commits, and various testcases seem to fail right now. I'll get back to it this weekend hopefully.

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