summaryrefslogtreecommitdiff
path: root/tests/btrfs/275
blob: 955a0c985f4c4f3e46d7bda4dc4bab449092e3e2 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. 275
#
# Test that no xattr can be changed once btrfs property is set to RO.
#
. ./common/preamble
_begin_fstest auto quick attr

. ./common/filter
. ./common/attr

_supported_fs btrfs
_fixed_by_kernel_commit b51111271b03 \
	"btrfs: check if root is readonly while setting security xattr"
_require_attrs
_require_btrfs_command "property"
_require_scratch

_scratch_mkfs >> $seqres.full 2>&1
_scratch_mount

FILENAME=$SCRATCH_MNT/foo

set_xattr()
{
	local value=$1
	$SETFATTR_PROG -n "user.one" -v $value $FILENAME 2>&1 | _filter_scratch
	$SETFATTR_PROG -n "security.one" -v $value $FILENAME 2>&1 | _filter_scratch
	$SETFATTR_PROG -n "trusted.one" -v $value $FILENAME 2>&1 | _filter_scratch
}

get_xattr()
{
	_getfattr --absolute-names -n "user.one" $FILENAME 2>&1 | _filter_scratch
	_getfattr --absolute-names -n "security.one" $FILENAME 2>&1 | _filter_scratch
	_getfattr --absolute-names -n "trusted.one" $FILENAME 2>&1 | _filter_scratch
}

del_xattr()
{
	$SETFATTR_PROG -x "user.one" $FILENAME 2>&1 | _filter_scratch
	$SETFATTR_PROG -x "security.one" $FILENAME 2>&1 | _filter_scratch
	$SETFATTR_PROG -x "trusted.one" $FILENAME 2>&1 | _filter_scratch
}

# Create a test file.
echo "hello world" > $FILENAME

set_xattr 1

$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true
$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro

# Attempt to change values of RO (property) filesystem.
set_xattr 2

# Check the values of RO (property) filesystem are not changed.
get_xattr

# Attempt to remove xattr from RO (property) filesystem.
del_xattr

# Check if xattr still exist.
get_xattr

# Change filesystem property RO to false
$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false
$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro

# Change the xattrs after RO is false.
set_xattr 2

# Get the changed values.
get_xattr

# Remove xattr.
del_xattr

# check if the xattrs are really deleted.
get_xattr

status=0
exit