6a380158d50030d8a2df6d57dbd64e83c64ef672
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 029-send-p-different-mountpoints / test.sh
1 #!/bin/bash
2 # test that send -p does not corrupt paths when send is using 2 different mount
3 # points
4
5 source "$TOP/tests/common"
6
7 check_prereq btrfs
8 check_prereq mkfs.btrfs
9
10 setup_root_helper
11 prepare_test_dev
12
13 # we need two mount points, cannot nest the subvoolume under TEST_MNT
14 SUBVOL_MNT="$TEST_MNT/subvol"
15 TOPLEVEL_MNT="$TEST_MNT/toplevel"
16 TEST_MNT="$TOPLEVEL_MNT"
17 mkdir -p "$TOPLEVEL_MNT" "$SUBVOL_MNT"
18
19 run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
20 run_check_mount_test_dev
21
22 run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TOPLEVEL_MNT/subv1"
23 run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$TEST_DEV" "$SUBVOL_MNT"
24
25 run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TOPLEVEL_MNT/test-subvol"
26 run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \
27         "$TOPLEVEL_MNT/test-subvol" "$SUBVOL_MNT/test-subvol-mnt-subvol"
28 run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \
29         "$TOPLEVEL_MNT/test-subvol" "$TOPLEVEL_MNT/test-subvol-mnt-root"
30
31 run_mustfail_stdout "send -p on 2 mount points" \
32         $SUDO_HELPER "$TOP/btrfs" send -f /dev/null -p \
33         "$SUBVOL_MNT/test-subvol-mnt-subvol" "$TOPLEVEL_MNT/test-subvol-mnt-root" \
34         | _log_stdout \
35         | grep -q "not on mount point.*/toplevel" \
36         || _fail "expected output not found, please check the logs"
37
38 # without a fix, this leads to a corrupted path, with something like:
39 #
40 # ERROR: open st-subvol-mnt-subvol failed. No such file or directory
41 #             ^^^^^^^^^^^^^^^^^^^^
42 # ERROR: could not resolve rootid for .../tests/mnt/subvol/test-subvol-mnt-subvol
43
44 # expected output:
45 # ERROR: not on mount point: .../tests/mnt/toplevel
46
47 run_check_umount_test_dev "$SUBVOL_MNT"
48 run_check_umount_test_dev "$TOPLEVEL_MNT"
49
50 rmdir "$SUBVOL_MNT"
51 rmdir "$TOPLEVEL_MNT"