From: Andreas Dilger Date: Mon, 13 Dec 2021 06:35:30 +0000 (-0700) Subject: e2fsck: no parent lookup in disconnected dir X-Git-Tag: v1.46.6-rc1~60 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=6b0e3bd7bd2f2db3c3993c5d91379ad55e60b51e;p=tools%2Fe2fsprogs.git e2fsck: no parent lookup in disconnected dir Don't call into ext2fs_get_pathname() to do a name lookup for a disconnected directory, since the directory block traversal in pass1 has already scanned all of the leaf blocks and never finds the entry, always printing "???". If the name entry had been found earlier, the directory would not be disconnected in pass3. Instead, lookup ".." and print the parent name in the prompt, and then do not search for the current directory name at all. This avoids a useless full directory scan for each disconnected entry, which can potentially be slow if the parent directory is large. Separate the recursively looped directory case to a new error code, since it is a different problem that should use its own descriptive text, and a proper pathname can be shown in this case. Lustre-bug-Id: https://jira.whamcloud.com/browse/LU-15330 Change-Id: If17a92689f24f365ca1fbe5c837e7d5f383ebbe5 Signed-off-by: Andreas Dilger Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c index cedaaf5..d6b8c8b 100644 --- a/e2fsck/pass3.c +++ b/e2fsck/pass3.c @@ -22,7 +22,7 @@ * will offer to reconnect it to /lost+found. While it is chasing * parent pointers up the filesystem tree, if pass3 sees a directory * twice, then it has detected a filesystem loop, and it will again - * offer to reconnect the directory to /lost+found in to break the + * offer to reconnect the directory to /lost+found in order to break the * filesystem loop. * * Pass 3 also contains the subroutine, e2fsck_reconnect_file() to @@ -304,7 +304,7 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir, * If it was marked done already, then we've reached a * parent we've already checked. */ - if (ext2fs_mark_inode_bitmap2(inode_done_map, ino)) + if (ext2fs_mark_inode_bitmap2(inode_done_map, ino)) break; if (e2fsck_dir_info_get_parent(ctx, ino, &parent)) { @@ -319,13 +319,18 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir, */ if (!parent || (loop_pass && - (ext2fs_test_inode_bitmap2(inode_loop_detect, - parent)))) { + ext2fs_test_inode_bitmap2(inode_loop_detect, parent))) { pctx->ino = ino; - if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) { - if (e2fsck_reconnect_file(ctx, pctx->ino)) + if (parent) + pctx->dir = parent; + else + ext2fs_lookup(fs, ino, "..", 2, NULL, + &pctx->dir); + if (fix_problem(ctx, !parent ? PR_3_UNCONNECTED_DIR : + PR_3_LOOPED_DIR, pctx)) { + if (e2fsck_reconnect_file(ctx, pctx->ino)) { ext2fs_unmark_valid(fs); - else { + } else { fix_dotdot(ctx, pctx->ino, ctx->lost_and_found); parent = ctx->lost_and_found; diff --git a/e2fsck/problem.c b/e2fsck/problem.c index 2d02468..46a7427 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -1852,7 +1852,7 @@ static struct e2fsck_problem problem_table[] = { /* Unconnected directory inode */ { PR_3_UNCONNECTED_DIR, /* xgettext:no-c-format */ - N_("Unconnected @d @i %i (%p)\n"), + N_("Unconnected @d @i %i (was in %q)\n"), PROMPT_CONNECT, 0, 0, 0, 0 }, /* /lost+found not found */ @@ -1989,6 +1989,12 @@ static struct e2fsck_problem problem_table[] = { N_("/@l is encrypted\n"), PROMPT_CLEAR, 0, 0, 0, 0 }, + /* Recursively looped directory inode */ + { PR_3_LOOPED_DIR, + /* xgettext:no-c-format */ + N_("Recursively looped @d @i %i (%p)\n"), + PROMPT_CONNECT, 0, 0, 0, 0 }, + /* Pass 3A Directory Optimization */ /* Pass 3A: Optimizing directories */ diff --git a/e2fsck/problem.h b/e2fsck/problem.h index 24cdcf9..e86bc88 100644 --- a/e2fsck/problem.h +++ b/e2fsck/problem.h @@ -1132,6 +1132,9 @@ struct problem_context { /* Lost+found is encrypted */ #define PR_3_LPF_ENCRYPTED 0x03001B +/* Recursively looped directory inode */ +#define PR_3_LOOPED_DIR 0x03001D + /* * Pass 3a --- rehashing directories */ diff --git a/tests/f_bad_encryption/expect.1 b/tests/f_bad_encryption/expect.1 index d743e66..7027095 100644 --- a/tests/f_bad_encryption/expect.1 +++ b/tests/f_bad_encryption/expect.1 @@ -54,13 +54,13 @@ Encrypted entry '\M-ggCeM-/?M-^BM-{(M-^OM-9M-^QQAM-^N=M-c^Mo' in /edir (12) refe Clear? yes Pass 3: Checking directory connectivity -Unconnected directory inode 18 (/edir/???) +Unconnected directory inode 18 (was in /edir) Connect to /lost+found? yes -Unconnected directory inode 24 (/edir/???) +Unconnected directory inode 24 (was in /edir) Connect to /lost+found? yes -Unconnected directory inode 27 (/edir/???) +Unconnected directory inode 27 (was in /edir) Connect to /lost+found? yes Pass 4: Checking reference counts diff --git a/tests/f_badroot/expect.1 b/tests/f_badroot/expect.1 index f9d01e5..ff92426 100644 --- a/tests/f_badroot/expect.1 +++ b/tests/f_badroot/expect.1 @@ -9,7 +9,7 @@ Entry '..' in <2>/<11> (11) has deleted/unused inode 2. Clear? yes Pass 3: Checking directory connectivity Root inode not allocated. Allocate? yes -Unconnected directory inode 11 (...) +Unconnected directory inode 11 (was in /) Connect to /lost+found? yes /lost+found not found. Create? yes diff --git a/tests/f_encrypted_lpf/expect.1 b/tests/f_encrypted_lpf/expect.1 index 7e215b7..63ac5f3 100644 --- a/tests/f_encrypted_lpf/expect.1 +++ b/tests/f_encrypted_lpf/expect.1 @@ -1,7 +1,7 @@ Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity -Unconnected directory inode 12 (/???) +Unconnected directory inode 12 (was in /) Connect to /lost+found? yes /lost+found is encrypted @@ -13,7 +13,7 @@ Restarting e2fsck from the beginning... Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity -Unconnected directory inode 11 (/???) +Unconnected directory inode 11 (was in /) Connect to /lost+found? yes Pass 3A: Optimizing directories diff --git a/tests/f_expand/expect.1.gz b/tests/f_expand/expect.1.gz index 1015e15..81fe7dd 100644 Binary files a/tests/f_expand/expect.1.gz and b/tests/f_expand/expect.1.gz differ diff --git a/tests/f_lpf2/expect.1 b/tests/f_lpf2/expect.1 index 633586c..ab5d9ba 100644 --- a/tests/f_lpf2/expect.1 +++ b/tests/f_lpf2/expect.1 @@ -1,12 +1,12 @@ Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity -Unconnected directory inode 12 (/???) +Unconnected directory inode 12 (was in /) Connect to /lost+found? yes /lost+found not found. Create? yes -Unconnected directory inode 13 (/???) +Unconnected directory inode 13 (was in /) Connect to /lost+found? yes Pass 4: Checking reference counts diff --git a/tests/f_noroot/expect.1 b/tests/f_noroot/expect.1 index 7bdd7cb..f8f652e 100644 --- a/tests/f_noroot/expect.1 +++ b/tests/f_noroot/expect.1 @@ -11,12 +11,12 @@ Entry '..' in /foo (12) has deleted/unused inode 2. Clear? yes Pass 3: Checking directory connectivity Root inode not allocated. Allocate? yes -Unconnected directory inode 11 (...) +Unconnected directory inode 11 (was in /) Connect to /lost+found? yes /lost+found not found. Create? yes -Unconnected directory inode 12 (...) +Unconnected directory inode 12 (was in /lost+found) Connect to /lost+found? yes Pass 4: Checking reference counts diff --git a/tests/f_orphan_dotdot_ft/expect.1 b/tests/f_orphan_dotdot_ft/expect.1 index 6a1373f..6092495 100644 --- a/tests/f_orphan_dotdot_ft/expect.1 +++ b/tests/f_orphan_dotdot_ft/expect.1 @@ -17,13 +17,13 @@ Entry '..' in <12>/<15> (15) has an incorrect filetype (was 2, should be 6). Fix? yes Pass 3: Checking directory connectivity -Unconnected directory inode 13 (<12>/<13>) +Unconnected directory inode 13 (was in <12>) Connect to /lost+found? yes -Unconnected directory inode 14 (<12>/<14>) +Unconnected directory inode 14 (was in <12>) Connect to /lost+found? yes -Unconnected directory inode 15 (<12>/<15>) +Unconnected directory inode 15 (was in <12>) Connect to /lost+found? yes Pass 4: Checking reference counts diff --git a/tests/f_rebuild_csum_rootdir/expect.1 b/tests/f_rebuild_csum_rootdir/expect.1 index 91e6027..063fb8c 100644 --- a/tests/f_rebuild_csum_rootdir/expect.1 +++ b/tests/f_rebuild_csum_rootdir/expect.1 @@ -13,7 +13,7 @@ Pass 3: Checking directory connectivity '..' in / (2) is (0), should be / (2). Fix? yes -Unconnected directory inode 11 (/???) +Unconnected directory inode 11 (was in /) Connect to /lost+found? yes /lost+found not found. Create? yes diff --git a/tests/f_recnect_bad/expect.1 b/tests/f_recnect_bad/expect.1 index 97ffcc5..685eedf 100644 --- a/tests/f_recnect_bad/expect.1 +++ b/tests/f_recnect_bad/expect.1 @@ -12,7 +12,7 @@ i_faddr for inode 13 (/test/???) is 12, should be zero. Clear? yes Pass 3: Checking directory connectivity -Unconnected directory inode 13 (/test/???) +Unconnected directory inode 13 (was in /test) Connect to /lost+found? yes Pass 4: Checking reference counts diff --git a/tests/f_resize_inode_meta_bg/expect.1 b/tests/f_resize_inode_meta_bg/expect.1 index 769f71a..e248083 100644 --- a/tests/f_resize_inode_meta_bg/expect.1 +++ b/tests/f_resize_inode_meta_bg/expect.1 @@ -45,7 +45,7 @@ Pass 3: Checking directory connectivity '..' in / (2) is (0), should be / (2). Fix? yes -Unconnected directory inode 11 (/???) +Unconnected directory inode 11 (was in /) Connect to /lost+found? yes /lost+found not found. Create? yes