[PATCH RFC 04/11] nvmet: Add function to get nvmet_fabrics_ops from trtype
Mike Christie
michael.christie at oracle.com
Wed Mar 12 22:18:05 PDT 2025
In the next patches we allow users to create static controllers if the
driver supports it. To get this info we need the nvmet_fabrics_ops
a little sooner then port enablement so this creates a function to go
from trtype to nvmet_fabrics_ops.
Signed-off-by: Mike Christie <michael.christie at oracle.com>
---
drivers/nvme/target/core.c | 41 +++++++++++++++++++++++--------------
drivers/nvme/target/nvmet.h | 1 +
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 4de534eafd89..06967c00e9a2 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -306,6 +306,30 @@ void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops)
}
EXPORT_SYMBOL_GPL(nvmet_unregister_transport);
+const struct nvmet_fabrics_ops *nvmet_get_ops_by_transport(int trtype)
+{
+ const struct nvmet_fabrics_ops *ops;
+
+ lockdep_assert_held(&nvmet_config_sem);
+
+ ops = nvmet_transports[trtype];
+ if (!ops) {
+ up_write(&nvmet_config_sem);
+ request_module("nvmet-transport-%d", trtype);
+ down_write(&nvmet_config_sem);
+ ops = nvmet_transports[trtype];
+ if (!ops) {
+ pr_err("transport type %d not supported\n", trtype);
+ return NULL;
+ }
+ }
+
+ if (!try_module_get(ops->owner))
+ return NULL;
+
+ return ops;
+}
+
void nvmet_port_del_ctrls(struct nvmet_port *port, struct nvmet_subsys *subsys)
{
struct nvmet_ctrl *ctrl;
@@ -325,22 +349,9 @@ int nvmet_enable_port(struct nvmet_port *port)
lockdep_assert_held(&nvmet_config_sem);
- ops = nvmet_transports[port->disc_addr.trtype];
- if (!ops) {
- up_write(&nvmet_config_sem);
- request_module("nvmet-transport-%d", port->disc_addr.trtype);
- down_write(&nvmet_config_sem);
- ops = nvmet_transports[port->disc_addr.trtype];
- if (!ops) {
- pr_err("transport type %d not supported\n",
- port->disc_addr.trtype);
- return -EINVAL;
- }
- }
-
- if (!try_module_get(ops->owner))
+ ops = nvmet_get_ops_by_transport(port->disc_addr.trtype);
+ if (!ops)
return -EINVAL;
-
/*
* If the user requested PI support and the transport isn't pi capable,
* don't enable the port.
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index ec3d10eb316a..052ea4a105fc 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -622,6 +622,7 @@ void nvmet_port_send_ana_event(struct nvmet_port *port);
int nvmet_register_transport(const struct nvmet_fabrics_ops *ops);
void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops);
+const struct nvmet_fabrics_ops *nvmet_get_ops_by_transport(int trtype);
void nvmet_port_del_ctrls(struct nvmet_port *port,
struct nvmet_subsys *subsys);
--
2.43.0
More information about the Linux-nvme
mailing list