misc nvme ioctl cleanups
Christoph Hellwig
maintainerHi all,
this series untangles some of our ioctl code a little more.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 1/7 nvme: open code nvme_put_ns_from_disk in nvme_ns_head_chr_ioctl
nvme_ns_head_chr_ioctl is always used on multipath nodes, so just call srcu_read_unlock and consolidate the two unlock paths.
--- drivers/nvme/host/ioctl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/nvme/host/ioctl.c +5 -7
@@ -419,21 +419,19 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, container_of(cdev, struct nvme_ns_head, cdev);void __user *argp = (void __user *)arg;struct nvme_ns *ns; -int srcu_idx, ret; +int srcu_idx, ret = -EWOULDBLOCK ; srcu_idx =srcu_read_lock (&head->srcu); ns =nvme_find_path (head); -if (!ns) { -srcu_read_unlock (&head->srcu, srcu_idx); -return -EWOULDBLOCK ; - } +if (!ns) + goto out_unlock;if (is_ctrl_ioctl (cmd))return nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx); ret =nvme_ns_ioctl (ns, cmd, argp); -nvme_put_ns_from_disk (head, srcu_idx); - +out_unlock: +srcu_read_unlock (&head->srcu, srcu_idx); return ret; }#endif /* CONFIG_NVME_MULTIPATH */
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 2/7 nvne: open code nvme_{get, put}_ns_from_disk in nvme_ns_head_ioctl
In reply to Christoph Hellwignvme_ns_head_ioctl is always used on multipath nodes, no need to deal with the de-multiplexers.
--- drivers/nvme/host/ioctl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/nvme/host/ioctl.c +10 -10
@@ -387,14 +387,15 @@ static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,int nvme_ns_head_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg) { -struct nvme_ns_head *head =NULL ; +struct nvme_ns_head *head = bdev->bd_disk->private_data;void __user *argp = (void __user *)arg;struct nvme_ns *ns; -int srcu_idx, ret; +int srcu_idx, ret = -EWOULDBLOCK ; - ns =nvme_get_ns_from_disk (bdev->bd_disk, &head, &srcu_idx); -if (unlikely (!ns)) -return -EWOULDBLOCK ; + srcu_idx =srcu_read_lock (&head->srcu); + ns =nvme_find_path (head); +if (!ns) + goto out_unlock;/* * Handle ioctls that apply to the controller instead of the namespace
@@ -402,12 +403,11 @@ int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,* deadlock when deleting namespaces using the passthrough interface. */ if (is_ctrl_ioctl (cmd)) - ret =nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx); -else { - ret =nvme_ns_ioctl (ns, cmd, argp); -nvme_put_ns_from_disk (head, srcu_idx); - } +return nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx); + ret =nvme_ns_ioctl (ns, cmd, argp); +out_unlock: +srcu_read_unlock (&head->srcu, srcu_idx);return ret; }
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 3/7 nvme: open code nvme_put_ns_from_disk in nvme_ns_head_ctrl_ioctl
In reply to Christoph Hellwignvme_ns_head_ctrl_ioctl is always used on multipath nodes, so just call srcu_read_unlock directly.
--- drivers/nvme/host/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/ioctl.c +1 -1
@@ -377,7 +377,7 @@ static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,int ret;nvme_get_ctrl (ns->ctrl); -nvme_put_ns_from_disk (head, srcu_idx); +srcu_read_unlock (&head->srcu, srcu_idx); ret =nvme_ctrl_ioctl (ns->ctrl, cmd, argp);nvme_put_ctrl (ctrl);
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 4/7 nvme: add a sparse annotation to nvme_ns_head_ctrl_ioctl
In reply to Christoph HellwigAdd the __releases annotation to tell sparse that nvme_ns_head_ctrl_ioctl is expected to unlock head->srcu.
--- drivers/nvme/host/ioctl.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/ioctl.c +1 -0
@@ -372,6 +372,7 @@ long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)#ifdef CONFIG_NVME_MULTIPATH static int nvme_ns_head_ctrl_ioctl (struct nvme_ns *ns,unsigned int cmd,void __user *argp,struct nvme_ns_head *head,int srcu_idx) + __releases(&head->srcu) {struct nvme_ctrl *ctrl = ns->ctrl;int ret;
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 5/7 nvme: move the CSI sanity check into nvme_ns_report_zones
In reply to Christoph HellwigMove the CSI check into nvme_ns_report_zones to clean up the code a little bit and prepare for further refactoring.
--- drivers/nvme/host/zns.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/nvme/host/zns.c +4 -5
@@ -180,6 +180,9 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,unsigned int nz, i;size_t buflen; +if (ns->head->ids.csi !=NVME_CSI_ZNS ) +return -EINVAL ; + report =nvme_zns_alloc_report_buffer (ns, nr_zones, &buflen);if (!report)return -ENOMEM ;
@@ -237,11 +240,7 @@ int nvme_report_zones(struct gendisk *disk, sector_t sector, ns =nvme_get_ns_from_disk (disk, &head, &srcu_idx);if (unlikely (!ns))return -EWOULDBLOCK ; - -if (ns->head->ids.csi ==NVME_CSI_ZNS ) - ret =nvme_ns_report_zones (ns, sector, nr_zones, cb, data); -else - ret = -EINVAL ; + ret =nvme_ns_report_zones (ns, sector, nr_zones, cb, data);nvme_put_ns_from_disk (head, srcu_idx);return ret;
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 6/7 nvme: split nvme_report_zones
In reply to Christoph HellwigSplit multipath support out of nvme_report_zones into a separate helper and simplify the non-multipath version as a result.
--- drivers/nvme/host/core.c | 11 +++++++++++ drivers/nvme/host/multipath.c | 21 ++++++++++++++++++++- drivers/nvme/host/nvme.h | 7 ++----- drivers/nvme/host/zns.c | 20 ++------------------ 4 files changed, 35 insertions(+), 24 deletions(-)
drivers/nvme/host/core.c +11 -0
@@ -2073,6 +2073,17 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,EXPORT_SYMBOL_GPL (nvme_sec_submit);#endif /* CONFIG_BLK_SED_OPAL */ +#ifdef CONFIG_BLK_DEV_ZONED +static int nvme_report_zones (struct gendisk *disk,sector_t sector, +unsigned int nr_zones,report_zones_cb cb,void *data) +{ +return nvme_ns_report_zones (disk->private_data, sector, nr_zones, cb, + data); +} +#else +#define nvme_report_zones NULL +#endif /* CONFIG_BLK_DEV_ZONED */ +static const struct block_device_operations nvme_bdev_ops = { .owner =THIS_MODULE , .ioctl = nvme_ioctl,
drivers/nvme/host/multipath.c +20 -1
@@ -349,6 +349,25 @@ static void nvme_ns_head_release(struct gendisk *disk, fmode_t mode)nvme_put_ns_head (disk->private_data); } +#ifdef CONFIG_BLK_DEV_ZONED +static int nvme_ns_head_report_zones (struct gendisk *disk,sector_t sector, +unsigned int nr_zones,report_zones_cb cb,void *data) +{ +struct nvme_ns_head *head = disk->private_data; +struct nvme_ns *ns; +int srcu_idx, ret = -EWOULDBLOCK ; + + srcu_idx =srcu_read_lock (&head->srcu); + ns =nvme_find_path (head); +if (ns) + ret =nvme_ns_report_zones (ns, sector, nr_zones, cb, data); +srcu_read_unlock (&head->srcu, srcu_idx); +return ret; +} +#else +#define nvme_ns_head_report_zones NULL +#endif /* CONFIG_BLK_DEV_ZONED */ +const struct block_device_operations nvme_ns_head_ops = { .owner =THIS_MODULE , .submit_bio = nvme_ns_head_submit_bio,
@@ -356,7 +375,7 @@ const struct block_device_operations nvme_ns_head_ops = { .release = nvme_ns_head_release, .ioctl = nvme_ns_head_ioctl, .getgeo = nvme_getgeo, - .report_zones = nvme_report_zones, + .report_zones = nvme_ns_head_report_zones, .pr_ops = &nvme_pr_ops, };
drivers/nvme/host/nvme.h +2 -5
@@ -810,17 +810,14 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)#endif /* CONFIG_NVME_MULTIPATH */ int nvme_revalidate_zones (struct nvme_ns *ns); +int nvme_ns_report_zones (struct nvme_ns *ns,sector_t sector, +unsigned int nr_zones,report_zones_cb cb,void *data);#ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf); -int nvme_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); -blk_status_t nvme_setup_zone_mgmt_send (struct nvme_ns *ns,struct request *req,struct nvme_command *cmnd,enum nvme_zone_mgmt_action action);#else -#define nvme_report_zones NULL -static inline blk_status_t nvme_setup_zone_mgmt_send (struct nvme_ns *ns,struct request *req,struct nvme_command *cmnd,enum nvme_zone_mgmt_action action)
drivers/nvme/host/zns.c +2 -18
@@ -171,8 +171,8 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,return cb (&zone, idx, data); } -static int nvme_ns_report_zones (struct nvme_ns *ns,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +int nvme_ns_report_zones (struct nvme_ns *ns,sector_t sector, +unsigned int nr_zones,report_zones_cb cb,void *data) {struct nvme_zone_report *report;struct nvme_command c = { };
@@ -230,22 +230,6 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,return ret; } -int nvme_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) -{ -struct nvme_ns_head *head =NULL ; -struct nvme_ns *ns; -int srcu_idx, ret; - - ns =nvme_get_ns_from_disk (disk, &head, &srcu_idx); -if (unlikely (!ns)) -return -EWOULDBLOCK ; - ret =nvme_ns_report_zones (ns, sector, nr_zones, cb, data); -nvme_put_ns_from_disk (head, srcu_idx); - -return ret; -} -blk_status_t nvme_setup_zone_mgmt_send (struct nvme_ns *ns,struct request *req,struct nvme_command *c,enum nvme_zone_mgmt_action action) {
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 7/7 nvme: remove nvme_{get,put}_ns_from_disk
In reply to Christoph HellwigNow that only one caller is left remove the helpers by restructuring nvme_pr_command so that it has two helpers for sending a command of to a given nsid using either the ns_head for multipath, or the namespace stored in the gendisk.
--- drivers/nvme/host/core.c | 68 ++++++++++++++++------------------------ drivers/nvme/host/nvme.h | 5 +-- 2 files changed, 28 insertions(+), 45 deletions(-)
drivers/nvme/host/core.c +27 -41
@@ -1542,36 +1542,6 @@ static void nvme_enable_aen(struct nvme_ctrl *ctrl)queue_work (nvme_wq, &ctrl->async_event_work); } -/* -* Issue ioctl requests on the first available path. Note that unlike normal -* block layer requests we will not retry failed request on another controller. -*/ -struct nvme_ns *nvme_get_ns_from_disk (struct gendisk *disk, -struct nvme_ns_head **head,int *srcu_idx) -{ -#ifdef CONFIG_NVME_MULTIPATH -if (disk->fops == &nvme_ns_head_ops) { -struct nvme_ns *ns; - - *head = disk->private_data; - *srcu_idx =srcu_read_lock (&(*head)->srcu); - ns =nvme_find_path (*head); -if (!ns) -srcu_read_unlock (&(*head)->srcu, *srcu_idx); -return ns; - } -#endif - *head =NULL ; - *srcu_idx =-1 ; -return disk->private_data; -} - -void nvme_put_ns_from_disk (struct nvme_ns_head *head,int idx) -{ -if (head) -srcu_read_unlock (&head->srcu, idx); -} -static int nvme_ns_open (struct nvme_ns *ns) {
@@ -1968,30 +1938,46 @@ static char nvme_pr_type(enum pr_type type) } }; +static int nvme_send_ns_head_pr_command (struct block_device *bdev, +struct nvme_command *c,u8 data[16 ]) +{ +struct nvme_ns_head *head = bdev->bd_disk->private_data; +int srcu_idx =srcu_read_lock (&head->srcu); +struct nvme_ns *ns =nvme_find_path (head); +int ret = -EWOULDBLOCK ; + +if (ns) { + c->common.nsid =cpu_to_le32 (ns->head->ns_id); + ret =nvme_submit_sync_cmd (ns->queue, c, data,16 ); + } +srcu_read_unlock (&head->srcu, srcu_idx); +return ret; +} + +static int nvme_send_ns_pr_command (struct nvme_ns *ns,struct nvme_command *c, +u8 data[16 ]) +{ + c->common.nsid =cpu_to_le32 (ns->head->ns_id); +return nvme_submit_sync_cmd (ns->queue, c, data,16 ); +} +static int nvme_pr_command (struct block_device *bdev,u32 cdw10,u64 key,u64 sa_key,u8 op) { -struct nvme_ns_head *head =NULL ; -struct nvme_ns *ns;struct nvme_command c; -int srcu_idx, ret;u8 data[16 ] = {0 , }; - ns =nvme_get_ns_from_disk (bdev->bd_disk, &head, &srcu_idx); -if (unlikely (!ns)) -return -EWOULDBLOCK ; -put_unaligned_le64 (key, &data[0 ]);put_unaligned_le64 (sa_key, &data[8 ]);memset (&c,0 ,sizeof (c)); c.common.opcode = op; - c.common.nsid =cpu_to_le32 (ns->head->ns_id); c.common.cdw10 =cpu_to_le32 (cdw10); - ret =nvme_submit_sync_cmd (ns->queue, &c, data,16 ); -nvme_put_ns_from_disk (head, srcu_idx); -return ret; +if (IS_ENABLED (CONFIG_NVME_MULTIPATH ) && + bdev->bd_disk->fops == &nvme_ns_head_ops) +return nvme_send_ns_head_pr_command (bdev, &c, data); +return nvme_send_ns_pr_command (bdev->bd_disk->private_data, &c, data); } static int nvme_pr_register(struct block_device *bdev, u64 old,
drivers/nvme/host/nvme.h +1 -4
@@ -674,9 +674,6 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl);void nvme_queue_scan (struct nvme_ctrl *ctrl);int nvme_get_log (struct nvme_ctrl *ctrl,u32 nsid,u8 log_page,u8 lsp,u8 csi,void *log,size_t size,u64 offset); -struct nvme_ns *nvme_get_ns_from_disk (struct gendisk *disk, -struct nvme_ns_head **head,int *srcu_idx); -void nvme_put_ns_from_disk (struct nvme_ns_head *head,int idx);bool nvme_tryget_ns_head (struct nvme_ns_head *head);void nvme_put_ns_head (struct nvme_ns_head *head); int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
@@ -697,6 +694,7 @@ extern const struct attribute_group *nvme_ns_id_attr_groups[];extern const struct pr_ops nvme_pr_ops;extern const struct block_device_operations nvme_ns_head_ops; +struct nvme_ns *nvme_find_path (struct nvme_ns_head *head);#ifdef CONFIG_NVME_MULTIPATH static inline bool nvme_ctrl_use_ana (struct nvme_ctrl *ctrl) {
@@ -718,7 +716,6 @@ void nvme_mpath_uninit(struct nvme_ctrl *ctrl);void nvme_mpath_stop (struct nvme_ctrl *ctrl);bool nvme_mpath_clear_current_path (struct nvme_ns *ns);void nvme_mpath_clear_ctrl_paths (struct nvme_ctrl *ctrl); -struct nvme_ns *nvme_find_path (struct nvme_ns_head *head);static inline void nvme_mpath_check_last_path (struct nvme_ns *ns) {
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
These all look good to me.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Me too,
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme