* [PATCH 0/2] fstests: test device reappearance with new maj:min
@ 2025-09-18 0:32 Anand Jain
2025-09-18 0:32 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs Anand Jain
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Anand Jain @ 2025-09-18 0:32 UTC (permalink / raw)
To: fstests; +Cc: linux-btrfs
From: Anand Jain <anand.jain@oracle.com>
Tests filesystem behavior when a device reappears with a different
MAJ:MIN after a block layer transport failure.
Anand Jain (2):
common/rc: helper functions to handle block devices via sysfs
generic: test case for reappearing device
common/rc | 26 ++++++++++++++++
tests/generic/809 | 72 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/809.out | 2 ++
3 files changed, 100 insertions(+)
create mode 100755 tests/generic/809
create mode 100644 tests/generic/809.out
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs 2025-09-18 0:32 [PATCH 0/2] fstests: test device reappearance with new maj:min Anand Jain @ 2025-09-18 0:32 ` Anand Jain 2025-09-26 15:57 ` Zorro Lang 2025-09-18 0:32 ` [PATCH 2/2] generic: test case for reappearing device Anand Jain 2025-09-18 17:15 ` [PATCH 0/2] fstests: test device reappearance with new maj:min Neal Gompa 2 siblings, 1 reply; 6+ messages in thread From: Anand Jain @ 2025-09-18 0:32 UTC (permalink / raw) To: fstests; +Cc: linux-btrfs From: Anand Jain <anand.jain@oracle.com> _bdev_handle(dev) get sysfs handle for a given block device. _has_bdev_sysfs_delete(dev_path) Checks if the block device supports sysfs-based delete. _require_scratch_bdev_delete() Test if the scratch device does not support sysfs delete. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- common/rc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/common/rc b/common/rc index 81587dad500c..627ddcc02fb8 100644 --- a/common/rc +++ b/common/rc @@ -4388,6 +4388,32 @@ _get_file_extent_sector() echo "$result" } +_bdev_handle() +{ + local device=$(echo $1 | rev | cut -d"/" -f1 | rev) + + test -e /sys/class/block/${device}/device/scsi_disk/ || \ + _notrun "Failed to obtain sys block handle" + + ls /sys/class/block/${device}/device/scsi_disk/ +} + +_has_bdev_sysfs_delete() +{ + local dev_path=$1 + local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev) + local delete_path=/sys/class/block/${device}/device/delete + + test -e $delete_path +} + +_require_scratch_bdev_delete() +{ + if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then + _notrun "require scratch device sys delete support" + fi +} + # arg 1 is dev to remove and is output of the below eg. # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev _devmgt_remove() -- 2.51.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs 2025-09-18 0:32 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs Anand Jain @ 2025-09-26 15:57 ` Zorro Lang 2025-09-30 3:47 ` Anand Jain 0 siblings, 1 reply; 6+ messages in thread From: Zorro Lang @ 2025-09-26 15:57 UTC (permalink / raw) To: Anand Jain; +Cc: fstests, linux-btrfs On Thu, Sep 18, 2025 at 08:32:46AM +0800, Anand Jain wrote: > From: Anand Jain <anand.jain@oracle.com> > > _bdev_handle(dev) > get sysfs handle for a given block device. > > _has_bdev_sysfs_delete(dev_path) > Checks if the block device supports sysfs-based delete. > > _require_scratch_bdev_delete() > Test if the scratch device does not support sysfs delete. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > common/rc | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/common/rc b/common/rc > index 81587dad500c..627ddcc02fb8 100644 > --- a/common/rc > +++ b/common/rc > @@ -4388,6 +4388,32 @@ _get_file_extent_sector() > echo "$result" > } > > +_bdev_handle() > +{ > + local device=$(echo $1 | rev | cut -d"/" -f1 | rev) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ basename $1 ? if you hope to make sure it's not link, you can basename $(_real_dev $1) > + > + test -e /sys/class/block/${device}/device/scsi_disk/ || \ > + _notrun "Failed to obtain sys block handle" > + > + ls /sys/class/block/${device}/device/scsi_disk/ > +} > + > +_has_bdev_sysfs_delete() > +{ > + local dev_path=$1 > + local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev) > + local delete_path=/sys/class/block/${device}/device/delete > + > + test -e $delete_path > +} > + > +_require_scratch_bdev_delete() > +{ I'm wondering if it's better to call "_require_block_device" at first, before checking the /sys ? > + if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then > + _notrun "require scratch device sys delete support" > + fi > +} > + > # arg 1 is dev to remove and is output of the below eg. > # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev > _devmgt_remove() > -- > 2.51.0 > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs 2025-09-26 15:57 ` Zorro Lang @ 2025-09-30 3:47 ` Anand Jain 0 siblings, 0 replies; 6+ messages in thread From: Anand Jain @ 2025-09-30 3:47 UTC (permalink / raw) To: Zorro Lang; +Cc: fstests, linux-btrfs On 26/9/25 23:57, Zorro Lang wrote: > On Thu, Sep 18, 2025 at 08:32:46AM +0800, Anand Jain wrote: >> From: Anand Jain <anand.jain@oracle.com> >> >> _bdev_handle(dev) >> get sysfs handle for a given block device. >> >> _has_bdev_sysfs_delete(dev_path) >> Checks if the block device supports sysfs-based delete. >> >> _require_scratch_bdev_delete() >> Test if the scratch device does not support sysfs delete. >> >> Signed-off-by: Anand Jain <anand.jain@oracle.com> >> --- >> common/rc | 26 ++++++++++++++++++++++++++ >> 1 file changed, 26 insertions(+) >> >> diff --git a/common/rc b/common/rc >> index 81587dad500c..627ddcc02fb8 100644 >> --- a/common/rc >> +++ b/common/rc >> @@ -4388,6 +4388,32 @@ _get_file_extent_sector() >> echo "$result" >> } >> >> +_bdev_handle() >> +{ >> + local device=$(echo $1 | rev | cut -d"/" -f1 | rev) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > basename $1 ? > > if you hope to make sure it's not link, you can > > basename $(_real_dev $1) Whoops, not sure what I was thinking. There's actually a helper for this, _short_dev(). The changes below will fix it. I can send v2 if needed, unless it can be fixed at merge time. Let me know what works best. ----------------------------------- $ git diff diff --git a/common/rc b/common/rc index 627ddcc02fb8..085fab6e34f0 100644 --- a/common/rc +++ b/common/rc @@ -4390,7 +4390,7 @@ _get_file_extent_sector() _bdev_handle() { - local device=$(echo $1 | rev | cut -d"/" -f1 | rev) + local device=$(_short_dev $1) test -e /sys/class/block/${device}/device/scsi_disk/ || \ _notrun "Failed to obtain sys block handle" @@ -4401,7 +4401,7 @@ _bdev_handle() _has_bdev_sysfs_delete() { local dev_path=$1 - local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev) + local device=$(_short_dev $1) local delete_path=/sys/class/block/${device}/device/delete test -e $delete_path --------------------------------------------- >> + >> + test -e /sys/class/block/${device}/device/scsi_disk/ || \ >> + _notrun "Failed to obtain sys block handle" >> + >> + ls /sys/class/block/${device}/device/scsi_disk/ >> +} >> + >> +_has_bdev_sysfs_delete() >> +{ >> + local dev_path=$1 >> + local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev) >> + local delete_path=/sys/class/block/${device}/device/delete >> + >> + test -e $delete_path >> +} >> + >> +_require_scratch_bdev_delete() >> +{ > > I'm wondering if it's better to call "_require_block_device" at first, before > checking the /sys ? There’s no harm in using _require_block_device() here, but I don’t think it will help, a non block device won't reach this place anyway. config: _check_device() will fail for non-block devices. Thanks, Anand >> + if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then >> + _notrun "require scratch device sys delete support" >> + fi >> +} >> + >> # arg 1 is dev to remove and is output of the below eg. >> # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev >> _devmgt_remove() >> -- >> 2.51.0 >> >> > ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] generic: test case for reappearing device 2025-09-18 0:32 [PATCH 0/2] fstests: test device reappearance with new maj:min Anand Jain 2025-09-18 0:32 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs Anand Jain @ 2025-09-18 0:32 ` Anand Jain 2025-09-18 17:15 ` [PATCH 0/2] fstests: test device reappearance with new maj:min Neal Gompa 2 siblings, 0 replies; 6+ messages in thread From: Anand Jain @ 2025-09-18 0:32 UTC (permalink / raw) To: fstests; +Cc: linux-btrfs From: Anand Jain <anand.jain@oracle.com> Tests how the filesystem handles a device that reappears with a different MAJ:MIN due to a block layer transport failure. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- tests/generic/809 | 72 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/809.out | 2 ++ 2 files changed, 74 insertions(+) create mode 100755 tests/generic/809 create mode 100644 tests/generic/809.out diff --git a/tests/generic/809 b/tests/generic/809 new file mode 100755 index 000000000000..3e9943f9ac85 --- /dev/null +++ b/tests/generic/809 @@ -0,0 +1,72 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 809 +# +# Tests how the filesystem handles a device that reappears with a different +# MAJ:MIN while the old MAJ:MIN is still mounted and in use, due to a block +# layer transport failure. + +. ./common/preamble + +_begin_fstest auto quick tempfsid shutdown + +_cleanup() +{ + local new_blk_handle + + cd / + rm -r -f $tmp.* + $UMOUNT_PROG $mnt1 &> /dev/null + $UMOUNT_PROG $SCRATCH_MNT &> /dev/null + + if [[ ! -b $new_scratch_dev ]]; then + echo "_cleanup: failed to restore the scratch device." + return + fi + new_blk_handle=$(_bdev_handle $new_scratch_dev) + _devmgt_remove $new_blk_handle $new_scratch_dev + _devmgt_add $new_blk_handle + + [[ -b $SCRATCH_DEV ]] || \ + echo "_cleanup: failed to restore scratch device." +} + +_require_test +_require_scratch +_require_scratch_bdev_delete + +mnt1=$TEST_DIR/$seq/mnt1 +rm -r -f $mnt1 +mkdir -p $mnt1 + +_scratch_mkfs >> /dev/null +_scratch_mount + +$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo >> $seqres.full +_mount $SCRATCH_DEV $mnt1 +$UMOUNT_PROG $mnt1 + +# Ensure data is flushed to disk before the device disappears +sync + +id1=$(lsblk -ndo MAJ:MIN $SCRATCH_DEV) +scratch_fsid=$(blkid --probe --match-tag UUID $SCRATCH_DEV | \ + $AWK_PROG '{print $2}' | sed -e 's/UUID=//g' | sed -e 's/\"//g') +blk_handle=$(_bdev_handle $SCRATCH_DEV) +_devmgt_remove $blk_handle $SCRATCH_DEV +_devmgt_add $blk_handle +new_scratch_dev=$(blkid -l -o device -t UUID=$scratch_fsid) +id2=$(lsblk -ndo MAJ:MIN $new_scratch_dev) +[[ -b $new_scratch_dev ]] || _fail "Device failed to reappear" +[[ "$id1" != "$id2" ]] || \ + _not_run "Device cannot reappear with a different major:minor" + +# Mount the reappeared device while the old node is still mounted +# (not supported on XFS). +[[ $FSTYP == "xfs" ]] && $UMOUNT_PROG $SCRATCH_MNT +_mount $new_scratch_dev $mnt1 +echo Silence is golden +status=0 +exit diff --git a/tests/generic/809.out b/tests/generic/809.out new file mode 100644 index 000000000000..e90865ca8f8c --- /dev/null +++ b/tests/generic/809.out @@ -0,0 +1,2 @@ +QA output created by 809 +Silence is golden -- 2.51.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] fstests: test device reappearance with new maj:min 2025-09-18 0:32 [PATCH 0/2] fstests: test device reappearance with new maj:min Anand Jain 2025-09-18 0:32 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs Anand Jain 2025-09-18 0:32 ` [PATCH 2/2] generic: test case for reappearing device Anand Jain @ 2025-09-18 17:15 ` Neal Gompa 2 siblings, 0 replies; 6+ messages in thread From: Neal Gompa @ 2025-09-18 17:15 UTC (permalink / raw) To: Anand Jain; +Cc: fstests, linux-btrfs On Wed, Sep 17, 2025 at 8:33 PM Anand Jain <anajain.sg@gmail.com> wrote: > > From: Anand Jain <anand.jain@oracle.com> > > Tests filesystem behavior when a device reappears with a different > MAJ:MIN after a block layer transport failure. > > Anand Jain (2): > common/rc: helper functions to handle block devices via sysfs > generic: test case for reappearing device > > common/rc | 26 ++++++++++++++++ > tests/generic/809 | 72 +++++++++++++++++++++++++++++++++++++++++++ > tests/generic/809.out | 2 ++ > 3 files changed, 100 insertions(+) > create mode 100755 tests/generic/809 > create mode 100644 tests/generic/809.out > > -- > 2.51.0 > This series looks good to me. Reviewed-by: Neal Gompa <neal@gompa.dev> -- 真実はいつも一つ!/ Always, there's only one truth! ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-30 3:47 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-18 0:32 [PATCH 0/2] fstests: test device reappearance with new maj:min Anand Jain 2025-09-18 0:32 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs Anand Jain 2025-09-26 15:57 ` Zorro Lang 2025-09-30 3:47 ` Anand Jain 2025-09-18 0:32 ` [PATCH 2/2] generic: test case for reappearing device Anand Jain 2025-09-18 17:15 ` [PATCH 0/2] fstests: test device reappearance with new maj:min Neal Gompa
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).