2010-01-20 10:27:08 +11:00
|
|
|
#! /bin/bash
|
2009-05-28 17:04:15 +02:00
|
|
|
# FS QA Test No. 062
|
|
|
|
|
#
|
|
|
|
|
# Exercises the getfattr/setfattr tools
|
|
|
|
|
# Derived from tests originally written by Andreas Gruenbacher for ext2
|
2009-05-12 13:24:15 -05:00
|
|
|
#
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
# Copyright (c) 2000-2002 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.
|
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
#
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
#
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
seq=`basename $0`
|
2013-03-15 12:28:02 +00:00
|
|
|
seqres=$RESULT_DIR/$seq
|
2001-10-05 08:12:26 +00:00
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
|
|
here=`pwd`
|
|
|
|
|
tmp=/tmp/$$
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
2013-03-15 12:28:04 +00:00
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
|
|
|
|
. ./common/attr
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
|
{
|
2004-06-15 07:32:36 +00:00
|
|
|
cd /
|
2001-10-05 08:12:26 +00:00
|
|
|
echo; echo "*** unmount"
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount 2>/dev/null
|
2001-10-05 08:12:26 +00:00
|
|
|
rm -f $tmp.*
|
|
|
|
|
}
|
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
2002-02-25 22:12:17 +00:00
|
|
|
getfattr()
|
|
|
|
|
{
|
2010-09-09 19:02:17 +02:00
|
|
|
$GETFATTR_PROG --absolute-names -dh $@ 2>&1 | _filter_scratch
|
2002-02-25 22:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setfattr()
|
|
|
|
|
{
|
2010-09-09 19:02:17 +02:00
|
|
|
$SETFATTR_PROG $@ 2>&1 | _filter_scratch
|
2002-02-25 22:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
2001-10-05 08:12:26 +00:00
|
|
|
_create_test_bed()
|
|
|
|
|
{
|
|
|
|
|
echo "*** create test bed"
|
|
|
|
|
touch $SCRATCH_MNT/reg
|
|
|
|
|
mkdir -p $SCRATCH_MNT/dir
|
|
|
|
|
ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
|
|
|
|
|
mkdir $SCRATCH_MNT/dev
|
|
|
|
|
mknod $SCRATCH_MNT/dev/b b 0 0
|
2015-12-21 18:07:48 +11:00
|
|
|
mknod $SCRATCH_MNT/dev/c c 1 3
|
2001-10-05 08:12:26 +00:00
|
|
|
mknod $SCRATCH_MNT/dev/p p
|
|
|
|
|
# sanity check
|
2012-01-27 12:28:20 -06:00
|
|
|
find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
|
2001-10-07 22:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
# real QA test starts here
|
2011-08-01 12:31:19 +02:00
|
|
|
_supported_fs generic
|
2004-06-15 07:32:36 +00:00
|
|
|
_supported_os Linux
|
|
|
|
|
|
2001-10-05 08:12:26 +00:00
|
|
|
_require_scratch
|
2010-10-21 21:11:48 +02:00
|
|
|
_require_attrs
|
|
|
|
|
|
2013-03-15 12:28:02 +00:00
|
|
|
rm -f $tmp.backup1 $tmp.backup2 $seqres.full
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
# real QA test starts here
|
2011-08-01 12:31:19 +02:00
|
|
|
_scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
|
2003-05-22 04:16:45 +00:00
|
|
|
_scratch_mount || _fail "mount failed"
|
2001-10-05 08:12:26 +00:00
|
|
|
_create_test_bed
|
|
|
|
|
|
2011-08-19 09:57:12 -05:00
|
|
|
# In kernels before 3.0, getxattr() fails with EPERM for an attribute which
|
|
|
|
|
# cannot exist. Later kernels fail with ENODATA. Accept both results.
|
|
|
|
|
invalid_attribute_filter() {
|
|
|
|
|
sed -e "s:\(No such attribute\|Operation not permitted\):No such attribute or operation not permitted:"
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-26 00:31:25 +00:00
|
|
|
if [ "$USE_ATTR_SECURE" = yes ]; then
|
|
|
|
|
ATTR_MODES="user security trusted"
|
|
|
|
|
else
|
|
|
|
|
ATTR_MODES="user trusted"
|
|
|
|
|
fi
|
|
|
|
|
for nsp in $ATTR_MODES; do
|
2001-10-05 08:12:26 +00:00
|
|
|
for inode in reg dir lnk dev/b dev/c dev/p; do
|
|
|
|
|
|
|
|
|
|
echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
|
|
|
|
|
echo "*** set/get one initially empty attribute"
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
|
|
|
|
|
getfattr -m $nsp $SCRATCH_MNT/$inode
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** overwrite empty, set several new attributes"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
|
|
|
|
|
setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
|
|
|
|
|
setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** fetch several attribute names and values (hex)"
|
2002-02-25 23:04:21 +00:00
|
|
|
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** fetch several attribute names and values (base64)"
|
2002-02-25 23:04:21 +00:00
|
|
|
getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2001-10-05 08:12:26 +00:00
|
|
|
echo "*** shrink value of an existing attribute"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
|
|
|
|
|
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** grow value of existing attribute"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
|
|
|
|
|
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2001-10-05 08:12:26 +00:00
|
|
|
echo "*** set an empty value for second attribute"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
|
2011-08-19 09:57:12 -05:00
|
|
|
getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** overwrite empty value"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
|
2011-08-19 09:57:12 -05:00
|
|
|
getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** remove attribute"
|
2002-02-25 23:04:21 +00:00
|
|
|
setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
|
2011-08-19 09:57:12 -05:00
|
|
|
getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** final list (strings, type=$inode, nsp=$nsp)"
|
2004-01-20 06:39:32 +00:00
|
|
|
getfattr -m '.' -e hex $SCRATCH_MNT/$inode
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2001-10-05 08:12:26 +00:00
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test the directory descent code
|
|
|
|
|
#
|
|
|
|
|
echo; echo
|
|
|
|
|
|
|
|
|
|
_extend_test_bed()
|
|
|
|
|
{
|
|
|
|
|
echo "*** extend test bed"
|
|
|
|
|
# must set some descents' attributes to be useful
|
|
|
|
|
mkdir -p $SCRATCH_MNT/here/up/ascend
|
|
|
|
|
mkdir -p $SCRATCH_MNT/descend/down/here
|
2001-11-02 00:13:11 +00:00
|
|
|
find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
|
|
|
|
|
find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
|
2003-02-25 09:13:13 +00:00
|
|
|
find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
|
|
|
|
|
find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
|
2001-10-05 08:12:26 +00:00
|
|
|
# whack a symlink in the middle, just to be difficult
|
|
|
|
|
ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
|
|
|
|
|
# dump out our new starting point
|
2012-01-27 12:28:20 -06:00
|
|
|
find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
|
2001-10-05 08:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_extend_test_bed
|
|
|
|
|
|
|
|
|
|
echo
|
2002-02-25 23:04:21 +00:00
|
|
|
echo "*** directory descent with us following symlinks"
|
2012-01-27 12:28:20 -06:00
|
|
|
getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT | _sort_getfattr_output
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo
|
2002-02-25 23:04:21 +00:00
|
|
|
echo "*** directory descent without following symlinks"
|
2012-01-27 12:28:20 -06:00
|
|
|
getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT | _sort_getfattr_output
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test the backup/restore code
|
|
|
|
|
#
|
|
|
|
|
echo; echo
|
|
|
|
|
|
|
|
|
|
_backup()
|
|
|
|
|
{
|
2016-12-12 22:57:01 -08:00
|
|
|
# Note: we don't filter scratch here since we need to restore too. But
|
|
|
|
|
# we *do* sort the output by path, since it otherwise would depend on
|
|
|
|
|
# readdir order, which on some filesystems may change after re-creating
|
|
|
|
|
# the files.
|
|
|
|
|
$GETFATTR_PROG --absolute-names -dh -R -m '.' $SCRATCH_MNT | _sort_getfattr_output >$1
|
2013-03-15 12:28:02 +00:00
|
|
|
echo BACKUP $1 >>$seqres.full
|
|
|
|
|
cat $1 >> $seqres.full
|
2001-10-05 08:12:26 +00:00
|
|
|
[ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "*** backup everything"
|
|
|
|
|
_backup $tmp.backup1
|
|
|
|
|
|
|
|
|
|
echo "*** clear out the scratch device"
|
|
|
|
|
rm -fr $SCRATCH_MNT/*
|
2013-03-15 12:28:02 +00:00
|
|
|
echo "AFTER REMOVE" >>$seqres.full
|
|
|
|
|
getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** reset test bed with no extended attributes"
|
|
|
|
|
_create_test_bed
|
|
|
|
|
_extend_test_bed
|
|
|
|
|
|
|
|
|
|
echo "*** restore everything"
|
2002-02-26 22:30:57 +00:00
|
|
|
setfattr -h --restore=$tmp.backup1
|
2001-10-05 08:12:26 +00:00
|
|
|
_backup $tmp.backup2
|
|
|
|
|
|
2013-03-15 12:28:02 +00:00
|
|
|
echo "AFTER RESTORE" >>$seqres.full
|
|
|
|
|
getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
|
2001-10-05 08:12:26 +00:00
|
|
|
|
|
|
|
|
echo "*** compare before and after backups"
|
|
|
|
|
diff $tmp.backup1 $tmp.backup2
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
echo "urk, failed - creating $seq.backup1 and $seq.backup2"
|
|
|
|
|
cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
|
|
|
|
|
status=1
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
|
status=0
|
|
|
|
|
exit
|