From: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> This patch introduces two helpers for obtaining + releasing nvmet_fabric_ops for nvmet_port usage, and the associated struct module ops->owner reference. This is required in order to support nvmet/configfs-ng and multiple nvmet_port configfs groups living under /sys/kernel/config/nvmet/subsystems/$SUBSYS_NQN/ports/ Cc: Jens Axboe <axboe@xxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Martin Petersen <martin.petersen@xxxxxxxxxx> Cc: Sagi Grimberg <sagi@xxxxxxxxxxx> Cc: Hannes Reinecke <hare@xxxxxxx> Cc: Mike Christie <michaelc@xxxxxxxxxxx> Signed-off-by: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> --- drivers/nvme/target/core.c | 32 ++++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index e0b3f01..689ad4c 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -191,6 +191,38 @@ void nvmet_disable_port(struct nvmet_port *port) module_put(ops->owner); } +struct nvmet_fabrics_ops * +nvmet_get_transport(struct nvmf_disc_rsp_page_entry *disc_addr) +{ + struct nvmet_fabrics_ops *ops; + + down_write(&nvmet_config_sem); + ops = nvmet_transports[disc_addr->trtype]; + if (!ops) { + pr_err("transport type %d not supported\n", + disc_addr->trtype); + return ERR_PTR(-EINVAL); + } + + if (!try_module_get(ops->owner)) { + up_write(&nvmet_config_sem); + return ERR_PTR(-EINVAL); + } + up_write(&nvmet_config_sem); + + return ops; +} + +void nvmet_put_transport(struct nvmf_disc_rsp_page_entry *disc_addr) +{ + struct nvmet_fabrics_ops *ops; + + down_write(&nvmet_config_sem); + ops = nvmet_transports[disc_addr->trtype]; + module_put(ops->owner); + up_write(&nvmet_config_sem); +} + static void nvmet_keep_alive_timer(struct work_struct *work) { struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work), diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 57dd6d8..17fd217 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -299,6 +299,10 @@ void nvmet_unregister_transport(struct nvmet_fabrics_ops *ops); int nvmet_enable_port(struct nvmet_port *port); void nvmet_disable_port(struct nvmet_port *port); +struct nvmet_fabrics_ops *nvmet_get_transport( + struct nvmf_disc_rsp_page_entry *disc_addr); +void nvmet_put_transport(struct nvmf_disc_rsp_page_entry *disc_addr);; + void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port); void nvmet_referral_disable(struct nvmet_port *port); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html