fstests: _fail test by default when _scratch_mount fails
[xfstests-dev.git] / tests / btrfs / 136
1 #! /bin/bash
2 # FS QA Test 136
3 #
4 # Test btrfs-convert
5 #
6 # 1) create ext3 filesystem & populate it.
7 # 2) upgrade ext3 filesystem to ext4.
8 # 3) populate data.
9 # 4) source has combination of non-extent and extent files.
10 # 5) convert it to btrfs, mount and verify contents.
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2017 Lakshmipathi.G  All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         cd /
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # remove previous $seqres.full before test
49 rm -f $seqres.full
50
51 # real QA test starts here
52
53 # Modify as appropriate.
54 _supported_fs btrfs
55 _supported_os Linux
56 _require_scratch_nocheck
57
58 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
59 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
60 _require_command "$E2FSCK_PROG" e2fsck
61 _require_command "$TUNE2FS_PROG" tune2fs
62
63 rm -f $seqres.full
64
65 BLOCK_SIZE=`_get_block_size $TEST_DIR`
66 EXT_MD5SUM="$tmp.ext43"
67 BTRFS_MD5SUM="$tmp.btrfs"
68
69 populate_data(){
70         data_path=$1
71         mkdir -p $data_path
72         args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $data_path`
73         echo "Run fsstress $args" >>$seqres.full
74         $FSSTRESS_PROG $args >/dev/null 2>&1 &
75         fsstress_pid=$!
76         wait $fsstress_pid
77 }
78
79 # Create & populate an ext3 filesystem
80 $MKFS_EXT4_PROG -F -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
81         _notrun "Could not create ext3 filesystem"
82
83 # mount and populate non-extent file
84 mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
85 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext3"
86 _scratch_unmount
87
88 # Upgrade it to ext4.
89 $TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 2>&1
90 # After Conversion, its highly recommended to run e2fsck.
91 $E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1
92
93 # mount and populate extent file
94 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
95 populate_data "$SCRATCH_MNT/ext3_ext4_data/ext4"
96
97 # Compute md5 of ext3,ext4 files.
98 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$EXT_MD5SUM"
99 sort "$EXT_MD5SUM" -o "$EXT_MD5SUM"
100 _scratch_unmount
101
102 # Convert non-extent & extent data to btrfs, mount it, verify the data
103 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
104         _fail "btrfs-convert failed"
105 _try_scratch_mount || _fail "Could not mount new btrfs fs"
106
107 # Compute md5 for converted files.
108 find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$BTRFS_MD5SUM"
109 sort "$BTRFS_MD5SUM" -o "$BTRFS_MD5SUM"
110
111 # Compare two md5sum files.
112 btrfs_perm=`md5sum "$BTRFS_MD5SUM" | cut -f1 -d' '`
113 ext_perm=`md5sum "$EXT_MD5SUM" | cut -f1 -d' '`
114
115 if [ "$btrfs_perm" != "$ext_perm" ];then
116        echo "md5sum mismatch"
117 fi
118
119 # success, all done
120 echo "Silence is golden"
121 status=0
122 exit