@@ -45,7 +45,7 @@ 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)
+ victim=$(_random_file "$SCRATCH_MNT/src")
rm "$SCRATCH_MNT/src/$victim"
fi
i=$((i + 1))
@@ -69,7 +69,7 @@ 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
@@ -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 | 4 ++-- tests/btrfs/192 | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-)