fsx/fsstress: round blocksize properly
[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 _require_scratch
39 _require_attrs
40
41 rm -f $seqres.full
42
43 xattr_name="user.something"
44 xattr_value1="foobar"
45 xattr_value2="rabbit_hole"
46
47 set_xattr_loop()
48 {
49         local name=$1
50         local cur_val=$xattr_value1
51         while true; do
52                 $SETFATTR_PROG -n $xattr_name -v $cur_val $SCRATCH_MNT/$name
53                 if [ "$cur_val" == "$xattr_value1" ]; then
54                         cur_val=$xattr_value2
55                 else
56                         cur_val=$xattr_value1
57                 fi
58         done
59 }
60
61 value_filter()
62 {
63         grep "$xattr_name=" | cut -d '=' -f 2 | \
64                 sed -e "s/$xattr_value1/GOOD/" -e "s/$xattr_value2/GOOD/"
65 }
66
67 _scratch_mkfs >>$seqres.full 2>&1
68 _scratch_mount
69
70 test_file="test_xattr_replace"
71 touch $SCRATCH_MNT/$test_file
72 $SETFATTR_PROG -n $xattr_name -v $xattr_value1 $SCRATCH_MNT/$test_file
73
74 set_xattr_loop $test_file &
75 setter_pid=$!
76
77 for ((i = 0; i < 1000; i++)); do
78         _getfattr --absolute-names -n $xattr_name \
79                 $SCRATCH_MNT/$test_file | value_filter
80 done
81
82 status=0
83 exit