From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6C69C433E1 for ; Thu, 16 Jul 2020 21:17:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7CAA20760 for ; Thu, 16 Jul 2020 21:17:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=deltatee.com header.i=@deltatee.com header.b="cC5Xks6q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbgGPVRr (ORCPT ); Thu, 16 Jul 2020 17:17:47 -0400 Received: from ale.deltatee.com ([204.191.154.188]:47670 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbgGPVRq (ORCPT ); Thu, 16 Jul 2020 17:17:46 -0400 X-Greylist: delayed 2660 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 Jul 2020 17:17:46 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=AQCEG0bH+gkQSxPbjGRwXaXeTXWxGzo0AtT6lOP7ofI=; b=cC5Xks6q3R8siit7AR8s/XhBR9 Gk9Me2NXvxfqlW91YhlyIS91jjfA4RLHKNsgueYezzykphRMyjZ13YEYA/dRfn6sCv0f31hgM4Ekp C2QVShJUyRIwxEHv4djE6DXJoiFy2SYV5kZpObKDb/CHvWA7+hRtTIskULvY0ek0zAHl6lGHLPJv6 sF3QPQHF+2CLv/9P0eKJTkbjGr89weq3HPa+b1ol7WWOJEwmVVvjHfpsWI9Ni/SMRDIfR9rf97f3Y /IE2mmUJ2p92RHZm4jbBXH1O9/eIvVGCXRPU1TsSvSlM2BUG4rpQmtyq+SFbvjmyXcCx7dgPDzMom 3XUODU0Q==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jwAZQ-0005uH-Ac; Thu, 16 Jul 2020 14:33:33 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1jwAZF-0004BW-0u; Thu, 16 Jul 2020 14:33:21 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Christoph Hellwig , Sagi Grimberg , Keith Busch , Jens Axboe , Chaitanya Kulkarni , Max Gurtovoy , Stephen Bates , Logan Gunthorpe Date: Thu, 16 Jul 2020 14:33:15 -0600 Message-Id: <20200716203319.16022-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200716203319.16022-1-logang@deltatee.com> References: <20200716203319.16022-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me, kbusch@kernel.org, axboe@fb.com, Chaitanya.Kulkarni@wdc.com, maxg@mellanox.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH v15 5/9] nvme-core: Introduce nvme_ctrl_get_by_path() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org nvme_ctrl_get_by_path() is analagous to blkdev_get_by_path() except it gets a struct nvme_ctrl from the path to its char dev (/dev/nvme0). It makes use of filp_open() to open the file and uses the private data to obtain a pointer to the struct nvme_ctrl. If the fops of the file do not match, -EINVAL is returned. The purpose of this function is to support NVMe-OF target passthru. Signed-off-by: Logan Gunthorpe Reviewed-by: Max Gurtovoy Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 817ab76d2838..6e7d5cb43a06 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4572,6 +4572,37 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl) } EXPORT_SYMBOL_GPL(nvme_sync_queues); +#ifdef CONFIG_NVME_TARGET_PASSTHRU +/* + * The exports that follow within this ifdef are only for + * use by the nvmet-passthru and should not be used for + * other things. + */ + +struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path) +{ + struct nvme_ctrl *ctrl; + struct file *f; + + f = filp_open(path, O_RDWR, 0); + if (IS_ERR(f)) + return ERR_CAST(f); + + if (f->f_op != &nvme_dev_fops) { + ctrl = ERR_PTR(-EINVAL); + goto out_close; + } + + ctrl = f->private_data; + nvme_get_ctrl(ctrl); + +out_close: + filp_close(f, NULL); + return ctrl; +} +EXPORT_SYMBOL_GPL(nvme_ctrl_get_by_path); +#endif /* CONFIG_NVME_TARGET_PASSTHRU */ + /* * Check we didn't inadvertently grow the command structure sizes: */ diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 13ca90bcd352..485492a98ef5 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -763,4 +763,10 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl); static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { } #endif +/* + * These functions are only for use by nvmet-passthru and are only exported + * if CONFIG_NVME_TARGET_PASSTHRU is set. + */ +struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path); + #endif /* _NVME_H */ -- 2.20.1