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 # $1: type of the filesystem
26 # $2+: free form, command to create the filesystem, with appended -F
27 convert_test_prep_fs() {
32 # TEST_DEV not removed as the file might have special permissions, eg.
33 # when test image is on NFS and would not be writable for root
34 run_check truncate -s 0 "$TEST_DEV"
35 # 256MB is the smallest acceptable btrfs image.
36 run_check truncate -s 512M "$TEST_DEV"
37 run_check "$@" -F "$TEST_DEV"
39 # create a file to check btrfs-convert can convert regular file correct
40 run_check_mount_test_dev
42 # create a file inside the fs before convert, to make sure there is
43 # data covering btrfs backup superblock range (64M)
44 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
45 of="$TEST_MNT/convert_space_holder"
48 # generate md5 checksums of files on $TEST_MNT
49 # $1: path where the checksums will be stored
50 convert_test_gen_checksums() {
53 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
54 count=1 >/dev/null 2>&1
55 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1"
57 # list $TEST_MNT data set file permissions.
58 # $1: path where the permissions will be stored
64 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
66 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
67 count=1 >/dev/null 2>&1
68 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
69 # Fix directory entries order
70 sort "$FILES_LIST" -o "$FILES_LIST"
71 for file in `cat "$FILES_LIST"` ;do
72 run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
76 # list acls of files on $TEST_MNT
77 # $1: path where the acls will be stored
81 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
83 run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
84 # Fix directory entries order
85 sort "$FILES_LIST" -o "$FILES_LIST"
86 for file in `cat "$FILES_LIST"`;do
87 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
92 # do conversion with given features and nodesize, fsck afterwards
93 # $1: features, argument of -O, can be empty
94 # $2: nodesize, argument of -N, can be empty
95 convert_test_do_convert() {
96 run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV"
97 run_check "$TOP/btrfs" check "$TEST_DEV"
98 run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV"
101 # post conversion check, verify file permissions.
102 # $1: file with ext permissions.
103 convert_test_post_check_permissions() {
109 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
110 convert_test_perm "$BTRFS_PERMTMP"
112 btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '`
113 ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '`
115 if [ "$btrfs_perm" != "$ext_perm" ];
117 btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '`
118 ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '`
119 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
122 rm -- "$BTRFS_PERMTMP"
124 # post conversion check, compare BTRFS file acls against EXT.
125 # $1: file with ext acls.
126 convert_test_post_check_acl() {
132 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
133 convert_test_acl "$BTRFS_ACLTMP"
135 btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '`
136 ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '`
138 if [ "$btrfs_acl" != "$ext_acl" ]
140 btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '`
141 ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '`
142 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
145 rm -- "$BTRFS_ACLTMP"
148 # post conversion checks, verify md5sums
149 convert_test_post_check_checksums() {
151 run_check_stdout $SUDO_HELPER md5sum -c "$1" |
152 grep -q 'FAILED' && _fail "file validation failed"
155 # post conversion checks, all three in one call, on an unmounted image
156 # $1: file with checksums
157 # $2: file with permissions.
158 # $3: file with acl entries.
159 convert_test_post_checks_all() {
164 run_check_mount_test_dev
165 convert_test_post_check_checksums "$1"
166 convert_test_post_check_permissions "$2"
167 convert_test_post_check_acl "$3"
169 # Create a large file to trigger data chunk allocation
170 generate_dataset "large"
171 run_check_umount_test_dev
174 # do rollback and fsck
175 convert_test_post_rollback() {
176 run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
177 run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV"
180 # simple wrapper for a convert test
181 # $1: type of the converted filesystem
182 # $2: btrfs features, argument to -O
183 # $3: description of the test "ext2 8k nodesize"
185 # $5 + rest: command to create the ext2 image
200 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
201 convert_test_prep_fs "$fstype" "$@"
203 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
204 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
205 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
206 convert_test_gen_checksums "$CHECKSUMTMP"
207 convert_test_perm "$EXT_PERMTMP"
208 convert_test_acl "$EXT_ACLTMP"
210 run_check_umount_test_dev
212 convert_test_do_convert "$features" "$nodesize"
213 convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
218 convert_test_post_rollback