From f86a7b4d3cd1697253baa27dcd6822ddcb0d31f6 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Thu, 5 Jun 2025 14:33:42 -0700 Subject: [PATCH] Fully wait for orphan inode scan to complete. The issue with the previous attempt to fix the orphan-inodes test was that we would regularly exceed the 120s timeout value put in there. Instead, in this commit, we change the code to add a new counter to indicate orphan deletion progress. When orphan inodes are deleted, the increment of this counter indicates progress happened. Inversely, every time the counter doesn't increment, and the orphan scan attempts counter increments, we know that there was no more work to be done. For safety, we wait until 2 consecutive scan attempts were made without forward progress in the test case. Signed-off-by: Auke Kok --- kmod/src/counters.h | 1 + kmod/src/inode.c | 3 +++ tests/tests/orphan-inodes.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/kmod/src/counters.h b/kmod/src/counters.h index 18e6daf1..c6d38775 100644 --- a/kmod/src/counters.h +++ b/kmod/src/counters.h @@ -90,6 +90,7 @@ EXPAND_COUNTER(forest_read_items) \ EXPAND_COUNTER(forest_roots_next_hint) \ EXPAND_COUNTER(forest_set_bloom_bits) \ + EXPAND_COUNTER(inode_deleted) \ EXPAND_COUNTER(item_cache_count_objects) \ EXPAND_COUNTER(item_cache_scan_objects) \ EXPAND_COUNTER(item_clear_dirty) \ diff --git a/kmod/src/inode.c b/kmod/src/inode.c index 5e3f724f..61f06cd0 100644 --- a/kmod/src/inode.c +++ b/kmod/src/inode.c @@ -1854,6 +1854,9 @@ static int try_delete_inode_items(struct super_block *sb, u64 ino) goto out; ret = delete_inode_items(sb, ino, &sinode, lock, orph_lock); + if (ret == 0) + scoutfs_inc_counter(sb, inode_deleted); + out: if (clear_trying) clear_bit(bit_nr, ldata->trying); diff --git a/tests/tests/orphan-inodes.sh b/tests/tests/orphan-inodes.sh index 756f041e..fd0d1d75 100644 --- a/tests/tests/orphan-inodes.sh +++ b/tests/tests/orphan-inodes.sh @@ -69,8 +69,32 @@ while test -d $(echo /sys/fs/scoutfs/*/fence/* | cut -d " " -f 1); do done # wait for orphan scans to run t_set_all_sysfs_mount_options orphan_scan_delay_ms 1000 -# also have to wait for delayed log merge work from mount -sleep 15 +# wait until we see two consecutive orphan scan attempts without +# any inode deletion forward progress in each mount +for nr in $(t_fs_nrs); do + C=0 + LOSA=$(t_counter orphan_scan_attempts $nr) + LDOP=$(t_counter inode_deleted $nr) + + while [ $C -lt 2 ]; do + sleep 1 + + OSA=$(t_counter orphan_scan_attempts $nr) + DOP=$(t_counter inode_deleted $nr) + + if [ $OSA != $LOSA ]; then + if [ $DOP == $LDOP ]; then + (( C++ )) + else + C=0 + fi + fi + + LOSA=$OSA + LDOP=$DOP + done +done + for ino in $inos; do inode_exists $ino && echo "$ino still exists" done