#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2017 Ernesto A. Fernandez. All Rights Reserved.
+#
# FS QA Test 449
#
# Fill the device and set as many extended attributes to a file as
# possible. Then call setfacl on it and, if this fails for lack of
# space, test that the permissions remain the same.
#
-#-----------------------------------------------------------------------
-# Copyright (c) 2017 Ernesto A. Fernandez. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#-----------------------------------------------------------------------
-#
-
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
# Modify as appropriate.
_supported_fs generic
-_supported_os Linux
_require_scratch
_require_test
_require_acls
-_require_attrs
+_require_attrs trusted
-_scratch_mkfs_sized $((50 * 1024 * 1024)) >> $seqres.full 2>&1
+_scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
_scratch_mount || _fail "mount failed"
+# This is a test of xattr behavior when we run out of disk space for xattrs,
+# so make sure the pwrite goes to the data device and not the rt volume.
+test "$FSTYP" = "xfs" && \
+ $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+
TFILE=$SCRATCH_MNT/testfile.$seq
# Create the test file and choose its permissions
chmod go-rwx $TFILE
# Try to run out of space so setfacl will fail
-$XFS_IO_PROG -c "pwrite 0 50m" $TFILE >>$seqres.full 2>&1
+$XFS_IO_PROG -c "pwrite 0 256m" $TFILE >>$seqres.full 2>&1
i=1
+
+# Setting acls on an xfs filesystem will succeed even after running out of
+# space for user attributes. Use trusted attributes
+while $SETFATTR_PROG -n trusted.$i -v $(perl -e 'print "a"x1024') $TFILE &>/dev/null; do
+ ((++i))
+done
j=1
ret=0
while [ $ret -eq 0 ]; do
# On btrfs, setfattr will sometimes fail when free space is
# low, long before it's actually exhausted. Insist until it
# fails consistently.
- $SETFATTR_PROG -n user.$i"x"$j $TFILE &>/dev/null
+ $SETFATTR_PROG -n trusted.$i"x"$j $TFILE &>/dev/null
ret=$(( $ret && $? ))
((++j))
done