btrfs: functional test cases for tempfsid
PATCH v3 1/10 assign SCRATCH_DEV_POOL to an array
In reply to Anand JainMany test cases use local variables to manage the names of each device in SCRATCH_DEV_POOL. Let _scratch_dev_pool_get set an array, SCRATCH_DEV_NAME, for it.
Usage:
_scratch_dev_pool_get <n>
# device names are in the array SCRATCH_DEV_NAME.
${SCRATCH_DEV_NAME[0]} ${SCRATCH_DEV_NAME[1]} ...
_scratch_dev_pool_put---
v3: add rb
v2:
Fix typo in the commit log.
Fix array SCRATCH_DEV_POOL_SAVED handling.
common/rc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
common/rc +14 -4
@@ -835,8 +835,9 @@ _spare_dev_put() # to make sure it has the enough scratch devices including # replace-target and spare device. Now arg1 here is the # required number of scratch devices by a-test-case excluding -# the replace-target and spare device. So this function will -# set SCRATCH_DEV_POOL to the specified number of devices. +# the replace-target and spare device. So, this function sets +# SCRATCH_DEV_POOL to the specified number of devices and also +# sets a SCRATCH_DEV_NAME array with the names of the devices. # # Usage: # _scratch_dev_pool_get() <ndevs>
@@ -867,19 +868,28 @@ _scratch_dev_pool_get() export SCRATCH_DEV_POOL_SAVED SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs} export SCRATCH_DEV_POOL + SCRATCH_DEV_NAME=( $SCRATCH_DEV_POOL ) + export SCRATCH_DEV_NAME } _scratch_dev_pool_put() { + local ret1 + local ret2 + typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1 - if [ $? -ne 0 ]; then + ret1=$? + typeset -p SCRATCH_DEV_NAME >/dev/null 2>&1 + ret2=$? + if [[ $ret1 -ne 0 || $ret2 -ne 0 ]]; then _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put" fi - if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then + if [[ -z "$SCRATCH_DEV_POOL_SAVED" || -z "${SCRATCH_DEV_NAME[@]}" ]]; then _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put" fi + export SCRATCH_DEV_NAME=() export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED export SCRATCH_DEV_POOL_SAVED="" }
Signature · 1 line
2.39.3
v3 cover btrfs: functional test cases for tempfsid
v3: Mainly, move the prerequisite checks
_require_btrfs_command inspect-internal dump-super _require_btrfs_mkfs_uuid_option
to the common/btrfs function mkfs_clone() and move
_require_btrfs_command inspect-internal dump-super
to check_fsid() from each individual testcase. A few more changes as in each individual testcase.
v2: Each individual patch has undergone numerous fixes based on the feedback received. Please refer to the individual patches.
This patch set validates the tempfsid feature in Btrfs, testing its functionality and limitations. Also, has one minor bug fix.
Anand Jain (10):
assign SCRATCH_DEV_POOL to an array
btrfs: introduce tempfsid test group
btrfs: create a helper function, check_fsid(), to verify the tempfsid
btrfs: verify that subvolume mounts are unaffected by tempfsid
btrfs: check if cloned device mounts with tempfsid
btrfs: test case prerequisite _require_btrfs_mkfs_uuid_option
btrfs: introduce helper for creating cloned devices with mkfs
btrfs: verify tempfsid clones using mkfs
btrfs: validate send-receive operation with tempfsid.
btrfs: test tempfsid with device add, seed, and balance
common/btrfs | 71 ++++++++++++++++++++++++++++++++++++ common/rc | 18 +++++++--- doc/group-names.txt | 1 + tests/btrfs/311 | 88 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/311.out | 24 +++++++++++++ tests/btrfs/312 | 84 +++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/312.out | 19 ++++++++++ tests/btrfs/313 | 53 +++++++++++++++++++++++++++ tests/btrfs/313.out | 16 +++++++++ tests/btrfs/314 | 79 ++++++++++++++++++++++++++++++++++++++++ tests/btrfs/314.out | 23 ++++++++++++ tests/btrfs/315 | 78 ++++++++++++++++++++++++++++++++++++++++ tests/btrfs/315.out | 10 ++++++ 13 files changed, 560 insertions(+), 4 deletions(-) create mode 100755 tests/btrfs/311 create mode 100644 tests/btrfs/311.out create mode 100755 tests/btrfs/312 create mode 100644 tests/btrfs/312.out create mode 100755 tests/btrfs/313 create mode 100644 tests/btrfs/313.out create mode 100755 tests/btrfs/314 create mode 100644 tests/btrfs/314.out create mode 100755 tests/btrfs/315 create mode 100644 tests/btrfs/315.out
Signature · 1 line
2.39.3
PATCH v3 2/10 btrfs: introduce tempfsid test group
Introducing a new test group named tempfsid.
Tempfsid is a feature of the Btrfs filesystem. When encountering another device with the same fsid as one already mounted, the system will mount the new device with a temporary, randomly generated in-memory fsid.
---
v3: -
v2: add rb.
doc/group-names.txt | 1 + 1 file changed, 1 insertion(+)
doc/group-names.txt +1 -0
@@ -131,6 +131,7 @@ swap swap files swapext XFS_IOC_SWAPEXT ioctl symlink symbolic links tape dump and restore with a tape +tempfsid temporary fsid thin thin provisioning trim FITRIM ioctl udf UDF functionality tests
Signature · 1 line
2.39.3
PATCH v3 3/10 btrfs: create a helper function, check_fsid(), to verify the tempfsid
In reply to Anand Jaincheck_fsid() provides a method to verify if the given device is mounted with the tempfsid in the kernel. Function sb() is an internal only function.
---
v3:
add rb
add _require_btrfs_command inspect-internal dump-super
v2:
Fix typo in the commit log.
Fix array SCRATCH_DEV_POOL_SAVED handling.
common/btrfs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
common/btrfs +37 -0
@@ -792,3 +792,40 @@ _has_btrfs_sysfs_feature_attr() test -e /sys/fs/btrfs/features/$feature_attr } + +# Print the fsid and metadata uuid replaced with constant strings FSID and +# METADATA_UUID. Compare temp_fsid with fsid and metadata_uuid, then echo what +# it matches to or TEMP_FSID. This helps in comparing with the golden output. +check_fsid() +{ + local dev1=$1 + local fsid + local metadata_uuid + + _require_btrfs_command inspect-internal dump-super + + # on disk fsid + fsid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep ^fsid | $AWK_PROG -d" " '{print $2}') + echo -e "On disk fsid:\t\t$fsid" | sed -e "s/$fsid/FSID/g" + + # Print FSID even if it is not the same as metadata_uuid because it has + # to match in the golden output. + metadata_uuid=$(cat /sys/fs/btrfs/$fsid/metadata_uuid) + echo -e "Metadata uuid:\t\tFSID" + + # This returns the temp_fsid if set + tempfsid=$(_btrfs_get_fsid $dev1) + if [[ $tempfsid == $fsid ]]; then + echo -e "Temp fsid:\t\tFSID" + elif [[ $tempfsid == $metadata_uuid ]]; then + # If we are here, it means there is a bug; let it not match with + # the golden output. + echo -e "Temp fsid:\t\t$metadata_uuid" + else + echo -e "Temp fsid:\t\tTEMPFSID" + fi + + echo -e -n "Tempfsid status:\t" + cat /sys/fs/btrfs/$tempfsid/temp_fsid +}
Signature · 1 line
2.39.3
PATCH v3 4/10 btrfs: verify that subvolume mounts are unaffected by tempfsid
In reply to Anand JainThe tempfsid logic must determine whether the incoming mount request is for a device already mounted or a new device mount. Verify that it recognizes the device already mounted well by creating reflink across the subvolume mount points.
---
v3:
Fix subvolume create output with _filter_scratch and its golden output add rb
remove _require_btrfs_command inspect-internal dump-super v2:
add subvol group
use $UMOUNT_PROG
remove _fail for _cp_reflink
tests/btrfs/311 | 88 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/311.out | 24 +++++++++++++ 2 files changed, 112 insertions(+) create mode 100755 tests/btrfs/311 create mode 100644 tests/btrfs/311.out
tests/btrfs/311 new file +88 -0
@@ -0,0 +1,88 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 311 +# +# Mount the device twice check if the reflink works, this helps to +# ensure device is mounted as the same device. +# +. ./common/preamble +_begin_fstest auto quick subvol tempfsid + +# Override the default cleanup function. +_cleanup() +{ + cd / + $UMOUNT_PROG $mnt1 > /dev/null 2>&1 + rm -r -f $tmp.* + rm -r -f $mnt1 +} + +. ./common/filter.btrfs +. ./common/reflink + +# Modify as appropriate. +_supported_fs btrfs +_require_cp_reflink +_require_btrfs_sysfs_fsid +_require_btrfs_fs_feature temp_fsid +_require_scratch + +mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +same_dev_mount() +{ + echo ---- $FUNCNAME ---- + + _scratch_mkfs >> $seqres.full 2>&1 + + _scratch_mount + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \ + _filter_xfs_io + + echo Mount the device again to a different mount point + _mount $SCRATCH_DEV $mnt1 + + _cp_reflink $SCRATCH_MNT/foo $mnt1/bar + echo Checksum of reflinked files + md5sum $SCRATCH_MNT/foo | _filter_scratch + md5sum $mnt1/bar | _filter_test_dir + + check_fsid $SCRATCH_DEV +} + +same_dev_subvol_mount() +{ + echo ---- $FUNCNAME ---- + _scratch_mkfs >> $seqres.full 2>&1 + + _scratch_mount + $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/subvol/foo | \ + _filter_xfs_io + + echo Mounting a subvol + _mount -o subvol=subvol $SCRATCH_DEV $mnt1 + + _cp_reflink $SCRATCH_MNT/subvol/foo $mnt1/bar + echo Checksum of reflinked files + md5sum $SCRATCH_MNT/subvol/foo | _filter_scratch + md5sum $mnt1/bar | _filter_test_dir + + check_fsid $SCRATCH_DEV +} + +same_dev_mount + +_scratch_unmount +_cleanup +mkdir -p $mnt1 + +same_dev_subvol_mount + +# success, all done +status=0 +exit
tests/btrfs/311.out new file +24 -0
@@ -0,0 +1,24 @@ +QA output created by 311 +---- same_dev_mount ---- +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Mount the device again to a different mount point +Checksum of reflinked files +42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/foo +42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/311/mnt1/bar +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0 +---- same_dev_subvol_mount ---- +Create subvolume 'SCRATCH_MNT/subvol' +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Mounting a subvol +Checksum of reflinked files +42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/subvol/foo +42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/311/mnt1/bar +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0
Signature · 1 line
2.39.3
PATCH v3 5/10 btrfs: check if cloned device mounts with tempfsid
In reply to Anand JainIf another device with the same fsid and uuid would mount then verify if it mounts with a temporary fsid.
---
v3:
add clone group
fix use $UMOUNT_PROG
remove (_require_btrfs_command inspect-internal dump-super) v2:
Bring create_cloned_devices() into the testcase. Just use _cp_reflink output to match with golden output.
tests/btrfs/312 | 84 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/312.out | 19 ++++++++++ 2 files changed, 103 insertions(+) create mode 100755 tests/btrfs/312 create mode 100644 tests/btrfs/312.out
tests/btrfs/312 new file +84 -0
@@ -0,0 +1,84 @@ +#! /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_btrfs_sysfs_fsid +_require_btrfs_fs_feature temp_fsid +_require_scratch_dev_pool 2 +_scratch_dev_pool_get 2 + +mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +create_cloned_devices() +{ + local dev1=$1 + local dev2=$2 + + [[ -z $dev1 || -z $dev2 ]] && \ + _fail "create_cloned_devices() requires two devices as arguments" + + 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() +{ + 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 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
tests/btrfs/312.out new file +19 -0
@@ -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
Signature · 1 line
2.39.3
PATCH v3 6/10 btrfs: test case prerequisite _require_btrfs_mkfs_uuid_option
In reply to Anand JainFor easier and more effective testing of btrfs tempfsid, newer versions of mkfs.btrfs contain options such as --device-uuid. Check if the currently running mkfs.btrfs contains this option.
---
v3:
add rb
v2:
Fix coding style, add space before grep
Fix typp option -> options
common/btrfs | 11 +++++++++++ 1 file changed, 11 insertions(+)
common/btrfs +11 -0
@@ -88,6 +88,17 @@ _require_btrfs_mkfs_feature() _notrun "Feature $feat not supported in the available version of mkfs.btrfs" } +_require_btrfs_mkfs_uuid_option() +{ + local cnt + + cnt=$($MKFS_BTRFS_PROG --help 2>&1 | \ + grep -E --count "\-\-uuid|\-\-device-uuid") + if [ $cnt != 2 ]; then + _notrun "Require $MKFS_BTRFS_PROG with --uuid and --device-uuid options" + fi +} + _require_btrfs_fs_feature() { if [ -z $1 ]; then
Signature · 1 line
2.39.3
PATCH v3 7/10 btrfs: introduce helper for creating cloned devices with mkfs
In reply to Anand JainUse newer mkfs.btrfs option to generate two cloned devices, used in test cases.
---
v3:
call
_require_btrfs_command inspect-internal dump-super _require_btrfs_mkfs_uuid_option
in the function mkfs_clone()
Remove the conflict fix metadata line
v2:
Organize changes to its right patch.
Fix _fail erorr message.
Declare local variables for fsid and uuid.
common/btrfs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
common/btrfs +23 -0
@@ -840,3 +840,26 @@ check_fsid() echo -e -n "Tempfsid status:\t" cat /sys/fs/btrfs/$tempfsid/temp_fsid } + +mkfs_clone() +{ + local fsid + local uuid + local dev1=$1 + local dev2=$2 + + _require_btrfs_command inspect-internal dump-super + _require_btrfs_mkfs_uuid_option + + [[ -z $dev1 || -z $dev2 ]] && \ + _fail "mkfs_clone requires two devices as arguments" + + _mkfs_dev -fq $dev1 + + fsid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep -E ^fsid | $AWK_PROG '{print $2}') + uuid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep -E ^dev_item.uuid | $AWK_PROG '{print $2}') + + _mkfs_dev -fq --uuid $fsid --device-uuid $uuid $dev2 +}
Signature · 1 line
2.39.3
PATCH v3 8/10 btrfs: verify tempfsid clones using mkfs
In reply to Anand JainCreate appearing to be a clone using the mkfs.btrfs option and test if the tempfsid is active.
---
v3:
prerequisite checks are in the function mkfs_clone(), remove from the testcase.
v2:
Remove unnecessary function.
Add clone group
use $UMOUNT_PROG
Let _cp_reflink fail on the stdout.
tests/btrfs/313 | 53 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/313.out | 16 ++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 tests/btrfs/313 create mode 100644 tests/btrfs/313.out
tests/btrfs/313 new file +53 -0
@@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 313 +# +# Functional test for the tempfsid, clone devices created using the mkfs option. +# +. ./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_cp_reflink +_require_btrfs_sysfs_fsid +_require_scratch_dev_pool 2 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 2 + +mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +echo ---- clone_uuids_verify_tempfsid ---- +mkfs_clone ${SCRATCH_DEV_NAME[0]} ${SCRATCH_DEV_NAME[1]} + +echo Mounting original device +_mount ${SCRATCH_DEV_NAME[0]} $SCRATCH_MNT +check_fsid ${SCRATCH_DEV_NAME[0]} + +echo Mounting cloned device +_mount ${SCRATCH_DEV_NAME[1]} $mnt1 +check_fsid ${SCRATCH_DEV_NAME[1]} + +$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | _filter_xfs_io +echo cp reflink must fail +_cp_reflink $SCRATCH_MNT/foo $mnt1/bar 2>&1 | _filter_testdir_and_scratch + +_scratch_dev_pool_put + +# success, all done +status=0 +exit
tests/btrfs/313.out new file +16 -0
@@ -0,0 +1,16 @@ +QA output created by 313 +---- clone_uuids_verify_tempfsid ---- +Mounting original device +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0 +Mounting cloned device +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: TEMPFSID +Tempfsid status: 1 +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +cp reflink must fail +cp: failed to clone 'TEST_DIR/313/mnt1/bar' from 'SCRATCH_MNT/foo': Invalid cross-device link
Signature · 1 line
2.39.3
PATCH v3 9/10 btrfs: validate send-receive operation with tempfsid.
In reply to Anand JainGiven concurrent mounting of both the original and its clone device on the same system, this test confirms the integrity of send and receive operations in the presence of active tempfsid.
---
v3:
Drop prerequisite check in the testcase
v2:
Organize changes to its right patch.
Fix _fail erorr message.
Declare local variables for fsid and uuid.
tests/btrfs/314 | 79 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/314.out | 23 +++++++++++++ 2 files changed, 102 insertions(+) create mode 100755 tests/btrfs/314 create mode 100644 tests/btrfs/314.out
tests/btrfs/314 new file +79 -0
@@ -0,0 +1,79 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 314 +# +# Send and receive functionality test between a normal and +# tempfsid filesystem. +# +. ./common/preamble +_begin_fstest auto quick snapshot send tempfsid + +_cleanup() +{ + cd / + $UMOUNT_PROG $tempfsid_mnt 2>/dev/null + rm -r -f $tmp.* + rm -r -f $sendfile + rm -r -f $tempfsid_mnt +} + +. ./common/filter.btrfs + +_supported_fs btrfs +_require_btrfs_sysfs_fsid +_require_scratch_dev_pool 2 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 2 + +# mount point for the tempfsid device +tempfsid_mnt=$TEST_DIR/$seq/tempfsid_mnt +sendfile=$TEST_DIR/$seq/replicate.send + +send_receive_tempfsid() +{ + local src=$1 + local dst=$2 + + # Use first 2 devices from the SCRATCH_DEV_POOL + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + _scratch_mount + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' ${src}/foo | _filter_xfs_io + $BTRFS_UTIL_PROG subvolume snapshot -r ${src} ${src}/snap1 | \ + _filter_testdir_and_scratch + + echo Send ${src} | _filter_testdir_and_scratch + $BTRFS_UTIL_PROG send -f ${sendfile} ${src}/snap1 2>&1 | \ + _filter_testdir_and_scratch + echo Receive ${dst} | _filter_testdir_and_scratch + $BTRFS_UTIL_PROG receive -f ${sendfile} ${dst} | \ + _filter_testdir_and_scratch + echo -e -n "Send:\t" + md5sum ${src}/foo | _filter_testdir_and_scratch + echo -e -n "Recv:\t" + md5sum ${dst}/snap1/foo | _filter_testdir_and_scratch +} + +mkdir -p $tempfsid_mnt + +echo -e \\nFrom non-tempfsid ${SCRATCH_MNT} to tempfsid ${tempfsid_mnt} | \ + _filter_testdir_and_scratch +send_receive_tempfsid $SCRATCH_MNT $tempfsid_mnt + +_scratch_unmount +_cleanup +mkdir -p $tempfsid_mnt + +echo -e \\nFrom tempfsid ${tempfsid_mnt} to non-tempfsid ${SCRATCH_MNT} | \ + _filter_testdir_and_scratch +send_receive_tempfsid $tempfsid_mnt $SCRATCH_MNT + +_scratch_dev_pool_put + +# success, all done +status=0 +exit
tests/btrfs/314.out new file +23 -0
@@ -0,0 +1,23 @@ +QA output created by 314 + +From non-tempfsid SCRATCH_MNT to tempfsid TEST_DIR/314/tempfsid_mnt +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Create a readonly snapshot of 'SCRATCH_MNT' in 'SCRATCH_MNT/snap1' +Send SCRATCH_MNT +At subvol SCRATCH_MNT/snap1 +Receive TEST_DIR/314/tempfsid_mnt +At subvol snap1 +Send: 42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/foo +Recv: 42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/314/tempfsid_mnt/snap1/foo + +From tempfsid TEST_DIR/314/tempfsid_mnt to non-tempfsid SCRATCH_MNT +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Create a readonly snapshot of 'TEST_DIR/314/tempfsid_mnt' in 'TEST_DIR/314/tempfsid_mnt/snap1' +Send TEST_DIR/314/tempfsid_mnt +At subvol TEST_DIR/314/tempfsid_mnt/snap1 +Receive SCRATCH_MNT +At subvol snap1 +Send: 42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/314/tempfsid_mnt/foo +Recv: 42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/snap1/foo
Signature · 1 line
2.39.3
PATCH v3 10/10 btrfs: test tempfsid with device add, seed, and balance
In reply to Anand JainMake sure that basic functions such as seeding and device add fail, while balance runs successfully with tempfsid.
---
v3:
Comment updated.
Add balance group.
Drop prerequisite checks.
Use error (from subvol create) in the golden output instead of calling _fail.
v2:
Remove unnecessary function.
Add clone group
use $UMOUNT_PROG
Let _cp_reflink fail on the stdout.
tests/btrfs/315 | 78 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/315.out | 10 ++++++ 2 files changed, 88 insertions(+) create mode 100755 tests/btrfs/315 create mode 100644 tests/btrfs/315.out
tests/btrfs/315 new file +78 -0
@@ -0,0 +1,78 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 315 +# +# Verify if the seed and device add to a tempfsid filesystem fails +# and balance devices is successful. +# +. ./common/preamble +_begin_fstest auto quick volume seed balance tempfsid + +_cleanup() +{ + cd / + $UMOUNT_PROG $tempfsid_mnt 2>/dev/null + rm -r -f $tmp.* + rm -r -f $tempfsid_mnt +} + +. ./common/filter.btrfs + +_supported_fs btrfs +_require_btrfs_sysfs_fsid +_require_scratch_dev_pool 3 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 3 + +# mount point for the tempfsid device +tempfsid_mnt=$TEST_DIR/$seq/tempfsid_mnt + +seed_device_must_fail() +{ + echo ---- $FUNCNAME ---- + + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + + $BTRFS_TUNE_PROG -S 1 ${SCRATCH_DEV} + $BTRFS_TUNE_PROG -S 1 ${SCRATCH_DEV_NAME[1]} + + _scratch_mount 2>&1 | _filter_scratch + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} 2>&1 | _filter_test_dir +} + +device_add_must_fail() +{ + echo ---- $FUNCNAME ---- + + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + _scratch_mount + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \ + _filter_xfs_io + +$BTRFS_UTIL_PROG device add -f ${SCRATCH_DEV_NAME[2]} ${tempfsid_mnt} 2>&1 | \ + grep -v "Performing full device TRIM" | _filter_scratch_pool + + echo Balance must be successful + _run_btrfs_balance_start ${tempfsid_mnt} +} + +mkdir -p $tempfsid_mnt + +seed_device_must_fail + +_scratch_unmount +_cleanup +mkdir -p $tempfsid_mnt + +device_add_must_fail + +_scratch_dev_pool_put + +# success, all done +status=0 +exit
tests/btrfs/315.out new file +10 -0
@@ -0,0 +1,10 @@ +QA output created by 315 +---- seed_device_must_fail ---- +mount: SCRATCH_MNT: WARNING: source write-protected, mounted read-only. +mount: TEST_DIR/315/tempfsid_mnt: mount(2) system call failed: File exists. +---- device_add_must_fail ---- +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +ERROR: error adding device 'SCRATCH_DEV': Invalid argument +Balance must be successful +Done, had to relocate 3 out of 3 chunks
Signature · 1 line
2.39.3
Re: [PATCH v3 03/10] btrfs: create a helper function, check_fsid(), to verify the tempfsid
In reply to Anand JainQuoted 27 lines · Anand Jain
check_fsid()provides a method to verify if the given device is mounted with the tempfsid in the kernel. Functionsb()is an internal only function.Signed-off-by Anand Jain <[email protected]>Reviewed-by Filipe Manana <[email protected]>---
v3:
add rb
add_require_btrfs_commandinspect-internal dump-super
v2:
Fix typo in the commit log.
Fix arraySCRATCH_DEV_POOL_SAVEDhandling.common/btrfs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)common/btrfs +1
-0@@ -792,3 +792,40 @@ _has_btrfs_sysfs_feature_attr() test -e /sys/fs/btrfs/features/$feature_attr } +
common/btrfs _has_btrfs_sysfs_feature_attr() · line 805
Quoted 10 lines
common/btrfs +10
-0+# Print the fsid and metadata uuid replaced with constant strings FSID and +# METADATA_UUID. Compare temp_fsid with fsid and metadata_uuid, then echo what +# it matches to or TEMP_FSID. This helps in comparing with the golden output. +check_fsid() +{ + local dev1=$1 + local fsid + local metadata_uuid + + _require_btrfs_command inspect-internal dump-super
So, as pointed out in the previous version of the patchset, the function should do the require for everything it needs that may not be available.
It's doing for the inspect-internal command, but it's missing a:
_require_btrfs_sysfs_fsid
Instead this is being called for every test case that calls this new helper function, when those requirements should be hidden from the tests themselves.
Thanks.
Quoted 29 lines
common/btrfs +26
-1+ + # on disk fsid + fsid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep ^fsid | $AWK_PROG -d" " '{print $2}') + echo -e "On disk fsid:\t\t$fsid" | sed -e "s/$fsid/FSID/g" + + # Print FSID even if it is not the same as metadata_uuid because it has + # to match in the golden output. + metadata_uuid=$(cat /sys/fs/btrfs/$fsid/metadata_uuid) + echo -e "Metadata uuid:\t\tFSID" + + # This returns the temp_fsid if set + tempfsid=$(_btrfs_get_fsid $dev1) + if [[ $tempfsid == $fsid ]]; then + echo -e "Temp fsid:\t\tFSID" + elif [[ $tempfsid == $metadata_uuid ]]; then + # If we are here, it means there is a bug; let it not match with + # the golden output. + echo -e "Temp fsid:\t\t$metadata_uuid" + else + echo -e "Temp fsid:\t\tTEMPFSID" + fi + + echo -e -n "Tempfsid status:\t" + cat /sys/fs/btrfs/$tempfsid/temp_fsid +} --2.39.3
Re: [PATCH v3 04/10] btrfs: verify that subvolume mounts are unaffected by tempfsid
In reply to Anand JainQuoted 49 lines · Anand Jain
The tempfsid logic must determine whether the incoming mount request is for a device already mounted or a new device mount. Verify that it recognizes the device already mounted well by creating reflink across the subvolume mount points.
Signed-off-by Anand Jain <[email protected]>Reviewed-by Filipe Manana <[email protected]>Signed-off-by Anand Jain <[email protected]>---
v3:
Fix subvolume create output with_filter_scratchand its golden output add rb
remove_require_btrfs_commandinspect-internal dump-super v2:
add subvol group
use $UMOUNT_PROG
remove_failfor_cp_reflinktests/btrfs/311 | 88 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/311.out | 24 +++++++++++++ 2 files changed, 112 insertions(+) create mode 100755 tests/btrfs/311 create mode 100644 tests/btrfs/311.outtests/btrfs/311 new file +18
-0@@ -0,0 +1,88 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 311 +# +# Mount the device twice check if the reflink works, this helps to +# ensure device is mounted as the same device. +# +. ./common/preamble +_begin_fstest auto quick subvol tempfsid + +# Override the default cleanup function. +_cleanup() +{ + cd / + $UMOUNT_PROG $mnt1 > /dev/null 2>&1 + rm -r -f $tmp.*
tests/btrfs/311 line 28
Quoted 10 lines
tests/btrfs/311 new file +10
-0+ rm -r -f $mnt1 +} + +. ./common/filter.btrfs +. ./common/reflink + +# Modify as appropriate. +_supported_fs btrfs +_require_cp_reflink +_require_btrfs_sysfs_fsid
This requirement should be inside the check_fsid() helper, as pointed before.
Thanks.
Quoted 93 lines
tests/btrfs/311 new file +60
-0+_require_btrfs_fs_feature temp_fsid +_require_scratch + +mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +same_dev_mount() +{ + echo ---- $FUNCNAME ---- + + _scratch_mkfs >> $seqres.full 2>&1 + + _scratch_mount + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \ + _filter_xfs_io + + echo Mount the device again to a different mount point + _mount $SCRATCH_DEV $mnt1 + + _cp_reflink $SCRATCH_MNT/foo $mnt1/bar + echo Checksum of reflinked files + md5sum $SCRATCH_MNT/foo | _filter_scratch + md5sum $mnt1/bar | _filter_test_dir + + check_fsid $SCRATCH_DEV +} + +same_dev_subvol_mount() +{ + echo ---- $FUNCNAME ---- + _scratch_mkfs >> $seqres.full 2>&1 + + _scratch_mount + $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/subvol/foo | \ + _filter_xfs_io + + echo Mounting a subvol + _mount -o subvol=subvol $SCRATCH_DEV $mnt1 + + _cp_reflink $SCRATCH_MNT/subvol/foo $mnt1/bar + echo Checksum of reflinked files + md5sum $SCRATCH_MNT/subvol/foo | _filter_scratch + md5sum $mnt1/bar | _filter_test_dir + + check_fsid $SCRATCH_DEV +} + +same_dev_mount + +_scratch_unmount +_cleanup +mkdir -p $mnt1 + +same_dev_subvol_mount + +# success, all done +status=0 +exittests/btrfs/311.out new file +24
-1@@ -0,0 +1,24 @@ +QA output created by 311 +---- same_dev_mount ---- +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Mount the device again to a different mount point +Checksum of reflinked files +42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/foo +42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/311/mnt1/bar +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0 +---- same_dev_subvol_mount ---- +Create subvolume 'SCRATCH_MNT/subvol' +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Mounting a subvol +Checksum of reflinked files +42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/subvol/foo +42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/311/mnt1/bar +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0 --2.39.3
Re: [PATCH v3 05/10] btrfs: check if cloned device mounts with tempfsid
In reply to Anand JainQuoted 40 lines · Anand Jain
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 <[email protected]>---
v3:
add clone group
fix use $UMOUNT_PROG
remove (_require_btrfs_commandinspect-internal dump-super) v2:
Bringcreate_cloned_devices()into the testcase. Just use_cp_reflinkoutput to match with golden output.tests/btrfs/312 | 84 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/312.out | 19 ++++++++++ 2 files changed, 103 insertions(+) create mode 100755 tests/btrfs/312 create mode 100644 tests/btrfs/312.outtests/btrfs/312 new file +14
-0@@ -0,0 +1,84 @@ +#! /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 /
tests/btrfs/312 line 24
Quoted 10 lines
tests/btrfs/312 new file +10
-0+ $UMOUNT_PROG $mnt1 > /dev/null 2>&1 + rm -r -f $tmp.* + rm -r -f $mnt1 +} + +. ./common/filter.btrfs +. ./common/reflink + +_supported_fs btrfs +_require_btrfs_sysfs_fsid
This requirement should be inside the check_fsid() helper, as pointed before.
Quoted 4 lines
tests/btrfs/312 new file +4
-0+_require_btrfs_fs_feature temp_fsid +_require_scratch_dev_pool 2 +_scratch_dev_pool_get 2 +
tests/btrfs/312 line 38
Quoted 10 lines
tests/btrfs/312 new file +10
-0+mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +create_cloned_devices() +{ + local dev1=$1 + local dev2=$2 + + [[ -z $dev1 || -z $dev2 ]] && \ + _fail "create_cloned_devices() requires two devices as arguments"
Now that the function is not generic, in common/btrfs, and used only once in this test, this check doesn't make that much sense anymore.
tests/btrfs/312 line 40
Quoted 2 lines
tests/btrfs/312 new file +2
-0+ + echo -n Creating cloned device...
Wondering why the -n here, makes the golden output a bit weird.
Quoted 6 lines
tests/btrfs/312 new file +6
-0+ _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
tests/btrfs/312 line 56
Quoted 10 lines
tests/btrfs/312 new file +10
-0+ $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() +{ + local ret
Unused variable.
Thanks.
Quoted 56 lines
tests/btrfs/312 new file +28
-0+ + 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 +exittests/btrfs/312.out new file +19
-1@@ -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
Re: [PATCH v3 07/10] btrfs: introduce helper for creating cloned devices with mkfs
In reply to Anand JainQuoted 5 lines · Anand Jain
Use newer mkfs.btrfs option to generate two cloned devices, used in test cases.
Signed-off-by Anand Jain <[email protected]>
Looks good, thanks.
Quoted 50 lines
---
v3:
call
_require_btrfs_commandinspect-internal dump-super_require_btrfs_mkfs_uuid_option
in the functionmkfs_clone()
Remove the conflict fix metadata linev2:
Organize changes to its right patch.
Fix_failerorr message.
Declare local variables for fsid and uuid.common/btrfs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)common/btrfs +23
-1@@ -840,3 +840,26 @@ check_fsid() echo -e -n "Tempfsid status:\t" cat /sys/fs/btrfs/$tempfsid/temp_fsid } + +mkfs_clone() +{ + local fsid + local uuid + local dev1=$1 + local dev2=$2 + + _require_btrfs_command inspect-internal dump-super + _require_btrfs_mkfs_uuid_option + + [[ -z $dev1 || -z $dev2 ]] && \ + _fail "mkfs_clone requires two devices as arguments" + + _mkfs_dev -fq $dev1 + + fsid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep -E ^fsid | $AWK_PROG '{print $2}') + uuid=$($BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | \ + grep -E ^dev_item.uuid | $AWK_PROG '{print $2}') + + _mkfs_dev -fq --uuid $fsid --device-uuid $uuid $dev2 +} --2.39.3
Re: [PATCH v3 08/10] btrfs: verify tempfsid clones using mkfs
In reply to Anand JainQuoted 43 lines · Anand Jain
Create appearing to be a clone using the mkfs.btrfs option and test if the tempfsid is active.
Signed-off-by Anand Jain <[email protected]>---
v3:
prerequisite checks are in the functionmkfs_clone(), remove from the testcase.v2:
Remove unnecessary function.
Add clone group
use $UMOUNT_PROG
Let_cp_reflinkfail on the stdout.tests/btrfs/313 | 53 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/313.out | 16 ++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 tests/btrfs/313 create mode 100644 tests/btrfs/313.outtests/btrfs/313 new file +15
-0@@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 313 +# +# Functional test for the tempfsid, clone devices created using the mkfs option. +# +. ./common/preamble +_begin_fstest auto quick clone tempfsid + +_cleanup() +{ + cd / + $UMOUNT_PROG $mnt1 > /dev/null 2>&1
tests/btrfs/313 line 25
Quoted 10 lines
tests/btrfs/313 new file +10
-0+ rm -r -f $tmp.* + rm -r -f $mnt1 +} + +. ./common/filter.btrfs +. ./common/reflink + +_supported_fs btrfs +_require_cp_reflink +_require_btrfs_sysfs_fsid
This requirement should be inside the check_fsid() helper, as pointed before.
Thanks.
Quoted 53 lines
tests/btrfs/313 new file +28
-0+_require_scratch_dev_pool 2 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 2 + +mnt1=$TEST_DIR/$seq/mnt1 +mkdir -p $mnt1 + +echo ---- clone_uuids_verify_tempfsid ---- +mkfs_clone ${SCRATCH_DEV_NAME[0]} ${SCRATCH_DEV_NAME[1]} + +echo Mounting original device +_mount ${SCRATCH_DEV_NAME[0]} $SCRATCH_MNT +check_fsid ${SCRATCH_DEV_NAME[0]} + +echo Mounting cloned device +_mount ${SCRATCH_DEV_NAME[1]} $mnt1 +check_fsid ${SCRATCH_DEV_NAME[1]} + +$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | _filter_xfs_io +echo cp reflink must fail +_cp_reflink $SCRATCH_MNT/foo $mnt1/bar 2>&1 | _filter_testdir_and_scratch + +_scratch_dev_pool_put + +# success, all done +status=0 +exittests/btrfs/313.out new file +16
-1@@ -0,0 +1,16 @@ +QA output created by 313 +---- clone_uuids_verify_tempfsid ---- +Mounting original device +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: FSID +Tempfsid status: 0 +Mounting cloned device +On disk fsid: FSID +Metadata uuid: FSID +Temp fsid: TEMPFSID +Tempfsid status: 1 +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +cp reflink must fail +cp: failed to clone 'TEST_DIR/313/mnt1/bar' from 'SCRATCH_MNT/foo': Invalid cross-device link --2.39.3
Re: [PATCH v3 09/10] btrfs: validate send-receive operation with tempfsid.
In reply to Anand JainQuoted 42 lines · Anand Jain
Given concurrent mounting of both the original and its clone device on the same system, this test confirms the integrity of send and receive operations in the presence of active tempfsid.
Signed-off-by Anand Jain <[email protected]>---
v3:
Drop prerequisite check in the testcasev2:
Organize changes to its right patch.
Fix_failerorr message.
Declare local variables for fsid and uuid.tests/btrfs/314 | 79 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/314.out | 23 +++++++++++++ 2 files changed, 102 insertions(+) create mode 100755 tests/btrfs/314 create mode 100644 tests/btrfs/314.outtests/btrfs/314 new file +15
-0@@ -0,0 +1,79 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 314 +# +# Send and receive functionality test between a normal and +# tempfsid filesystem. +# +. ./common/preamble +_begin_fstest auto quick snapshot send tempfsid + +_cleanup() +{ + cd /
tests/btrfs/314 line 25
Quoted 10 lines
tests/btrfs/314 new file +10
-0+ $UMOUNT_PROG $tempfsid_mnt 2>/dev/null + rm -r -f $tmp.* + rm -r -f $sendfile + rm -r -f $tempfsid_mnt +} + +. ./common/filter.btrfs + +_supported_fs btrfs +_require_btrfs_sysfs_fsid
This requirement of the sysfs fsid path is not needed in the test, as it's not used anywhere in this test (likely copy-pasted from other tests in this patchset).
Thanks.
Quoted 86 lines
tests/btrfs/314 new file +54
-0+_require_scratch_dev_pool 2 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 2 + +# mount point for the tempfsid device +tempfsid_mnt=$TEST_DIR/$seq/tempfsid_mnt +sendfile=$TEST_DIR/$seq/replicate.send + +send_receive_tempfsid() +{ + local src=$1 + local dst=$2 + + # Use first 2 devices from the SCRATCH_DEV_POOL + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + _scratch_mount + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' ${src}/foo | _filter_xfs_io + $BTRFS_UTIL_PROG subvolume snapshot -r ${src} ${src}/snap1 | \ + _filter_testdir_and_scratch + + echo Send ${src} | _filter_testdir_and_scratch + $BTRFS_UTIL_PROG send -f ${sendfile} ${src}/snap1 2>&1 | \ + _filter_testdir_and_scratch + echo Receive ${dst} | _filter_testdir_and_scratch + $BTRFS_UTIL_PROG receive -f ${sendfile} ${dst} | \ + _filter_testdir_and_scratch + echo -e -n "Send:\t" + md5sum ${src}/foo | _filter_testdir_and_scratch + echo -e -n "Recv:\t" + md5sum ${dst}/snap1/foo | _filter_testdir_and_scratch +} + +mkdir -p $tempfsid_mnt + +echo -e \\nFrom non-tempfsid ${SCRATCH_MNT} to tempfsid ${tempfsid_mnt} | \ + _filter_testdir_and_scratch +send_receive_tempfsid $SCRATCH_MNT $tempfsid_mnt + +_scratch_unmount +_cleanup +mkdir -p $tempfsid_mnt + +echo -e \\nFrom tempfsid ${tempfsid_mnt} to non-tempfsid ${SCRATCH_MNT} | \ + _filter_testdir_and_scratch +send_receive_tempfsid $tempfsid_mnt $SCRATCH_MNT + +_scratch_dev_pool_put + +# success, all done +status=0 +exittests/btrfs/314.out new file +23
-1@@ -0,0 +1,23 @@ +QA output created by 314 + +From non-tempfsid SCRATCH_MNT to tempfsid TEST_DIR/314/tempfsid_mnt +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Create a readonly snapshot of 'SCRATCH_MNT' in 'SCRATCH_MNT/snap1' +Send SCRATCH_MNT +At subvol SCRATCH_MNT/snap1 +Receive TEST_DIR/314/tempfsid_mnt +At subvol snap1 +Send: 42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/foo +Recv: 42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/314/tempfsid_mnt/snap1/foo + +From tempfsid TEST_DIR/314/tempfsid_mnt to non-tempfsid SCRATCH_MNT +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Create a readonly snapshot of 'TEST_DIR/314/tempfsid_mnt' in 'TEST_DIR/314/tempfsid_mnt/snap1' +Send TEST_DIR/314/tempfsid_mnt +At subvol TEST_DIR/314/tempfsid_mnt/snap1 +Receive SCRATCH_MNT +At subvol snap1 +Send: 42d69d1a6d333a7ebdf64792a555e392 TEST_DIR/314/tempfsid_mnt/foo +Recv: 42d69d1a6d333a7ebdf64792a555e392 SCRATCH_MNT/snap1/foo --2.39.3
Re: [PATCH v3 10/10] btrfs: test tempfsid with device add, seed, and balance
In reply to Anand JainQuoted 44 lines · Anand Jain
Make sure that basic functions such as seeding and device add fail, while balance runs successfully with tempfsid.
Signed-off-by Anand Jain <[email protected]>---
v3:
Comment updated.
Add balance group.
Drop prerequisite checks.
Use error (from subvol create) in the golden output instead of calling_fail.v2:
Remove unnecessary function.
Add clone group
use $UMOUNT_PROG
Let_cp_reflinkfail on the stdout.tests/btrfs/315 | 78 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/315.out | 10 ++++++ 2 files changed, 88 insertions(+) create mode 100755 tests/btrfs/315 create mode 100644 tests/btrfs/315.outtests/btrfs/315 new file +14
-0@@ -0,0 +1,78 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 315 +# +# Verify if the seed and device add to a tempfsid filesystem fails +# and balance devices is successful. +# +. ./common/preamble +_begin_fstest auto quick volume seed balance tempfsid + +_cleanup() +{
tests/btrfs/315 line 24
Quoted 10 lines
tests/btrfs/315 new file +10
-0+ cd / + $UMOUNT_PROG $tempfsid_mnt 2>/dev/null + rm -r -f $tmp.* + rm -r -f $tempfsid_mnt +} + +. ./common/filter.btrfs + +_supported_fs btrfs +_require_btrfs_sysfs_fsid
Same as in the previous test case. This requirement is not needed, the sysfs fsid path is not used anywhere in this test, likely copy-pasted from previous test cases in this patchset.
Thanks.
Quoted 73 lines
tests/btrfs/315 new file +54
-0+_require_scratch_dev_pool 3 +_require_btrfs_fs_feature temp_fsid + +_scratch_dev_pool_get 3 + +# mount point for the tempfsid device +tempfsid_mnt=$TEST_DIR/$seq/tempfsid_mnt + +seed_device_must_fail() +{ + echo ---- $FUNCNAME ---- + + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + + $BTRFS_TUNE_PROG -S 1 ${SCRATCH_DEV} + $BTRFS_TUNE_PROG -S 1 ${SCRATCH_DEV_NAME[1]} + + _scratch_mount 2>&1 | _filter_scratch + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} 2>&1 | _filter_test_dir +} + +device_add_must_fail() +{ + echo ---- $FUNCNAME ---- + + mkfs_clone ${SCRATCH_DEV} ${SCRATCH_DEV_NAME[1]} + _scratch_mount + _mount ${SCRATCH_DEV_NAME[1]} ${tempfsid_mnt} + + $XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo | \ + _filter_xfs_io + +$BTRFS_UTIL_PROG device add -f ${SCRATCH_DEV_NAME[2]} ${tempfsid_mnt} 2>&1 | \ + grep -v "Performing full device TRIM" | _filter_scratch_pool + + echo Balance must be successful + _run_btrfs_balance_start ${tempfsid_mnt} +} + +mkdir -p $tempfsid_mnt + +seed_device_must_fail + +_scratch_unmount +_cleanup +mkdir -p $tempfsid_mnt + +device_add_must_fail + +_scratch_dev_pool_put + +# success, all done +status=0 +exittests/btrfs/315.out new file +10
-1@@ -0,0 +1,10 @@ +QA output created by 315 +---- seed_device_must_fail ---- +mount: SCRATCH_MNT: WARNING: source write-protected, mounted read-only. +mount: TEST_DIR/315/tempfsid_mnt: mount(2) system call failed: File exists. +---- device_add_must_fail ---- +wrote 9000/9000 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +ERROR: error adding device 'SCRATCH_DEV': Invalid argument +Balance must be successful +Done, had to relocate 3 out of 3 chunks --2.39.3
Re: [PATCH v3 03/10] btrfs: create a helper function, check_fsid(), to verify the tempfsid
In reply to Filipe MananaQuoted 7 lines
function should do the require for everything it needs that may not be available.
It's doing for the inspect-internal command, but it's missing a:
_require_btrfs_sysfs_fsid
Yes, it did. Actually, check_fsid() would need the following to cover all the prerequisites.
_require_btrfs_fs_sysfs _require_btrfs_fs_feature temp_fsid _require_btrfs_fs_feature metadata_uuid _require_btrfs_command inspect-internal dump-super
I already have v4 with what you just suggested, I am going to send it.
Quoted 3 lines
Instead this is being called for every test case that calls this new helper function, when those requirements should be hidden from the tests themselves.
However, I am a bit skeptical if we should move all prerequisites to the helpers or only some major prerequisites.
Because returning _notrun() in the middle of the testcase is something I am not sure is better than at the beginning of the testcase (I do not have a specific example where it is not a good idea, though).
And, theoretically, figuring out if the test case would run/_notrun() will be complicated.
Next, we shall end up checking the _require..() multiple times in a test case, though one time is enough (the test cases 311, 312, 313 call check_fsid() two times).
Furthermore, it will inconsistent, as a lot of command wraps are already missing such a requirement; I'm not sure if we shall ever achieve consistency across fstests (For example: _cp_reflink() missing _require_cp_reflink).
Lastly, if there are duplicating prerequisites across the helper functions, then we call _require..() many more times (for example:
313 will call mkfs_clone() and check_fsid() two times, which means we would verify the following three times in a testcase.
_require_btrfs_fs_feature metadata_uuid _require_btrfs_command inspect-internal dump-super
So, how about prerequisites of the newer functions as comments above the function to be copied into the test case?
Thanks, Anand
Re: [PATCH v3 03/10] btrfs: create a helper function, check_fsid(), to verify the tempfsid
Quoted 50 lines · Anand Jain
Quoted 8 lines
function should do the require for everything it needs that may not be available.
It's doing for the inspect-internal command, but it's missing a:
_require_btrfs_sysfs_fsidYes, it did. Actually,
check_fsid()would need the following to cover all the prerequisites.
_require_btrfs_fs_sysfs_require_btrfs_fs_featuretemp_fsid_require_btrfs_fs_featuremetadata_uuid_require_btrfs_commandinspect-internal dump-superI already have v4 with what you just suggested, I am going to send it.
Quoted 3 lines
Instead this is being called for every test case that calls this new helper function, when those requirements should be hidden from the tests themselves.
However, I am a bit skeptical if we should move all prerequisites to the helpers or only some major prerequisites.
Because returning
_notrun()in the middle of the testcase is something I am not sure is better than at the beginning of the testcase (I do not have a specific example where it is not a good idea, though).And, theoretically, figuring out if the test case would run/_notrun() will be complicated.
Next, we shall end up checking the _require..() multiple times in a test case, though one time is enough (the test cases 311, 312, 313 call
check_fsid()two times).Furthermore, it will inconsistent, as a lot of command wraps are already missing such a requirement; I'm not sure if we shall ever achieve consistency across fstests (For example:
_cp_reflink()missing_require_cp_reflink).Lastly, if there are duplicating prerequisites across the helper functions, then we call _require..() many more times (for example:
313 will callmkfs_clone()andcheck_fsid()two times, which means we would verify the following three times in a testcase.
Quoted 6 lines
_require_btrfs_fs_featuremetadata_uuid_require_btrfs_commandinspect-internal dump-superSo, how about prerequisites of the newer functions as comments above the function to be copied into the test case?
Calling the require functions doesn't take that much time, I'm not worried about more 1, 2, 3 or 10 milliseconds of test run time.
Now having each test that uses a common function to call all the require functions is hard to maintain and messy.
Commenting the requirements on top of each function is not bullet proof - test authors will have to do it and reviewers as well all the time.
Not to mention that if a function's implementation changes and now it has different requirements, we'll have to change every single test that uses it.
Thanks.
Quoted 2 lines
Thanks, Anand
Re: [PATCH v3 09/10] btrfs: validate send-receive operation with tempfsid.
In reply to Filipe MananaQuoted 10 lines
tests/btrfs/314 line 25
Quoted 5 lines
+. ./common/filter.btrfs
tests/btrfs/314 new file +3
-0+ +_supported_fs btrfs +_require_btrfs_sysfs_fsidThis requirement of the sysfs fsid path is not needed in the test, as it's not used anywhere in this test (likely copy-pasted from other tests in this patchset).
Right. But it requires '_require_btrfs_fs_feature temp_fsid'. Added.
Thanks, Anand
Re: [PATCH v3 05/10] btrfs: check if cloned device mounts with tempfsid
In reply to Filipe MananaQuoted 11 lines
tests/btrfs/312 line 38
Quoted 7 lines
tests/btrfs/312 new file +7
-0+create_cloned_devices() +{ + local dev1=$1 + local dev2=$2 + + [[ -z $dev1 || -z $dev2 ]] && \ + _fail "create_cloned_devices() requires two devices as arguments"Now that the function is not generic, in common/btrfs, and used only once in this test, this check doesn't make that much sense anymore.
Removed.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + echo -n Creating cloned device...Wondering why the -n here, makes the golden output a bit weird.
Overall it limits the output to a line; organized well w.r.t the helper function, deciding to keep it. Thx.
Quoted 10 lines
Quoted 10 lines
tests/btrfs/312 new file +10
-0+ _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: $?"
Quoted 9 lines
tests/btrfs/312 line 56
Quoted 6 lines
tests/btrfs/312 new file +6
-0+ echo done +} + +mount_cloned_device() +{ + local retUnused variable.
Removed.
Thanks. Anand
Quoted 58 lines
Thanks.
Quoted 56 lines
tests/btrfs/312 new file +28
-0+ + 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 +exittests/btrfs/312.out new file +19
-1@@ -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
Re: [PATCH v3 10/10] btrfs: test tempfsid with device add, seed, and balance
In reply to Filipe MananaQuoted 7 lines
Quoted 2 lines
+_require_btrfs_sysfs_fsid
Same as in the previous test case. This requirement is not needed, the sysfs fsid path is not used anywhere in this test, likely copy-pasted from previous test cases in this patchset.
Yep. Replaced with "_require_btrfs_fs_feature temp_fsid"
Quoted 11 lines
tests/btrfs/315.out line 4
Quoted 11 lines
tests/btrfs/315.out new file +4
-0@@ -0,0 +1,10 @@ +QA output created by 315 +---- seed_device_must_fail ---- +mount: SCRATCH_MNT: WARNING: source write-protected, mounted read-only. +mount: TEST_DIR/315/tempfsid_mnt: mount(2) system call failed: File exists.
The error output has changed due to some external fixes. V4 contains changes accordingly.
Old:
mount: <mnt-point>: mount(2) system call failed: File exists.
New:
mount: <mnt-point>: fsconfig system call failed: File exists. dmesg(1) may have more information after failed mount system call.
Thanks, Anand
Re: [PATCH v3 03/10] btrfs: create a helper function, check_fsid(), to verify the tempfsid
In reply to Filipe MananaQuoted 64 lines · Filipe Manana
Quoted 50 lines · Anand Jain
Quoted 8 lines
function should do the require for everything it needs that may not be available.
It's doing for the inspect-internal command, but it's missing a:
_require_btrfs_sysfs_fsidYes, it did. Actually,
check_fsid()would need the following to cover all the prerequisites.
_require_btrfs_fs_sysfs_require_btrfs_fs_featuretemp_fsid_require_btrfs_fs_featuremetadata_uuid_require_btrfs_commandinspect-internal dump-superI already have v4 with what you just suggested, I am going to send it.
Quoted 3 lines
Instead this is being called for every test case that calls this new helper function, when those requirements should be hidden from the tests themselves.
However, I am a bit skeptical if we should move all prerequisites to the helpers or only some major prerequisites.
Because returning
_notrun()in the middle of the testcase is something I am not sure is better than at the beginning of the testcase (I do not have a specific example where it is not a good idea, though).And, theoretically, figuring out if the test case would run/_notrun() will be complicated.
Next, we shall end up checking the _require..() multiple times in a test case, though one time is enough (the test cases 311, 312, 313 call
check_fsid()two times).Furthermore, it will inconsistent, as a lot of command wraps are already missing such a requirement; I'm not sure if we shall ever achieve consistency across fstests (For example:
_cp_reflink()missing_require_cp_reflink).Lastly, if there are duplicating prerequisites across the helper functions, then we call _require..() many more times (for example:
313 will callmkfs_clone()andcheck_fsid()two times, which means we would verify the following three times in a testcase.Quoted 6 lines
_require_btrfs_fs_featuremetadata_uuid_require_btrfs_commandinspect-internal dump-superSo, how about prerequisites of the newer functions as comments above the function to be copied into the test case?
Calling the require functions doesn't take that much time, I'm not worried about more 1, 2, 3 or 10 milliseconds of test run time.
Now having each test that uses a common function to call all the require functions is hard to maintain and messy.
Quoted 6 lines
Commenting the requirements on top of each function is not bullet proof - test authors will have to do it and reviewers as well all the time.
Not to mention that if a function's implementation changes and now it has different requirements, we'll have to change every single test that uses it.
I was trying to keep the code optimized and avoid duplicate '_require..' statements as much as possible. Also, I aimed to avoid '_notrun' in the middle of the testcase, which keeps it inline with the rest of the older testcases. However, it seems not to be a big deal, so let the '_require..' statements be in the helpers. This makes the test case look more concise and further makes it easy to make changes. For example, if a helper is deleted, the testcase will still be fine without bugs. I have updated the rest of the test cases with this idea in v4.
Thanks, Anand