diff mbox series

[v2,1/2] common: add helper _require_chattr_inherit

Message ID 20230921143102.127526-2-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Test for overlayfs fix in v6.6-rc2 | expand

Commit Message

Amir Goldstein Sept. 21, 2023, 2:31 p.m. UTC
Similar to _require_chattr, but also checks if an attribute is
inheritted from parent dir to children.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 common/rc | 52 +++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 9 deletions(-)

Comments

Zorro Lang Sept. 21, 2023, 3:26 p.m. UTC | #1
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@gmail.com>
> ---
>  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
>
diff mbox series

Patch

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
+
+	touch $path
+	$CHATTR_PROG "+$attribute" $path > $tmp.chattr 2>&1
+	local ret=$?
+	if [ -n "$inherit" ]; then
+		touch "$path/$inherit"
+	fi
+	$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()