From patchwork Tue Jun 7 06:36:49 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: 9159903 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 67E1D60801 for ; Tue, 7 Jun 2016 06:37:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59A042823D for ; Tue, 7 Jun 2016 06:37:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C83E28345; Tue, 7 Jun 2016 06:37:59 +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 A41CA2823D for ; Tue, 7 Jun 2016 06:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753601AbcFGGhw (ORCPT ); Tue, 7 Jun 2016 02:37:52 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:47867 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753586AbcFGGhs (ORCPT ); Tue, 7 Jun 2016 02:37:48 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 3235822CAAB; Tue, 7 Jun 2016 06:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=linux-iscsi.org; s=default.private; t=1465281421; bh=yfK9BC6Z72KTZhv7BrrZKAA0zt4lJ7b QKglUIWkGtCU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References; b=vEaX31r7FcK6bXpwvyfU6PDl+PxjlkU7Pta5PSNzrg+UmGckkDnf IDf75iw1xwiG0/Ud9k3fnItXZNgqgK010ileYu5BhbqYM1iZOGbRMHI4KjubpE6wSAP WCdh6bnLD/rpbRy0ot5i++OgebfRaX6DYWoZOCGaJx3nYO1LL0ws= From: "Nicholas A. Bellinger" 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 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> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1465281416-28355-1-git-send-email-nab@linux-iscsi.org> References: <1465281416-28355-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 | 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);