62190e14b65d648d0863220eb522682753642379
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 009-subvolume-sync-must-wait / test.sh
1 #!/bin/bash
2 #
3 # Verify that subvolume sync waits until the subvolume is cleaned
4
5 source "$TEST_TOP/common"
6
7 check_prereq mkfs.btrfs
8 check_prereq btrfs
9
10 setup_root_helper
11
12 prepare_test_dev
13 run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV"
14 run_check_mount_test_dev
15 run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
16
17 cd "$TEST_MNT"
18
19 for i in `seq 5`; do
20         run_check dd if=/dev/zero of=file$i bs=1M count=10
21 done
22
23 for sn in `seq 4`;do
24         run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . snap$sn
25         for i in `seq 10`; do
26                 run_check dd if=/dev/zero of="snap$sn/file$i" bs=1M count=10
27         done
28 done
29
30 run_check $SUDO_HELPER "$TOP/btrfs" subvolume list .
31 run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d .
32
33 idtodel=`run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal rootid snap3`
34
35 # delete, sync after some time
36 run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete -c snap3
37 { sleep 5; run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"; } &
38
39 run_check $SUDO_HELPER "$TOP/btrfs" subvolume sync . "$idtodel"
40
41 if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -d . |
42                 grep -q "ID $idtodel.*DELETED"; then
43         _fail "sync did not wait for the subvolume cleanup"
44 fi
45
46 run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"
47 run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d .
48
49 wait
50 cd ..
51
52 run_check_umount_test_dev