diff mbox series

zram/zram_lib.sh: Check fielsystem support more throughly

Message ID 1531299325-27779-1-git-send-email-yangx.jy@cn.fujitsu.com
State Changes Requested
Headers show
Series zram/zram_lib.sh: Check fielsystem support more throughly | expand

Commit Message

Xiao Yang July 11, 2018, 8:55 a.m. UTC
When mkfs command supports a specified filesystem and kernel doesn't support it,
mkfs can format zram device to the filesystem successfully, but mount will fail
with "unknown filesystem type".

For example, running zram01 got the following error when only mkfs supported btrfs
filesystem:
---------------------------------------------------------------------------------
mount: /tmp/ltp-aJSv2PMZGl/zram01.46mBiYaa3M/zram3: unknown filesystem type 'btrfs'.
---------------------------------------------------------------------------------

We should add a fielsystem support check for both kernel and mkfs command, and use
ext2 fielsystem by default if either of them doesn't support a specified filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/device-drivers/zram/zram_lib.sh | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis July 18, 2018, 12:46 p.m. UTC | #1
Hi!
> +zram_check_fs_support()
> +{
> +	tst_check_cmds which modprobe
> +	local filesystem=$1
> +
> +	# Check if mkfs command supports fs
> +	which mkfs.$filesystem > /dev/null 2>&1 || return 1
> +
> +	# Check if kernel supports fs
> +	if ! grep -qw $filesystem /proc/filesystems; then

Actually grepping /proc/filesystems is not enough to figure out if
filesystem is supported or not, since for example ext2 and ext3 are
handled with ext4 these days.

But happily we do already have all the code in tst_supported_fs_types.c
in the test library, we all that is needed to to do is to create a C
helper on the top of tst_get_supported_fs_types() function that returns
array of supported filesystems. So we can write a small helper binary on
the top of that.

I would be for adding a tst_supported_fs binary into the testcases/lib/
that would, without any parameter print the list of supported
filesystems into the stdout. and if passed a fs type as a parameter
would use return value to indicate if the filesystem is supported or
not.

> +		modprobe $filesystem > /dev/null 2>&1 || return 1
> +	fi
> +}
> +
>  zram_makefs()
>  {
> -	tst_check_cmds mkfs which
> +	tst_check_cmds mkfs
>  	local i=0
>  	for fs in $zram_filesystems; do
>  		# if requested fs not supported default it to ext2
> -		which mkfs.$fs > /dev/null 2>&1 || fs=ext2
> +		zram_check_fs_support $fs || fs=ext2
>  
>  		tst_resm TINFO "make $fs filesystem on /dev/zram$i"
>  		mkfs.$fs /dev/zram$i > err.log 2>&1
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
diff mbox series

Patch

diff --git a/testcases/kernel/device-drivers/zram/zram_lib.sh b/testcases/kernel/device-drivers/zram/zram_lib.sh
index 224b407..d6ce74a 100755
--- a/testcases/kernel/device-drivers/zram/zram_lib.sh
+++ b/testcases/kernel/device-drivers/zram/zram_lib.sh
@@ -193,13 +193,27 @@  zram_swapoff()
 	tst_resm TPASS "swapoff completed"
 }
 
+zram_check_fs_support()
+{
+	tst_check_cmds which modprobe
+	local filesystem=$1
+
+	# Check if mkfs command supports fs
+	which mkfs.$filesystem > /dev/null 2>&1 || return 1
+
+	# Check if kernel supports fs
+	if ! grep -qw $filesystem /proc/filesystems; then
+		modprobe $filesystem > /dev/null 2>&1 || return 1
+	fi
+}
+
 zram_makefs()
 {
-	tst_check_cmds mkfs which
+	tst_check_cmds mkfs
 	local i=0
 	for fs in $zram_filesystems; do
 		# if requested fs not supported default it to ext2
-		which mkfs.$fs > /dev/null 2>&1 || fs=ext2
+		zram_check_fs_support $fs || fs=ext2
 
 		tst_resm TINFO "make $fs filesystem on /dev/zram$i"
 		mkfs.$fs /dev/zram$i > err.log 2>&1