From patchwork Tue Jun 14 04:35:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 9174953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2228C6048C for ; Tue, 14 Jun 2016 04:36:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A06281DB for ; Tue, 14 Jun 2016 04:36:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C1312821F; Tue, 14 Jun 2016 04:36:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, URIBL_BLACK autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0A71281DB for ; Tue, 14 Jun 2016 04:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933261AbcFNEgy (ORCPT ); Tue, 14 Jun 2016 00:36:54 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:38486 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932562AbcFNEgv (ORCPT ); Tue, 14 Jun 2016 00:36:51 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 8A22922CABB; Tue, 14 Jun 2016 04:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=linux-iscsi.org; s=default.private; t=1465878953; bh=2eVtuF13+o+nYe7Jf1XRbB2QjvtyvUZ hX4rS/QweuDI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References; b=0Z8fGb7Uc9RnAx5M8qUwh5dDIz/N0RnVplobqvdObmP7m/Js7Y8Y tVVAWIB6ZH8MUDXKy98gm26QORmLIphvb2Lr4yey2DC0LWth39zjhFP39Tu+NDq2cKX gaxEDEzmn540X/1BUQnaKjACTbBmb28hs6y4yGkIP7I8ocpbLKCQ= From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , linux-nvme , Jens Axboe , Christoph Hellwig , Keith Busch , Jay Freyensee , Martin Petersen , Sagi Grimberg , Hannes Reinecke , Mike Christie , Dave B Minturn , Nicholas Bellinger Subject: [RFC-v2 02/11] nvmet: Add nvmet_fabric_ops get/put transport helpers Date: Tue, 14 Jun 2016 04:35:37 +0000 Message-Id: <1465878946-26556-3-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1465878946-26556-1-git-send-email-nab@linux-iscsi.org> References: <1465878946-26556-1-git-send-email-nab@linux-iscsi.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 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);