]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs: check if cloned device mounts with tempfsid
authorAnand Jain <anand.jain@oracle.com>
Mon, 19 Feb 2024 19:48:45 +0000 (03:48 +0800)
committerZorro Lang <zlang@kernel.org>
Fri, 1 Mar 2024 11:22:36 +0000 (19:22 +0800)
If another device with the same fsid and uuid would mount then verify if
it mounts with a temporary fsid.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
tests/btrfs/312 [new file with mode: 0755]
tests/btrfs/312.out [new file with mode: 0644]

diff --git a/tests/btrfs/312 b/tests/btrfs/312
new file mode 100755 (executable)
index 0000000..eedcf11
--- /dev/null
@@ -0,0 +1,78 @@
+#! /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
new file mode 100644 (file)
index 0000000..b7de6ce
--- /dev/null
@@ -0,0 +1,19 @@
+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