From: Darrick J. Wong Date: Fri, 12 Feb 2021 22:23:06 +0000 (-0500) Subject: xfs_scrub: handle concurrent directory updates during name scan X-Git-Tag: v5.11.0-rc1~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=942d5946d744d4abde0cf56678997f79207f81fa;p=thirdparty%2Fxfsprogs-dev.git xfs_scrub: handle concurrent directory updates during name scan The name scanner in xfs_scrub cannot lock a namespace (dirent or xattr) and the kernel does not provide a stable cursor interface, which means that we can see the same byte sequence multiple times during a scan. This isn't a confusing name error since the kernel enforces uniqueness on the byte sequence, so all we need to do here is update the old entry. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Eric Sandeen --- diff --git a/scrub/unicrash.c b/scrub/unicrash.c index de3217c29..cb0880c10 100644 --- a/scrub/unicrash.c +++ b/scrub/unicrash.c @@ -68,7 +68,7 @@ struct name_entry { xfs_ino_t ino; - /* Raw UTF8 name */ + /* Raw dirent name */ size_t namelen; char name[0]; }; @@ -627,6 +627,20 @@ unicrash_add( uc->buckets[bucket] = new_entry; while (entry != NULL) { + /* + * If we see the same byte sequence then someone's modifying + * the namespace while we're scanning it. Update the existing + * entry's inode mapping and erase the new entry from existence. + */ + if (new_entry->namelen == entry->namelen && + !memcmp(new_entry->name, entry->name, entry->namelen)) { + entry->ino = new_entry->ino; + uc->buckets[bucket] = new_entry->next; + name_entry_free(new_entry); + *badflags = 0; + return; + } + /* Same normalization? */ if (new_entry->normstrlen == entry->normstrlen && !u_strcmp(new_entry->normstr, entry->normstr) &&