btrfs: check qgroup doesn't crash when beyond limit
[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 _require_scratch_nocheck
41
42 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
43 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
44 _require_command "$E2FSCK_PROG" e2fsck
45 _require_command "$TUNE2FS_PROG" tune2fs
46
47 rm -f $seqres.full
48
49 BLOCK_SIZE=`_get_block_size $TEST_DIR`
50 EXT_MD5SUM="$tmp.ext43"
51 BTRFS_MD5SUM="$tmp.btrfs"
52
53 populate_data(){
54         data_path=$1
55         mkdir -p $data_path
56         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $data_path`
57         echo "Run fsstress $args" >>$seqres.full
58         $FSSTRESS_PROG $args >/dev/null 2>&1 &
59         fsstress_pid=$!
60         wait $fsstress_pid
61 }
62
63 # Create & populate an ext3 filesystem
64 $MKFS_EXT4_PROG -F -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
65         _notrun "Could not create ext3 filesystem"
66
67 # mount and populate non-extent file
68 mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
69 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext3"
70 _scratch_unmount
71
72 # Upgrade it to ext4.
73 $TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 2>&1
74 # After Conversion, its highly recommended to run e2fsck.
75 $E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1
76
77 # mount and populate extent file
78 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
79 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext4"
80
81 # Compute md5 of ext3,ext4 files.
82 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$EXT_MD5SUM"
83 sort "$EXT_MD5SUM" -o "$EXT_MD5SUM"
84 _scratch_unmount
85
86 # Convert non-extent & extent data to btrfs, mount it, verify the data
87 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
88         _fail "btrfs-convert failed"
89 _try_scratch_mount || _fail "Could not mount new btrfs fs"
90
91 # Compute md5 for converted files.
92 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$BTRFS_MD5SUM"
93 sort "$BTRFS_MD5SUM" -o "$BTRFS_MD5SUM"
94
95 # Compare two md5sum files.
96 btrfs_perm=`md5sum "$BTRFS_MD5SUM" | cut -f1 -d' '`
97 ext_perm=`md5sum "$EXT_MD5SUM" | cut -f1 -d' '`
98
99 if [ "$btrfs_perm" != "$ext_perm" ];then
100        echo "md5sum mismatch"
101 fi
102
103 # success, all done
104 echo "Silence is golden"
105 status=0
106 exit