2 # helpers for btrfs-convert tests
4 # mount image of converted filesystem of a given type
5 # $1: type of the filesystem
6 run_check_mount_convert_dev()
15 if [ -z "$fstype" ]; then
16 _fail "Missing source filesystem type"
18 if [ "$fstype" = 'btrfs' ]; then
19 _fail "Incorrect type for converted filesystem: btrfs"
22 if [[ -b "$TEST_DEV" ]]; then
24 elif [[ -f "$TEST_DEV" ]]; then
27 _fail "Invalid \$TEST_DEV: $TEST_DEV"
30 [[ -d "$TEST_MNT" ]] || {
31 _fail "Invalid \$TEST_MNT: $TEST_MNT"
34 run_check $SUDO_HELPER mount $loop_opt -t "$fstype" "$@" "$TEST_DEV" "$TEST_MNT"
39 for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
40 generate_dataset "$dataset_type"
44 # verbose message before the test, same arguments as convert_test
45 convert_test_preamble() {
52 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
53 echo "creating ext image with: $@" >> "$RESULTS"
56 # prepare TEST_DEV before conversion, create filesystem and mount it, image
58 # $1: type of the filesystem
59 # $2+: free form, command to create the filesystem, with appended -F
60 convert_test_prep_fs() {
65 # TEST_DEV not removed as the file might have special permissions, eg.
66 # when test image is on NFS and would not be writable for root
67 run_check truncate -s 0 "$TEST_DEV"
68 # 256MB is the smallest acceptable btrfs image.
69 run_check truncate -s 512M "$TEST_DEV"
70 run_check "$@" -F "$TEST_DEV"
72 # create a file to check btrfs-convert can convert regular file correct
73 run_check_mount_convert_dev "$fstype"
75 # create a file inside the fs before convert, to make sure there is
76 # data covering btrfs backup superblock range (64M)
77 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
78 of="$TEST_MNT/convert_space_holder"
81 # generate md5 checksums of files on $TEST_MNT
82 # $1: path where the checksums will be stored
83 convert_test_gen_checksums() {
86 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
87 count=1 >/dev/null 2>&1
88 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1"
90 # list $TEST_MNT data set file permissions.
91 # $1: path where the permissions will be stored
97 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
99 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
100 count=1 >/dev/null 2>&1
101 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
102 # Fix directory entries order
103 sort "$FILES_LIST" -o "$FILES_LIST"
104 for file in `cat "$FILES_LIST"` ;do
105 run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
109 # list acls of files on $TEST_MNT
110 # $1: path where the acls will be stored
114 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
116 run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
117 # Fix directory entries order
118 sort "$FILES_LIST" -o "$FILES_LIST"
119 for file in `cat "$FILES_LIST"`;do
120 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
125 # do conversion with given features and nodesize, fsck afterwards
126 # $1: features, argument of -O, can be empty
127 # $2: nodesize, argument of -N, can be empty
128 convert_test_do_convert() {
129 run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV"
130 run_check "$TOP/btrfs" check "$TEST_DEV"
131 run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV"
134 # post conversion check, verify file permissions.
135 # $1: file with ext permissions.
136 convert_test_post_check_permissions() {
142 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
143 convert_test_perm "$BTRFS_PERMTMP"
145 btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '`
146 ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '`
148 if [ "$btrfs_perm" != "$ext_perm" ];
150 btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '`
151 ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '`
152 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
155 rm -- "$BTRFS_PERMTMP"
157 # post conversion check, compare BTRFS file acls against EXT.
158 # $1: file with ext acls.
159 convert_test_post_check_acl() {
165 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
166 convert_test_acl "$BTRFS_ACLTMP"
168 btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '`
169 ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '`
171 if [ "$btrfs_acl" != "$ext_acl" ]
173 btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '`
174 ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '`
175 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
178 rm -- "$BTRFS_ACLTMP"
181 # post conversion checks, verify md5sums
182 convert_test_post_check_checksums() {
184 run_check_stdout $SUDO_HELPER md5sum -c "$1" |
185 grep -q 'FAILED' && _fail "file validation failed"
188 # post conversion checks, all three in one call, on an unmounted image
189 # $1: file with checksums
190 # $2: file with permissions.
191 # $3: file with acl entries.
192 convert_test_post_checks_all() {
197 run_check_mount_test_dev
198 convert_test_post_check_checksums "$1"
199 convert_test_post_check_permissions "$2"
200 convert_test_post_check_acl "$3"
202 # Create a large file to trigger data chunk allocation
203 generate_dataset "large"
204 run_check_umount_test_dev
207 # do rollback and fsck
208 convert_test_post_rollback() {
209 run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
210 run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV"
213 # simple wrapper for a convert test
214 # $1: type of the converted filesystem
215 # $2: btrfs features, argument to -O
216 # $3: description of the test "ext2 8k nodesize"
218 # $5 + rest: command to create the ext2 image
233 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
234 convert_test_prep_fs "$fstype" "$@"
236 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
237 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
238 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
239 convert_test_gen_checksums "$CHECKSUMTMP"
240 convert_test_perm "$EXT_PERMTMP"
241 convert_test_acl "$EXT_ACLTMP"
243 run_check_umount_test_dev
245 convert_test_do_convert "$features" "$nodesize"
246 convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
251 convert_test_post_rollback