generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
19 _begin_fstest auto quick attr metadata
20
21 # Override the default cleanup function.
22 _cleanup()
23 {
24         kill $setter_pid
25         rm -f $tmp.*
26 }
27
28 # Import common functions.
29 . ./common/filter
30 . ./common/attr
31
32 # real QA test starts here
33 _supported_fs generic
34 _require_scratch
35 _require_attrs
36
37 xattr_name="user.something"
38 xattr_value1="foobar"
39 xattr_value2="rabbit_hole"
40
41 set_xattr_loop()
42 {
43         local name=$1
44         local cur_val=$xattr_value1
45         while true; do
46                 $SETFATTR_PROG -n $xattr_name -v $cur_val $SCRATCH_MNT/$name
47                 if [ "$cur_val" == "$xattr_value1" ]; then
48                         cur_val=$xattr_value2
49                 else
50                         cur_val=$xattr_value1
51                 fi
52         done
53 }
54
55 value_filter()
56 {
57         grep "$xattr_name=" | cut -d '=' -f 2 | \
58                 sed -e "s/$xattr_value1/GOOD/" -e "s/$xattr_value2/GOOD/"
59 }
60
61 _scratch_mkfs >>$seqres.full 2>&1
62 _scratch_mount
63
64 test_file="test_xattr_replace"
65 touch $SCRATCH_MNT/$test_file
66 $SETFATTR_PROG -n $xattr_name -v $xattr_value1 $SCRATCH_MNT/$test_file
67
68 set_xattr_loop $test_file &
69 setter_pid=$!
70
71 for ((i = 0; i < 1000; i++)); do
72         _getfattr --absolute-names -n $xattr_name \
73                 $SCRATCH_MNT/$test_file | value_filter
74 done
75
76 status=0
77 exit