2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
7 # test UUID modification of CRC-enabled filesystems
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.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
34 # real QA test starts here
39 _require_no_large_scratch_dev
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.
53 _scratch_xfs_db -x -c "uuid $ACTION" \
54 | _filter_uuid $EXPECTED_UUID
55 NEW_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`
57 _try_scratch_mount || _fail "Mount failed after UUID $ACTION"
65 $XFS_DB_PROG -r -c version $FS | grep -q META_UUID
70 _scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"
72 ORIG_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`
75 # Put some stuff on the fs
76 $FSSTRESS_PROG -d $SCRATCH_MNT -n 100 -p 4 >> $seqres.full 2>&1
79 # Can xfs_db change it?
81 echo "== Generate new UUID"
83 [ "$NEW_UUID" == "$ORIG_UUID" ] && _fail "Failed to change UUID"
84 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
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"
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"
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"
102 # Ok, now what does xfs_copy do; it changes UUID by default
104 IMGFILE=$TEST_DIR/$seq.copy.img
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"
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"