]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
xfs_repair: bump the irec on-disk nlink when adding lost+found
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 26 Apr 2019 20:39:23 +0000 (15:39 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 26 Apr 2019 20:39:23 +0000 (15:39 -0500)
commitfe4bd71b9b9db50d63640effa958057ad502453e
tree4cbdb131c4926ae26f50e3e0540536c5ab9f378d
parent1da4e1f0e61c076bb11ad166f10b1fb338852bdb
xfs_repair: bump the irec on-disk nlink when adding lost+found

We increment the nlink of the root directory inode when creating a
"lost+found" directory during phase 6, but we don't update the irec copy
of the root dir nlink.  This normally gets papered over by phase 7, but
this can fail badly if:

1) The root directory had an entry to a busted subdirectory, so
   that root directory will have nlink == 3, but in the ino_tree,
   counted_nlinks == 2 and disk_nlinks == 3.

2) Phase 6 creates lost+found to root the files that were in the busted
   directory, we'll set nlink = 4 and counted_nlinks = 3.  The correct
   nlink is 3 ('.', '..', 'lost+found'), not 4.

3) During phase 7, we see that counted_nlinks == disk_nlinks and so we
   totally fail to correct the on-disk inode.

4) A subsequent run of xfs_repair complains about the nlink being 4
   instead of 3.

To fix this, we have to adjust the irec's disk_nlinks in step 2 so that
phase 7 seeds that counted_nlinks < disk_nlinks and resets nlink to
counted_nlinks.  This can be reproduced somewhat frequently by xfs/117.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
repair/phase6.c