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 && $SUDO_HELPER ln -s $dataset_type.$num $dirpath/slink.$num && cd /
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
76 for num in $(seq 1 $DATASET_SIZE); do
77 run_check $SUDO_HELPER mkfifo $dirpath/$dataset_type.$num
82 long_filename=`date +%s | sha256sum | cut -f1 -d'-'`
83 run_check $SUDO_HELPER touch $dirpath/$long_filename
84 for num in $(seq 1 $DATASET_SIZE); do
85 run_check $SUDO_HELPER ln -s $dirpath/$long_filename $dirpath/slow_slink.$num
93 for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
94 generate_dataset "$dataset_type"
98 # verbose message before the test, same arguments as convert_test
99 convert_test_preamble() {
106 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
107 echo "creating ext image with: $@" >> $RESULTS
110 # prepare TEST_DEV before conversion, create filesystem and mount it, image
112 # $@: free form, command to create the filesystem, with appended -F
113 convert_test_prep_fs() {
114 # TEST_DEV not removed as the file might have special permissions, eg.
115 # when test image is on NFS and would not be writable for root
116 run_check truncate -s 0 $TEST_DEV
117 # 256MB is the smallest acceptable btrfs image.
118 run_check truncate -s 512M $TEST_DEV
119 run_check "$@" -F $TEST_DEV
121 # create a file to check btrfs-convert can convert regular file correct
122 run_check_mount_test_dev
124 # create a file inside the fs before convert, to make sure there is
125 # data covering btrfs backup superblock range (64M)
126 run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
127 of=$TEST_MNT/convert_space_holder
130 # generate md5 checksums of files on $TEST_MNT
131 # $1: path where the checksums will be stored
132 convert_test_gen_checksums() {
136 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
137 count=1 >/dev/null 2>&1
138 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP"
140 # list $TEST_MNT data set file permissions.
141 # $1: path where the permissions will be stored
142 convert_test_perm() {
145 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
147 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
148 count=1 >/dev/null 2>&1
149 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -fprint $FILES_LIST
150 # Fix directory entries order
151 sort $FILES_LIST -o $FILES_LIST
152 for file in `cat $FILES_LIST` ;do
153 run_check_stdout $SUDO_HELPER getfacl --absolute-names $file >> "$PERMTMP"
157 # list acls of files on $TEST_MNT
158 # $1: path where the acls will be stored
162 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
164 run_check_stdout $SUDO_HELPER find $TEST_MNT/acls -type f -fprint $FILES_LIST
165 # Fix directory entries order
166 sort $FILES_LIST -o $FILES_LIST
167 for file in `cat $FILES_LIST`;do
168 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d $file >> "$ACLTMP"
173 # do conversion with given features and nodesize, fsck afterwards
174 # $1: features, argument of -O, can be empty
175 # $2: nodesize, argument of -N, can be empty
176 convert_test_do_convert() {
177 run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV
178 run_check $TOP/btrfs check $TEST_DEV
179 run_check $TOP/btrfs inspect-internal dump-super -Ffa $TEST_DEV
182 # post conversion check, verify file permissions.
183 # $1: file with ext permissions.
184 convert_test_post_check_permissions() {
189 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
190 convert_test_perm "$BTRFS_PERMTMP"
192 btrfs_perm=`md5sum $BTRFS_PERMTMP | cut -f1 -d' '`
193 ext_perm=`md5sum $EXT_PERMTMP | cut -f1 -d' '`
195 if [ "$btrfs_perm" != "$ext_perm" ];
197 btrfs_perm_file=`md5sum $BTRFS_PERMTMP | cut -f2 -d' '`
198 ext_perm_file=`md5sum $EXT_PERMTMP | cut -f2 -d' '`
199 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
204 # post conversion check, compare BTRFS file acls against EXT.
205 # $1: file with ext acls.
206 convert_test_post_check_acl() {
211 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
212 convert_test_acl "$BTRFS_ACLTMP"
214 btrfs_acl=`md5sum $BTRFS_ACLTMP | cut -f1 -d' '`
215 ext_acl=`md5sum $EXT_ACLTMP | cut -f1 -d' '`
217 if [ "$btrfs_acl" != "$ext_acl" ]
219 btrfs_acl_file=`md5sum $BTRFS_ACLTMP | cut -f2 -d' '`
220 ext_acl_file=`md5sum $EXT_ACLTMP | cut -f2 -d' '`
221 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
226 # post conversion checks, verify md5sums
227 # $1: file with checksums
228 # $2: file with permissions.
229 # $3: file with acl entries.
230 convert_test_post_check() {
239 run_check_mount_test_dev
240 run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" |
241 grep -q 'FAILED' && _fail "file validation failed"
242 convert_test_post_check_permissions "$EXT_PERMTMP"
243 convert_test_post_check_acl "$EXT_ACLTMP"
244 run_check_umount_test_dev
247 # do rollback and fsck
248 convert_test_post_rollback() {
249 run_check $TOP/btrfs-convert --rollback $TEST_DEV
250 run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV
253 # simple wrapper for a convert test
254 # $1: btrfs features, argument to -O
255 # $2: description of the test "ext2 8k nodesize"
257 # $4 + rest: command to create the ext2 image
270 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
271 convert_test_prep_fs "$@"
273 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
274 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
275 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
276 convert_test_gen_checksums "$CHECKSUMTMP"
277 convert_test_perm "$EXT_PERMTMP"
278 convert_test_acl "$EXT_ACLTMP"
280 run_check_umount_test_dev
282 convert_test_do_convert "$features" "$nodesize"
283 convert_test_post_check "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
288 convert_test_post_rollback