2 # helpers for btrfs-convert tests
6 for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
7 generate_dataset "$dataset_type"
11 # verbose message before the test, same arguments as convert_test
12 convert_test_preamble() {
19 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
20 echo "creating ext image with: $@" >> "$RESULTS"
23 # prepare TEST_DEV before conversion, create filesystem and mount it, image
25 # $@: free form, command to create the filesystem, with appended -F
26 convert_test_prep_fs() {
27 # TEST_DEV not removed as the file might have special permissions, eg.
28 # when test image is on NFS and would not be writable for root
29 run_check truncate -s 0 "$TEST_DEV"
30 # 256MB is the smallest acceptable btrfs image.
31 run_check truncate -s 512M "$TEST_DEV"
32 run_check "$@" -F "$TEST_DEV"
34 # create a file to check btrfs-convert can convert regular file correct
35 run_check_mount_test_dev
37 # create a file inside the fs before convert, to make sure there is
38 # data covering btrfs backup superblock range (64M)
39 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
40 of="$TEST_MNT/convert_space_holder"
43 # generate md5 checksums of files on $TEST_MNT
44 # $1: path where the checksums will be stored
45 convert_test_gen_checksums() {
48 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
49 count=1 >/dev/null 2>&1
50 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1"
52 # list $TEST_MNT data set file permissions.
53 # $1: path where the permissions will be stored
59 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
61 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
62 count=1 >/dev/null 2>&1
63 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
64 # Fix directory entries order
65 sort "$FILES_LIST" -o "$FILES_LIST"
66 for file in `cat "$FILES_LIST"` ;do
67 run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
71 # list acls of files on $TEST_MNT
72 # $1: path where the acls will be stored
76 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
78 run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
79 # Fix directory entries order
80 sort "$FILES_LIST" -o "$FILES_LIST"
81 for file in `cat "$FILES_LIST"`;do
82 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
87 # do conversion with given features and nodesize, fsck afterwards
88 # $1: features, argument of -O, can be empty
89 # $2: nodesize, argument of -N, can be empty
90 convert_test_do_convert() {
91 run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV"
92 run_check "$TOP/btrfs" check "$TEST_DEV"
93 run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV"
96 # post conversion check, verify file permissions.
97 # $1: file with ext permissions.
98 convert_test_post_check_permissions() {
104 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
105 convert_test_perm "$BTRFS_PERMTMP"
107 btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '`
108 ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '`
110 if [ "$btrfs_perm" != "$ext_perm" ];
112 btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '`
113 ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '`
114 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
117 rm -- "$BTRFS_PERMTMP"
119 # post conversion check, compare BTRFS file acls against EXT.
120 # $1: file with ext acls.
121 convert_test_post_check_acl() {
127 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
128 convert_test_acl "$BTRFS_ACLTMP"
130 btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '`
131 ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '`
133 if [ "$btrfs_acl" != "$ext_acl" ]
135 btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '`
136 ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '`
137 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
140 rm -- "$BTRFS_ACLTMP"
143 # post conversion checks, verify md5sums
144 convert_test_post_check_checksums() {
146 run_check_stdout $SUDO_HELPER md5sum -c "$1" |
147 grep -q 'FAILED' && _fail "file validation failed"
150 # post conversion checks, all three in one call, on an unmounted image
151 # $1: file with checksums
152 # $2: file with permissions.
153 # $3: file with acl entries.
154 convert_test_post_checks_all() {
159 run_check_mount_test_dev
160 convert_test_post_check_checksums "$1"
161 convert_test_post_check_permissions "$2"
162 convert_test_post_check_acl "$3"
164 # Create a large file to trigger data chunk allocation
165 generate_dataset "large"
166 run_check_umount_test_dev
169 # do rollback and fsck
170 convert_test_post_rollback() {
171 run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
172 run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV"
175 # simple wrapper for a convert test
176 # $1: btrfs features, argument to -O
177 # $2: description of the test "ext2 8k nodesize"
179 # $4 + rest: command to create the ext2 image
192 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
193 convert_test_prep_fs "$@"
195 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
196 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
197 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
198 convert_test_gen_checksums "$CHECKSUMTMP"
199 convert_test_perm "$EXT_PERMTMP"
200 convert_test_acl "$EXT_ACLTMP"
202 run_check_umount_test_dev
204 convert_test_do_convert "$features" "$nodesize"
205 convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
210 convert_test_post_rollback