fstests: _fail test by default when _scratch_mount fails
[xfstests-dev.git] / tests / xfs / 077
1 #! /bin/bash
2 # FS QA Test 077
3 #
4 # test UUID modification of CRC-enabled filesystems
5 #
6 # CRC-enabled / V5 superblock filesystems have a UUID stamped into
7 # every piece of metadata, and a mechanism was added later to allow
8 # changing the user-visible UUID by copying the original UUID (which
9 # matches all the existing metadata) to a new superblock location.
10 # Exercise some of that behavior.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2015 Red Hat, Inc.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # real QA test starts here
50
51 _supported_fs xfs
52 _supported_os Linux
53 # xfs_copy does not support realtime devices
54 _require_no_realtime
55 _require_scratch
56 _require_xfs_crc
57 _require_meta_uuid
58
59 # Takes 2 args, 2nd optional:
60 #  1: generate, rewrite, or restore
61 #  2: Expected UUID after the action.  Blank if new uuid generated
62 # After the action check the fs, and make sure it can be mounted
63 # Sets NEW_UUID to the resulting UUID.
64 _test_uuid()
65 {
66         ACTION=$1
67         EXPECTED_UUID=$2
68
69         _scratch_xfs_db -x -c "uuid $ACTION" \
70                                         | _filter_uuid $EXPECTED_UUID
71         NEW_UUID=`_scratch_xfs_db -c "uuid"  | awk '{print $NF}'`
72         _check_scratch_fs
73         _try_scratch_mount || _fail "Mount failed after UUID $ACTION"
74         _scratch_unmount
75
76 }
77
78 _fs_has_META_UUID()
79 {
80         FS=$1
81         $XFS_DB_PROG -r -c version $FS | grep -q META_UUID
82 }
83
84 rm -f $seqres.full
85
86 _scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"
87
88 ORIG_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`
89
90 _scratch_mount
91 # Put some stuff on the fs
92 $FSSTRESS_PROG -d $SCRATCH_MNT -n 100 -p 4 >> $seqres.full 2>&1
93 _scratch_unmount
94
95 # Can xfs_db change it?
96
97 echo "== Generate new UUID"
98 _test_uuid generate
99 [ "$NEW_UUID" == "$ORIG_UUID" ] && _fail "Failed to change UUID"
100 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
101
102 # This should be a no-op
103 echo "== Rewrite UUID"
104 _test_uuid rewrite $NEW_UUID
105 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
106
107 # Can we change it back?
108 echo "== Restore old UUID"
109 _test_uuid restore $ORIG_UUID
110 [ "$NEW_UUID" != "$ORIG_UUID" ] && _fail "Failed to restore UUID"
111 _fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"
112
113 # This should be a no-op too.
114 echo "== Rewrite UUID"
115 _test_uuid rewrite $ORIG_UUID
116 _fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"
117
118 # Ok, now what does xfs_copy do; it changes UUID by default
119
120 IMGFILE=$TEST_DIR/$seq.copy.img
121 rm -f $IMGFILE
122
123 # xfs_copy changes the UUID by default
124 echo "== xfs_copy with new UUID"
125 $XFS_COPY_PROG $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
126         _fail "xfs_copy (new UUID) failed"
127 _check_xfs_filesystem $IMGFILE none none || _fail "Copy looks corrupted"
128 # The copy should have META_UUID feature set
129 _fs_has_META_UUID $IMGFILE || _fail "META_UUID feature not set on copy"
130 _try_scratch_mount || _fail "Mount failed after UUID rewrite"
131 _scratch_unmount
132
133 rm -f $IMGFILE
134
135 # duplicating the UUID should be fine too
136 echo "== xfs_copy with duplicate UUID"
137 $XFS_COPY_PROG -d $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
138         _fail "xfs_copy (duplicate) failed"
139 _check_xfs_filesystem $IMGFILE none none || _fail "Duplicate copy looks corrupted"
140 # The copy should not have META_UUID feature set
141 _fs_has_META_UUID $IMGFILE && _fail "META_UUID feature should not be set on copy"
142
143 # success, all done
144 status=0
145 exit