summaryrefslogtreecommitdiff
path: root/tests/xfs/270
blob: 16e508035a9c7d04b247315a9cf903ed4722ac07 (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
115
116
117
118
119
120
121
122
123
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test 270
#
# Today ro-compat features can't be mounted rw, but a bug allows
# an ro->rw remount transition. This bug has been fixed on linux
# kernel (d0a58e8 xfs: disallow rw remount on fs with unknown
# ro-compat features), and this case is the regression testcase.
#
. ./common/preamble
_begin_fstest auto quick mount

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs xfs
_fixed_by_kernel_commit 74ad4693b647 \
	"xfs: fix log recovery when unknown rocompat bits are set"
# skip fs check because superblock contains unknown ro-compat features
_require_scratch_nocheck
# Only V5 XFS disallow rw mount/remount with unknown ro-compat features
_require_scratch_xfs_crc
_require_scratch_shutdown

# set the highest bit of features_ro_compat, use it as an unknown
# feature bit. If one day this bit become known feature, please
# change this case.
set_bad_rocompat() {
	ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
	echo $ro_compat | grep -q -E '^0x[[:xdigit:]]+$'
	if [[ $? != 0  ]]; then
		echo ":$ro_compat:"
		echo "features_ro_compat has an invalid value."
		return 1
	fi

	ro_compat=$(echo $ro_compat | \
			    awk '/^0x[[:xdigit:]]+/ {
					printf("0x%x\n", or(strtonum($1), 0x80000000))
				}')

	# write the new ro compat field to the superblock
	_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
					> $seqres.full 2>&1

	# read the newly set ro compat filed for verification
	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
							2>/dev/null)

	# verify the new ro_compat field is correct. Without xfsprogs commit
	# f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()"),
	# we can't get new_ro_compat value.
	if [ "$new_ro_compat" != "$ro_compat" ]; then
		echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
		return 1
	fi
	return 0
}

# Once with a clean filesystem...
_scratch_mkfs_xfs >>$seqres.full 2>&1
_scratch_mount
echo moo > $SCRATCH_MNT/testfile
_scratch_unmount
set_bad_rocompat

# rw mount with unknown ro-compat feature should fail
echo "rw mount test"
_try_scratch_mount 2>>$seqres.full
if [ $? -eq 0 ]; then
	_fail "rw mount test failed"
fi

# But ro mount should succeed
echo "ro mount test"
_try_scratch_mount -o ro
if [ $? -ne 0 ]; then
	_fail "ro mount test failed"
else
	# no hang/panic is fine
	cat $SCRATCH_MNT/testfile > /dev/null
	$FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 400 >>$seqres.full 2>&1
fi

# remount as rw, kernel should reject it
echo "rw remount test"
_scratch_remount rw 2>>$seqres.full
if [ $? -eq 0 ]; then
	dmesg | tail -n 15 >> $seqres.full
	_fail "rw remount test failed"
fi

_scratch_unmount

# And again with a dirty filesystem...
_scratch_mkfs_xfs >>$seqres.full 2>&1
_scratch_mount
echo moo > $SCRATCH_MNT/testfile
$XFS_IO_PROG -x -c 'shutdown -f' "${SCRATCH_MNT}"
_scratch_unmount
set_bad_rocompat

# rw mount with unknown ro-compat feature should fail
echo "rw mount test"
_try_scratch_mount 2>>$seqres.full
if [ $? -eq 0 ]; then
	_fail "rw mount test failed"
fi

# ro mount should succeed even with log recovery
echo "ro mount test"
_try_scratch_mount -o ro 2>>$seqres.full
if [ $? -ne 0 ]; then
	_fail "ro mount test failed"
fi
cat $SCRATCH_MNT/testfile > /dev/null

# success, all done
status=0
exit