3 # convert ext2/3/4 images to btrfs images, and make sure the results are
10 SCRIPT_DIR=$(dirname $(readlink -f $0))
11 TOP=$(readlink -f $SCRIPT_DIR/../)
12 RESULTS="$TOP/tests/convert-tests-results.txt"
13 # how many files to create.
16 source $TOP/tests/common
18 # Allow child test to use $TOP and $RESULTS
28 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
34 echo " [TEST/conv] $testname"
36 echo "=== Entering $testname" >> $RESULTS
37 if [ -x test.sh ]; then
38 # Difference convert test case needs different tools to restore
39 # and check image, so only support custom test scripts
42 _fail "test failed for case $(basename $testname)"
45 _fail "custom test script not found"
52 dirpath=$TEST_MNT/$dataset_type
53 run_check $SUDO_HELPER mkdir -p $dirpath
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
64 for num in $(seq 1 $DATASET_SIZE); do
65 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
66 run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num
71 for num in $(seq 1 $DATASET_SIZE); do
72 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
73 run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
78 for num in $(seq 1 $DATASET_SIZE); do
79 run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
84 for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
85 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
86 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
87 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
88 if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
92 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
93 run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
99 for num in $(seq 1 $DATASET_SIZE); do
100 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
101 count=1 >/dev/null 2>&1
102 run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
103 run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
104 oflag=append conv=notrunc count=1 >/dev/null 2>&1
105 run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
110 for num in $(seq 1 $DATASET_SIZE); do
111 run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
112 run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
113 run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
121 for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
122 generate_dataset "$dataset_type"
133 if [ -z "$features" ]; then
134 echo " [TEST/conv] $1, btrfs defaults"
136 echo " [TEST/conv] $1, btrfs $features"
140 echo "creating ext image with: $*" >> $RESULTS
141 # TEST_DEV not removed as the file might have special permissions, eg.
142 # when test image is on NFS and would not be writable for root
143 run_check truncate -s 0 $TEST_DEV
144 # 256MB is the smallest acceptable btrfs image.
145 run_check truncate -s 512M $TEST_DEV
146 run_check $* -F $TEST_DEV
148 # create a file to check btrfs-convert can convert regular file
150 run_check_mount_test_dev
152 # create a file inside the fs before convert, to make sure there is
153 # data covering btrfs backup superblock range (64M)
154 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
155 of=$TEST_MNT/convert_space_holder
158 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
159 count=1 >/dev/null 2>&1
160 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP
161 run_check_umount_test_dev
163 run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV
164 run_check $TOP/btrfs check $TEST_DEV
165 run_check $TOP/btrfs-show-super -Ffa $TEST_DEV
167 run_check_mount_test_dev
168 run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP |
169 grep -q 'FAILED' && _fail "file validation failed."
170 run_check_umount_test_dev
172 run_check $TOP/btrfs-convert --rollback $TEST_DEV
173 run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV
176 if ! [ -z "$TEST" ]; then
177 echo " [TEST/conv] skipped all convert tests, TEST=$TEST"
181 for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
182 convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096
183 convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096
184 convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
185 convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096
186 convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096
187 convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
188 convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096
189 convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096
190 convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
191 convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096
192 convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096
193 convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
194 convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096
195 convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096
196 convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096
199 # Test special images
200 for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \
201 ${TEST:+-name "$TEST"} | sort)