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 <behlendorf1@llnl.gov>
Closes #6128
This commit is contained in:
Brian Behlendorf 2017-05-18 20:22:04 -04:00
parent 95401cb6f7
commit 5a6d6cf839
17 changed files with 370 additions and 169 deletions

View File

@ -547,11 +547,11 @@ tests = ['vdev_zaps_001_pos', 'vdev_zaps_002_pos', 'vdev_zaps_003_pos',
[tests/functional/write_dirs] [tests/functional/write_dirs]
tests = ['write_dirs_001_pos', 'write_dirs_002_pos'] tests = ['write_dirs_001_pos', 'write_dirs_002_pos']
#[tests/functional/xattr] [tests/functional/xattr]
#tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos', 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_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos',
# 'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos', 'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos',
# 'xattr_013_pos'] 'xattr_013_pos']
[tests/functional/zvol/zvol_ENOSPC] [tests/functional/zvol/zvol_ENOSPC]
tests = ['zvol_ENOSPC_001_pos'] tests = ['zvol_ENOSPC_001_pos']

View File

@ -3,6 +3,7 @@ dist_pkgdata_SCRIPTS = \
xattr_common.kshlib \ xattr_common.kshlib \
setup.ksh \ setup.ksh \
cleanup.ksh \ cleanup.ksh \
xattr.cfg \
xattr_001_pos.ksh \ xattr_001_pos.ksh \
xattr_002_neg.ksh \ xattr_002_neg.ksh \
xattr_003_neg.ksh \ xattr_003_neg.ksh \

View File

@ -28,15 +28,14 @@
# #
. $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
ZFS_USER=$(cat /tmp/zfs-xattr-test-user.txt) del_user $ZFS_USER
rm /tmp/zfs-xattr-test-user.txt del_group $ZFS_GROUP
USES_NIS=$(cat /tmp/zfs-xattr-test-nis.txt) USES_NIS=$(cat /tmp/zfs-xattr-test-nis.txt)
rm /tmp/zfs-xattr-test-nis.txt rm /tmp/zfs-xattr-test-nis.txt
del_user $ZFS_USER
if [ "${USES_NIS}" == "true" ] if [ "${USES_NIS}" == "true" ]
then then
svcadm enable svc:/network/nis/client:default svcadm enable svc:/network/nis/client:default

View File

@ -28,33 +28,24 @@
# #
. $STF_SUITE/include/libtest.shlib . $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 # if we're running NIS, turn it off until we clean up
# (it can cause useradd to take a long time, hitting our TIMEOUT) # (it can cause useradd to take a long time, hitting our TIMEOUT)
USES_NIS=false if is_linux; then
svcs svc:/network/nis/client:default | grep online > /dev/null USED_NIS=false
if [ $? -eq 0 ] else
then 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 svcadm disable -t svc:/network/nis/client:default
USES_NIS=true USES_NIS=true
fi
fi fi
# Make sure we use a brand new user for this # Make sure we use a brand new user for this
ZFS_USER=zxtr log_must add_group $ZFS_GROUP
ZFS_GROUP=staff
while [ -z "${FOUND}" ]
do
COUNT=0
USER_EXISTS=$( grep $ZFS_USER /etc/passwd )
if [ ! -z "${USER_EXISTS}" ]
then
ZFS_USER="${ZFS_USER}${COUNT}"
COUNT=$(( $COUNT + 1 ))
else
FOUND="true"
fi
done
log_must add_user $ZFS_GROUP $ZFS_USER log_must add_user $ZFS_GROUP $ZFS_USER
echo $ZFS_USER > /tmp/zfs-xattr-test-user.txt echo $ZFS_USER > /tmp/zfs-xattr-test-user.txt

View File

@ -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

View File

@ -52,12 +52,18 @@ function cleanup {
fi fi
} }
set -A args "on" "sa"
log_assert "Create/read/write/append of xattrs works" log_assert "Create/read/write/append of xattrs works"
log_onexit cleanup log_onexit cleanup
log_must touch $TESTDIR/myfile.$$ for arg in ${args[*]}; do
create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd log_must zfs set xattr=$arg $TESTPOOL
verify_write_xattr $TESTDIR/myfile.$$ passwd
delete_xattr $TESTDIR/myfile.$$ passwd 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" log_pass "Create/read/write of xattrs works"

View File

@ -46,11 +46,17 @@ function cleanup {
} }
set -A args "on" "sa"
log_assert "A read of a non-existent xattr fails" log_assert "A read of a non-existent xattr fails"
log_onexit cleanup log_onexit cleanup
# create a file for arg in ${args[*]}; do
log_must touch $TESTDIR/myfile.$$ log_must zfs set xattr=$arg $TESTPOOL
log_mustnot eval "cat $TESTDIR/myfile.$$ not-here.txt > /dev/null 2>&1"
log_pass "A read of a non-existent xattr fails" # 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"
done

View File

@ -56,7 +56,21 @@ log_must touch $TESTDIR/myfile.$$
create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
log_must chmod 000 $TESTDIR/myfile.$$ log_must chmod 000 $TESTDIR/myfile.$$
log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cat passwd" if is_linux; then
log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cp /etc/passwd ." 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" log_pass "read/write xattr on a file with no permissions fails"

View File

@ -50,8 +50,7 @@ verify_runnable "global"
# Make sure we clean up properly # Make sure we clean up properly
function cleanup { function cleanup {
if [ $( ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS ) ] if ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS; then
then
log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ log_must umount /tmp/$NEWFS_DEFAULT_FS.$$
log_must rm -rf /tmp/$NEWFS_DEFAULT_FS.$$ log_must rm -rf /tmp/$NEWFS_DEFAULT_FS.$$
fi fi
@ -63,25 +62,62 @@ log_onexit cleanup
# Create a UFS|EXT2 file system that we can work in # Create a UFS|EXT2 file system that we can work in
log_must zfs create -V128m $TESTPOOL/$TESTFS/zvol log_must zfs create -V128m $TESTPOOL/$TESTFS/zvol
block_device_wait 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 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. # Create files in ext2 and tmpfs, and set some xattrs on them.
log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ # Use small values for xattrs for ext2 compatibility.
log_must touch /tmp/tmpfs-file.$$ 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 touch /tmp/tmpfs-file.$$
log_must runat /tmp/tmpfs-file.$$ cp /etc/group . 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 # copy those files to ZFS
log_must cp -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ $TESTDIR log_must cp -a /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \
log_must cp -@ /tmp/tmpfs-file.$$ $TESTDIR $TESTDIR
log_must cp -a /tmp/tmpfs-file.$$ $TESTDIR
# ensure the xattr information has been copied correctly # ensure the xattr information has been copied correctly
log_must runat $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ diff passwd /etc/passwd log_must eval "attr -q -g xattr1 $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \
log_must runat $TESTDIR/tmpfs-file.$$ diff group /etc/group >/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." log_pass "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info."

View File

@ -69,13 +69,22 @@ log_must touch $TESTDIR/myfile2.$$
log_must zfs snapshot $TESTPOOL/$TESTFS@snap log_must zfs snapshot $TESTPOOL/$TESTFS@snap
# we shouldn't be able to alter the first file's xattr # we shouldn't be able to alter the first file's xattr
log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ 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" cp /etc/passwd . >/tmp/output.$$ 2>&1"
log_must grep -i Read-only /tmp/output.$$ log_must grep -i Read-only /tmp/output.$$
log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
ls >/tmp/output.$$ 2>&1" ls >/tmp/output.$$ 2>&1"
create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw
fi
log_must diff /tmp/output.$$ /tmp/expected_output.$$ log_must diff /tmp/output.$$ /tmp/expected_output.$$
log_pass "create/write xattr on a snapshot fails" log_pass "create/write xattr on a snapshot fails"

View File

@ -49,6 +49,10 @@ function cleanup {
done 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_assert "special . and .. dirs work as expected for xattrs"
log_onexit cleanup log_onexit cleanup

View File

@ -40,6 +40,10 @@
# 3. Verify we're unable to create a hard link # 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 { function cleanup {
log_must rm $TESTDIR/myfile.$$ log_must rm $TESTDIR/myfile.$$

View File

@ -41,6 +41,10 @@
# #
# #
if is_linux; then
log_unsupported "Test case isn't applicable to Linux"
fi
function cleanup { function cleanup {
log_must rm $TESTDIR/myfile.$$ log_must rm $TESTDIR/myfile.$$

View File

@ -65,60 +65,74 @@ create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
# and try various cpio options extracting the archives # and try various cpio options extracting the archives
# with and without xattr support, checking for correct behaviour # with and without xattr support, checking for correct behaviour
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
log_note "Checking cpio" # we should have no xattr here
log_must touch $TESTDIR/cpio.$$ log_must cpio -iu < /tmp/xattr.$$.cpio
create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1"
echo $TESTDIR/cpio.$$ | cpio -o@ > /tmp/xattr.$$.cpio
echo $TESTDIR/cpio.$$ | cpio -o > /tmp/noxattr.$$.cpio
# we should have no xattr here # we should have an xattr here
log_must cpio -iu < /tmp/xattr.$$.cpio log_must cpio -iu@ < /tmp/xattr.$$.cpio
log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" log_must 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
# 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" log_note "Checking cp"
# check that with the right flag, the xattr is preserved # check that with the right flag, the xattr is preserved
log_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ if is_linux; then
compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd log_must cp -a $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
log_must rm $TESTDIR/myfile2.$$
# without the right flag, there should be no xattr compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd
log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ log_must rm $TESTDIR/myfile2.$$
log_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1"
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 # create a file without xattrs, and check that find -xattr only finds
# our test file that has an xattr. # our test file that has an xattr.
log_must mkdir $TESTDIR/noxattrs if is_linux; then
log_must touch $TESTDIR/noxattrs/no-xattr 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.$$ find $TESTDIR -xattr | grep myfile.$$
[[ $? -ne 0 ]] && \ [[ $? -ne 0 ]] && \
log_fail "find -xattr didn't find our file that had an xattr." log_fail "find -xattr didn't find our file that had an xattr."
find $TESTDIR -xattr | grep no-xattr find $TESTDIR -xattr | grep no-xattr
[[ $? -eq 0 ]] && \ [[ $? -eq 0 ]] && \
log_fail "find -xattr found a file that didn't have an xattr." log_fail "find -xattr found a file that didn't have an xattr."
log_must rm -rf $TESTDIR/noxattrs log_must rm -rf $TESTDIR/noxattrs
fi
log_note "Checking mv" log_note "Checking mv"
# mv doesn't have any flags to preserve/ommit xattrs - they're # 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 verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd
log_must rm $TESTDIR/mvfile2.$$ log_must rm $TESTDIR/mvfile2.$$
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.$$
log_note "Checking pax" # we should have no xattr here
log_must touch $TESTDIR/pax.$$ log_must pax -r -f $TESTDIR/noxattr.pax
create_xattr $TESTDIR/pax.$$ passwd /etc/passwd log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1"
log_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$ log_must rm $TESTDIR/pax.$$
log_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$
log_must rm $TESTDIR/pax.$$
# we should have no xattr here # we should have no xattr here
log_must pax -r -f $TESTDIR/noxattr.pax log_must pax -r@ -f $TESTDIR/noxattr.pax
log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1"
log_must rm $TESTDIR/pax.$$ log_must rm $TESTDIR/pax.$$
# we should have no xattr here # we should have an xattr here
log_must pax -r@ -f $TESTDIR/noxattr.pax log_must pax -r@ -f $TESTDIR/xattr.pax
log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd
log_must rm $TESTDIR/pax.$$ 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
# 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_note "Checking tar"
log_must touch $TESTDIR/tar.$$ if is_linux; then
create_xattr $TESTDIR/tar.$$ passwd /etc/passwd log_must touch $TESTDIR/tar.$$
create_xattr $TESTDIR/tar.$$ passwd /etc/passwd
log_must cd $TESTDIR log_must cd $TESTDIR
log_must tar cf noxattr.tar tar.$$ log_must tar -cf noxattr.tar tar.$$
log_must tar c@f xattr.tar tar.$$ log_must tar --xattrs -cf xattr.tar tar.$$
log_must rm $TESTDIR/tar.$$ log_must rm $TESTDIR/tar.$$
# we should have no xattr here # we should have no xattr here
log_must tar xf xattr.tar log_must tar --no-xattrs -xf xattr.tar
log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" log_mustnot attr -q -g passwd $TESTDIR/tar.$$
log_must rm $TESTDIR/tar.$$ log_must rm $TESTDIR/tar.$$
# we should have an xattr here # we should have an xattr here
log_must tar x@f xattr.tar log_must tar --xattrs -xf xattr.tar
verify_xattr tar.$$ passwd /etc/passwd verify_xattr tar.$$ passwd /etc/passwd
log_must rm $TESTDIR/tar.$$ log_must rm $TESTDIR/tar.$$
# we should have no xattr here # we should have no xattr here
log_must tar xf $TESTDIR/noxattr.tar log_must tar --no-xattrs -xf $TESTDIR/noxattr.tar
log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" log_mustnot attr -q -g passwd $TESTDIR/tar.$$
log_must rm $TESTDIR/tar.$$ log_must rm $TESTDIR/tar.$$
# we should have no xattr here # we should have no xattr here
log_must tar x@f $TESTDIR/noxattr.tar log_must tar --xattrs -xf $TESTDIR/noxattr.tar
log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" log_mustnot attr -q -g passwd $TESTDIR/tar.$$
log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.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" log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"

View File

@ -79,10 +79,16 @@ fi
FS_SIZE=$(zfs get -p -H -o value used $TESTPOOL/$TESTFS) 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 #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 # now check to see if our pool disk usage has increased
if is_global_zone if is_global_zone

View File

@ -65,13 +65,25 @@ log_must umount $TESTDIR
log_must zfs mount -o noxattr $TESTPOOL/$TESTFS log_must zfs mount -o noxattr $TESTPOOL/$TESTFS
# check that we can't perform xattr operations # check that we can't perform xattr operations
log_mustnot eval "runat $TESTDIR/myfile.$$ cat passwd > /dev/null 2>&1" if is_linux; then
log_mustnot eval "runat $TESTDIR/myfile.$$ rm passwd > /dev/null 2>&1" log_mustnot attr -q -g passwd $TESTDIR/myfile.$$
log_mustnot eval "runat $TESTDIR/myfile.$$ cp /etc/passwd . > /dev/null 2>&1" log_mustnot attr -q -r passwd $TESTDIR/myfile.$$
log_mustnot attr -q -s passwd $TESTDIR/myfile.$$ </etc/passwd
log_must touch $TESTDIR/new.$$ log_must touch $TESTDIR/new.$$
log_mustnot eval "runat $TESTDIR/new.$$ cp /etc/passwd . > /dev/null 2>&1" log_mustnot attr -q -s passwd $TESTDIR/new.$$ </etc/passwd
log_mustnot eval "runat $TESTDIR/new.$$ rm passwd > /dev/null 2>&1" 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 # now mount the filesystem again as normal
log_must umount $TESTDIR 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 # there should be no xattr on the file we created while the fs was mounted
# -o noxattr # -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 create_xattr $TESTDIR/new.$$ passwd /etc/passwd
log_pass "The noxattr mount option functions as expected" log_pass "The noxattr mount option functions as expected"

View File

@ -29,6 +29,7 @@
# #
. $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/xattr/xattr.cfg
# a function that takes a file, then creates and verifies # a function that takes a file, then creates and verifies
# an xattr on that file. The xattr_contents is the file # 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_NAME=$2
typeset XATTR_CONTENTS=$3 typeset XATTR_CONTENTS=$3
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 # read any empty xattr on that file
log_must runat $FILE ls log_must runat $FILE ls
# create the xattr # create the xattr
log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME
fi
verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
} }
@ -53,8 +59,13 @@ function compare_xattrs { # filename1 filename2 xattr_name
typeset FILE2=$2 typeset FILE2=$2
typeset XATTR_NAME=$3 typeset XATTR_NAME=$3
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 $FILE1 cat $XATTR_NAME > /tmp/file1.$$
runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$ runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$
fi
log_must diff /tmp/file1.$$ /tmp/file2.$$ log_must diff /tmp/file1.$$ /tmp/file2.$$
log_must rm /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 typeset XATTR_CONTENTS=$3
# read the xattr, writing it to a temp file # 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.$$ log_must diff $XATTR_CONTENTS /tmp/$XATTR_NAME.$$
rm /tmp/$XATTR_NAME.$$ rm /tmp/$XATTR_NAME.$$
} }
@ -76,8 +94,13 @@ function delete_xattr { # filename xattr_name
typeset XATTR_NAME=$2 typeset XATTR_NAME=$2
# delete the xattr # delete the xattr
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_must runat $FILE rm $XATTR_NAME
log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1" log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1"
fi
} }
# not sure about this : really this should be testing write/append # 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 FILE=$1
typeset XATTR_NAME=$2 typeset XATTR_NAME=$2
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 dd if=/etc/passwd of=$XATTR_NAME"
log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" 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 dd if=/etc/passwd of=/tmp/passwd_dd.$$
log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$