nvme: Allow sending of admin commands to inaccessible paths
PATCH 1/1 nvme: Allow sending of admin commands to inaccessible paths
The NVMe Base Specification (Section 8.1.1.10) specifies that admin commands should not be affected by ANA states. So implement a function nvme_find_admin_path() to return the first non-disabled path irrespective of the ANA state.
Signed-off-by Hannes Reinecke <[email protected]>
--- drivers/nvme/host/ioctl.c | 33 +++++++++++++++++++------------ drivers/nvme/host/multipath.c | 37 +++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 1 + 3 files changed, 58 insertions(+), 13 deletions(-)
drivers/nvme/host/ioctl.c +20 -13
@@ -723,19 +723,22 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode, flags |=NVME_IOCTL_PARTITION ; srcu_idx =srcu_read_lock (&head->srcu); +if (is_ctrl_ioctl (cmd)) { + ns =nvme_find_admin_path (head); +if (!ns) + goto out_unlock; +/* +* Handle ioctls that apply to the controller instead of the namespace +* seperately and drop the ns SRCU reference early. This avoids a +* deadlock when deleting namespaces using the passthrough interface. +*/ +return nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx, + open_for_write); + } ns =nvme_find_path (head);if (!ns) goto out_unlock; -/* -* Handle ioctls that apply to the controller instead of the namespace -* seperately and drop the ns SRCU reference early. This avoids a -* deadlock when deleting namespaces using the passthrough interface. -*/ -if (is_ctrl_ioctl (cmd)) -return nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx, - open_for_write); - ret =nvme_ns_ioctl (ns, cmd, argp, flags, open_for_write); out_unlock:srcu_read_unlock (&head->srcu, srcu_idx);
@@ -754,13 +757,17 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,int srcu_idx, ret = -EWOULDBLOCK ; srcu_idx =srcu_read_lock (&head->srcu); - ns =nvme_find_path (head); -if (!ns) - goto out_unlock; +if (is_ctrl_ioctl (cmd)) { + ns =nvme_find_admin_path (head); +if (!ns) + goto out_unlock; -if (is_ctrl_ioctl (cmd))return nvme_ns_head_ctrl_ioctl (ns, cmd, argp, head, srcu_idx, open_for_write); + } + ns =nvme_find_path (head); +if (!ns) + goto out_unlock; ret =nvme_ns_ioctl (ns, cmd, argp,0 , open_for_write); out_unlock:
drivers/nvme/host/multipath.c +37 -0
@@ -473,6 +473,43 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head) } } +inline struct nvme_ns *nvme_find_admin_path (struct nvme_ns_head *head) +{ +struct nvme_ns *found =NULL , *fallback =NULL , *ns; + + ns =srcu_dereference (head->current_path[numa_node_id ()], &head->srcu); +if (ns && !nvme_path_is_disabled (ns)) +return ns; + +/* +* Return the first optimized path or, failing that, the first non- +* disabled path. Processing rules for admin commands are different +* than those for I/O commands (NVMe Base Spec v2.2 section 8.1.1.10 +* "Asymmetric Namespace Access States Command Processing Effects") +* so do not set the current path. +*/ +list_for_each_entry_srcu (ns, &head->list, siblings, +srcu_read_lock_held (&head->srcu)) { +if (nvme_path_is_disabled (ns)) +continue ; + +switch (ns->ana_state) { +case NVME_ANA_OPTIMIZED : +return ns; +case NVME_ANA_NONOPTIMIZED : + found = ns; +break ; +default : + fallback = ns; +break ; + } + } + +if (!found) + found = fallback; +return found; +} +static bool nvme_available_path (struct nvme_ns_head *head) {struct nvme_ns *ns;
drivers/nvme/host/nvme.h +1 -0
@@ -952,6 +952,7 @@ extern const struct block_device_operations nvme_bdev_ops;void nvme_delete_ctrl_sync (struct nvme_ctrl *ctrl);struct nvme_ns *nvme_find_path (struct nvme_ns_head *head); +struct nvme_ns *nvme_find_admin_path (struct nvme_ns_head *head);#ifdef CONFIG_NVME_MULTIPATH static inline bool nvme_ctrl_use_ana (struct nvme_ctrl *ctrl) {
Signature · 1 line
2.35.3
Christoph Hellwig
maintainerQuoted 4 lines · Hannes Reinecke
The NVMe Base Specification (Section 8.1.1.10) specifies that admin commands should not be affected by ANA states. So implement a function
nvme_find_admin_path()to return the first non-disabled path irrespective of the ANA state.
Nothing in here explains why we'd want to support passthrough of admin commans to inaccessible controllers. What problems does this solve to justify all the extra code?