btrfs: Verify falloc on multiple holes won't leak qgroup reserved data space
[xfstests-dev.git] / tests / btrfs / 136
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Lakshmipathi.G  All Rights Reserved.
4 #
5 # FS QA Test 136
6 #
7 # Test btrfs-convert
8 #
9 # 1) create ext3 filesystem & populate it.
10 # 2) upgrade ext3 filesystem to ext4.
11 # 3) populate data.
12 # 4) source has combination of non-extent and extent files.
13 # 5) convert it to btrfs, mount and verify contents.
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37
38 # Modify as appropriate.
39 _supported_fs btrfs
40 _supported_os Linux
41 _require_scratch_nocheck
42
43 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
44 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
45 _require_command "$E2FSCK_PROG" e2fsck
46 _require_command "$TUNE2FS_PROG" tune2fs
47
48 rm -f $seqres.full
49
50 BLOCK_SIZE=`_get_block_size $TEST_DIR`
51 EXT_MD5SUM="$tmp.ext43"
52 BTRFS_MD5SUM="$tmp.btrfs"
53
54 populate_data(){
55         data_path=$1
56         mkdir -p $data_path
57         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $data_path`
58         echo "Run fsstress $args" >>$seqres.full
59         $FSSTRESS_PROG $args >/dev/null 2>&1 &
60         fsstress_pid=$!
61         wait $fsstress_pid
62 }
63
64 # Create & populate an ext3 filesystem
65 $MKFS_EXT4_PROG -F -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
66         _notrun "Could not create ext3 filesystem"
67
68 # mount and populate non-extent file
69 mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
70 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext3"
71 _scratch_unmount
72
73 # Upgrade it to ext4.
74 $TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 2>&1
75 # After Conversion, its highly recommended to run e2fsck.
76 $E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1
77
78 # mount and populate extent file
79 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
80 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext4"
81
82 # Compute md5 of ext3,ext4 files.
83 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$EXT_MD5SUM"
84 sort "$EXT_MD5SUM" -o "$EXT_MD5SUM"
85 _scratch_unmount
86
87 # Convert non-extent & extent data to btrfs, mount it, verify the data
88 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
89         _fail "btrfs-convert failed"
90 _try_scratch_mount || _fail "Could not mount new btrfs fs"
91
92 # Compute md5 for converted files.
93 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$BTRFS_MD5SUM"
94 sort "$BTRFS_MD5SUM" -o "$BTRFS_MD5SUM"
95
96 # Compare two md5sum files.
97 btrfs_perm=`md5sum "$BTRFS_MD5SUM" | cut -f1 -d' '`
98 ext_perm=`md5sum "$EXT_MD5SUM" | cut -f1 -d' '`
99
100 if [ "$btrfs_perm" != "$ext_perm" ];then
101        echo "md5sum mismatch"
102 fi
103
104 # success, all done
105 echo "Silence is golden"
106 status=0
107 exit