On Thu, Feb 15, 2024 at 6:35 AM Anand Jain <anand.jain@xxxxxxxxxx> wrote: > > If another device with the same fsid and uuid would mount then verify if > it mounts with a temporary fsid. > > Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx> > --- > tests/btrfs/312 | 67 +++++++++++++++++++++++++++++++++++++++++++++ > tests/btrfs/312.out | 19 +++++++++++++ > 2 files changed, 86 insertions(+) > create mode 100755 tests/btrfs/312 > create mode 100644 tests/btrfs/312.out > > diff --git a/tests/btrfs/312 b/tests/btrfs/312 > new file mode 100755 > index 000000000000..782490b1c62f > --- /dev/null > +++ b/tests/btrfs/312 > @@ -0,0 +1,67 @@ > +#! /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 tempfsid Also add the 'clone' group, as it uses reflinks. > + > +_cleanup() > +{ > + cd / > + umount $mnt1 > /dev/null 2>&1 Use $UMOUNT_PROG. > + rm -r -f $tmp.* > + rm -r -f $mnt1 > +} > + > +. ./common/filter.btrfs > +. ./common/reflink > + > +_supported_fs btrfs > +_require_btrfs_sysfs_fsid > +_require_btrfs_fs_feature temp_fsid > +_require_btrfs_command inspect-internal dump-super > +_require_scratch_dev_pool 2 > +_scratch_dev_pool_get 2 > + > +mnt1=$TEST_DIR/$seq/mnt1 > +mkdir -p $mnt1 > + > +mount_cloned_device() > +{ > + local ret > + > + 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 > $tmp.cp.out 2>&1 > + ret=$? > + cat $tmp.cp.out | _filter_testdir_and_scratch > + if [ $ret -ne 1 ]; then > + _fail "reflink failed to fail" > + fi Such complexity to check if a reflink fails... All this could be accomplished with a single line: _cp_reflink $SCRATCH_MNT/foo $mnt1/bar And then have the golden output expect an error message. That's the most standard and prefered way to do things in fstests. No need to redirect stdout and stderr to a temporary file, check return value, check the temporary file, etc... > + > + check_fsid ${SCRATCH_DEV_NAME[1]} > +} > + > +mount_cloned_device Really, why have all the test code inside a function that is called only once? Get rid of the function... Thanks. > + > +_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 > index 000000000000..b7de6ce3cc6e > --- /dev/null > +++ b/tests/btrfs/312.out > @@ -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 > -- > 2.39.3 > >