[PATCH v2 11/13] libmultipath: Add support for block device IOCTL
John Garry
john.g.garry at oracle.com
Tue Apr 28 04:11:03 PDT 2026
Add mpath_bdev_ioctl() as a multipath block device IOCTL handler. This
handler calls into the mpath_device bdev fops handler.
Like what is done for cdev IOCTL handler, use .ioctl_begin and
.ioctl_finish methods to know when the until the SRCU read lock - this is
for special NVMe controller IOCTL handling.
The .compat_ioctl handler is given the standard handler.
Signed-off-by: John Garry <john.g.garry at oracle.com>
---
lib/multipath.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/lib/multipath.c b/lib/multipath.c
index c72f35e02e2ab..e2998c1b277c0 100644
--- a/lib/multipath.c
+++ b/lib/multipath.c
@@ -490,6 +490,38 @@ static void mpath_bdev_release(struct gendisk *disk)
mpath_put_head(mpath_head);
}
+static int mpath_bdev_ioctl(struct block_device *bdev, blk_mode_t mode,
+ unsigned int cmd, unsigned long arg)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ struct mpath_head *mpath_head = mpath_gendisk_to_head(disk);
+ struct mpath_device *mpath_device;
+ int srcu_idx, err;
+ void *unlocked_ioctl_data = NULL;
+
+ srcu_idx = srcu_read_lock(&mpath_head->srcu);
+ mpath_device = mpath_find_path(mpath_head);
+ if (!mpath_device) {
+ err = -EWOULDBLOCK;
+ goto out_unlock;
+ }
+
+ if (mpath_head->mpdt->ioctl_begin)
+ mpath_head->mpdt->ioctl_begin(mpath_device, cmd,
+ &unlocked_ioctl_data);
+ if (unlocked_ioctl_data)
+ srcu_read_unlock(&mpath_head->srcu, srcu_idx);
+ err = mpath_device->disk->fops->ioctl(
+ mpath_device->disk->part0, mode, cmd, arg);
+ if (unlocked_ioctl_data) {
+ mpath_head->mpdt->ioctl_finish(unlocked_ioctl_data);
+ return err;
+ }
+out_unlock:
+ srcu_read_unlock(&mpath_head->srcu, srcu_idx);
+ return err;
+}
+
static int mpath_pr_register(struct block_device *bdev, u64 old_key,
u64 new_key, unsigned int flags)
{
@@ -676,6 +708,8 @@ const struct block_device_operations mpath_ops = {
.open = mpath_bdev_open,
.release = mpath_bdev_release,
.submit_bio = mpath_bdev_submit_bio,
+ .ioctl = mpath_bdev_ioctl,
+ .compat_ioctl = blkdev_compat_ptr_ioctl,
.report_zones = mpath_bdev_report_zones,
.pr_ops = &mpath_pr_ops,
};
--
2.43.5
More information about the Linux-nvme
mailing list