diff --git a/kmod/src/srch.c b/kmod/src/srch.c index b113614c..54b0711d 100644 --- a/kmod/src/srch.c +++ b/kmod/src/srch.c @@ -1481,10 +1481,11 @@ static int kway_merge(struct super_block *sb, int ind; int i; - if (WARN_ON_ONCE(nr <= 1)) + if (WARN_ON_ONCE(nr <= 0)) return -EINVAL; - nr_parents = roundup_pow_of_two(nr) - 1; + /* always at least one parent for single leaf */ + nr_parents = max_t(unsigned long, 1, roundup_pow_of_two(nr) - 1); /* root at [1] for easy sib/parent index calc, final pad for odd sib */ nr_nodes = 1 + nr_parents + nr + 1; tnodes = __vmalloc(nr_nodes * sizeof(struct tourn_node), diff --git a/tests/golden/srch-basic-functionality b/tests/golden/srch-basic-functionality index c46d1701..e135bb58 100644 --- a/tests/golden/srch-basic-functionality +++ b/tests/golden/srch-basic-functionality @@ -2,6 +2,7 @@ == update existing xattr == remove an xattr == remove xattr with files +== trigger small log merges by rotating single block with unmount == create entries in current log == delete small fraction == remove files diff --git a/tests/tests/srch-basic-functionality.sh b/tests/tests/srch-basic-functionality.sh index 55c709f5..1b982489 100644 --- a/tests/tests/srch-basic-functionality.sh +++ b/tests/tests/srch-basic-functionality.sh @@ -42,6 +42,31 @@ echo "== remove xattr with files" rm -f "$T_D0/"{create,update} diff_srch_find scoutfs.srch.test +echo "== trigger small log merges by rotating single block with unmount" +sv=$(t_server_nr) +i=1 +while [ "$i" -lt "8" ]; do + for nr in $(t_fs_nrs); do + # not checking, can go over limit by fs_nrs + ((i++)) + + if [ $nr == $sv ]; then + continue; + fi + + eval path="\$T_D${nr}/single-block-$i" + touch "$path" + setfattr -n scoutfs.srch.single-block-logs -v $i "$path" + t_umount $nr + t_mount $nr + + ((i++)) + done +done +# wait for srch compaction worker delay +sleep 10 +rm -rf "$T_D0/single-block-*" + echo "== create entries in current log" DIR="$T_D0/dir" NR=$((LOG / 4))