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
38 # xfs_copy does not support realtime devices
41 _require_no_large_scratch_dev
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.
55 _scratch_xfs_db -x -c "uuid $ACTION" \
56 | _filter_uuid $EXPECTED_UUID
57 NEW_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`
59 _try_scratch_mount || _fail "Mount failed after UUID $ACTION"
67 $XFS_DB_PROG -r -c version $FS | grep -q META_UUID
72 _scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"
74 ORIG_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`
77 # Put some stuff on the fs
78 $FSSTRESS_PROG -d $SCRATCH_MNT -n 100 -p 4 >> $seqres.full 2>&1
81 # Can xfs_db change it?
83 echo "== Generate new UUID"
85 [ "$NEW_UUID" == "$ORIG_UUID" ] && _fail "Failed to change UUID"
86 _fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"
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"
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"
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"
104 # Ok, now what does xfs_copy do; it changes UUID by default
106 IMGFILE=$TEST_DIR/$seq.copy.img
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"
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"