From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Nicholas A. Bellinger" Subject: [RFC 1/8] nvmet: Add nvmet_fabric_ops get/put transport helpers Date: Tue, 7 Jun 2016 06:36:49 +0000 Message-ID: <1465281416-28355-2-git-send-email-nab@linux-iscsi.org> References: <1465281416-28355-1-git-send-email-nab@linux-iscsi.org> Return-path: In-Reply-To: <1465281416-28355-1-git-send-email-nab@linux-iscsi.org> Sender: target-devel-owner@vger.kernel.org To: target-devel Cc: linux-nvme , linux-scsi , Jens Axboe , Christoph Hellwig , Martin Petersen , Sagi Grimberg , Hannes Reinecke , Mike Christie , Dave B Minturn , Nicholas Bellinger List-Id: linux-scsi@vger.kernel.org From: Nicholas Bellinger 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 Cc: Christoph Hellwig Cc: Martin Petersen Cc: Sagi Grimberg Cc: Hannes Reinecke Cc: Mike Christie Signed-off-by: Nicholas Bellinger --- drivers/nvme/target/core.c | 31 +++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index e0b3f01..9af813c 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -191,6 +191,37 @@ void nvmet_disable_port(struct nvmet_port *port) module_put(ops->owner); } +struct nvmet_fabrics_ops *nvmet_get_transport(struct nvmet_port *port) +{ + struct nvmet_fabrics_ops *ops; + + 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 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 nvmet_port *port) +{ + struct nvmet_fabrics_ops *ops; + + down_write(&nvmet_config_sem); + ops = nvmet_transports[port->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..2bf15088b 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -299,6 +299,9 @@ 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 nvmet_port *port); +void nvmet_put_transport(struct nvmet_port *port); + void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port); void nvmet_referral_disable(struct nvmet_port *port); -- 1.9.1