2 # helpers for btrfs-convert tests
4 # how many files to create.
10 dirpath=$TEST_MNT/$dataset_type
11 run_check $SUDO_HELPER mkdir -p "$dirpath"
15 for num in $(seq 1 "$DATASET_SIZE"); do
16 run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \
17 count=1 >/dev/null 2>&1
22 for num in $(seq 1 "$DATASET_SIZE"); do
23 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
24 run_check $SUDO_HELPER ln "$dirpath/$dataset_type.$num" "$dirpath/hlink.$num"
29 for num in $(seq 1 "$DATASET_SIZE"); do
30 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
31 run_check cd "$dirpath" && \
32 $SUDO_HELPER ln -s "$dataset_type.$num" "$dirpath/slink.$num" && \
38 for num in $(seq 1 "$DATASET_SIZE"); do
39 run_check $SUDO_HELPER ln -s "$dirpath/$dataset_type.$num" "$dirpath/blink.$num"
44 for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
45 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
46 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
47 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
48 if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
52 run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes"
53 run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes"
59 for num in $(seq 1 "$DATASET_SIZE"); do
60 run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \
61 count=1 >/dev/null 2>&1
62 run_check $SUDO_HELPER truncate -s 500K "$dirpath/$dataset_type.$num"
63 run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \
64 oflag=append conv=notrunc count=1 >/dev/null 2>&1
65 run_check $SUDO_HELPER truncate -s 800K "$dirpath/$dataset_type.$num"
70 for num in $(seq 1 "$DATASET_SIZE"); do
71 run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num"
72 run_check $SUDO_HELPER setfacl -m "u:root:x" "$dirpath/$dataset_type.$num"
73 run_check $SUDO_HELPER setfattr -n user.foo -v "bar$num" "$dirpath/$dataset_type.$num"
78 for num in $(seq 1 "$DATASET_SIZE"); do
79 run_check $SUDO_HELPER mkfifo "$dirpath/$dataset_type.$num"
84 long_filename=`date +%s | sha256sum | cut -f1 -d'-'`
85 run_check $SUDO_HELPER touch "$dirpath/$long_filename"
86 for num in $(seq 1 "$DATASET_SIZE"); do
87 run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num"
95 for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
96 generate_dataset "$dataset_type"
100 # verbose message before the test, same arguments as convert_test
101 convert_test_preamble() {
108 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
109 echo "creating ext image with: $@" >> "$RESULTS"
112 # prepare TEST_DEV before conversion, create filesystem and mount it, image
114 # $@: free form, command to create the filesystem, with appended -F
115 convert_test_prep_fs() {
116 # TEST_DEV not removed as the file might have special permissions, eg.
117 # when test image is on NFS and would not be writable for root
118 run_check truncate -s 0 "$TEST_DEV"
119 # 256MB is the smallest acceptable btrfs image.
120 run_check truncate -s 512M "$TEST_DEV"
121 run_check "$@" -F "$TEST_DEV"
123 # create a file to check btrfs-convert can convert regular file correct
124 run_check_mount_test_dev
126 # create a file inside the fs before convert, to make sure there is
127 # data covering btrfs backup superblock range (64M)
128 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
129 of="$TEST_MNT/convert_space_holder"
132 # generate md5 checksums of files on $TEST_MNT
133 # $1: path where the checksums will be stored
134 convert_test_gen_checksums() {
137 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
138 count=1 >/dev/null 2>&1
139 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1"
141 # list $TEST_MNT data set file permissions.
142 # $1: path where the permissions will be stored
143 convert_test_perm() {
148 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
150 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \
151 count=1 >/dev/null 2>&1
152 run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST"
153 # Fix directory entries order
154 sort "$FILES_LIST" -o "$FILES_LIST"
155 for file in `cat "$FILES_LIST"` ;do
156 run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP"
160 # list acls of files on $TEST_MNT
161 # $1: path where the acls will be stored
165 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
167 run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST"
168 # Fix directory entries order
169 sort "$FILES_LIST" -o "$FILES_LIST"
170 for file in `cat "$FILES_LIST"`;do
171 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP"
176 # do conversion with given features and nodesize, fsck afterwards
177 # $1: features, argument of -O, can be empty
178 # $2: nodesize, argument of -N, can be empty
179 convert_test_do_convert() {
180 run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV"
181 run_check "$TOP/btrfs" check $TEST_DEV
182 run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV"
185 # post conversion check, verify file permissions.
186 # $1: file with ext permissions.
187 convert_test_post_check_permissions() {
193 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
194 convert_test_perm "$BTRFS_PERMTMP"
196 btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '`
197 ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '`
199 if [ "$btrfs_perm" != "$ext_perm" ];
201 btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '`
202 ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '`
203 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
206 rm -- "$BTRFS_PERMTMP"
208 # post conversion check, compare BTRFS file acls against EXT.
209 # $1: file with ext acls.
210 convert_test_post_check_acl() {
216 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
217 convert_test_acl "$BTRFS_ACLTMP"
219 btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '`
220 ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '`
222 if [ "$btrfs_acl" != "$ext_acl" ]
224 btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '`
225 ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '`
226 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
229 rm -- "$BTRFS_ACLTMP"
232 # post conversion checks, verify md5sums
233 convert_test_post_check_checksums() {
235 run_check_stdout $SUDO_HELPER md5sum -c "$1" |
236 grep -q 'FAILED' && _fail "file validation failed"
239 # post conversion checks, all three in one call, on an unmounted image
240 # $1: file with checksums
241 # $2: file with permissions.
242 # $3: file with acl entries.
243 convert_test_post_checks_all() {
248 run_check_mount_test_dev
249 convert_test_post_check_checksums "$1"
250 convert_test_post_check_permissions "$2"
251 convert_test_post_check_acl "$3"
252 run_check_umount_test_dev
255 # do rollback and fsck
256 convert_test_post_rollback() {
257 run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
258 run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV"
261 # simple wrapper for a convert test
262 # $1: btrfs features, argument to -O
263 # $2: description of the test "ext2 8k nodesize"
265 # $4 + rest: command to create the ext2 image
278 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
279 convert_test_prep_fs "$@"
281 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
282 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
283 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
284 convert_test_gen_checksums "$CHECKSUMTMP"
285 convert_test_perm "$EXT_PERMTMP"
286 convert_test_acl "$EXT_ACLTMP"
288 run_check_umount_test_dev
290 convert_test_do_convert "$features" "$nodesize"
291 convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
296 convert_test_post_rollback