* [PATCH] xfs_repair: invalidate dirhash entry when junking dirent
@ 2021-07-27 19:16 Darrick J. Wong
2021-07-27 22:17 ` Dave Chinner
0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2021-07-27 19:16 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs
From: Darrick J. Wong <djwong@kernel.org>
In longform_dir2_entry_check_data, we add the directory entries we find
to the incore dirent hash table after we've validated the name but
before we're totally done checking the entry. This sequence is
necessary to detect all duplicated names in the directory.
Unfortunately, if we later decide to junk the ondisk dirent, we neglect
to mark the dirhash entry, so if the directory gets rebuilt, it will get
rebuilt with the entry that we rejected.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
repair/phase6.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/repair/phase6.c b/repair/phase6.c
index 29259b38..84092269 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -237,6 +237,21 @@ dir_hash_add(
return !dup;
}
+/* Mark an existing directory hashtable entry as junk. */
+static void
+dir_hash_junkit(
+ struct dir_hash_tab *hashtab,
+ xfs_dir2_dataptr_t addr)
+{
+ struct dir_hash_ent *p;
+
+ p = radix_tree_lookup(&hashtab->byaddr, addr);
+ assert(p != NULL);
+
+ p->junkit = 1;
+ p->namebuf[0] = '/';
+}
+
static int
dir_hash_check(
struct dir_hash_tab *hashtab,
@@ -2009,6 +2024,7 @@ longform_dir2_entry_check_data(
if (entry_junked(
_("entry \"%s\" (ino %" PRIu64 ") in dir %" PRIu64 " is not in the the first block"), fname,
inum, ip->i_ino)) {
+ dir_hash_junkit(hashtab, addr);
dep->name[0] = '/';
libxfs_dir2_data_log_entry(&da, bp, dep);
}
@@ -2036,6 +2052,7 @@ longform_dir2_entry_check_data(
if (entry_junked(
_("entry \"%s\" in dir %" PRIu64 " is not the first entry"),
fname, inum, ip->i_ino)) {
+ dir_hash_junkit(hashtab, addr);
dep->name[0] = '/';
libxfs_dir2_data_log_entry(&da, bp, dep);
}
@@ -2124,6 +2141,7 @@ _("entry \"%s\" in dir inode %" PRIu64 " inconsistent with .. value (%" PRIu64 "
orphanage_ino = 0;
nbad++;
if (!no_modify) {
+ dir_hash_junkit(hashtab, addr);
dep->name[0] = '/';
libxfs_dir2_data_log_entry(&da, bp, dep);
if (verbose)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] xfs_repair: invalidate dirhash entry when junking dirent
2021-07-27 19:16 [PATCH] xfs_repair: invalidate dirhash entry when junking dirent Darrick J. Wong
@ 2021-07-27 22:17 ` Dave Chinner
0 siblings, 0 replies; 2+ messages in thread
From: Dave Chinner @ 2021-07-27 22:17 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Eric Sandeen, xfs
On Tue, Jul 27, 2021 at 12:16:11PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> In longform_dir2_entry_check_data, we add the directory entries we find
> to the incore dirent hash table after we've validated the name but
> before we're totally done checking the entry. This sequence is
> necessary to detect all duplicated names in the directory.
>
> Unfortunately, if we later decide to junk the ondisk dirent, we neglect
> to mark the dirhash entry, so if the directory gets rebuilt, it will get
> rebuilt with the entry that we rejected.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Makes sense.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-27 22:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-27 19:16 [PATCH] xfs_repair: invalidate dirhash entry when junking dirent Darrick J. Wong
2021-07-27 22:17 ` Dave Chinner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox