Skip to contentSkip to conversation

common: add support for the "local" file system type

PATCH In review Theodore Ts'o 4 participants 15 messages Sep 23, 2016 – Sep 30, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: add support for the "local" file system type

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

To support this test case, add support for a new file system type called "local". The TEST_DEV and SCRATCH_DEV should be have a non-block device format (e.g., local:/test or local:/scratch), and the TEST_DIR and SCRATCH_MNT directories should be pre-existing directories provided by the execution environment.

---
 common/rc         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tests/generic/027 |  2 +-
 2 files changed, 70 insertions(+), 4 deletions(-)
common/rc +69 -3
index 70d79c9..c03b132 100644
@@ -330,12 +330,29 @@ _overlay_scratch_unmount()
 	$UMOUNT_PROG $SCRATCH_MNT
 }
 
+_local_validate_mount_opt()
+{
+    case "$*" in
+	ro|ro,*|*,ro) _notrun "ro mount option not supported" ;;
+	*nosuid*) _notrun "nosuid mount option not supported" ;;
+	*noatime*) _notrun "noatime mount option not supported" ;;
+	*relatime*) _notrun "relatime mount option not supported" ;;
+	*diratime*) _notrun "diratime mount option not supported" ;;
+	*strictatime*) _notrun "strictatime mount option not supported" ;;
+    esac
+}
+
 _scratch_mount()
 {
     if [ "$FSTYP" == "overlay" ]; then
         _overlay_scratch_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+	_local_validate_mount_opt "$*"
+        mkdir -p $SCRATCH_MNT
+	return $?
+    fi
     _mount -t $FSTYP `_scratch_mount_options $*`
 }
 
@@ -348,6 +365,9 @@ _scratch_unmount()
 	btrfs)
 		$UMOUNT_PROG $SCRATCH_MNT
 		;;
+	local)
+                rm -rf $SCRATCH_MNT/*
+                ;;
 	*)
 		$UMOUNT_PROG $SCRATCH_DEV
 		;;
@@ -358,6 +378,10 @@ _scratch_remount()
 {
     local opts="$1"
 
+    if [ "$FSTYP" = "local" ]; then
+	_local_validate_mount_opt "$*"
+	return 0;
+    fi
     if test -n "$opts"; then
 	mount -o "remount,$opts" $SCRATCH_MNT
     fi
@@ -367,7 +391,7 @@ _scratch_cycle_mount()
 {
     local opts="$1"
 
-    if [ "$FSTYP" = tmpfs ]; then
+    if [ "$FSTYP" = "tmpfs" -o "$FSTYP" = "local" ] ; then
 	_scratch_remount "$opts"
 	return
     fi
@@ -384,6 +408,10 @@ _test_mount()
         _overlay_test_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+        mkdir -p $TEST_DIR
+	return $?
+    fi
     _test_options mount
     _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
 }
@@ -392,7 +420,7 @@ _test_unmount()
 {
 	if [ "$FSTYP" == "overlay" ]; then
 		_overlay_test_unmount
-	else
+	elif [ "$FSTYP" != "local" ]; then
 		$UMOUNT_PROG $TEST_DEV
 	fi
 }
@@ -811,6 +839,9 @@ _scratch_mkfs()
     tmpfs)
 	# do nothing for tmpfs
 	;;
+    local)
+        _scratch_cleanup_files
+	;;
     f2fs)
         $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
 	;;
@@ -1031,6 +1062,13 @@ _scratch_mkfs_sized()
 	fi
 	export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
 	;;
+    local)
+        _scratch_cleanup_files
+	free_space=$(_df_dir $SCRATCH_MNT | $AWK_PROG '{ print $5 }')
+	if [ "$(expr $free_space * 1024)" -lt "$fssize" ] ; then
+	   _notrun "Not enough space ($free_space) for local with $fssize bytes"
+	fi
+	;;
     *)
 	_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
 	;;
@@ -1517,6 +1555,13 @@ _require_scratch_nocheck()
 		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
+		then
+		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
+		fi
+		return 0
+		;;
 	*)
 		 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
 		 then
@@ -1602,6 +1647,13 @@ _require_test()
 		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
+		then
+		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
+		fi
+		return 0
+		;;
 	*)
 		 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
 		 then
@@ -2264,6 +2316,10 @@ _remount()
     device=$1
     mode=$2
 
+    if [ "$FSTYP" == "local" ] ; then
+       return 0
+    fi
+
     if ! mount -o remount,$mode $device
     then
         echo "_remount: failed to remount filesystem on $device as $mode"
@@ -2309,6 +2365,10 @@ _mount_or_remount_rw()
 	device=$2
 	mountpoint=$3
 
+	if [ "$FSTYP" == "local" ] ; then
+	    return 0
+	fi
+
 	if [ $USE_REMOUNT -eq 0 ]; then
 		if [ "$FSTYP" != "overlay" ]; then
 			_mount -t $FSTYP $mount_opts $device $mountpoint
@@ -2666,6 +2726,9 @@ _check_test_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $TEST_DEV
 	;;
@@ -2707,6 +2770,9 @@ _check_scratch_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $device
 	;;
@@ -3784,7 +3850,7 @@ init_rc()
 		fi
 	fi
 
-	if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
+	if [ "$FSTYP" != "local" -a "`_fs_type $TEST_DEV`" != "$FSTYP" ]
 	then
 		echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
 		# raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
tests/generic/027 +1 -1
index d2e59d6..73565fc 100755
@@ -77,7 +77,7 @@ rm -f $SCRATCH_MNT/testfile
 
 loop=100
 # btrfs takes much longer time, reduce the loop count
-if [ "$FSTYP" == "btrfs" ]; then
+if [ "$FSTYP" == "btrfs" -o "$FSTYP" == "local" ]; then
 	loop=10
 fi
 
Signature · 1 line
2.9.0.243.g5c589a7.dirty
#1 lore raw
Quoted 4 lines · Theodore Ts'o

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

This looks useful to me. But I'm not sure what other people think.

I tested this patch a bit (ran auto group), noticed some isuses.

- Tests call _require_scratch_shutdown would shutdown your root fs, if $SCRATCH_MNT is on root fs and root fs is xfs. e.g. generic/044
- Tests do freeze/unfreeze would freeze your root fs, e.g. generic/068
- Tests fulfill $SCRATCH_DEV would eat all free space on root fs, because _scratch_mkfs_sized for "local" only checks for lower boundary but not upper boundary, some tests rely on the upper boundary too, e.g. generic/027

There might be other issues I didn't notice, since I didn't manage to finish a "FSTYP=local ./check -g auto" run because of above issues.

Quoted 4 lines

To support this test case, add support for a new file system type called "local". The TEST_DEV and SCRATCH_DEV should be have a non-block device format (e.g., local:/test or local:/scratch), and the

It's probably good to have a new fstype, as how we test NFS and overlay. i.e. ./check -local, and do all the necessary checks as how we check NFS and overlay setups.

Quoted 2 lines

TEST_DIR and SCRATCH_MNT directories should be pre-existing directories provided by the execution environment.

Better to have these setups and requirements documented in README.

Quoted 17 lines
---
 common/rc         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tests/generic/027 |  2 +-
 2 files changed, 70 insertions(+), 4 deletions(-)
common/rc +2 -0
index 70d79c9..c03b132 100644
@@ -330,12 +330,29 @@ _overlay_scratch_unmount()
 	$UMOUNT_PROG $SCRATCH_MNT
 }
 
+_local_validate_mount_opt()
+{

common/rc _overlay_scratch_unmount() · line 344

Quoted 10 lines
common/rc +10 -0
+    case "$*" in
+	ro|ro,*|*,ro) _notrun "ro mount option not supported" ;;
+	*nosuid*) _notrun "nosuid mount option not supported" ;;
+	*noatime*) _notrun "noatime mount option not supported" ;;
+	*relatime*) _notrun "relatime mount option not supported" ;;
+	*diratime*) _notrun "diratime mount option not supported" ;;
+	*strictatime*) _notrun "strictatime mount option not supported" ;;
+    esac
+}
+

It's good to have some comments on this function.

common/rc _overlay_scratch_unmount() · line 355

Quoted 11 lines
common/rc +5 -0
 _scratch_mount()
 {
     if [ "$FSTYP" == "overlay" ]; then
         _overlay_scratch_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+	_local_validate_mount_opt "$*"
+        mkdir -p $SCRATCH_MNT
+	return $?
+    fi

Perhaps need a new helper like "_local_scratch_mount" here, and it's a good time to covert "if" to "case" switch, I think :)

Quoted 64 lines
common/rc +16 -2
     _mount -t $FSTYP `_scratch_mount_options $*`
 }
 
@@ -348,6 +365,9 @@ _scratch_unmount()
 	btrfs)
 		$UMOUNT_PROG $SCRATCH_MNT
 		;;
+	local)
+                rm -rf $SCRATCH_MNT/*
+                ;;
 	*)
 		$UMOUNT_PROG $SCRATCH_DEV
 		;;
@@ -358,6 +378,10 @@ _scratch_remount()
 {
     local opts="$1"
 
+    if [ "$FSTYP" = "local" ]; then
+	_local_validate_mount_opt "$*"
+	return 0;
+    fi
     if test -n "$opts"; then
 	mount -o "remount,$opts" $SCRATCH_MNT
     fi
@@ -367,7 +391,7 @@ _scratch_cycle_mount()
 {
     local opts="$1"
 
-    if [ "$FSTYP" = tmpfs ]; then
+    if [ "$FSTYP" = "tmpfs" -o "$FSTYP" = "local" ] ; then
 	_scratch_remount "$opts"
 	return
     fi
@@ -384,6 +408,10 @@ _test_mount()
         _overlay_test_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+        mkdir -p $TEST_DIR
+	return $?
+    fi
     _test_options mount
     _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
 }
@@ -392,7 +420,7 @@ _test_unmount()
 {
 	if [ "$FSTYP" == "overlay" ]; then
 		_overlay_test_unmount
-	else
+	elif [ "$FSTYP" != "local" ]; then
 		$UMOUNT_PROG $TEST_DEV
 	fi
 }
@@ -811,6 +839,9 @@ _scratch_mkfs()
     tmpfs)
 	# do nothing for tmpfs
 	;;
+    local)
+        _scratch_cleanup_files
+	;;
     f2fs)
         $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
 	;;

common/rc _scratch_mkfs_sized() · line 1071

Quoted 10 lines
common/rc +7 -0
@@ -1031,6 +1062,13 @@ _scratch_mkfs_sized()
 	fi
 	export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
 	;;
+    local)
+        _scratch_cleanup_files
+	free_space=$(_df_dir $SCRATCH_MNT | $AWK_PROG '{ print $5 }')
+	if [ "$(expr $free_space * 1024)" -lt "$fssize" ] ; then
+	   _notrun "Not enough space ($free_space) for local with $fssize bytes"
+	fi
+	;;

I'd prefer dropping _scratch_mkfs_sized support for "local", because of the generic/027 problem I met above.

Thanks,
Eryu

Quoted 102 lines
common/rc +29 -1
     *)
 	_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
 	;;
@@ -1517,6 +1555,13 @@ _require_scratch_nocheck()
 		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
+		then
+		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
+		fi
+		return 0
+		;;
 	*)
 		 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
 		 then
@@ -1602,6 +1647,13 @@ _require_test()
 		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
+		then
+		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
+		fi
+		return 0
+		;;
 	*)
 		 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
 		 then
@@ -2264,6 +2316,10 @@ _remount()
     device=$1
     mode=$2
 
+    if [ "$FSTYP" == "local" ] ; then
+       return 0
+    fi
+
     if ! mount -o remount,$mode $device
     then
         echo "_remount: failed to remount filesystem on $device as $mode"
@@ -2309,6 +2365,10 @@ _mount_or_remount_rw()
 	device=$2
 	mountpoint=$3
 
+	if [ "$FSTYP" == "local" ] ; then
+	    return 0
+	fi
+
 	if [ $USE_REMOUNT -eq 0 ]; then
 		if [ "$FSTYP" != "overlay" ]; then
 			_mount -t $FSTYP $mount_opts $device $mountpoint
@@ -2666,6 +2726,9 @@ _check_test_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $TEST_DEV
 	;;
@@ -2707,6 +2770,9 @@ _check_scratch_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $device
 	;;
@@ -3784,7 +3850,7 @@ init_rc()
 		fi
 	fi
 
-	if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
+	if [ "$FSTYP" != "local" -a "`_fs_type $TEST_DEV`" != "$FSTYP" ]
 	then
 		echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
 		# raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
tests/generic/027 +1 -1
index d2e59d6..73565fc 100755
@@ -77,7 +77,7 @@ rm -f $SCRATCH_MNT/testfile
 
 loop=100
 # btrfs takes much longer time, reduce the loop count
-if [ "$FSTYP" == "btrfs" ]; then
+if [ "$FSTYP" == "btrfs" -o "$FSTYP" == "local" ]; then
 	loop=10
 fi
 
Signature · 6 lines
2.9.0.243.g5c589a7.dirty

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 18 lines · Eryu Guan
Quoted 4 lines · Theodore Ts'o

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

This looks useful to me. But I'm not sure what other people think.

I tested this patch a bit (ran auto group), noticed some isuses.

- Tests call _require_scratch_shutdown would shutdown your root fs, if $SCRATCH_MNT is on root fs and root fs is xfs. e.g. generic/044
- Tests do freeze/unfreeze would freeze your root fs, e.g. generic/068
- Tests fulfill $SCRATCH_DEV would eat all free space on root fs, because _scratch_mkfs_sized for "local" only checks for lower boundary but not upper boundary, some tests rely on the upper boundary too, e.g. generic/027

Quoted 2 lines

There might be other issues I didn't notice, since I didn't manage to finish a "FSTYP=local ./check -g auto" run because of above issues.

Oops, I was testing on small test devices using ext4, so I didn't notice these issues. I'll fix them up.

Quoted 7 lines
Quoted 3 lines

To support this test case, add support for a new file system type called "local". The TEST_DEV and SCRATCH_DEV should be have a non-block device format (e.g., local:/test or local:/scratch), and the

It's probably good to have a new fstype, as how we test NFS and overlay. i.e. ./check -local, and do all the necessary checks as how we check NFS and overlay setups.

Even for NFS and overlayfs there are some tests we do where mounting and remounting the file system (e.g., with the ro mount option) probably does make sense. Although I do agree there are a large number of the NFS mounts and umounts which are largely pointless.

I was implementing the local file systme type for situations where it is simply *not* *possible* at all to mount and unmount the underlying file system because it was operating inside a docker container where even root didn't have access to modify the supplied file system. (Yes, in some cases we could test the underlying file system, but not all, and it is useful to have end-to-end tests.)

Quoted 4 lines
Quoted 2 lines

TEST_DIR and SCRATCH_MNT directories should be pre-existing directories provided by the execution environment.

Better to have these setups and requirements documented in README.

Agreed, I'll fix this in the next spin of the patch.

- Ted

#3 lore raw
Quoted 38 lines · Theodore Ts'o
Quoted 18 lines · Eryu Guan
Quoted 4 lines · Theodore Ts'o

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

This looks useful to me. But I'm not sure what other people think.

I tested this patch a bit (ran auto group), noticed some isuses.

- Tests call _require_scratch_shutdown would shutdown your root fs, if $SCRATCH_MNT is on root fs and root fs is xfs. e.g. generic/044
- Tests do freeze/unfreeze would freeze your root fs, e.g. generic/068
- Tests fulfill $SCRATCH_DEV would eat all free space on root fs, because _scratch_mkfs_sized for "local" only checks for lower boundary but not upper boundary, some tests rely on the upper boundary too, e.g. generic/027

Quoted 2 lines

There might be other issues I didn't notice, since I didn't manage to finish a "FSTYP=local ./check -g auto" run because of above issues.

Oops, I was testing on small test devices using ext4, so I didn't notice these issues. I'll fix them up.

Quoted 7 lines
Quoted 3 lines

To support this test case, add support for a new file system type called "local". The TEST_DEV and SCRATCH_DEV should be have a non-block device format (e.g., local:/test or local:/scratch), and the

It's probably good to have a new fstype, as how we test NFS and overlay. i.e. ./check -local, and do all the necessary checks as how we check NFS and overlay setups.

Even for NFS and overlayfs there are some tests we do where mounting and remounting the file system (e.g., with the ro mount option) probably does make sense. Although I do agree there are a large number of the NFS mounts and umounts which are largely pointless.

Quoted 6 lines

I was implementing the local file systme type for situations where it is simply *not* *possible* at all to mount and unmount the underlying file system because it was operating inside a docker container where even root didn't have access to modify the supplied file system. (Yes, in some cases we could test the underlying file system, but not all, and it is useful to have end-to-end tests.)

Sorry, I should have been more clear.

It has nothing to do with mount & umount, it's about adding a new "-local" option to "check", like "-nfs" and "-overlay". And do TEST_DEV/TEST_DIR and SCRATCH_DEV/SCRATCH_MNT validations in _require_test and _require_scratch_nocheck, as how we do the check for NFS and overlayfs. So we don't have to work around the validation by specifying TEST_DEV/SCRATCH_DEV in a non-block device format (e.g. local:/test to mimic an NFS export).

Thanks,
Eryu

#4 lore raw
Quoted 8 lines · Eryu Guan

It has nothing to do with mount & umount, it's about adding a new "-local" option to "check", like "-nfs" and "-overlay". And do TEST_DEV/TEST_DIR and SCRATCH_DEV/SCRATCH_MNT validations in _require_test and _require_scratch_nocheck, as how we do the check for NFS and overlayfs. So we don't have to work around the validation by specifying TEST_DEV/SCRATCH_DEV in a non-block device format (e.g. local:/test to mimic an NFS export).

I'd have to dig and check, but as I recall, there were assumptions that foo:/bar means "no block device" scattered around, and it's why we have to use a similar naming scheme for tmpfs. Is that really a problem? I had thought it was a standard convention for xfstests.

If we want to avoid forcing testers to use a foo:/bar naming scheme for TEST_DEV and SCRATCH_DEV, instead of a new command-line variable, I'd much rather have a function in rc/common that could be keyed off the file system type. You have to specify whether you are using tmpfs or nfs or local in FSTYP anyway, so why not just use that?

Cheers,

- Ted

#5 lore raw
In reply to Theodore Ts'o
Quoted 4 lines · Theodore Ts'o

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

Ignoring the code changes for the moment - what's the reason/use case for running /kernel/ test suites inside a user container with such restricted access to filesystems and devices? Especially considering test failures can take the kernel down, which will kill /everything/ on the machine, not just the container.

This doesn't make a whole lot of sense to me - who is going to use this and what extra test coverage does it bring to the table compared to just running inside a guest VM with full privileges?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#6 lore raw
Quoted 10 lines · Dave Chinner

Ignoring the code changes for the moment - what's the reason/use case for running /kernel/ test suites inside a user container with such restricted access to filesystems and devices? Especially considering test failures can take the kernel down, which will kill /everything/ on the machine, not just the container.

This doesn't make a whole lot of sense to me - who is going to use this and what extra test coverage does it bring to the table compared to just running inside a guest VM with full privileges?

So I'm doing this work on behalf of a team who is working on an to-be-announced project, so the details aren't mine to give. However, I can say that obviously, if they could do that they would.

Let me give an other example where this might be useful. Suppose you are using the Windows Subsystem for Linux which emulates system calls for Linux, so you can run most Linux binaries, but for which certain system calls simply aren't implemented, either for security reasons or because they just don't make sense (e.g., reboot, kexec, mount, unmount, etc.). To the extent that such a subsystem purports to offer Linux compatibility, and has a Linux VFS emulation, it would be useful to have a "local" file system type which doesn't try to do any mounts and unmounts, but which could otherwise stress test the file system layer and find bugs in the system call emulation for file systems, that would be a good and useful thing to do.

As I recall, AIX also had a Linux system emulator (the better to run the huge numbers of commercial third-party Linux binaries :-), and if I recall correctly, it didn't support mount and unmount either. NetBSD also has a Linux emulation layer (and in the past, an Irix emulation layer), and again, it's not clear that it would extend to things like mount/unmount --- nor would it really need to in order to be useful for most of their desired use cases.

Cheers,

- Ted

#7 lore raw
Quoted 8 lines · Theodore Ts'o
Quoted 7 lines · Dave Chinner

Ignoring the code changes for the moment - what's the reason/use case for running /kernel/ test suites inside a user container with such restricted access to filesystems and devices? Especially considering test failures can take the kernel down, which will kill /everything/ on the machine, not just the container.

Quoted 7 lines
Quoted 3 lines

This doesn't make a whole lot of sense to me - who is going to use this and what extra test coverage does it bring to the table compared to just running inside a guest VM with full privileges?

So I'm doing this work on behalf of a team who is working on an to-be-announced project, so the details aren't mine to give. However, I can say that obviously, if they could do that they would.

So, sooper-s3kr3t internal google stuff that you can't talk about and may never see the light of day. When it is announced and released, then let's talk about integration....

Quoted 11 lines

Let me give an other example where this might be useful. Suppose you are using the Windows Subsystem for Linux which emulates system calls for Linux, so you can run most Linux binaries, but for which certain system calls simply aren't implemented, either for security reasons or because they just don't make sense (e.g., reboot, kexec, mount, unmount, etc.). To the extent that such a subsystem purports to offer Linux compatibility, and has a Linux VFS emulation, it would be useful to have a "local" file system type which doesn't try to do any mounts and unmounts, but which could otherwise stress test the file system layer and find bugs in the system call emulation for file systems, that would be a good and useful thing to do.

xfstests is not designed for validating system call API compliance - it's for exercising /filesystem implementations/. xfstests assumes the syscall API is valid and working, and tries to break the underlying storage implementation. As such, your example really isn't something you should be using xfstests for - it doesn't test anything like what is needed to verify that the "VFS emulation" is valid and complete and working exactly as documented in the linux man pages.

As it is, we have a test harness that is supposed to validate Linux syscall behaviour exactly as you are describing: LTP.

Quoted 7 lines

As I recall, AIX also had a Linux system emulator (the better to run the huge numbers of commercial third-party Linux binaries :-), and if I recall correctly, it didn't support mount and unmount either. NetBSD also has a Linux emulation layer (and in the past, an Irix emulation layer), and again, it's not clear that it would extend to things like mount/unmount --- nor would it really need to in order to be useful for most of their desired use cases.

xfstests would be implemented on such platforms using the native mount/unmount commands, just like it is for Irix. Indeed, in this situation one should be testing the native filesystem implementation with xfstests, and then using LTP to test the linux emulation layer behaves as expected.

Use the right tool for the job....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#8 lore raw
Quoted 4 lines · Dave Chinner

So, sooper-s3kr3t internal google stuff that you can't talk about and may never see the light of day. When it is announced and released, then let's talk about integration....

Fair enough, I'll carry it as an out-of-tree patch at

https://github.com/tytso/xfstests

... for anyone else who might find it useful for their purposes.

Quoted 8 lines

xfstests is not designed for validating system call API compliance - it's for exercising /filesystem implementations/. xfstests assumes the syscall API is valid and working, and tries to break the underlying storage implementation. As such, your example really isn't something you should be using xfstests for - it doesn't test anything like what is needed to verify that the "VFS emulation" is valid and complete and working exactly as documented in the linux man pages.

Who says there isn't an underlying file system implementation which we want to test? In fact we *are* using the right tool for the job. (I'm quite aware of the other testing tools that might be available including LTP and others, such as the LSB tests.)

Cheers,

- Ted

#9 lore raw
Quoted 21 lines · Theodore Ts'o
Quoted 4 lines · Dave Chinner

So, sooper-s3kr3t internal google stuff that you can't talk about and may never see the light of day. When it is announced and released, then let's talk about integration....

Fair enough, I'll carry it as an out-of-tree patch at

https://github.com/tytso/xfstests

... for anyone else who might find it useful for their purposes.

Quoted 8 lines

xfstests is not designed for validating system call API compliance - it's for exercising /filesystem implementations/. xfstests assumes the syscall API is valid and working, and tries to break the underlying storage implementation. As such, your example really isn't something you should be using xfstests for
- it doesn't test anything like what is needed to verify that the "VFS emulation" is valid and complete and working exactly as documented in the linux man pages.

Quoted 2 lines

Who says there isn't an underlying file system implementation which we want to test? In fact we *are* using the right tool for the job.

Nobody outside the google echo chamber can say, Ted, because you haven't told anyone what it is you want this for. binary emulation layers (your example, not mine) don't implement persistent filesystems - they translate syscalls.

So let's revist this when everyone has the same information available and we can have an informed discussion....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#10 lore raw
Quoted 4 lines · Dave Chinner

Nobody outside the google echo chamber can say, Ted, because you haven't told anyone what it is you want this for. binary emulation layers (your example, not mine) don't implement persistent filesystems - they translate syscalls.

Is your only objection that you don't get to can't see what it's going to test?

That's generally not a reason to object to patches in various open source projects --- there are plenty of closed source programs for which we accept kernel patches, for example.

But sure, if that's the way you want to roll, as I said, I'll carry it as an out of tree patch.

- Ted

#11 lore raw
Quoted 8 lines · Theodore Ts'o
Quoted 4 lines · Dave Chinner

Nobody outside the google echo chamber can say, Ted, because you haven't told anyone what it is you want this for. binary emulation layers (your example, not mine) don't implement persistent filesystems - they translate syscalls.

Is your only objection that you don't get to can't see what it's going to test?

No, it isn't. But it's the most important one on my list right now because it affects fundamental architecture assumptions the test harness is based upon. I haven't looked at the implementation, because if we can't validate the basic architecture there's no point even looking at the code.

As it is, Eryu and Eric have already outlined a number of serious issues with the implementation (and your testing process). They've highlighted a number of magic snowflake conditions we'd have to sprinkle throughout random tests and maintain forever more. What's missing from your patch request is the information that allows us to determine if the benefits of this patchset outweigh the obvious, significant, ongoing cost of having to maintain these snowflakes.

Ted, as a kernel subsystem maintainer, you should know that understanding the full picture is a neccessary aspect of reviewing new proposals. Do you really merge code into ext4 that you think is going to be a significant future burden on the maintainer without knowing why it is needed, how it will be used, or even how you'll maintain it in a working condition over the long term?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#12 lore raw
Quoted 7 lines · Dave Chinner

As it is, Eryu and Eric have already outlined a number of serious issues with the implementation (and your testing process). They've highlighted a number of magic snowflake conditions we'd have to sprinkle throughout random tests and maintain forever more. What's missing from your patch request is the information that allows us to determine if the benefits of this patchset outweigh the obvious, significant, ongoing cost of having to maintain these snowflakes.

The issues Eryu and Eric pointed out (and many thanks for their review) were ones that are easily fixed, and I can restrict the changes to common/* (right now only common/rc), and I no longer need any changes in the tests/* hierarchy.

My first patch had only a single "snowflake" to generic/027 (and it was one that already had a snowflake exemption for btrfs). It was done to work around the fact that _scratch_mkfs_sized wouldn't restrict the size of the file system. I now will _notrun any test which uses _scratch_mkfs_sized, so I don't need that change any longer. This leaves only a single enospc test which will be run, which is a bit unfortunate, but it solves the "I could fill the root file system if TEST_DEV or SCRATCH_DEV is pointed on my root fs" problem".

So I believe the maintainance issue is something that can be be mitigated.

Testing is something that can be done using a standard Linux systems. (Indeed I did most of my testing using my existing gce-xfstests and kvm-xfstests frameworks, just because it was easier.) It's a fair point that I should make sure it doesn't cause problems when other file systems are used as the base file system, and if it is used on a root file system. Again, these are issues which I can fix in the patch. Indeed, all of the the specific issues pointed out by Eric and Eryu are already fixed in my tree.

In any case, since the commit are only adding some tests in common/rc (where we have lots of per-file system conditionals anyway), I can easily maintain this patch out-of-tree, since you seem to have fundamental philosophical problems with it.

Regards,

- Ted

#13 lore raw
In reply to Theodore Ts'o
Quoted 4 lines · Theodore Ts'o
Quoted 4 lines

xfstests is not designed for validating system call API compliance -

Quoted 3 lines

it's for exercising /filesystem implementations/. xfstests assumes the syscall API is valid and working, and tries to break the underlying storage implementation.

To play devil's advocate, I think there are a few tests that find problems pretty high up the callchain, possibly in the vfs or syscall layer...

Quoted 9 lines
Quoted 5 lines

As such, your example really

Quoted 4 lines

isn't something you should be using xfstests for - it doesn't test anything like what is needed to verify that the "VFS emulation" is valid and complete and working exactly as documented in the linux man pages.

Who says there isn't an underlying file system implementation which we want to test? In fact we *are* using the right tool for the job. (I'm quite aware of the other testing tools that might be available including LTP and others, such as the LSB tests.)

So you want to test a filesystem without being able to mount/unmount... Is this because you want to test how things behave in a restricted privs environment of some sort, or because the system under test has absolutely no way to mount & unmount a filesystem for any user?

So many of the current tests expect to check fs consistency, check data integrity after a shutdown or remount, test recovery, examine on-disk structures of a quiesced, consistent block device, test mount options, etc, I fear that there will be so many special snowflakes scattered around individual tests that this might be very hard to maintain.

-Eric

#14 lore raw
In reply to Theodore Ts'o
Quoted 4 lines · Theodore Ts'o

It is sometimes useful to be able to test the local file system provided in a restricted execution environment (such as that which is provided by Docker, for example) where it is not possible to mount and unmount the file system under test.

Big picture concerns logged elsewhere, but other things below :)

Quoted 3 lines

To support this test case, add support for a new file system type called "local". The TEST_DEV and SCRATCH_DEV should be have a non-block device format (e.g., local:/test or local:/scratch),

That convention should be documented in the README...

As Eryu found, running this on xfs could be disastrous as it stands. You checked ext4, but it probably needs a thorough workout for multiple filesystem types with various block sizes, mount options etc to see if this really covers the bases of running on an essentially uncontrolled, unknown filesystem environment...

Quoted 3 lines

and the
TEST_DIR and SCRATCH_MNT directories should be pre-existing directories provided by the execution environment.

no different than we have today, right?

Quoted 15 lines
---
 common/rc         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tests/generic/027 |  2 +-
 2 files changed, 70 insertions(+), 4 deletions(-)
common/rc +1 -0
index 70d79c9..c03b132 100644
@@ -330,12 +330,29 @@ _overlay_scratch_unmount()
 	$UMOUNT_PROG $SCRATCH_MNT
 }
 
+_local_validate_mount_opt()

common/rc _overlay_scratch_unmount() · line 343

Quoted 10 lines
common/rc +10 -0
+{
+    case "$*" in
+	ro|ro,*|*,ro) _notrun "ro mount option not supported" ;;
+	*nosuid*) _notrun "nosuid mount option not supported" ;;
+	*noatime*) _notrun "noatime mount option not supported" ;;
+	*relatime*) _notrun "relatime mount option not supported" ;;
+	*diratime*) _notrun "diratime mount option not supported" ;;
+	*strictatime*) _notrun "strictatime mount option not supported" ;;
+    esac
+}

Does this really cover them all? The number of mount options that might be tested across all filesystems is huge. I'd almost say that if /any/ mount option is specified, fail, because you have /no/ control over an already-mounted fs's behavior in your (unspecified) environment.

common/rc _overlay_scratch_unmount() · line 353

Quoted 10 lines
common/rc +4 -0
+
 _scratch_mount()
 {
     if [ "$FSTYP" == "overlay" ]; then
         _overlay_scratch_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+	_local_validate_mount_opt "$*"
+        mkdir -p $SCRATCH_MNT

surely $SCRATCH_MNT should already exist?

common/rc _scratch_unmount() · line 370

Quoted 12 lines
common/rc +5 -0
+	return $?
+    fi
     _mount -t $FSTYP `_scratch_mount_options $*`
 }
 
@@ -348,6 +365,9 @@ _scratch_unmount()
 	btrfs)
 		$UMOUNT_PROG $SCRATCH_MNT
 		;;
+	local)
+                rm -rf $SCRATCH_MNT/*
+                ;;

unmounting scratch doesn't run mkfs in the normal xfstests environment, so removing everything doesn't make sense to me. I'd expect this in _scratch_mkfs, not _scratch_unmount.

Quoted 15 lines
common/rc +4 -0
 	*)
 		$UMOUNT_PROG $SCRATCH_DEV
 		;;
@@ -358,6 +378,10 @@ _scratch_remount()
 {
     local opts="$1"
 
+    if [ "$FSTYP" = "local" ]; then
+	_local_validate_mount_opt "$*"
+	return 0;
+    fi
     if test -n "$opts"; then
 	mount -o "remount,$opts" $SCRATCH_MNT
     fi

common/rc _scratch_cycle_mount() · line 396

Quoted 7 lines
common/rc +1 -1
@@ -367,7 +391,7 @@ _scratch_cycle_mount()
 {
     local opts="$1"
 
-    if [ "$FSTYP" = tmpfs ]; then
+    if [ "$FSTYP" = "tmpfs" -o "$FSTYP" = "local" ] ; then
 	_scratch_remount "$opts"
 	return

tmpfs is special because an unmount loses all data. Not clear why a local fs would need this treatment. I'd expect an explicit no-op (even if that's what _scratch_remount does for this type)

common/rc _test_mount() · line 414

Quoted 9 lines
common/rc +4 -0
     fi
@@ -384,6 +408,10 @@ _test_mount()
         _overlay_test_mount $*
         return $?
     fi
+    if [ "$FSTYP" == "local" ]; then
+        mkdir -p $TEST_DIR
+	return $?
+    fi

Again, surely this should already exist?

Quoted 13 lines
common/rc +1 -1
     _test_options mount
     _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
 }
@@ -392,7 +420,7 @@ _test_unmount()
 {
 	if [ "$FSTYP" == "overlay" ]; then
 		_overlay_test_unmount
-	else
+	elif [ "$FSTYP" != "local" ]; then
 		$UMOUNT_PROG $TEST_DEV
 	fi
 }

common/rc _scratch_mkfs() · line 844

Quoted 6 lines
common/rc +3 -0
@@ -811,6 +839,9 @@ _scratch_mkfs()
     tmpfs)
 	# do nothing for tmpfs
 	;;
+    local)
+        _scratch_cleanup_files
+	;;

ok, so you do what I suggested earlier, here ;)

Quoted 4 lines
common/rc +0 -0
     f2fs)
         $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
 	;;

common/rc _scratch_mkfs_sized() · line 1071

Quoted 10 lines
common/rc +7 -0
@@ -1031,6 +1062,13 @@ _scratch_mkfs_sized()
 	fi
 	export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
 	;;
+    local)
+        _scratch_cleanup_files
+	free_space=$(_df_dir $SCRATCH_MNT | $AWK_PROG '{ print $5 }')
+	if [ "$(expr $free_space * 1024)" -lt "$fssize" ] ; then
+	   _notrun "Not enough space ($free_space) for local with $fssize bytes"
+	fi
+	;;

icky indentation here, at least ...

Wouldn't _require_fs_space be more straightforward here?

Quoted 4 lines
common/rc +0 -0
     *)
 	_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
 	;;

common/rc _require_scratch_nocheck() · line 1564

Quoted 10 lines
common/rc +7 -0
@@ -1517,6 +1555,13 @@ _require_scratch_nocheck()
 		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
+		then
+		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
+		fi
+		return 0
+		;;

Hm, I guess I'd need to read an updated README to know if this test is correct.

Quoted 4 lines
common/rc +0 -0
 	*)
 		 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
 		 then

common/rc _require_test() · line 1656

Quoted 10 lines
common/rc +7 -0
@@ -1602,6 +1647,13 @@ _require_test()
 		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
 		fi
 		;;
+	local)
+		if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
+		then
+		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
+		fi
+		return 0
+		;;

same here.

Quoted 46 lines
common/rc +14 -0
 	*)
 		 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
 		 then
@@ -2264,6 +2316,10 @@ _remount()
     device=$1
     mode=$2
 
+    if [ "$FSTYP" == "local" ] ; then
+       return 0
+    fi
+
     if ! mount -o remount,$mode $device
     then
         echo "_remount: failed to remount filesystem on $device as $mode"
@@ -2309,6 +2365,10 @@ _mount_or_remount_rw()
 	device=$2
 	mountpoint=$3
 
+	if [ "$FSTYP" == "local" ] ; then
+	    return 0
+	fi
+
 	if [ $USE_REMOUNT -eq 0 ]; then
 		if [ "$FSTYP" != "overlay" ]; then
 			_mount -t $FSTYP $mount_opts $device $mountpoint
@@ -2666,6 +2726,9 @@ _check_test_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $TEST_DEV
 	;;
@@ -2707,6 +2770,9 @@ _check_scratch_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    local)
+	# no way to check consistency for local
+	;;
     *)
 	_check_generic_filesystem $device
 	;;

common/rc init_rc() · line 3856

Quoted 8 lines
common/rc +1 -1
@@ -3784,7 +3850,7 @@ init_rc()
 		fi
 	fi
 
-	if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
+	if [ "$FSTYP" != "local" -a "`_fs_type $TEST_DEV`" != "$FSTYP" ]
 	then
 		echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
 		# raw $DF_PROG cannot handle NFS/CIFS/overlay correctly

I suppose for "local" I'd check that $TEST_DIR exists...

tests/generic/027 rm -f $SCRATCH_MNT/testfile · line 82

Quoted 12 lines
tests/generic/027 +1 -1
index d2e59d6..73565fc 100755
@@ -77,7 +77,7 @@ rm -f $SCRATCH_MNT/testfile
 
 loop=100
 # btrfs takes much longer time, reduce the loop count
-if [ "$FSTYP" == "btrfs" ]; then
+if [ "$FSTYP" == "btrfs" -o "$FSTYP" == "local" ]; then
 	loop=10
 fi

Ok, why?

This is the kind of special snowflake I worry about, I would not expect it to be the last... ;)

-Eric