diff mbox series

[v3,1/1] generic: move btrfs clone device testcase to the generic group

Message ID 670fe32950d328b6a6dd071a53d8a25e50ce6647.1712673602.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v3,1/1] generic: move btrfs clone device testcase to the generic group | expand

Commit Message

Anand Jain April 9, 2024, 2:43 p.m. UTC
Given that ext4 also allows mounting of a cloned filesystem, the btrfs
test case btrfs/312, which assesses the functionality of cloned filesystem
support, can be refactored to be under the generic group.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
Move back to generic

v2:
Move to shared testcase instead of generic.
commit log updated,
add _require_block_device $TEST_DEV.
add _require_duplicated_fsid

https://lore.kernel.org/all/440eff6d16407f12ec55df69db283ba6eb9b278c.1710599671.git.anand.jain@oracle.com/T/#m576217a155aee49af607aa1f2aaa102ac92835e9

v1:
https://lore.kernel.org/linux-btrfs/dd10c332377f315cd17abc46e08f296b87aed31c.1709970025.git.anand.jain@oracle.com/

 common/rc             | 14 +++++++
 tests/btrfs/312       | 78 --------------------------------------
 tests/btrfs/312.out   | 19 ----------
 tests/generic/744     | 87 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/744.out |  4 ++
 5 files changed, 105 insertions(+), 97 deletions(-)
 delete mode 100755 tests/btrfs/312
 delete mode 100644 tests/btrfs/312.out
 create mode 100755 tests/generic/744
 create mode 100644 tests/generic/744.out

Comments

Zorro Lang April 24, 2024, 10:45 a.m. UTC | #1
On Tue, Apr 09, 2024 at 10:43:42PM +0800, Anand Jain wrote:
> Given that ext4 also allows mounting of a cloned filesystem, the btrfs
> test case btrfs/312, which assesses the functionality of cloned filesystem
> support, can be refactored to be under the generic group.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v3:
> Move back to generic
> 
> v2:
> Move to shared testcase instead of generic.
> commit log updated,
> add _require_block_device $TEST_DEV.
> add _require_duplicated_fsid
> 
> https://lore.kernel.org/all/440eff6d16407f12ec55df69db283ba6eb9b278c.1710599671.git.anand.jain@oracle.com/T/#m576217a155aee49af607aa1f2aaa102ac92835e9
> 
> v1:
> https://lore.kernel.org/linux-btrfs/dd10c332377f315cd17abc46e08f296b87aed31c.1709970025.git.anand.jain@oracle.com/
> 
>  common/rc             | 14 +++++++
>  tests/btrfs/312       | 78 --------------------------------------
>  tests/btrfs/312.out   | 19 ----------
>  tests/generic/744     | 87 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/744.out |  4 ++
>  5 files changed, 105 insertions(+), 97 deletions(-)
>  delete mode 100755 tests/btrfs/312
>  delete mode 100644 tests/btrfs/312.out
>  create mode 100755 tests/generic/744
>  create mode 100644 tests/generic/744.out
> 
> diff --git a/common/rc b/common/rc
> index 3ef70dfdddaa..6b9d218e3b1c 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -5495,6 +5495,20 @@ _random_file() {
>  	echo "$basedir/$(ls -U $basedir | shuf -n 1)"
>  }
>  
> +_require_duplicate_fsid()
> +{
> +	case "$FSTYP" in
> +	"btrfs")
> +		_require_btrfs_fs_feature temp_fsid
> +		;;
> +	"ext4")
> +		;;
> +	*)
> +		_notrun "$FSTYP cannot support mounting with duplicate fsid"

We didn't do a visible "mount" at here, how about say:
  "$FSTYP does not support duplicate fsid" ?

> +		;;
> +	esac
> +}

OK, with this helper, we can move it into generic/. I'm not familar with
other filesystems, if any of other filesystems supports this feature, please
remind me.

> +
>  init_rc
>  

[snip]

> diff --git a/tests/generic/744 b/tests/generic/744
> new file mode 100755
> index 000000000000..5c7edf6499c1
> --- /dev/null
> +++ b/tests/generic/744
> @@ -0,0 +1,87 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2024 Oracle. All Rights Reserved.
> +#
> +# FS QA Test 744
> +#
> +# Set up a filesystem, create a clone, mount both, and verify if the cp reflink
> +# operation between these two mounts fails.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick clone volume tempfsid

I think it's not "quick" enough, right? It still need to take ~60s.

> +
> +_cleanup()
> +{
> +	cd /
> +	rm -r -f $tmp.*
> +
> +	$UMOUNT_PROG $mnt2 &> /dev/null
> +	rm -r -f $mnt2
> +	_destroy_loop_device $loop_dev2 &> /dev/null
> +	rm -r -f $loop_file2
> +
> +	$UMOUNT_PROG $mnt1 &> /dev/null
> +	rm -r -f $mnt1
> +	_destroy_loop_device $loop_dev1 &> /dev/null

The _destroy_loop_device will exit directly if it fails, so the "&> /dev/null"
isn't helpful. If the test _notrun by a _require_xxx helper, I doubt the
_destroy_loop_device might cause _fail. So how about use `losetup -d` directly?

$UMOUNT_PROG $mnt2 &> /dev/null
$UMOUNT_PROG $mnt1 &> /dev/null
[ -b "$loop_dev2" ] && losetup -d $loop_dev2
[ -b "$loop_dev1" ] && losetup -d $loop_dev1
[ -n "$seq" ] && rm -rf $TEST_DIR/$seq

> +	rm -r -f $loop_file1
> +}
> +
> +. ./common/filter
> +. ./common/reflink
> +
> +# Modify as appropriate.
> +_supported_fs generic
> +_require_duplicate_fsid
> +_require_cp_reflink
> +_require_test
> +_require_block_device $TEST_DEV
> +_require_loop
> +
> +clone_filesystem()
> +{
> +	local dev1=$1
> +	local dev2=$2
> +
> +	_mkfs_dev $dev1
> +
> +	_mount $dev1 $mnt1
> +	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo >> $seqres.full
> +	$UMOUNT_PROG $mnt1
> +
> +	# device dump of $dev1 to $dev2
> +	dd if=$dev1 of=$dev2 conv=fsync status=none || _fail "dd failed: $?"
> +}
> +
> +mnt1=$TEST_DIR/$seq/mnt1
> +rm -r -f $mnt1
> +mkdir -p $mnt1
> +
> +mnt2=$TEST_DIR/$seq/mnt2
> +rm -r -f $mnt2
> +mkdir -p $mnt2

You might want to remove the "$TEST_DIR/$seq" directly, e.g.

mnt1=$TEST_DIR/$seq/mnt1
mnt2=$TEST_DIR/$seq/mnt2
rm -rf $TEST_DIR/$seq
mkdir -p $mnt1 $mnt2


> +
> +loop_file1="$TEST_DIR/$seq/image1"
> +rm -r -f $loop_file1
> +truncate -s 300m "$loop_file1"
> +loop_dev1=$(_create_loop_device "$loop_file1")
> +
> +loop_file2="$TEST_DIR/$seq/image2"
> +rm -r -f $loop_file2
> +truncate -s 300m "$loop_file2"
> +loop_dev2=$(_create_loop_device "$loop_file2")
> +
> +clone_filesystem ${loop_dev1} ${loop_dev2}
> +
> +# Mounting original device
> +_mount $loop_dev1 $mnt1
> +$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo | _filter_xfs_io
> +
> +# Mounting cloned device
> +_mount $loop_dev2 $mnt2 || _fail "mount of cloned device failed"
> +
> +# cp reflink across two different filesystems must fail
> +_cp_reflink $mnt1/foo $mnt2/bar 2>&1 | _filter_test_dir

Don't we need to make sure the $FSTYP supports reflink feature? The
_require_cp_reflink only checks if the "cp" command has "reflink" option.

There's not a helper to check if $mnt1 and $mnt2 support reflink directly, but
I think we can use "_require_test_reflink".

Thanks,
Zorro


> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/744.out b/tests/generic/744.out
> new file mode 100644
> index 000000000000..1850a0ea2a5e
> --- /dev/null
> +++ b/tests/generic/744.out
> @@ -0,0 +1,4 @@
> +QA output created by 744
> +wrote 9000/9000 bytes at offset 0
> +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +cp: failed to clone 'TEST_DIR/744/mnt2/bar' from 'TEST_DIR/744/mnt1/foo': Invalid cross-device link
> -- 
> 2.39.3
> 
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 3ef70dfdddaa..6b9d218e3b1c 100644
--- a/common/rc
+++ b/common/rc
@@ -5495,6 +5495,20 @@  _random_file() {
 	echo "$basedir/$(ls -U $basedir | shuf -n 1)"
 }
 
+_require_duplicate_fsid()
+{
+	case "$FSTYP" in
+	"btrfs")
+		_require_btrfs_fs_feature temp_fsid
+		;;
+	"ext4")
+		;;
+	*)
+		_notrun "$FSTYP cannot support mounting with duplicate fsid"
+		;;
+	esac
+}
+
 init_rc
 
 ################################################################################
diff --git a/tests/btrfs/312 b/tests/btrfs/312
deleted file mode 100755
index eedcf11a2308..000000000000
--- a/tests/btrfs/312
+++ /dev/null
@@ -1,78 +0,0 @@ 
-#! /bin/bash
-# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2024 Oracle.  All Rights Reserved.
-#
-# FS QA Test 312
-#
-# On a clone a device check to see if tempfsid is activated.
-#
-. ./common/preamble
-_begin_fstest auto quick clone tempfsid
-
-_cleanup()
-{
-	cd /
-	$UMOUNT_PROG $mnt1 > /dev/null 2>&1
-	rm -r -f $tmp.*
-	rm -r -f $mnt1
-}
-
-. ./common/filter.btrfs
-. ./common/reflink
-
-_supported_fs btrfs
-_require_scratch_dev_pool 2
-_scratch_dev_pool_get 2
-_require_btrfs_fs_feature temp_fsid
-
-mnt1=$TEST_DIR/$seq/mnt1
-mkdir -p $mnt1
-
-create_cloned_devices()
-{
-	local dev1=$1
-	local dev2=$2
-
-	echo -n Creating cloned device...
-	_mkfs_dev -fq -b $((1024 * 1024 * 300)) $dev1
-
-	_mount $dev1 $SCRATCH_MNT
-
-	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \
-								_filter_xfs_io
-	$UMOUNT_PROG $SCRATCH_MNT
-	# device dump of $dev1 to $dev2
-	dd if=$dev1 of=$dev2 bs=300M count=1 conv=fsync status=none || \
-							_fail "dd failed: $?"
-	echo done
-}
-
-mount_cloned_device()
-{
-	echo ---- $FUNCNAME ----
-	create_cloned_devices ${SCRATCH_DEV_NAME[0]} ${SCRATCH_DEV_NAME[1]}
-
-	echo Mounting original device
-	_mount ${SCRATCH_DEV_NAME[0]} $SCRATCH_MNT
-	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \
-								_filter_xfs_io
-	check_fsid ${SCRATCH_DEV_NAME[0]}
-
-	echo Mounting cloned device
-	_mount ${SCRATCH_DEV_NAME[1]} $mnt1 || \
-				_fail "mount failed, tempfsid didn't work"
-
-	echo cp reflink must fail
-	_cp_reflink $SCRATCH_MNT/foo $mnt1/bar 2>&1 | \
-						_filter_testdir_and_scratch
-
-	check_fsid ${SCRATCH_DEV_NAME[1]}
-}
-
-mount_cloned_device
-
-_scratch_dev_pool_put
-
-# success, all done
-status=0
-exit
diff --git a/tests/btrfs/312.out b/tests/btrfs/312.out
deleted file mode 100644
index b7de6ce3cc6e..000000000000
--- a/tests/btrfs/312.out
+++ /dev/null
@@ -1,19 +0,0 @@ 
-QA output created by 312
----- mount_cloned_device ----
-Creating cloned device...wrote 9000/9000 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-done
-Mounting original device
-wrote 9000/9000 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-On disk fsid:		FSID
-Metadata uuid:		FSID
-Temp fsid:		FSID
-Tempfsid status:	0
-Mounting cloned device
-cp reflink must fail
-cp: failed to clone 'TEST_DIR/312/mnt1/bar' from 'SCRATCH_MNT/foo': Invalid cross-device link
-On disk fsid:		FSID
-Metadata uuid:		FSID
-Temp fsid:		TEMPFSID
-Tempfsid status:	1
diff --git a/tests/generic/744 b/tests/generic/744
new file mode 100755
index 000000000000..5c7edf6499c1
--- /dev/null
+++ b/tests/generic/744
@@ -0,0 +1,87 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024 Oracle. All Rights Reserved.
+#
+# FS QA Test 744
+#
+# Set up a filesystem, create a clone, mount both, and verify if the cp reflink
+# operation between these two mounts fails.
+#
+. ./common/preamble
+_begin_fstest auto quick clone volume tempfsid
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+
+	$UMOUNT_PROG $mnt2 &> /dev/null
+	rm -r -f $mnt2
+	_destroy_loop_device $loop_dev2 &> /dev/null
+	rm -r -f $loop_file2
+
+	$UMOUNT_PROG $mnt1 &> /dev/null
+	rm -r -f $mnt1
+	_destroy_loop_device $loop_dev1 &> /dev/null
+	rm -r -f $loop_file1
+}
+
+. ./common/filter
+. ./common/reflink
+
+# Modify as appropriate.
+_supported_fs generic
+_require_duplicate_fsid
+_require_cp_reflink
+_require_test
+_require_block_device $TEST_DEV
+_require_loop
+
+clone_filesystem()
+{
+	local dev1=$1
+	local dev2=$2
+
+	_mkfs_dev $dev1
+
+	_mount $dev1 $mnt1
+	$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo >> $seqres.full
+	$UMOUNT_PROG $mnt1
+
+	# device dump of $dev1 to $dev2
+	dd if=$dev1 of=$dev2 conv=fsync status=none || _fail "dd failed: $?"
+}
+
+mnt1=$TEST_DIR/$seq/mnt1
+rm -r -f $mnt1
+mkdir -p $mnt1
+
+mnt2=$TEST_DIR/$seq/mnt2
+rm -r -f $mnt2
+mkdir -p $mnt2
+
+loop_file1="$TEST_DIR/$seq/image1"
+rm -r -f $loop_file1
+truncate -s 300m "$loop_file1"
+loop_dev1=$(_create_loop_device "$loop_file1")
+
+loop_file2="$TEST_DIR/$seq/image2"
+rm -r -f $loop_file2
+truncate -s 300m "$loop_file2"
+loop_dev2=$(_create_loop_device "$loop_file2")
+
+clone_filesystem ${loop_dev1} ${loop_dev2}
+
+# Mounting original device
+_mount $loop_dev1 $mnt1
+$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $mnt1/foo | _filter_xfs_io
+
+# Mounting cloned device
+_mount $loop_dev2 $mnt2 || _fail "mount of cloned device failed"
+
+# cp reflink across two different filesystems must fail
+_cp_reflink $mnt1/foo $mnt2/bar 2>&1 | _filter_test_dir
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/744.out b/tests/generic/744.out
new file mode 100644
index 000000000000..1850a0ea2a5e
--- /dev/null
+++ b/tests/generic/744.out
@@ -0,0 +1,4 @@ 
+QA output created by 744
+wrote 9000/9000 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+cp: failed to clone 'TEST_DIR/744/mnt2/bar' from 'TEST_DIR/744/mnt1/foo': Invalid cross-device link