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"
126 # list $TEST_MNT data set file permissions.
127 # $1: path where the permissions will be stored
128 convert_test_perm() {
131 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
133 run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
134 count=1 >/dev/null 2>&1
135 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -fprint $FILES_LIST
136 # Fix directory entries order
137 sort $FILES_LIST -o $FILES_LIST
138 for file in `cat $FILES_LIST` ;do
139 run_check_stdout $SUDO_HELPER getfacl --absolute-names $file >> "$PERMTMP"
143 # list acls of files on $TEST_MNT
144 # $1: path where the acls will be stored
148 FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX)
150 run_check_stdout $SUDO_HELPER find $TEST_MNT/acls -type f -fprint $FILES_LIST
151 # Fix directory entries order
152 sort $FILES_LIST -o $FILES_LIST
153 for file in `cat $FILES_LIST`;do
154 run_check_stdout $SUDO_HELPER getfattr --absolute-names -d $file >> "$ACLTMP"
159 # do conversion with given features and nodesize, fsck afterwards
160 # $1: features, argument of -O, can be empty
161 # $2: nodesize, argument of -N, can be empty
162 convert_test_do_convert() {
163 run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV
164 run_check $TOP/btrfs check $TEST_DEV
165 run_check $TOP/btrfs-show-super -Ffa $TEST_DEV
168 # post conversion check, verify file permissions.
169 # $1: file with ext permissions.
170 convert_test_post_check_permissions() {
175 BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
176 convert_test_perm "$BTRFS_PERMTMP"
178 btrfs_perm=`md5sum $BTRFS_PERMTMP | cut -f1 -d' '`
179 ext_perm=`md5sum $EXT_PERMTMP | cut -f1 -d' '`
181 if [ "$btrfs_perm" != "$ext_perm" ];
183 btrfs_perm_file=`md5sum $BTRFS_PERMTMP | cut -f2 -d' '`
184 ext_perm_file=`md5sum $EXT_PERMTMP | cut -f2 -d' '`
185 _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
190 # post conversion check, compare BTRFS file acls against EXT.
191 # $1: file with ext acls.
192 convert_test_post_check_acl() {
197 BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
198 convert_test_acl "$BTRFS_ACLTMP"
200 btrfs_acl=`md5sum $BTRFS_ACLTMP | cut -f1 -d' '`
201 ext_acl=`md5sum $EXT_ACLTMP | cut -f1 -d' '`
203 if [ "$btrfs_acl" != "$ext_acl" ]
205 btrfs_acl_file=`md5sum $BTRFS_ACLTMP | cut -f2 -d' '`
206 ext_acl_file=`md5sum $EXT_ACLTMP | cut -f2 -d' '`
207 _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
212 # post conversion checks, verify md5sums
213 # $1: file with checksums
214 # $2: file with permissions.
215 # $3: file with acl entries.
216 convert_test_post_check() {
225 run_check_mount_test_dev
226 run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" |
227 grep -q 'FAILED' && _fail "file validation failed"
228 convert_test_post_check_permissions "$EXT_PERMTMP"
229 convert_test_post_check_acl "$EXT_ACLTMP"
230 run_check_umount_test_dev
233 # do rollback and fsck
234 convert_test_post_rollback() {
235 run_check $TOP/btrfs-convert --rollback $TEST_DEV
236 run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV
239 # simple wrapper for a convert test
240 # $1: btrfs features, argument to -O
241 # $2: description of the test "ext2 8k nodesize"
243 # $4 + rest: command to create the ext2 image
256 convert_test_preamble "$features" "$msg" "$nodesize" "$@"
257 convert_test_prep_fs "$@"
259 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
260 EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX)
261 EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX)
262 convert_test_gen_checksums "$CHECKSUMTMP"
263 convert_test_perm "$EXT_PERMTMP"
264 convert_test_acl "$EXT_ACLTMP"
266 run_check_umount_test_dev
268 convert_test_do_convert "$features" "$nodesize"
269 convert_test_post_check "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP"
274 convert_test_post_rollback