From: Zorro Lang Date: Thu, 23 Aug 2018 02:41:24 +0000 (+0800) Subject: fstests: filter redundant output by getfattr X-Git-Tag: v2022.05.01~1434 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=794f4594fbf46bb3c51ac0566058022bc28dfdfe;p=users%2Fhch%2Fxfstests-dev.git fstests: filter redundant output by getfattr When getfattr dumps values of all extended attributes (-d option), it doesn't print empty extended attributes. e.g: user.name. But from attr-2.4.48 this behavior is changed, new getfattr prints user.name="". The {=""} will break the golden image, so filter the redundant ="" at the end if it has. Signed-off-by: Zorro Lang Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/common/attr b/common/attr index 10b98eefc..20049de02 100644 --- a/common/attr +++ b/common/attr @@ -224,6 +224,18 @@ _sort_getfattr_output() awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS='' } +# 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]} +} + # set maximum total attr space based on fs type case "$FSTYP" in xfs|udf|pvfs2|9p|ceph) diff --git a/tests/ext4/022 b/tests/ext4/022 index 7dc19e8ea..1123e7a27 100755 --- a/tests/ext4/022 +++ b/tests/ext4/022 @@ -151,7 +151,7 @@ done # Dump all xattrs to see whether nothing broke for FILE in ${FNAMES[@]}; do - $GETFATTR_PROG -h -d --absolute-names $SCRATCH_MNT/$FILE 2>/dev/null | \ + _getfattr -h -d --absolute-names $SCRATCH_MNT/$FILE 2>/dev/null | \ _filter_scratch | sort done diff --git a/tests/ext4/026 b/tests/ext4/026 index f651fe6e6..5e0e88795 100755 --- a/tests/ext4/026 +++ b/tests/ext4/026 @@ -51,14 +51,14 @@ attr_set() $SETFATTR_PROG -n $name $file fi - tmp=$($GETFATTR_PROG --absolute-names --only-values -n $name $file) + tmp=$(_getfattr --absolute-names --only-values -n $name $file) [[ "$tmp" == "$value" ]] || echo "unexpected value returned: $tmp" } # List attributes on a file. attr_list() { - $GETFATTR_PROG --absolute-names $1 | grep -v '^#' + _getfattr --absolute-names $1 | grep -v '^#' } # Removes an extended attribute from a file. diff --git a/tests/generic/020 b/tests/generic/020 index 8bd5fe04f..936d84852 100755 --- a/tests/generic/020 +++ b/tests/generic/020 @@ -35,9 +35,9 @@ _attr() return $exit } -_getfattr() +do_getfattr() { - $GETFATTR_PROG $* 2>$tmp.err >$tmp.out + _getfattr $* 2>$tmp.err >$tmp.out exit=$? _filter $tmp.out _filter $tmp.err 1>&2 @@ -49,7 +49,7 @@ _attr_list() file=$1 echo " *** print attributes" - if ! _getfattr -d -e text --absolute-names $file + if ! do_getfattr -d -e text --absolute-names $file then echo " !!! error return" return 1 @@ -110,7 +110,7 @@ done echo "*** check" # don't print it all out... -getfattr --absolute-names $testfile \ +_getfattr --absolute-names $testfile \ | tee -a $seqres.full \ | $AWK_PROG ' /^#/ { next } diff --git a/tests/generic/037 b/tests/generic/037 index b5edd0336..d08232ae1 100755 --- a/tests/generic/037 +++ b/tests/generic/037 @@ -76,7 +76,7 @@ set_xattr_loop $test_file & setter_pid=$! for ((i = 0; i < 1000; i++)); do - $GETFATTR_PROG --absolute-names -n $xattr_name \ + _getfattr --absolute-names -n $xattr_name \ $SCRATCH_MNT/$test_file | value_filter done diff --git a/tests/generic/062 b/tests/generic/062 index df67960dd..b6e28e0fd 100755 --- a/tests/generic/062 +++ b/tests/generic/062 @@ -31,7 +31,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 getfattr() { - $GETFATTR_PROG --absolute-names -dh $@ 2>&1 | _filter_scratch + _getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch } setfattr() @@ -166,7 +166,7 @@ _backup() # 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 + _getfattr --absolute-names -dh -R -m '.' $SCRATCH_MNT | _sort_getfattr_output >$1 echo BACKUP $1 >>$seqres.full cat $1 >> $seqres.full [ ! -s $1 ] && echo "warning: $1 (backup file) is empty" diff --git a/tests/generic/066 b/tests/generic/066 index 7ad142186..3b3ff2bbb 100755 --- a/tests/generic/066 +++ b/tests/generic/066 @@ -72,7 +72,7 @@ _flakey_drop_and_remount # with the 3 xattrs that we had before deleting the second one and fsyncing the # file. echo "xattr names and values after first fsync log replay:" -$GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch +_getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch # Now write some data to our file, fsync it, remove the first xattr, add a new # hard link to our file and commit the fsync log by fsyncing some other new @@ -89,7 +89,7 @@ _flakey_drop_and_remount # Now only the xattr with name user.attr3 should be set in our file. echo "xattr names and values after second fsync log replay:" -$GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch +_getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch status=0 exit diff --git a/tests/generic/093 b/tests/generic/093 index fc609b062..a2467a5bb 100755 --- a/tests/generic/093 +++ b/tests/generic/093 @@ -63,7 +63,7 @@ $SETCAP_PROG cap_chown+ep $file $SETFATTR_PROG -n trusted.name -v value $file echo data2 >> $file cat $file -$GETFATTR_PROG -m '^trusted\.*' --absolute-names $file | filefilter +_getfattr -m '^trusted\.*' --absolute-names $file | filefilter echo "**** Verifying that chmod doesn't affect open file descriptors ****" rm -f $file diff --git a/tests/generic/097 b/tests/generic/097 index db8dc71a5..679f1a24b 100755 --- a/tests/generic/097 +++ b/tests/generic/097 @@ -30,7 +30,7 @@ _cleanup() getfattr() { - $GETFATTR_PROG --absolute-names "$@" |& _filter_test_dir + _getfattr --absolute-names "$@" |& _filter_test_dir } setfattr() diff --git a/tests/generic/337 b/tests/generic/337 index a76aa6124..344a3659d 100755 --- a/tests/generic/337 +++ b/tests/generic/337 @@ -49,7 +49,7 @@ $SETFATTR_PROG -n user.ping -v pong $SCRATCH_MNT/testfile # Now call getfattr with --dump, which calls the listxattrs system call. # It should list all the xattrs we have set before. -$GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/testfile | _filter_scratch +_getfattr --absolute-names --dump $SCRATCH_MNT/testfile | _filter_scratch status=0 exit diff --git a/tests/generic/364 b/tests/generic/364 index 6bed9ca26..b4634a442 100755 --- a/tests/generic/364 +++ b/tests/generic/364 @@ -23,6 +23,7 @@ _cleanup() # get standard environment, filters and checks . ./common/rc +. ./common/attr # remove previous $seqres.full before test rm -f $seqres.full @@ -59,11 +60,11 @@ $GETRICHACL_PROG x mkdir sub $SETRICHACL_PROG --set 'everyone@:rwpxd:fd:allow' sub stat -c %A+ sub -$GETFATTR_PROG -m system\.richacl sub +_getfattr -m system\.richacl sub chmod 775 sub stat -c %A+ sub -$GETFATTR_PROG -m system\.richacl sub +_getfattr -m system\.richacl sub $GETRICHACL_PROG sub touch sub/f diff --git a/tests/generic/403 b/tests/generic/403 index 9309d7133..39c640619 100755 --- a/tests/generic/403 +++ b/tests/generic/403 @@ -49,7 +49,7 @@ $SETFATTR_PROG -n trusted.small -v a $SCRATCH_MNT/file runfile="$tmp.getfattr" touch $runfile while [ -e $runfile ]; do - $GETFATTR_PROG --absolute-names -n trusted.small $SCRATCH_MNT/file \ + _getfattr --absolute-names -n trusted.small $SCRATCH_MNT/file \ > /dev/null || break done & getfattr_pid=$! diff --git a/tests/generic/454 b/tests/generic/454 index d9faf366d..4a0936c5d 100755 --- a/tests/generic/454 +++ b/tests/generic/454 @@ -58,7 +58,7 @@ testf() { echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full - actual_value="$($GETFATTR_PROG --absolute-names --only-values -n "user.${key}" "${testfile}")" + actual_value="$(_getfattr --absolute-names --only-values -n "user.${key}" "${testfile}")" if [ "${actual_value}" != "${value}" ]; then echo "Key ${key} has value ${actual_value}, expected ${value}." fi @@ -127,7 +127,7 @@ setf "zerojoin_moo\xe2\x80\x8ccow.txt" "zero width joiners" setf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks" setf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks" -$GETFATTR_PROG --absolute-names -d "${testfile}" >> $seqres.full +_getfattr --absolute-names -d "${testfile}" >> $seqres.full echo "Test files" testf "french_caf\xc3\xa9.txt" "NFC" @@ -175,7 +175,7 @@ testf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks" testf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks" echo "Uniqueness of keys?" -crazy_keys="$($GETFATTR_PROG --absolute-names -d "${testfile}" | egrep -c '(french_|chinese_|greek_|arabic_|urk)')" +crazy_keys="$(_getfattr --absolute-names -d "${testfile}" | egrep -c '(french_|chinese_|greek_|arabic_|urk)')" expected_keys=11 test "${crazy_keys}" -ne "${expected_keys}" && echo "Expected ${expected_keys} keys, saw ${crazy_keys}." diff --git a/tests/generic/489 b/tests/generic/489 index 1d3a916e3..b3a0972fc 100755 --- a/tests/generic/489 +++ b/tests/generic/489 @@ -58,7 +58,7 @@ $XFS_IO_PROG -c "pwrite -S 0xea 0 64K" \ # were not lost and neither was the data we wrote. _flakey_drop_and_remount echo "File xattrs after power failure:" -$GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch +_getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch echo "File data after power failure:" od -t x1 $SCRATCH_MNT/foobar diff --git a/tests/overlay/011 b/tests/overlay/011 index e2fedc90d..1d09341b2 100755 --- a/tests/overlay/011 +++ b/tests/overlay/011 @@ -56,7 +56,7 @@ $SETFATTR_PROG -n "trusted.overlay.opaque" -v "y" $upperdir/testdir $MOUNT_PROG -t overlay -o ro -o lowerdir=$upperdir:$lowerdir $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT # Dump trusted.overlay xattr, we should not see the "opaque" xattr -$GETFATTR_PROG -d -m overlay $SCRATCH_MNT/testdir +_getfattr -d -m overlay $SCRATCH_MNT/testdir echo "Silence is golden" # success, all done diff --git a/tests/overlay/026 b/tests/overlay/026 index 08cad42fc..d0d2a5bf9 100755 --- a/tests/overlay/026 +++ b/tests/overlay/026 @@ -71,7 +71,7 @@ touch $SCRATCH_MNT/testf1 $SETFATTR_PROG -n "trusted.overlayfsrz" -v "n" \ $SCRATCH_MNT/testf0 2>&1 | _filter_scratch -$GETFATTR_PROG --absolute-names -n "trusted.overlayfsrz" \ +_getfattr --absolute-names -n "trusted.overlayfsrz" \ $SCRATCH_MNT/testf0 2>&1 | _filter_scratch # {s,g}etfattr of "trusted.overlay.xxx" should fail. @@ -86,7 +86,7 @@ $SETFATTR_PROG -n "trusted.overlay.fsz" -v "n" \ $SCRATCH_MNT/testf1 2>&1 | _filter_scratch | \ sed -e 's/permitted/supported/g' -$GETFATTR_PROG --absolute-names -n "trusted.overlay.fsz" \ +_getfattr --absolute-names -n "trusted.overlay.fsz" \ $SCRATCH_MNT/testf1 2>&1 | _filter_scratch | \ sed -e 's/permitted/supported/g' diff --git a/tests/overlay/038 b/tests/overlay/038 index 716d0fcaa..25f9979be 100755 --- a/tests/overlay/038 +++ b/tests/overlay/038 @@ -77,7 +77,7 @@ subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino) mv $SCRATCH_MNT/test_file $impure_dir test_file_st_ino=$(stat -c '%i' $impure_dir/test_file) -impure=$($GETFATTR_PROG --absolute-names --only-values -n 'trusted.overlay.impure' \ +impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \ $upperdir/test_dir/impure_dir) [[ $impure == "y" ]] || echo "Impure directory missing impure xattr" @@ -109,7 +109,7 @@ $here/src/t_dir_type $impure_dir $test_file_st_ino $here/src/t_dir_type $impure_dir $impure_subdir_st_ino [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries" -impure=$($GETFATTR_PROG --absolute-names --only-values -n 'trusted.overlay.impure' \ +impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \ $upperdir/test_dir/impure_dir 2>/dev/null) [[ -z $impure ]] || echo "Pure directory has impure xattr" diff --git a/tests/overlay/041 b/tests/overlay/041 index 2c4f9fd1d..277fb9130 100755 --- a/tests/overlay/041 +++ b/tests/overlay/041 @@ -89,7 +89,7 @@ subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino) mv $SCRATCH_MNT/test_file $impure_dir test_file_st_ino=$(stat -c '%i' $impure_dir/test_file) -impure=$($GETFATTR_PROG --absolute-names --only-values -n 'trusted.overlay.impure' \ +impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \ $upperdir/test_dir/impure_dir) [[ $impure == "y" ]] || echo "Impure directory missing impure xattr" @@ -121,7 +121,7 @@ $here/src/t_dir_type $impure_dir $test_file_st_ino $here/src/t_dir_type $impure_dir $impure_subdir_st_ino [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries" -impure=$($GETFATTR_PROG --absolute-names --only-values -n 'trusted.overlay.impure' \ +impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \ $upperdir/test_dir/impure_dir 2>/dev/null) [[ -z $impure ]] || echo "Pure directory has impure xattr" diff --git a/tests/overlay/046 b/tests/overlay/046 index 1c09609c3..6338a383b 100755 --- a/tests/overlay/046 +++ b/tests/overlay/046 @@ -57,7 +57,7 @@ check_redirect() local target=$1 local expect=$2 - value=$($GETFATTR_PROG --absolute-names --only-values -n \ + value=$(_getfattr --absolute-names --only-values -n \ $OVL_XATTR_REDIRECT $target) [[ "$value" == "$expect" ]] || echo "Redirect xattr incorrect" @@ -67,7 +67,7 @@ check_no_redirect() { local target=$1 - value=$($GETFATTR_PROG --absolute-names -d -m \ + value=$(_getfattr --absolute-names -d -m \ $OVL_XATTR_REDIRECT $target) [[ -z "$value" ]] || echo "Redirect xattr not empty" @@ -78,7 +78,7 @@ check_opaque() { local target=$1 - value=$($GETFATTR_PROG --absolute-names --only-values -n \ + value=$(_getfattr --absolute-names --only-values -n \ $OVL_XATTR_OPAQUE $target) [[ "$value" == "$OVL_XATTR_OPAQUE_VAL" ]] || \ diff --git a/tests/overlay/056 b/tests/overlay/056 index 778e1f6a9..44ffb54a7 100755 --- a/tests/overlay/056 +++ b/tests/overlay/056 @@ -64,7 +64,7 @@ check_impure() { local target=$1 - value=$($GETFATTR_PROG --absolute-names --only-values -n \ + value=$(_getfattr --absolute-names --only-values -n \ $OVL_XATTR_IMPURE $target) [[ "$value" == "$OVL_XATTR_IMPURE_VAL" ]] || echo "Missing impure xattr" diff --git a/tests/overlay/060 b/tests/overlay/060 index 68b8776ea..2e0764e94 100755 --- a/tests/overlay/060 +++ b/tests/overlay/060 @@ -24,6 +24,7 @@ _cleanup() # get standard environment, filters and checks . ./common/rc . ./common/filter +. ./common/attr # remove previous $seqres.full before test rm -f $seqres.full @@ -58,7 +59,7 @@ check_metacopy() local out_f target_f local msg - out_f=$($GETFATTR_PROG --absolute-names --only-values -n \ + out_f=$(_getfattr --absolute-names --only-values -n \ $OVL_XATTR_METACOPY $target 2>&1 | _filter_scratch) if [ "$exist" == "y" ];then @@ -86,7 +87,7 @@ check_redirect() local target=$1 local expect=$2 - value=$($GETFATTR_PROG --absolute-names --only-values -n \ + value=$(_getfattr --absolute-names --only-values -n \ $OVL_XATTR_REDIRECT $target) [[ "$value" == "$expect" ]] || echo "Redirect xattr incorrect. Expected=\"$expect\", actual=\"$value\"" diff --git a/tests/shared/002 b/tests/shared/002 index 30ece3370..305b32273 100755 --- a/tests/shared/002 +++ b/tests/shared/002 @@ -90,7 +90,7 @@ echo "File xattrs after crash and log replay:" for ((i = 1; i <= $num_xattrs; i++)); do name="user.attr_$(printf "%04d" $i)" echo -n "$name=" - $GETFATTR_PROG --absolute-names -n $name --only-values $SCRATCH_MNT/foo + _getfattr --absolute-names -n $name --only-values $SCRATCH_MNT/foo echo done diff --git a/tests/xfs/021 b/tests/xfs/021 index e600b8184..336b59800 100755 --- a/tests/xfs/021 +++ b/tests/xfs/021 @@ -41,9 +41,9 @@ _attr() return $exit } -_getfattr() +do_getfattr() { - ${GETFATTR_PROG} $* 2>$tmp.err >$tmp.out + _getfattr $* 2>$tmp.err >$tmp.out exit=$? sed \ -e "s#$SCRATCH_MNT[^ .:]*##g" \ @@ -79,7 +79,7 @@ echo "*** make test file 1" touch $testfile.1 echo "v1" | _attr -s "a1" $testfile.1 >/dev/null echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null -_getfattr --absolute-names $testfile.1 +do_getfattr --absolute-names $testfile.1 inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'` echo "*** make test file 2" @@ -89,7 +89,7 @@ echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null ( echo start; POSIXLY_CORRECT=yes dd if=/dev/zero bs=65525 count=1; echo end )\ | _attr -s "a3" $testfile.2 >/dev/null -_getfattr --absolute-names $testfile.2 +do_getfattr --absolute-names $testfile.2 # print name and size from 1st line of output _attr -g "a3" $testfile.2 > $tmp.hahahahaplonk diff --git a/tests/xfs/187 b/tests/xfs/187 index e705cf553..b666f94d3 100755 --- a/tests/xfs/187 +++ b/tests/xfs/187 @@ -105,7 +105,7 @@ _scratch_mount -o noattr2 cd $SCRATCH_MNT touch testfile $SETFATTR_PROG -n user.test -v 0xbabe testfile -$GETFATTR_PROG testfile +_getfattr testfile cd $here $UMOUNT_PROG $SCRATCH_MNT _scratch_xfs_db -r -c version 2>&1 | _filter_version