]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: handle spurious wakeups in scan_fs_tree
authorDarrick J. Wong <djwong@kernel.org>
Wed, 20 Dec 2023 16:53:46 +0000 (08:53 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 22 Dec 2023 02:29:14 +0000 (18:29 -0800)
Coverity reminded me that the pthread_cond_wait can wake up and return
without the predicate variable (sft.nr_dirs > 0) actually changing.
Therefore, one has to retest the condition after each wakeup.

Coverity-id: 1554280
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/vfs.c

index 577eb6dc3e868729dd3cb92c732c1e7a8a78b1c8..3c1825a75e7d8050e890f0898e0ff93ed89b9908 100644 (file)
@@ -263,7 +263,7 @@ scan_fs_tree(
         * about to tear everything down.
         */
        pthread_mutex_lock(&sft.lock);
-       if (sft.nr_dirs)
+       while (sft.nr_dirs > 0)
                pthread_cond_wait(&sft.wakeup, &sft.lock);
        assert(sft.nr_dirs == 0);
        pthread_mutex_unlock(&sft.lock);