diff options
author | Brian Behlendorf <[email protected]> | 2017-05-18 20:22:04 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-05-22 12:34:42 -0400 |
commit | 5a6d6cf839fe547f2007912f60eac23827b4a8de (patch) | |
tree | 34d43ca143942efee917018fa2290b173dabc997 /tests | |
parent | 95401cb6f7aa9ec3dd2d61335d2dcc9459c2661c (diff) |
Enable xattr tests
Updated the xattr_common.ksh helper functions to use the attr
command on Linux to manipulate xattrs. Added an xattr.cfg file
and reworked the user/group functionality to be consist with
the existing delegate test cases. The intent of each test
case was preserved.
* xattr_001_pos, xattr_002_neg - Updated to verity xattr=on
and xattr=sa sytle xattrs.
* xattr_003_neg - Use user_run helper instead of su.
* xattr_004_pos - Updated to work with ext2 xattrs.
* xattr_007_neg - Updated to use attr instead of runat.
* xattr_008_pos, xattr_009_neg8_pos, xattr_010_neg -
Test cases disables since they aren't applicable to Linux.
* xattr_011_pos - Updated to expected behavior from GNU
versions of the tested utilities.
* xattr_012_pos - Updated to use xattrtest to create many
small xattrs instead of a single large one.
* xattr_013_pos - Updated to use attr instead of runat.
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #6128
Diffstat (limited to 'tests')
17 files changed, 387 insertions, 186 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 55fdd5dbe..e83a9ed0f 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -547,11 +547,11 @@ tests = ['vdev_zaps_001_pos', 'vdev_zaps_002_pos', 'vdev_zaps_003_pos', [tests/functional/write_dirs] tests = ['write_dirs_001_pos', 'write_dirs_002_pos'] -#[tests/functional/xattr] -#tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos', -# 'xattr_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos', -# 'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos', -# 'xattr_013_pos'] +[tests/functional/xattr] +tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos', + 'xattr_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos', + 'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos', + 'xattr_013_pos'] [tests/functional/zvol/zvol_ENOSPC] tests = ['zvol_ENOSPC_001_pos'] diff --git a/tests/zfs-tests/tests/functional/xattr/Makefile.am b/tests/zfs-tests/tests/functional/xattr/Makefile.am index ac2cb54b5..e404e84b1 100644 --- a/tests/zfs-tests/tests/functional/xattr/Makefile.am +++ b/tests/zfs-tests/tests/functional/xattr/Makefile.am @@ -3,6 +3,7 @@ dist_pkgdata_SCRIPTS = \ xattr_common.kshlib \ setup.ksh \ cleanup.ksh \ + xattr.cfg \ xattr_001_pos.ksh \ xattr_002_neg.ksh \ xattr_003_neg.ksh \ diff --git a/tests/zfs-tests/tests/functional/xattr/cleanup.ksh b/tests/zfs-tests/tests/functional/xattr/cleanup.ksh index 10cd733d2..5f0a84616 100755 --- a/tests/zfs-tests/tests/functional/xattr/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/xattr/cleanup.ksh @@ -28,15 +28,14 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib -ZFS_USER=$(cat /tmp/zfs-xattr-test-user.txt) -rm /tmp/zfs-xattr-test-user.txt +del_user $ZFS_USER +del_group $ZFS_GROUP USES_NIS=$(cat /tmp/zfs-xattr-test-nis.txt) rm /tmp/zfs-xattr-test-nis.txt -del_user $ZFS_USER - if [ "${USES_NIS}" == "true" ] then svcadm enable svc:/network/nis/client:default diff --git a/tests/zfs-tests/tests/functional/xattr/setup.ksh b/tests/zfs-tests/tests/functional/xattr/setup.ksh index ac82c5919..64f89a3d0 100755 --- a/tests/zfs-tests/tests/functional/xattr/setup.ksh +++ b/tests/zfs-tests/tests/functional/xattr/setup.ksh @@ -28,33 +28,24 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib # if we're running NIS, turn it off until we clean up # (it can cause useradd to take a long time, hitting our TIMEOUT) -USES_NIS=false -svcs svc:/network/nis/client:default | grep online > /dev/null -if [ $? -eq 0 ] -then - svcadm disable -t svc:/network/nis/client:default - USES_NIS=true -fi - -# Make sure we use a brand new user for this -ZFS_USER=zxtr -ZFS_GROUP=staff -while [ -z "${FOUND}" ] -do - COUNT=0 - USER_EXISTS=$( grep $ZFS_USER /etc/passwd ) - if [ ! -z "${USER_EXISTS}" ] +if is_linux; then + USED_NIS=false +else + USES_NIS=false + svcs svc:/network/nis/client:default | grep online > /dev/null + if [ $? -eq 0 ] then - ZFS_USER="${ZFS_USER}${COUNT}" - COUNT=$(( $COUNT + 1 )) - else - FOUND="true" + svcadm disable -t svc:/network/nis/client:default + USES_NIS=true fi -done +fi +# Make sure we use a brand new user for this +log_must add_group $ZFS_GROUP log_must add_user $ZFS_GROUP $ZFS_USER echo $ZFS_USER > /tmp/zfs-xattr-test-user.txt diff --git a/tests/zfs-tests/tests/functional/xattr/xattr.cfg b/tests/zfs-tests/tests/functional/xattr/xattr.cfg new file mode 100644 index 000000000..5f47562bb --- /dev/null +++ b/tests/zfs-tests/tests/functional/xattr/xattr.cfg @@ -0,0 +1,30 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2017 by Lawrence Livermore National Security, LLC. +# Use is subject to license terms. +# + +export NISSTAFILE=/var/tmp/nis_state + +export ZFS_USER=zxtr +export ZFS_GROUP=zfsgrp diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh index adb5132f2..ffb700438 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh @@ -52,12 +52,18 @@ function cleanup { fi } +set -A args "on" "sa" + log_assert "Create/read/write/append of xattrs works" log_onexit cleanup -log_must touch $TESTDIR/myfile.$$ -create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd -verify_write_xattr $TESTDIR/myfile.$$ passwd -delete_xattr $TESTDIR/myfile.$$ passwd +for arg in ${args[*]}; do + log_must zfs set xattr=$arg $TESTPOOL + + log_must touch $TESTDIR/myfile.$$ + create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd + verify_write_xattr $TESTDIR/myfile.$$ passwd + delete_xattr $TESTDIR/myfile.$$ passwd +done log_pass "Create/read/write of xattrs works" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh index 99212a011..e379d1586 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh @@ -46,11 +46,17 @@ function cleanup { } +set -A args "on" "sa" + log_assert "A read of a non-existent xattr fails" log_onexit cleanup -# create a file -log_must touch $TESTDIR/myfile.$$ -log_mustnot eval "cat $TESTDIR/myfile.$$ not-here.txt > /dev/null 2>&1" +for arg in ${args[*]}; do + log_must zfs set xattr=$arg $TESTPOOL + + # create a file + log_must touch $TESTDIR/myfile.$$ + log_mustnot eval "cat $TESTDIR/myfile.$$ not-here.txt > /dev/null 2>&1" -log_pass "A read of a non-existent xattr fails" + log_pass "A read of a non-existent xattr fails" +done diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh index 28fae8e65..a56fce4ea 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh @@ -56,7 +56,21 @@ log_must touch $TESTDIR/myfile.$$ create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd log_must chmod 000 $TESTDIR/myfile.$$ -log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cat passwd" -log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cp /etc/passwd ." +if is_linux; then + user_run $ZFS_USER eval \ + "attr -q -g passwd $TESTDIR/myfile.$$ >/tmp/passwd.$$" + log_mustnot diff /etc/passwd /tmp/passwd.$$ + log_must rm /tmp/passwd.$$ + + user_run $ZFS_USER eval \ + "attr -q -s passwd $TESTDIR/myfile.$$ </etc/group" + log_must chmod 644 $TESTDIR/myfile.$$ + attr -q -g passwd $TESTDIR/myfile.$$ >/tmp/passwd.$$ + log_must diff /etc/passwd /tmp/passwd.$$ + log_must rm /tmp/passwd.$$ +else + log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cat passwd" + log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cp /etc/passwd ." +fi log_pass "read/write xattr on a file with no permissions fails" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh index 921526315..e5f61d3bf 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh @@ -50,8 +50,7 @@ verify_runnable "global" # Make sure we clean up properly function cleanup { - if [ $( ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS ) ] - then + if ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS; then log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ log_must rm -rf /tmp/$NEWFS_DEFAULT_FS.$$ fi @@ -63,25 +62,62 @@ log_onexit cleanup # Create a UFS|EXT2 file system that we can work in log_must zfs create -V128m $TESTPOOL/$TESTFS/zvol block_device_wait -log_must eval "echo y | $NEWFS $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1" +log_must eval "echo y | newfs $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1" log_must mkdir /tmp/$NEWFS_DEFAULT_FS.$$ -log_must mount $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol /tmp/$NEWFS_DEFAULT_FS.$$ +if is_linux; then + log_must mount -o user_xattr \ + $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol /tmp/$NEWFS_DEFAULT_FS.$$ -# Create files in ufs|ext2 and tmpfs, and set some xattrs on them. -log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ -log_must touch /tmp/tmpfs-file.$$ + # Create files in ext2 and tmpfs, and set some xattrs on them. + # Use small values for xattrs for ext2 compatibility. + log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ -log_must runat /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ cp /etc/passwd . -log_must runat /tmp/tmpfs-file.$$ cp /etc/group . + log_must touch /tmp/tmpfs-file.$$ + echo "TEST XATTR" >/tmp/xattr1 + echo "1234567890" >/tmp/xattr2 + log_must attr -q -s xattr1 \ + /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ </tmp/xattr1 + log_must attr -q -s xattr2 /tmp/tmpfs-file.$$ </tmp/xattr2 -# copy those files to ZFS -log_must cp -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ $TESTDIR -log_must cp -@ /tmp/tmpfs-file.$$ $TESTDIR + # copy those files to ZFS + log_must cp -a /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ + $TESTDIR + log_must cp -a /tmp/tmpfs-file.$$ $TESTDIR -# ensure the xattr information has been copied correctly -log_must runat $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ diff passwd /etc/passwd -log_must runat $TESTDIR/tmpfs-file.$$ diff group /etc/group + # ensure the xattr information has been copied correctly + log_must eval "attr -q -g xattr1 $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \ + >/tmp/xattr1.$$" + + log_must diff /tmp/xattr1.$$ /tmp/xattr1 + log_must eval "attr -q -g xattr2 $TESTDIR/tmpfs-file.$$ >/tmp/xattr2.$$" + log_must diff /tmp/xattr2.$$ /tmp/xattr2 + log_must rm /tmp/xattr1 /tmp/xattr1.$$ /tmp/xattr2 /tmp/xattr2.$$ + + log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ +else + log_must mount $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol \ + /tmp/$NEWFS_DEFAULT_FS.$$ + + # Create files in ufs and tmpfs, and set some xattrs on them. + log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ + log_must touch /tmp/tmpfs-file.$$ + + log_must runat /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ + cp /etc/passwd . + log_must runat /tmp/tmpfs-file.$$ cp /etc/group . + + # copy those files to ZFS + log_must cp -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ + $TESTDIR + log_must cp -@ /tmp/tmpfs-file.$$ $TESTDIR + + # ensure the xattr information has been copied correctly + log_must runat $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \ + diff passwd /etc/passwd + log_must runat $TESTDIR/tmpfs-file.$$ diff group /etc/group + + log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ +fi -log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ log_pass "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info." diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh index 6b3feeafc..977434ceb 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh @@ -69,13 +69,22 @@ log_must touch $TESTDIR/myfile2.$$ log_must zfs snapshot $TESTPOOL/$TESTFS@snap # we shouldn't be able to alter the first file's xattr -log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ - cp /etc/passwd . >/tmp/output.$$ 2>&1" -log_must grep -i Read-only /tmp/output.$$ +if is_linux; then + log_mustnot eval "attr -s cp $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ + </etc/passwd >/tmp/output.$$ 2>&1" + log_must grep -i Read-only /tmp/output.$$ + log_must eval "attr -q -l $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ + >/tmp/output.$$ 2>&1" + log_must eval "attr -q -l $TESTDIR/myfile2.$$ >/tmp/expected_output.$$" +else + log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ + cp /etc/passwd . >/tmp/output.$$ 2>&1" + log_must grep -i Read-only /tmp/output.$$ + log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ + ls >/tmp/output.$$ 2>&1" + create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw +fi -log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ - ls >/tmp/output.$$ 2>&1" -create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw log_must diff /tmp/output.$$ /tmp/expected_output.$$ log_pass "create/write xattr on a snapshot fails" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh index 20319967c..735f1859a 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh @@ -49,6 +49,10 @@ function cleanup { done } +if is_linux; then + log_unsupported "Test case isn't applicable to Linux" +fi + log_assert "special . and .. dirs work as expected for xattrs" log_onexit cleanup diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh index 6a953cf84..ea5b40eec 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh @@ -40,6 +40,10 @@ # 3. Verify we're unable to create a hard link # +if is_linux; then + log_unsupported "Test case isn't applicable to Linux" +fi + function cleanup { log_must rm $TESTDIR/myfile.$$ diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh index 43502bfff..db218c434 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh @@ -41,6 +41,10 @@ # # +if is_linux; then + log_unsupported "Test case isn't applicable to Linux" +fi + function cleanup { log_must rm $TESTDIR/myfile.$$ diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh index 12f067489..9276d3a1a 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh @@ -65,60 +65,74 @@ create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd # and try various cpio options extracting the archives # with and without xattr support, checking for correct behaviour - -log_note "Checking cpio" -log_must touch $TESTDIR/cpio.$$ -create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd -echo $TESTDIR/cpio.$$ | cpio -o@ > /tmp/xattr.$$.cpio -echo $TESTDIR/cpio.$$ | cpio -o > /tmp/noxattr.$$.cpio - -# we should have no xattr here -log_must cpio -iu < /tmp/xattr.$$.cpio -log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" - -# we should have an xattr here -log_must cpio -iu@ < /tmp/xattr.$$.cpio -log_must eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" - -# we should have no xattr here -log_must cpio -iu < /tmp/noxattr.$$.cpio -log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" - -# we should have no xattr here -log_must cpio -iu@ < /tmp/noxattr.$$.cpio -log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/cpio.$$ /tmp/xattr.$$.cpio /tmp/noxattr.$$.cpio - - +if is_linux; then + log_note "Checking cpio - unsupported" +else + log_note "Checking cpio" + log_must touch $TESTDIR/cpio.$$ + create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd + echo $TESTDIR/cpio.$$ | cpio -o@ > /tmp/xattr.$$.cpio + echo $TESTDIR/cpio.$$ | cpio -o > /tmp/noxattr.$$.cpio + + # we should have no xattr here + log_must cpio -iu < /tmp/xattr.$$.cpio + log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" + + # we should have an xattr here + log_must cpio -iu@ < /tmp/xattr.$$.cpio + log_must eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" + + # we should have no xattr here + log_must cpio -iu < /tmp/noxattr.$$.cpio + log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" + + # we should have no xattr here + log_must cpio -iu@ < /tmp/noxattr.$$.cpio + log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/cpio.$$ /tmp/xattr.$$.cpio /tmp/noxattr.$$.cpio +fi log_note "Checking cp" # check that with the right flag, the xattr is preserved -log_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ -compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd -log_must rm $TESTDIR/myfile2.$$ +if is_linux; then + log_must cp -a $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ -# without the right flag, there should be no xattr -log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ -log_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1" -log_must rm $TESTDIR/myfile2.$$ + compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd + log_must rm $TESTDIR/myfile2.$$ + # without the right flag, there should be no xattr + log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ + log_mustnot attr -q -g passwd $TESTDIR/myfile2.$$ + log_must rm $TESTDIR/myfile2.$$ +else + log_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ + compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd + log_must rm $TESTDIR/myfile2.$$ + + # without the right flag, there should be no xattr + log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ + log_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1" + log_must rm $TESTDIR/myfile2.$$ +fi -log_note "Checking find" # create a file without xattrs, and check that find -xattr only finds # our test file that has an xattr. -log_must mkdir $TESTDIR/noxattrs -log_must touch $TESTDIR/noxattrs/no-xattr - -find $TESTDIR -xattr | grep myfile.$$ -[[ $? -ne 0 ]] && \ - log_fail "find -xattr didn't find our file that had an xattr." -find $TESTDIR -xattr | grep no-xattr -[[ $? -eq 0 ]] && \ - log_fail "find -xattr found a file that didn't have an xattr." -log_must rm -rf $TESTDIR/noxattrs - - +if is_linux; then + log_note "Checking find - unsupported" +else + log_note "Checking find" + log_must mkdir $TESTDIR/noxattrs + log_must touch $TESTDIR/noxattrs/no-xattr + + find $TESTDIR -xattr | grep myfile.$$ + [[ $? -ne 0 ]] && \ + log_fail "find -xattr didn't find our file that had an xattr." + find $TESTDIR -xattr | grep no-xattr + [[ $? -eq 0 ]] && \ + log_fail "find -xattr found a file that didn't have an xattr." + log_must rm -rf $TESTDIR/noxattrs +fi log_note "Checking mv" # mv doesn't have any flags to preserve/ommit xattrs - they're @@ -129,65 +143,96 @@ log_must mv $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$ verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd log_must rm $TESTDIR/mvfile2.$$ - -log_note "Checking pax" -log_must touch $TESTDIR/pax.$$ -create_xattr $TESTDIR/pax.$$ passwd /etc/passwd -log_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$ -log_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$ -log_must rm $TESTDIR/pax.$$ - -# we should have no xattr here -log_must pax -r -f $TESTDIR/noxattr.pax -log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/pax.$$ - -# we should have no xattr here -log_must pax -r@ -f $TESTDIR/noxattr.pax -log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/pax.$$ - - -# we should have an xattr here -log_must pax -r@ -f $TESTDIR/xattr.pax -verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd -log_must rm $TESTDIR/pax.$$ - -# we should have no xattr here -log_must pax -r -f $TESTDIR/xattr.pax $TESTDIR -log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax - +if is_linux; then + log_note "Checking pax - unsupported" +else + log_note "Checking pax" + log_must touch $TESTDIR/pax.$$ + create_xattr $TESTDIR/pax.$$ passwd /etc/passwd + log_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$ + log_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$ + log_must rm $TESTDIR/pax.$$ + + # we should have no xattr here + log_must pax -r -f $TESTDIR/noxattr.pax + log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/pax.$$ + + # we should have no xattr here + log_must pax -r@ -f $TESTDIR/noxattr.pax + log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/pax.$$ + + # we should have an xattr here + log_must pax -r@ -f $TESTDIR/xattr.pax + verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd + log_must rm $TESTDIR/pax.$$ + + # we should have no xattr here + log_must pax -r -f $TESTDIR/xattr.pax $TESTDIR + log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax +fi log_note "Checking tar" -log_must touch $TESTDIR/tar.$$ -create_xattr $TESTDIR/tar.$$ passwd /etc/passwd - -log_must cd $TESTDIR - -log_must tar cf noxattr.tar tar.$$ -log_must tar c@f xattr.tar tar.$$ -log_must rm $TESTDIR/tar.$$ - -# we should have no xattr here -log_must tar xf xattr.tar -log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/tar.$$ - -# we should have an xattr here -log_must tar x@f xattr.tar -verify_xattr tar.$$ passwd /etc/passwd -log_must rm $TESTDIR/tar.$$ - -# we should have no xattr here -log_must tar xf $TESTDIR/noxattr.tar -log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/tar.$$ - -# we should have no xattr here -log_must tar x@f $TESTDIR/noxattr.tar -log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" -log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar - +if is_linux; then + log_must touch $TESTDIR/tar.$$ + create_xattr $TESTDIR/tar.$$ passwd /etc/passwd + + log_must cd $TESTDIR + + log_must tar -cf noxattr.tar tar.$$ + log_must tar --xattrs -cf xattr.tar tar.$$ + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar --no-xattrs -xf xattr.tar + log_mustnot attr -q -g passwd $TESTDIR/tar.$$ + log_must rm $TESTDIR/tar.$$ + + # we should have an xattr here + log_must tar --xattrs -xf xattr.tar + verify_xattr tar.$$ passwd /etc/passwd + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar --no-xattrs -xf $TESTDIR/noxattr.tar + log_mustnot attr -q -g passwd $TESTDIR/tar.$$ + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar --xattrs -xf $TESTDIR/noxattr.tar + log_mustnot attr -q -g passwd $TESTDIR/tar.$$ + log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar +else + log_must touch $TESTDIR/tar.$$ + create_xattr $TESTDIR/tar.$$ passwd /etc/passwd + + log_must cd $TESTDIR + + log_must tar cf noxattr.tar tar.$$ + log_must tar c@f xattr.tar tar.$$ + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar xf xattr.tar + log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/tar.$$ + + # we should have an xattr here + log_must tar x@f xattr.tar + verify_xattr tar.$$ passwd /etc/passwd + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar xf $TESTDIR/noxattr.tar + log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/tar.$$ + + # we should have no xattr here + log_must tar x@f $TESTDIR/noxattr.tar + log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" + log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar +fi log_assert "Basic applications work with xattrs: cpio cp find mv pax tar" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh index 26d6bd7dd..7241caf8e 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh @@ -79,10 +79,16 @@ fi FS_SIZE=$(zfs get -p -H -o value used $TESTPOOL/$TESTFS) -log_must runat $TESTDIR/myfile.$$ mkfile 200m xattr +if is_linux; then + # Linux setxattr() syscalls limits individual xattrs to 64k. Create + # 100 files, with 128 xattrs each of size 16k. 100*128*16k=200m + log_must xattrtest -k -f 100 -x 128 -s 16384 -p $TESTDIR +else + log_must runat $TESTDIR/myfile.$$ mkfile 200m xattr +fi #Make sure the newly created file is counted into zpool usage -log_must sync +sync_pool # now check to see if our pool disk usage has increased if is_global_zone diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh index 50b8ffbfa..e9eed6955 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh @@ -65,13 +65,25 @@ log_must umount $TESTDIR log_must zfs mount -o noxattr $TESTPOOL/$TESTFS # check that we can't perform xattr operations -log_mustnot eval "runat $TESTDIR/myfile.$$ cat passwd > /dev/null 2>&1" -log_mustnot eval "runat $TESTDIR/myfile.$$ rm passwd > /dev/null 2>&1" -log_mustnot eval "runat $TESTDIR/myfile.$$ cp /etc/passwd . > /dev/null 2>&1" - -log_must touch $TESTDIR/new.$$ -log_mustnot eval "runat $TESTDIR/new.$$ cp /etc/passwd . > /dev/null 2>&1" -log_mustnot eval "runat $TESTDIR/new.$$ rm passwd > /dev/null 2>&1" +if is_linux; then + log_mustnot attr -q -g passwd $TESTDIR/myfile.$$ + log_mustnot attr -q -r passwd $TESTDIR/myfile.$$ + log_mustnot attr -q -s passwd $TESTDIR/myfile.$$ </etc/passwd + + log_must touch $TESTDIR/new.$$ + log_mustnot attr -q -s passwd $TESTDIR/new.$$ </etc/passwd + log_mustnot attr -q -r passwd $TESTDIR/new.$$ +else + log_mustnot eval "runat $TESTDIR/myfile.$$ cat passwd > /dev/null 2>&1" + log_mustnot eval "runat $TESTDIR/myfile.$$ rm passwd > /dev/null 2>&1" + log_mustnot eval "runat $TESTDIR/myfile.$$ cp /etc/passwd . \ + > /dev/null 2>&1" + + log_must touch $TESTDIR/new.$$ + log_mustnot eval "runat $TESTDIR/new.$$ cp /etc/passwd . \ + > /dev/null 2>&1" + log_mustnot eval "runat $TESTDIR/new.$$ rm passwd > /dev/null 2>&1" +fi # now mount the filesystem again as normal log_must umount $TESTDIR @@ -82,7 +94,11 @@ verify_xattr $TESTDIR/myfile.$$ passwd /etc/passwd # there should be no xattr on the file we created while the fs was mounted # -o noxattr -log_mustnot eval "runat $TESTDIR/new.$$ cat passwd > /dev/null 2>&1" +if is_linux; then + log_mustnot attr -q -g passwd $TESTDIR/new.$$ +else + log_mustnot eval "runat $TESTDIR/new.$$ cat passwd > /dev/null 2>&1" +fi create_xattr $TESTDIR/new.$$ passwd /etc/passwd log_pass "The noxattr mount option functions as expected" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib b/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib index 567100934..d2399310b 100644 --- a/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib +++ b/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib @@ -29,6 +29,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/xattr/xattr.cfg # a function that takes a file, then creates and verifies # an xattr on that file. The xattr_contents is the file @@ -38,10 +39,15 @@ function create_xattr { # filename xattr_name xattr_contents typeset XATTR_NAME=$2 typeset XATTR_CONTENTS=$3 - # read any empty xattr on that file - log_must runat $FILE ls - # create the xattr - log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME + if is_linux; then + log_mustnot attr -q -g $XATTR_NAME $FILE + log_must attr -q -s $XATTR_NAME $FILE < $XATTR_CONTENTS + else + # read any empty xattr on that file + log_must runat $FILE ls + # create the xattr + log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME + fi verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS } @@ -53,8 +59,13 @@ function compare_xattrs { # filename1 filename2 xattr_name typeset FILE2=$2 typeset XATTR_NAME=$3 - runat $FILE1 cat $XATTR_NAME > /tmp/file1.$$ - runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$ + if is_linux; then + attr -q -g $XATTR_NAME $FILE1 >/tmp/file1.$$ + attr -q -g $XATTR_NAME $FILE2 >/tmp/file2.$$ + else + runat $FILE1 cat $XATTR_NAME > /tmp/file1.$$ + runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$ + fi log_must diff /tmp/file1.$$ /tmp/file2.$$ log_must rm /tmp/file1.$$ /tmp/file2.$$ @@ -66,7 +77,14 @@ function verify_xattr { # filename xattr_name xattr_contents typeset XATTR_CONTENTS=$3 # read the xattr, writing it to a temp file - log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" + if is_linux; then + log_must eval \ + "attr -q -g $XATTR_NAME $FILE >/tmp/$XATTR_NAME.$$" + else + log_must eval \ + "runat $FILE cat $XATTR_NAME >/tmp/$XATTR_NAME.$$ 2>&1" + fi + log_must diff $XATTR_CONTENTS /tmp/$XATTR_NAME.$$ rm /tmp/$XATTR_NAME.$$ } @@ -76,8 +94,13 @@ function delete_xattr { # filename xattr_name typeset XATTR_NAME=$2 # delete the xattr - log_must runat $FILE rm $XATTR_NAME - log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1" + if is_linux; then + log_must attr -r $XATTR_NAME $FILE + log_mustnot attr -q -g $XATTR_NAME $FILE + else + log_must runat $FILE rm $XATTR_NAME + log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1" + fi } # not sure about this : really this should be testing write/append @@ -85,8 +108,15 @@ function verify_write_xattr { # filename xattr_name typeset FILE=$1 typeset XATTR_NAME=$2 - log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME" - log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" + if is_linux; then + log_must attr -q -s $XATTR_NAME $FILE < /etc/passwd + log_must eval \ + "attr -q -g $XATTR_NAME $FILE >/tmp/$XATTR_NAME.$$" + else + log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME" + log_must eval \ + "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" + fi log_must dd if=/etc/passwd of=/tmp/passwd_dd.$$ log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ |