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