@@ -45,8 +45,8 @@ fill_workload()
# Randomly remove some files for every 5 loop
if [ $(( $i % 5 )) -eq 0 ]; then
- victim=$(ls "$SCRATCH_MNT/src" | sort -R | head -n1)
- rm "$SCRATCH_MNT/src/$victim"
+ victim=$(_random_file "$SCRATCH_MNT/src")
+ rm "$victim"
fi
i=$((i + 1))
done
@@ -69,13 +69,12 @@ delete_workload()
trap "wait; exit" SIGTERM
while true; do
sleep $((sleep_time * 2))
- victim=$(ls "$SCRATCH_MNT/snapshots" | sort -R | head -n1)
+ victim=$(_random_file "$SCRATCH_MNT/snapshots")
if [ -z "$victim" ]; then
# No snapshots available, sleep and retry later.
continue
fi
- $BTRFS_UTIL_PROG subvolume delete \
- "$SCRATCH_MNT/snapshots/$victim" > /dev/null
+ $BTRFS_UTIL_PROG subvolume delete "$victim" > /dev/null
done
}
@@ -69,12 +69,6 @@ $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/src > /dev/null
mkdir -p $SCRATCH_MNT/snapshots
mkdir -p $SCRATCH_MNT/src/padding
-random_file()
-{
- local basedir=$1
- echo "$basedir/$(ls $basedir | sort -R | tail -1)"
-}
-
snapshot_workload()
{
trap "wait; exit" SIGTERM
@@ -85,9 +79,9 @@ snapshot_workload()
$SCRATCH_MNT/src $SCRATCH_MNT/snapshots/$i \
> /dev/null
# Do something small to make snapshots different
- rm -f "$(random_file $SCRATCH_MNT/src/padding)"
- rm -f "$(random_file $SCRATCH_MNT/src/padding)"
- touch "$(random_file $SCRATCH_MNT/src/padding)"
+ rm -f "$(_random_file $SCRATCH_MNT/src/padding)"
+ rm -f "$(_random_file $SCRATCH_MNT/src/padding)"
+ touch "$(_random_file $SCRATCH_MNT/src/padding)"
touch "$SCRATCH_MNT/src/padding/random_$RANDOM"
i=$(($i + 1))
@@ -102,7 +96,7 @@ delete_workload()
while true; do
sleep 2
$BTRFS_UTIL_PROG subvolume delete \
- "$(random_file $SCRATCH_MNT/snapshots)" \
+ "$(_random_file $SCRATCH_MNT/snapshots)" \
> /dev/null 2>&1
done
}
Use _random_file() helper to choose a random file in a directory. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- tests/btrfs/179 | 9 ++++----- tests/btrfs/192 | 14 ++++---------- 2 files changed, 8 insertions(+), 15 deletions(-)