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 $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
36 for num in $(seq 1 $DATASET_SIZE); do
37 run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
42 for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
43 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
44 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
45 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
46 if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
50 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
51 run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
57 for num in $(seq 1 $DATASET_SIZE); do
58 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
59 count=1 >/dev/null 2>&1
60 run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
61 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
62 oflag=append conv=notrunc count=1 >/dev/null 2>&1
63 run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
68 for num in $(seq 1 $DATASET_SIZE); do
69 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
70 run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
71 run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
79 for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
80 generate_dataset "$dataset_type"
84 # verbose message before the test, same arguments as convert_test
85 convert_test_preamble() {
92 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
93 echo "creating ext image with: $@" >> $RESULTS
96 # prepare TEST_DEV before conversion, create filesystem and mount it, image
98 # $@: free form, command to create the filesystem, with appended -F
99 convert_test_prep_fs() {
100 # TEST_DEV not removed as the file might have special permissions, eg.
101 # when test image is on NFS and would not be writable for root
102 run_check truncate -s 0 $TEST_DEV
103 # 256MB is the smallest acceptable btrfs image.
104 run_check truncate -s 512M $TEST_DEV
105 run_check "$@" -F $TEST_DEV
107 # create a file to check btrfs-convert can convert regular file correct
108 run_check_mount_test_dev
110 # create a file inside the fs before convert, to make sure there is
111 # data covering btrfs backup superblock range (64M)
112 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
113 of=$TEST_MNT/convert_space_holder
116 # generate md5 checksums of files on $TEST_MNT
117 # $1: path where the checksums will be stored
118 convert_test_gen_checksums() {
122 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
123 count=1 >/dev/null 2>&1
124 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP"
127 # do conversion with given features and nodesize, fsck afterwards
128 # $1: features, argument of -O, can be empty
129 # $2: nodesize, argument of -N, can be empty
130 convert_test_do_convert() {
131 run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV
132 run_check $TOP/btrfs check $TEST_DEV
133 run_check $TOP/btrfs-show-super -Ffa $TEST_DEV
136 # post conversion checks, verify md5sums
137 # $1: file with checksums
138 convert_test_post_check() {
142 run_check_mount_test_dev
143 run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" |
144 grep -q 'FAILED' && _fail "file validation failed"
145 run_check_umount_test_dev
148 # do rollback and fsck
149 convert_test_post_rollback() {
150 run_check $TOP/btrfs-convert --rollback $TEST_DEV
151 run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV
154 # simple wrapper for a convert test
155 # $1: btrfs features, argument to -O
156 # $2: description of the test "ext2 8k nodesize"
158 # $4 + rest: command to create the ext2 image
169 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
170 convert_test_prep_fs "$@"
172 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
173 convert_test_gen_checksums "$CHECKSUMTMP"
175 run_check_umount_test_dev
177 convert_test_do_convert "$features" "$nodesize"
178 convert_test_post_check "$CHECKSUMTMP"
181 convert_test_post_rollback