[PATCH 2/4] xfs_scrub: handle spurious wakeups in scan_fs_tree

Darrick J. Wong
2023-11-22T23:07:58Z

From: Darrick J. Wong <djwong@kernel.org>

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>
---
scrub/vfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scrub/vfs.c b/scrub/vfs.c
index 577eb6dc3e8..3c1825a75e7 100644
--- a/scrub/vfs.c
+++ b/scrub/vfs.c
@@ -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);