diff mbox series

[1/2] common/rc: Check 'tPnE' flags on a directory instead of a regilar file

Message ID 20200908131523.20899-1-yangx.jy@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show
Series [1/2] common/rc: Check 'tPnE' flags on a directory instead of a regilar file | expand

Commit Message

Xiao Yang Sept. 8, 2020, 1:15 p.m. UTC
'tPnE' flags are only valid for a directory so check them on a directory.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 common/rc | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Eryu Guan Sept. 13, 2020, 3:34 p.m. UTC | #1
On Tue, Sep 08, 2020 at 09:15:22PM +0800, Xiao Yang wrote:
> 'tPnE' flags are only valid for a directory so check them on a directory.
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
>  common/rc | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index aa5a7409..cf31eebc 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2168,8 +2168,14 @@ _require_xfs_io_command()
>  		fi
>  		# Test xfs_io chattr support AND
>  		# filesystem FS_IOC_FSSETXATTR support
> -		testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
> -		$XFS_IO_PROG -F -f -r -c "chattr -$param" $testfile 2>&1
> +		# 'tPnE' flags are only valid for a directory so check them on a directory.
> +		if echo "$param" | egrep -q 't|P|n|E'; then
> +			testio=`$XFS_IO_PROG -F -c "chattr +$param" $TEST_DIR 2>&1`
> +			$XFS_IO_PROG -F -r -c "chattr -$param" $TEST_DIR 2>&1

I don't think it's a good idea to try chattr on $TEST_DIR, it may change
the behavior of all sub-dirs and files in it and cause unexpected
failures. (I know we do "chattr -$param" right away, but it still looks
dangerous to me.) It's better to create a new $testdir like $testfile to
try on, and remove it after test.

Thanks,
Eryu

> +		else
> +			testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
> +			$XFS_IO_PROG -F -r -c "chattr -$param" $testfile 2>&1
> +		fi
>  		param_checked="+$param"
>  		;;
>  	"chproj")
> -- 
> 2.21.0
> 
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index aa5a7409..cf31eebc 100644
--- a/common/rc
+++ b/common/rc
@@ -2168,8 +2168,14 @@  _require_xfs_io_command()
 		fi
 		# Test xfs_io chattr support AND
 		# filesystem FS_IOC_FSSETXATTR support
-		testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
-		$XFS_IO_PROG -F -f -r -c "chattr -$param" $testfile 2>&1
+		# 'tPnE' flags are only valid for a directory so check them on a directory.
+		if echo "$param" | egrep -q 't|P|n|E'; then
+			testio=`$XFS_IO_PROG -F -c "chattr +$param" $TEST_DIR 2>&1`
+			$XFS_IO_PROG -F -r -c "chattr -$param" $TEST_DIR 2>&1
+		else
+			testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
+			$XFS_IO_PROG -F -r -c "chattr -$param" $testfile 2>&1
+		fi
 		param_checked="+$param"
 		;;
 	"chproj")