007d05de4579616091eaf314ae3c48a296cbc6b4
[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 _require_scratch
54 _require_xfs_crc
55 _require_meta_uuid
56
57 # Takes 2 args, 2nd optional:
58 #  1: generate, rewrite, or restore
59 #  2: Expected UUID after the action.  Blank if new uuid generated
60 # After the action check the fs, and make sure it can be mounted
61 # Sets NEW_UUID to the resulting UUID.
62 _test_uuid()
63 {
64         ACTION=$1
65         EXPECTED_UUID=$2
66
67         $XFS_DB_PROG -x -c "uuid $ACTION" $SCRATCH_DEV \
68                                         | _filter_uuid $EXPECTED_UUID
69         NEW_UUID=`$XFS_DB_PROG -c "uuid"  $SCRATCH_DEV | awk '{print $NF}'`
70         _check_scratch_fs
71         _scratch_mount || _fail "Mount failed after UUID $ACTION"
72         _scratch_unmount
73
74 }
75
76 _fs_has_META_UUID()
77 {
78         FS=$1
79         $XFS_DB_PROG -r -c version $FS | grep -q META_UUID
80 }
81
82 rm -f $seqres.full
83
84 _scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"
85
86 ORIG_UUID=`$XFS_DB_PROG -c "uuid" $SCRATCH_DEV | awk '{print $NF}'`
87
88 _scratch_mount
89 # Put some stuff on the fs
90 $FSSTRESS_PROG -d $SCRATCH_MNT -n 100 -p 4 >> $seqres.full 2>&1
91 _scratch_unmount
92
93 # Can xfs_db change it?
94
95 echo "== Generate new UUID"
96 _test_uuid generate
97 [ "$NEW_UUID" == "$ORIG_UUID" ] && _fail "Failed to change UUID"
98 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
99
100 # This should be a no-op
101 echo "== Rewrite UUID"
102 _test_uuid rewrite $NEW_UUID
103 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
104
105 # Can we change it back?
106 echo "== Restore old UUID"
107 _test_uuid restore $ORIG_UUID
108 [ "$NEW_UUID" != "$ORIG_UUID" ] && _fail "Failed to restore UUID"
109 _fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"
110
111 # This should be a no-op too.
112 echo "== Rewrite UUID"
113 _test_uuid rewrite $ORIG_UUID
114 _fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"
115
116 # Ok, now what does xfs_copy do; it changes UUID by default
117
118 IMGFILE=$TEST_DIR/$seq.copy.img
119 rm -f $IMGFILE
120
121 # xfs_copy changes the UUID by default
122 echo "== xfs_copy with new UUID"
123 $XFS_COPY_PROG $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
124         _fail "xfs_copy (new UUID) failed"
125 _check_xfs_filesystem $IMGFILE none none || _fail "Copy looks corrupted"
126 # The copy should have META_UUID feature set
127 _fs_has_META_UUID $IMGFILE || _fail "META_UUID feature not set on copy"
128 _scratch_mount || _fail "Mount failed after UUID rewrite"
129 _scratch_unmount
130
131 rm -f $IMGFILE
132
133 # duplicating the UUID should be fine too
134 echo "== xfs_copy with duplicate UUID"
135 $XFS_COPY_PROG -d $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
136         _fail "xfs_copy (duplicate) failed"
137 _check_xfs_filesystem $IMGFILE none none || _fail "Duplicate copy looks corrupted"
138 # The copy should not have META_UUID feature set
139 _fs_has_META_UUID $IMGFILE && _fail "META_UUID feature should not be set on copy"
140
141 # success, all done
142 status=0
143 exit