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 test 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() {
67 # TEST_DEV not removed as the file might have special permissions, eg.
68 # when test image is on NFS and would not be writable for root
69 run_check truncate -s 0 "$TEST_DEV"
70 # 256MB is the smallest acceptable btrfs image.
71 run_check truncate -s 512M "$TEST_DEV"
79 mountopts="-o acl,user_xattr,attrs" ;;
81 _fail "unknown filesystem to convert: $fstype"
83 run_check "$@" $force "$TEST_DEV"
85 # create a file to check btrfs-convert can convert regular file correct
86 run_check_mount_convert_dev "$fstype" $mountopts
88 # create a file inside the fs before convert, to make sure there is
89 # data covering btrfs backup superblock range (64M)
90 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
91 of="$TEST_MNT/convert_space_holder"
94 # generate md5 checksums of files on $TEST_MNT
95 # $1: path where the checksums will be stored
96 convert_test_gen_checksums() {
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' -exec md5sum {} \+ > "$1"
103 # list $TEST_MNT data set file permissions.
104 # $1: path where the permissions will be stored
105 convert_test_perm() {
110 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
112 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
113 count=1 >/dev/null 2>&1
114 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
115 # Fix directory entries order
116 sort "$FILES_LIST" -o "$FILES_LIST"
117 for file in `cat "$FILES_LIST"` ;do
118 run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
122 # list acls of files on $TEST_MNT
123 # $1: path where the acls will be stored
127 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
129 run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
130 # Fix directory entries order
131 sort "$FILES_LIST" -o "$FILES_LIST"
132 for file in `cat "$FILES_LIST"`;do
133 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
138 # do conversion with given features and nodesize, fsck afterwards
139 # $1: features, argument of -O, can be empty
140 # $2: nodesize, argument of -N, can be empty
141 convert_test_do_convert() {
142 run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV"
143 run_check "$TOP/btrfs" check "$TEST_DEV"
144 run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV"
147 # post conversion check, verify file permissions.
148 # $1: file with ext permissions.
149 convert_test_post_check_permissions() {
155 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
156 convert_test_perm "$BTRFS_PERMTMP"
158 btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '`
159 ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '`
161 if [ "$btrfs_perm" != "$ext_perm" ];
163 btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '`
164 ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '`
165 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
168 rm -- "$BTRFS_PERMTMP"
170 # post conversion check, compare BTRFS file acls against EXT.
171 # $1: file with ext acls.
172 convert_test_post_check_acl() {
178 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
179 convert_test_acl "$BTRFS_ACLTMP"
181 btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '`
182 ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '`
184 if [ "$btrfs_acl" != "$ext_acl" ]
186 btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '`
187 ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '`
188 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
191 rm -- "$BTRFS_ACLTMP"
194 # post conversion checks, verify md5sums
195 convert_test_post_check_checksums() {
197 run_check_stdout $SUDO_HELPER md5sum -c "$1" |
198 grep -q 'FAILED' && _fail "file validation failed"
201 # post conversion checks, all three in one call, on an unmounted image
202 # $1: file with checksums
203 # $2: file with permissions.
204 # $3: file with acl entries.
205 convert_test_post_checks_all() {
210 run_check_mount_test_dev
211 convert_test_post_check_checksums "$1"
212 convert_test_post_check_permissions "$2"
213 convert_test_post_check_acl "$3"
215 # Create a large file to trigger data chunk allocation
216 generate_dataset "large"
217 run_check_umount_test_dev
220 # do rollback and fsck
221 # $1: filesystem name or alias (ext2 includes ext3 and ext4),
222 convert_test_post_rollback() {
225 run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
227 _fail "missing filesystem type to check"
230 ext[234]) types=ext2,ext3,ext4 ;;
231 reiserfs) types=reiserfs ;;
232 *) _fail "unknown filesystem type to check: $1" ;;
235 run_check fsck -n -t "$types" "$TEST_DEV"
238 # simple wrapper for a convert test
239 # $1: type of the converted filesystem
240 # $2: btrfs features, argument to -O
241 # $3: description of the test "ext2 8k nodesize"
243 # $5 + rest: command to create the ext2 image
258 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
259 convert_test_prep_fs "$fstype" "$@"
261 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
262 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
263 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
264 convert_test_gen_checksums "$CHECKSUMTMP"
265 convert_test_perm "$EXT_PERMTMP"
266 convert_test_acl "$EXT_ACLTMP"
268 run_check_umount_test_dev
270 convert_test_do_convert "$features" "$nodesize"
271 convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
276 convert_test_post_rollback "$fstype"
279 load_module_reiserfs()
281 $SUDO_HELPER modprobe reiserfs
284 check_kernel_support_reiserfs()
286 if ! grep -iq 'reiserfs' /proc/filesystems; then
287 echo "WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped"