Re: [PATCH v2 1/2] common: add helper _require_chattr_inherit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 21, 2023 at 05:31:01PM +0300, Amir Goldstein wrote:
> Similar to _require_chattr, but also checks if an attribute is
> inheritted from parent dir to children.
> 
> Signed-off-by: Amir Goldstein <amir73il@xxxxxxxxx>
> ---
>  common/rc | 52 +++++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 43 insertions(+), 9 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index 1618ded5..00cfd434 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4235,23 +4235,57 @@ _require_test_lsattr()
>  		_notrun "lsattr not supported by test filesystem type: $FSTYP"
>  }
>  
> +_check_chattr_inherit()
> +{
> +	local attribute=$1
> +	local path=$2
> +	local inherit=$3

As I understand, this function calls _check_chattr_inherit, so it will
return zero or non-zero to clarify if $path support $attribute inheritance.
...

> +
> +	touch $path
> +	$CHATTR_PROG "+$attribute" $path > $tmp.chattr 2>&1
> +	local ret=$?
> +	if [ -n "$inherit" ]; then
> +		touch "$path/$inherit"
> +	fi

... but looks like it doesn't, it only create a $inherit file, then let the
caller check if the $attribute is inherited.

I think that's a little confused. I think we can name the function as
_check_chattr() and the 3rd argument $inherit as a bool variable, to
decide if we check inheritance or not.

Or you'd like to have two functions _check_chattr and _check_chattr_inherit,
_check_chattr_inherit calls _check_chattr then keep checking inheritance.

What do you think?

Thanks,
Zorro

> +	$CHATTR_PROG "-$attribute" $path > $tmp.chattr 2>&1
> +	if [ "$ret" -ne 0 ]; then
> +		_notrun "file system doesn't support chattr +$attribute"
> +	fi
> +	cat $tmp.chattr >> $seqres.full
> +	rm -f $tmp.chattr
> +	return $ret
> +}
> +
>  _require_chattr()
>  {
>  	if [ -z "$1" ]; then
>  		echo "Usage: _require_chattr <attr>"
>  		exit 1
>  	fi
> -	local attribute=$1
> +	_check_chattr_inherit $1 $TEST_DIR/syscalltest
> +}
>  
> -	touch $TEST_DIR/syscalltest
> -	chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
> -	local ret=$?
> -	chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
> -	if [ "$ret" -ne 0 ]; then
> -		_notrun "file system doesn't support chattr +$attribute"
> +_require_chattr_inherit()
> +{
> +	if [ -z "$1" ]; then
> +		echo "Usage: _require_chattr_inherit <attr>"
> +		exit 1
>  	fi
> -	cat $TEST_DIR/syscalltest.out >> $seqres.full
> -	rm -f $TEST_DIR/syscalltest.out
> +	local attribute=$1
> +	local testdir="$TEST_DIR/chattrtest"
> +	mkdir -p $testdir
> +	_check_chattr_inherit $attribute $testdir testfile || \
> +		return
> +
> +	local testfile="$TEST_DIR/chattrtest/testfile"
> +	local lsattrout=($($LSATTR_PROG $testfile 2>> $seqres.full))
> +	echo ${lsattrout[*]} >> $seqres.full
> +	echo ${lsattrout[0]} | grep -q $attribute || \
> +		_notrun "file system doesn't inherit chattr +$attribute"
> +
> +	$CHATTR_PROG "-$attribute" $testfile >> $seqres.full 2>&1
> +	rm -f $testfile
> +	rmdir $testdir
>  }
>  
>  _get_total_inode()
> -- 
> 2.34.1
> 




[Index of Archives]     [Linux Filesystems Devel]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux