summaryrefslogtreecommitdiff
path: root/tests/generic/037
blob: 55beddb49351e232c80bac779f42a031db9209a3 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 037
#
# Verify that replacing a xattr's value is an atomic operation.
# This is motivated by an issue in btrfs where replacing a xattr's value
# wasn't an atomic operation, it consisted of removing the old value and
# then inserting the new value in a btree. This made readers (getxattr
# and listxattrs) not getting neither the old nor the new value during
# a short time window.
#
# The btrfs issue was fixed by the following linux kernel patch:
#
#    Btrfs: make xattr replace operations atomic
#
. ./common/preamble
_begin_fstest auto quick attr metadata

# Override the default cleanup function.
_cleanup()
{
	kill $setter_pid
	rm -f $tmp.*
}

# Import common functions.
. ./common/filter
. ./common/attr

# real QA test starts here
_supported_fs generic
_require_scratch
_require_attrs

xattr_name="user.something"
xattr_value1="foobar"
xattr_value2="rabbit_hole"

set_xattr_loop()
{
	local name=$1
	local cur_val=$xattr_value1
	while true; do
		$SETFATTR_PROG -n $xattr_name -v $cur_val $SCRATCH_MNT/$name
		if [ "$cur_val" == "$xattr_value1" ]; then
			cur_val=$xattr_value2
		else
			cur_val=$xattr_value1
		fi
	done
}

value_filter()
{
	grep "$xattr_name=" | cut -d '=' -f 2 | \
		sed -e "s/$xattr_value1/GOOD/" -e "s/$xattr_value2/GOOD/"
}

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

test_file="test_xattr_replace"
touch $SCRATCH_MNT/$test_file
$SETFATTR_PROG -n $xattr_name -v $xattr_value1 $SCRATCH_MNT/$test_file

set_xattr_loop $test_file &
setter_pid=$!

for ((i = 0; i < 1000; i++)); do
	_getfattr --absolute-names -n $xattr_name \
		$SCRATCH_MNT/$test_file | value_filter
done

status=0
exit