summaryrefslogtreecommitdiff
path: root/tests/xfs/077
blob: f24f6f004b50cc7dee04c84940e05ce933eec403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test 077
#
# test UUID modification of CRC-enabled filesystems
#
# CRC-enabled / V5 superblock filesystems have a UUID stamped into
# every piece of metadata, and a mechanism was added later to allow
# changing the user-visible UUID by copying the original UUID (which
# matches all the existing metadata) to a new superblock location.
# Exercise some of that behavior.
#
. ./common/preamble
_begin_fstest auto quick copy

# Import common functions.
. ./common/filter

# real QA test starts here

_supported_fs xfs
_require_xfs_copy
_require_scratch
_require_no_large_scratch_dev
_require_xfs_crc
_require_meta_uuid

# Takes 2 args, 2nd optional:
#  1: generate, rewrite, or restore
#  2: Expected UUID after the action.  Blank if new uuid generated
# After the action check the fs, and make sure it can be mounted
# Sets NEW_UUID to the resulting UUID.
_test_uuid()
{
	ACTION=$1
	EXPECTED_UUID=$2

	_scratch_xfs_db -x -c "uuid $ACTION" \
					| _filter_uuid $EXPECTED_UUID
	NEW_UUID=`_scratch_xfs_db -c "uuid"  | awk '{print $NF}'`
	_check_scratch_fs
	_try_scratch_mount || _fail "Mount failed after UUID $ACTION"
	_scratch_unmount

}

_fs_has_META_UUID()
{
	FS=$1
	$XFS_DB_PROG -r -c version $FS | grep -q META_UUID
}

_scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"

ORIG_UUID=`_scratch_xfs_db -c "uuid" | awk '{print $NF}'`

_scratch_mount
# Put some stuff on the fs
$FSSTRESS_PROG -d $SCRATCH_MNT -n 100 -p 4 >> $seqres.full 2>&1
_scratch_unmount

# Can xfs_db change it?

echo "== Generate new UUID"
_test_uuid generate
[ "$NEW_UUID" == "$ORIG_UUID" ] && _fail "Failed to change UUID"
_fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"

# This should be a no-op
echo "== Rewrite UUID"
_test_uuid rewrite $NEW_UUID
_fs_has_META_UUID $SCRATCH_DEV || _fail "META_UUID feature not set"

# Can we change it back?
echo "== Restore old UUID"
_test_uuid restore $ORIG_UUID
[ "$NEW_UUID" != "$ORIG_UUID" ] && _fail "Failed to restore UUID"
_fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"

# This should be a no-op too.
echo "== Rewrite UUID"
_test_uuid rewrite $ORIG_UUID
_fs_has_META_UUID $SCRATCH_DEV && _fail "META_UUID feature should not be not set"

# Ok, now what does xfs_copy do; it changes UUID by default

IMGFILE=$TEST_DIR/$seq.copy.img
rm -f $IMGFILE

# xfs_copy changes the UUID by default
echo "== xfs_copy with new UUID"
$XFS_COPY_PROG $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
	_fail "xfs_copy (new UUID) failed"
_check_xfs_filesystem $IMGFILE none none || _fail "Copy looks corrupted"
# The copy should have META_UUID feature set
_fs_has_META_UUID $IMGFILE || _fail "META_UUID feature not set on copy"
_try_scratch_mount || _fail "Mount failed after UUID rewrite"
_scratch_unmount

rm -f $IMGFILE

# duplicating the UUID should be fine too
echo "== xfs_copy with duplicate UUID"
$XFS_COPY_PROG -d $SCRATCH_DEV $IMGFILE 2>&1 >> $seqres.full || \
	_fail "xfs_copy (duplicate) failed"
_check_xfs_filesystem $IMGFILE none none || _fail "Duplicate copy looks corrupted"
# The copy should not have META_UUID feature set
_fs_has_META_UUID $IMGFILE && _fail "META_UUID feature should not be set on copy"

# success, all done
status=0
exit