Skip to content

Commit c1922c4

Browse files
committed
debug-scripts: add a snapshot+balance stressor
This just runs snapshot and balance and snapshot delete a bunch. Signed-off-by: Josef Bacik <[email protected]>
1 parent 4130b53 commit c1922c4

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

snapshot-balance.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
COMPILEBENCH=/root/compilebench-0.6/
4+
DEV=/dev/nvme1n1
5+
MNT=/mnt/test
6+
SNAP_INTERVAL=1
7+
NUM_SNAPS=10
8+
9+
_fail() {
10+
echo $1
11+
exit 1
12+
}
13+
14+
_snap_thread() {
15+
local i=0
16+
local del=0
17+
local DEL_MOD=$(( NUM_SNAPS * 2 ))
18+
local DEL_SNAPS=$NUM_SNAPS
19+
while [ 1 ]
20+
do
21+
sleep $SNAP_INTERVAL
22+
btrfs sub snap $MNT $MNT/snaps/snap$i > /dev/null || \
23+
_fail "failed to create snap$i"
24+
i=$(( i + 1 ))
25+
if [ "$(( i % DEL_MOD))" -eq "0" ]
26+
then
27+
for c in $(seq 1 $DEL_SNAPS)
28+
do
29+
btrfs subvolume delete $MNT/snaps/snap$del || \
30+
_fail "failed to delete snap$del"
31+
del=$((del + 1 ))
32+
done
33+
btrfs balance start --full-balance --bg $MNT
34+
DEL_SNAPS=20
35+
fi
36+
done
37+
}
38+
39+
_balance_thread() {
40+
while [ 1 ]
41+
do
42+
sleep $SNAP_INTERVAL
43+
btrfs balance start --full-balance $MNT || \
44+
_fail "failed to balance"
45+
done
46+
}
47+
48+
mkfs.btrfs -f -n 4096 $DEV || _fail "couldn't mkfs"
49+
mount $DEV $MNT || _fail "couldn't mount"
50+
51+
mkdir $MNT/snaps
52+
_snap_thread &
53+
SNAP_PID=$!
54+
55+
cd $COMPILEBENCH
56+
for i in $(seq 0 100)
57+
do
58+
./compilebench -i 300 -m -D $MNT || break
59+
done
60+
61+
[ "$?" -ne "0"] && echo "compilebench failed"
62+
63+
btrfs balance cancel $MNT
64+
kill -9 $SNAP_PID
65+
66+
wait

0 commit comments

Comments
 (0)