Skip to content

Commit aec2eb7

Browse files
author
Darrick J. Wong
committed
xfs: adjust parent pointer scrubber for sb-rooted metadata files
Starting with the metadata directory feature, we're allowed to call the directory and parent pointer scrubbers for every metadata file, including the ones that are children of the superblock. For these children, checking the link count against the number of parent pointers is a bit funny -- there's no such thing as a parent pointer for a child of the superblock since there's no corresponding dirent. For purposes of validating nlink, we pretend that there is a parent pointer. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 91fb423 commit aec2eb7

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

fs/xfs/scrub/parent.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,14 @@ xchk_parent_count_pptrs(
720720
pp->pptrs_found == 0)
721721
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
722722
} else {
723+
/*
724+
* Starting with metadir, we allow checking of parent pointers
725+
* of non-directory files that are children of the superblock.
726+
* Pretend that we found a parent pointer attr.
727+
*/
728+
if (xfs_has_metadir(sc->mp) && xchk_inode_is_sb_rooted(sc->ip))
729+
pp->pptrs_found++;
730+
723731
if (VFS_I(sc->ip)->i_nlink != pp->pptrs_found)
724732
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
725733
}

fs/xfs/scrub/parent_repair.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,21 +1354,40 @@ STATIC int
13541354
xrep_parent_rebuild_tree(
13551355
struct xrep_parent *rp)
13561356
{
1357+
struct xfs_scrub *sc = rp->sc;
1358+
bool try_adoption;
13571359
int error;
13581360

1359-
if (xfs_has_parent(rp->sc->mp)) {
1361+
if (xfs_has_parent(sc->mp)) {
13601362
error = xrep_parent_rebuild_pptrs(rp);
13611363
if (error)
13621364
return error;
13631365
}
13641366

1365-
if (rp->pscan.parent_ino == NULLFSINO) {
1366-
if (xrep_orphanage_can_adopt(rp->sc))
1367+
/*
1368+
* Any file with no parent could be adopted. This check happens after
1369+
* rebuilding the parent pointer structure because we might have cycled
1370+
* the ILOCK during that process.
1371+
*/
1372+
try_adoption = rp->pscan.parent_ino == NULLFSINO;
1373+
1374+
/*
1375+
* Starting with metadir, we allow checking of parent pointers
1376+
* of non-directory files that are children of the superblock.
1377+
* Lack of parent is ok here.
1378+
*/
1379+
if (try_adoption && xfs_has_metadir(sc->mp) &&
1380+
xchk_inode_is_sb_rooted(sc->ip))
1381+
try_adoption = false;
1382+
1383+
if (try_adoption) {
1384+
if (xrep_orphanage_can_adopt(sc))
13671385
return xrep_parent_move_to_orphanage(rp);
13681386
return -EFSCORRUPTED;
1387+
13691388
}
13701389

1371-
if (S_ISDIR(VFS_I(rp->sc->ip)->i_mode))
1390+
if (S_ISDIR(VFS_I(sc->ip)->i_mode))
13721391
return xrep_parent_reset_dotdot(rp);
13731392

13741393
return 0;
@@ -1422,6 +1441,14 @@ xrep_parent_set_nondir_nlink(
14221441
if (error)
14231442
return error;
14241443

1444+
/*
1445+
* Starting with metadir, we allow checking of parent pointers of
1446+
* non-directory files that are children of the superblock. Pretend
1447+
* that we found a parent pointer attr.
1448+
*/
1449+
if (xfs_has_metadir(sc->mp) && xchk_inode_is_sb_rooted(sc->ip))
1450+
rp->parents++;
1451+
14251452
if (rp->parents > 0 && xfs_inode_on_unlinked_list(ip)) {
14261453
xfs_trans_ijoin(sc->tp, sc->ip, 0);
14271454
joined = true;

0 commit comments

Comments
 (0)