generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 449
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Ernesto A. Fernandez.  All Rights Reserved.
4 #
5 # FS QA Test 449
6 #
7 # Fill the device and set as many extended attributes to a file as
8 # possible. Then call setfacl on it and, if this fails for lack of
9 # space, test that the permissions remain the same.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick acl attr enospc
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/attr
17
18 # real QA test starts here
19
20 # Modify as appropriate.
21 _supported_fs generic
22 _require_scratch
23 _require_test
24 _require_acls
25 _require_attrs trusted
26
27 _scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
28 _scratch_mount || _fail "mount failed"
29
30 # This is a test of xattr behavior when we run out of disk space for xattrs,
31 # so make sure the pwrite goes to the data device and not the rt volume.
32 test "$FSTYP" = "xfs" && \
33         _xfs_force_bdev data $SCRATCH_MNT
34
35 TFILE=$SCRATCH_MNT/testfile.$seq
36
37 # Create the test file and choose its permissions
38 touch $TFILE
39 chmod u+rwx $TFILE
40 chmod go-rwx $TFILE
41
42 # Try to run out of space so setfacl will fail
43 $XFS_IO_PROG -c "pwrite 0 256m" $TFILE >>$seqres.full 2>&1
44 i=1
45
46 # Setting acls on an xfs filesystem will succeed even after running out of
47 # space for user attributes. Use trusted attributes
48 while $SETFATTR_PROG -n trusted.$i -v $(perl -e 'print "a"x1024') $TFILE &>/dev/null; do
49         ((++i))
50 done
51 j=1
52 ret=0
53 while [ $ret -eq 0 ]; do
54         ret=1
55         while [ $j -le 1000 ]; do
56                 # On btrfs, setfattr will sometimes fail when free space is
57                 # low, long before it's actually exhausted. Insist until it
58                 # fails consistently.
59                 $SETFATTR_PROG -n trusted.$i"x"$j $TFILE &>/dev/null
60                 ret=$(( $ret && $? ))
61                 ((++j))
62         done
63         j=1
64         ((++i))
65 done
66
67 if setfacl -m m:r $TFILE &>/dev/null; then
68         # setfacl succeeded, so the test was meaningless
69         # The filesystem might still have an issue
70         _notrun "$FSTYP succeeds in setting acls despite running out of space for user attrs"
71 fi
72
73 # Since setfacl failed, the permissions should not have changed
74 stat -c %A $TFILE
75
76 status=0
77 exit