generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / common / attr
index cc9cfdac743b4bb7e4e841fdad78e80aa7386b7e..3ebba682c894f6f85f12189f675c61c5ec24e45f 100644 (file)
@@ -1,24 +1,7 @@
 ##/bin/bash
-#-----------------------------------------------------------------------
-#  Copyright (c) 2000-2004 Silicon Graphics, Inc.  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; either version 2 of the License, or
-#  (at your option) any later version.
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
 #
-#  This program is distributed in the hope that it will 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 to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
-#  USA
-#
-#  Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
-#  Mountain View, CA 94043, USA, or: http://www.sgi.com
-#-----------------------------------------------------------------------
 # common extended attribute and ACL support
 
 # filesystems that want to test maximum supported acl counts need to
@@ -30,7 +13,7 @@ _acl_get_max()
                # CRC format filesystems have much larger ACL counts. The actual
                # number is into the thousands, but testing that meany takes too
                # long, so just test well past the old limit of 25.
-               xfs_info $TEST_DIR | _filter_mkfs > /dev/null 2> $tmp.info
+               $XFS_INFO_PROG $TEST_DIR | _filter_mkfs > /dev/null 2> $tmp.info
                . $tmp.info
                rm $tmp.info
                if [ $_fs_has_crcs -eq 0 ]; then
@@ -42,6 +25,30 @@ _acl_get_max()
        jfs)
                echo 8191
                ;;
+       f2fs)
+               # If noinline_xattr is enabled, max xattr size should be:
+               # (4096 - 24) - (24 + 4) = 4044
+               # then ACL_MAX_ENTRIES should be:
+               # (4044 - (4 + 4 * 4)) / 8 + 4 = 507
+               _fs_options $TEST_DEV | grep "noinline_xattr" >/dev/null 2>&1
+               if [ $? -eq 0 ]; then
+                       echo 507
+               else
+                       # If inline_xattr is enabled, max xattr size should be:
+                       # (4096 - 24 + 200) - (24 + 4) = 4244
+                       # then ACL_MAX_ENTRIES should be:
+                       # (4244 - (4 + 4 * 4)) / 8 + 4 = 532
+                       _fs_options $TEST_DEV | grep "inline_xattr" >/dev/null 2>&1
+                       if [ $? -eq 0 ]; then
+                               echo 532
+                       else
+                               echo 507
+                       fi
+               fi
+               ;;
+       bcachefs)
+               echo 251
+               ;;
        *)
                echo 0
                ;;
@@ -65,10 +72,10 @@ _acl_setup_ids()
         j=1
         for(i=1; i<1000000 && j<=3;i++){
           if (! (i in ids)) {
-            printf "acl%d=%d;", j, i;           
+            printf "acl%d=%d;", j, i;
             j++
           }
-        }      
+        }
       }'`
 }
 
@@ -107,18 +114,6 @@ _getfacl_filter_id()
 _acl_ls()
 {
     _ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
-} 
-
-#
-_acl_list()
-{
-    _file1=$1
-
-    if [ $HOSTOS = "IRIX" ]; then
-       ls -dD $_file1 | _acl_filter_id
-    else 
-        chacl -l $_file1 | _acl_filter_id
-    fi
 }
 
 # create an ACL with n ACEs in it
@@ -146,7 +141,7 @@ _filter_aces()
        BEGIN {
            FS=":"
            while ( getline <tmpfile > 0 ) {
-               idlist[$1] = $3 
+               idlist[$1] = $3
            }
        }
        /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
@@ -168,13 +163,12 @@ _require_acls()
     [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
 
     #
-    # Test if chacl is able to list ACLs on the target filesystems.  On really
-    # old kernels the system calls might not be implemented at all, but the
-    # more common case is that the tested filesystem simply doesn't support
-    # ACLs.
+    # Test if chacl is able to set an ACL on a file.  On really old kernels
+    # the system calls might not be implemented at all, but the more common
+    # case is that the tested filesystem simply doesn't support ACLs.
     #
     touch $TEST_DIR/syscalltest
-    chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
+    chacl 'u::rw-,g::---,o::---' $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
     cat $TEST_DIR/syscalltest.out >> $seqres.full
 
     if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
@@ -196,30 +190,42 @@ _list_acl()
 
 _require_attrs()
 {
-    [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
-    [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
-    [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
+       local args
+       local nsp
 
-    #
-    # Test if chacl is able to write an attribute on the target filesystems.
-    # On really old kernels the system calls might not be implemented at all,
-    # but the more common case is that the tested filesystem simply doesn't
-    # support attributes.  Note that we can't simply list attributes as
-    # various security modules generate synthetic attributes not actually
-    # stored on disk.
-    #
-    touch $TEST_DIR/syscalltest
-    attr -s "user.xfstests" -V "attr" $TEST_DIR > $TEST_DIR/syscalltest.out 2>&1
-    cat $TEST_DIR/syscalltest.out >> $seqres.full
+       if [ $# -eq 0 ]; then
+               args="user"
+       else
+               args="$*"
+       fi
 
-    if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
-      _notrun "kernel does not support attrs"
-    fi
-    if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
-      _notrun "attrs not supported by this filesystem type: $FSTYP"
-    fi
+       [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
+       [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
+       [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
 
-    rm -f $TEST_DIR/syscalltest.out
+       for nsp in $args; do
+               #
+               # Test if chacl is able to write an attribute on the target
+               # filesystems.  On really old kernels the system calls might
+               # not be implemented at all, but the more common case is that
+               # the tested filesystem simply doesn't support attributes.
+               # Note that we can't simply list attributes as various security
+               # modules generate synthetic attributes not actually stored on
+               # disk.
+               #
+               touch $TEST_DIR/syscalltest
+               $SETFATTR_PROG -n "$nsp.xfstests" -v "attr" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
+               cat $TEST_DIR/syscalltest.out >> $seqres.full
+
+               if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
+                       _notrun "kernel does not support attrs"
+               fi
+               if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
+                       _notrun "attr namespace $nsp not supported by this filesystem type: $FSTYP"
+               fi
+
+               rm -f $TEST_DIR/syscalltest.out
+       done
 }
 
 _require_attr_v1()
@@ -233,7 +239,7 @@ _require_noattr2()
 {
        _scratch_mkfs_xfs > /dev/null 2>&1 \
                || _fail "_scratch_mkfs_xfs failed on $SCRATCH_DEV"
-       _mount -o noattr2 $SCRATCH_DEV > /dev/null 2>&1 \
+       _try_scratch_mount -o noattr2 > /dev/null 2>&1 \
                || _notrun "noattr2 mount option not supported on $SCRATCH_DEV"
        _scratch_unmount
 }
@@ -245,26 +251,17 @@ _sort_getfattr_output()
     awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
 }
 
-# set maximum total attr space based on fs type
-if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" ]; then
-       MAX_ATTRS=1000
-else # Assume max ~1 block of attrs
-       BLOCK_SIZE=`get_block_size $TEST_DIR`
-       # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
-       let MAX_ATTRS=$BLOCK_SIZE/40
-fi
-
-export MAX_ATTRS
-
-# Set max attr value size based on fs type
-if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" -o "$FSTYP" == "btrfs" ]; then
-       MAX_ATTRVAL_SIZE=64
-else # Assume max ~1 block of attrs
-       BLOCK_SIZE=`get_block_size $TEST_DIR`
-       # leave a little overhead
-       let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
-fi
+# Previously, when getfattr dumps values of all extended attributes, it prints
+# empty attr as 'user.name', but new getfattr (since attr-2.4.48) prints it as
+# 'user.name=""'. Filter out the ending '=""' so that both old and new getfattr
+# pints the same output.
+#
+# Note: This function returns the getfattr command result.
+_getfattr()
+{
+       $GETFATTR_PROG "$@" | sed -e 's/=\"\"//'
+       return ${PIPESTATUS[0]}
+}
 
-export MAX_ATTRVAL_SIZE
 # make sure this script returns success
 /bin/true