File: test.sh

package info (click to toggle)
btrfs-progs 6.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 17,244 kB
  • sloc: ansic: 114,376; sh: 9,576; python: 1,242; makefile: 820
file content (84 lines) | stat: -rwxr-xr-x 2,943 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Check if logical-resolve is resolving the paths correctly for different
# subvolume tree scenarios. This used to fail when a child subvolume was
# mounted without the parent subvolume being accessible.

source "$TEST_TOP/common"

setup_root_helper
prepare_test_dev

check_prereq btrfs
check_prereq mkfs.btrfs

check_logical_offset_filename()
{
	local offset

	offset="$1"

	while read file; do
		if [[ "$file" = *"inode "* ]]; then
			_log "$file"
		elif [ ! -f "$file" ]; then
			_fail "path '$file' file cannot be accessed"
		else
			_log "$file"
		fi
	done < <(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal \
					logical-resolve "$offset" "$TEST_MNT")
}

run_check_mkfs_test_dev
run_check_mount_test_dev

# Create top subvolume called '@'
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@"

# Create a file in each subvolume of @, and each file will have 2 EXTENT_DATA
# items, and also create a snapshot to have an extent being referenced by two
# different fs trees
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@/vol1"
vol1id=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal rootid "$TEST_MNT/@/vol1")
run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=150 of="$TEST_MNT/@/vol1/file1"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot "$TEST_MNT/@/vol1" "$TEST_MNT/@/snap1"

run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/@/vol1/subvol1"
subvol1id=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal rootid "$TEST_MNT/@/vol1/subvol1")
run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=150 of="$TEST_MNT/@/vol1/subvol1/file2"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot "$TEST_MNT/@/vol1/subvol1" \
							"$TEST_MNT/@/vol1/snapshot1"

run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"

run_check_umount_test_dev

run_check $SUDO_HELPER mount -o subvol=/@/vol1 "$TEST_DEV" "$TEST_MNT"
# Create a bind mount to vol1. logical-resolve should avoid bind mounts,
# otherwise the test will fail
run_check $SUDO_HELPER mkdir -p "$TEST_MNT/dir"
run_check mkdir -p mnt2
run_check $SUDO_HELPER mount --bind "$TEST_MNT/dir" mnt2
# Create another bind mount to confuse logical-resolve even more.
# logical-resolve can return the original mount or mnt3, both are valid
run_check mkdir -p mnt3
run_check $SUDO_HELPER mount --bind "$TEST_MNT" mnt3

for offset in $("$TOP/btrfs" inspect-internal dump-tree -t "$vol1id" "$TEST_DEV" |
		awk '/disk byte/ { print $5 }'); do
	check_logical_offset_filename "$offset"
done

run_check_umount_test_dev mnt3
run_check rmdir -- mnt3
run_check_umount_test_dev mnt2
run_check rmdir -- mnt2
run_check_umount_test_dev

run_check $SUDO_HELPER mount -o subvol="/@/vol1/subvol1" "$TEST_DEV" "$TEST_MNT"
for offset in $("$TOP/btrfs" inspect-internal dump-tree -t "$subvol1id" "$TEST_DEV" |
		awk '/disk byte/ { print $5 }'); do
	check_logical_offset_filename "$offset"
done

run_check_umount_test_dev