Skip to content

Commit

Permalink
Enable xattr tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
behlendorf committed May 22, 2017
1 parent 95401cb commit 5a6d6cf
Show file tree
Hide file tree
Showing 17 changed files with 387 additions and 186 deletions.
10 changes: 5 additions & 5 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/xattr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
7 changes: 3 additions & 4 deletions tests/zfs-tests/tests/functional/xattr/cleanup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 12 additions & 21 deletions tests/zfs-tests/tests/functional/xattr/setup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions tests/zfs-tests/tests/functional/xattr/xattr.cfg
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 10 additions & 4 deletions tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 16 additions & 2 deletions tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
68 changes: 52 additions & 16 deletions tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
21 changes: 15 additions & 6 deletions tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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.$$
Expand Down
4 changes: 4 additions & 0 deletions tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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.$$
Expand Down
Loading

0 comments on commit 5a6d6cf

Please sign in to comment.