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