From: Anand Jain <anajain.sg@gmail.com>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs
Date: Thu, 18 Sep 2025 08:32:46 +0800 [thread overview]
Message-ID: <512a6148be0d8da51278f94a29b959f3950bcc0b.1758148804.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1758148804.git.anand.jain@oracle.com>
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
next prev parent reply other threads:[~2025-09-18 0:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-09-26 15:57 ` [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=512a6148be0d8da51278f94a29b959f3950bcc0b.1758148804.git.anand.jain@oracle.com \
--to=anajain.sg@gmail.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).