fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 037
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 037
6 #
7 # Verify that replacing a xattr's value is an atomic operation.
8 # This is motivated by an issue in btrfs where replacing a xattr's value
9 # wasn't an atomic operation, it consisted of removing the old value and
10 # then inserting the new value in a btree. This made readers (getxattr
11 # and listxattrs) not getting neither the old nor the new value during
12 # a short time window.
13 #
14 # The btrfs issue was fixed by the following linux kernel patch:
15 #
16 #    Btrfs: make xattr replace operations atomic
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         kill $setter_pid
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/attr
35
36 # real QA test starts here
37 _supported_fs generic
38 _supported_os Linux
39 _require_scratch
40 _require_attrs
41
42 rm -f $seqres.full
43
44 xattr_name="user.something"
45 xattr_value1="foobar"
46 xattr_value2="rabbit_hole"
47
48 set_xattr_loop()
49 {
50         local name=$1
51         local cur_val=$xattr_value1
52         while true; do
53                 $SETFATTR_PROG -n $xattr_name -v $cur_val $SCRATCH_MNT/$name
54                 if [ "$cur_val" == "$xattr_value1" ]; then
55                         cur_val=$xattr_value2
56                 else
57                         cur_val=$xattr_value1
58                 fi
59         done
60 }
61
62 value_filter()
63 {
64         grep "$xattr_name=" | cut -d '=' -f 2 | \
65                 sed -e "s/$xattr_value1/GOOD/" -e "s/$xattr_value2/GOOD/"
66 }
67
68 _scratch_mkfs >>$seqres.full 2>&1
69 _scratch_mount
70
71 test_file="test_xattr_replace"
72 touch $SCRATCH_MNT/$test_file
73 $SETFATTR_PROG -n $xattr_name -v $xattr_value1 $SCRATCH_MNT/$test_file
74
75 set_xattr_loop $test_file &
76 setter_pid=$!
77
78 for ((i = 0; i < 1000; i++)); do
79         $GETFATTR_PROG --absolute-names -n $xattr_name \
80                 $SCRATCH_MNT/$test_file | value_filter
81 done
82
83 status=0
84 exit