Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1073706ybv; Thu, 20 Feb 2020 12:39:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyt4OEPwPK8AOdibLY6cGZRcyl5443Zv/Xx355a9gGr4VoeTmx0m4Y7b43DJ6WNdTyJCMXi X-Received: by 2002:a9d:7e99:: with SMTP id m25mr24615798otp.212.1582231158102; Thu, 20 Feb 2020 12:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582231158; cv=none; d=google.com; s=arc-20160816; b=EIhvMx4E3y3q4LsaFFrNQcqamxSxiDE3NMAvzy0volrk94794nLSTI+5iUJtrgT7cN t4DvdkPNpb2ta899ezE8c3UYev0horPb6kGGZee2OL+VJv7DlksAWjjSeDCjTmoe0qoS 5JQ+Aul82YKsei1xiu4K/y+6rch12HAQpixstwfg0kOfoodoBiefBj0WuSsedV2zsG/L EBQsystpcNFcJ9f1NkX1MpnEp0O0ua+gQUqm/ZZmRctJSOBEI1WFnXlbyhw0V5BQikGA RZtn5A2M/5r6UUm1OfErVeRxWXNXj7whgOBPCN3XCv/R2lW9DB5FfPKvFNy2oZ+HLyiP G4kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=vsUccgrUU9aHmNHlB/tKooVOPnBx0Hgb/GtcyftQbEU=; b=Nnct028UrAtEa3dZZB/5bDc5U2Ae/F+6mBVdcl1r4e96ip5fmQNonClCag1HwLP9gf B17XAaopkYWKKUtQaXE4rN0DBA9lbqvo8J82eEX2VsBaIZBF/tLGdqUoFufmAUf3E87a BhbtaNtb5ySudz4vyIm38W82QZ8Pt7cW4z9viinSrx2rF/JZam6s3CgVEswbNx+WLQQp +08yE/RYPh3kD/eP9Vo8Ddb3CwTLg7Rxx0Rjhqy0qPsvDWolMwtust5otZ6CTQSqC921 msocMqwVQMfGS5b9g3GoZUnzdYeT+UMW4ObZn5raDV33e3eZbeZ4osAxuVnCfTBo4h5+ rqcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11si206885oic.20.2020.02.20.12.39.06; Thu, 20 Feb 2020 12:39:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729069AbgBTUhV (ORCPT + 99 others); Thu, 20 Feb 2020 15:37:21 -0500 Received: from ale.deltatee.com ([207.54.116.67]:45162 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729131AbgBTUhD (ORCPT ); Thu, 20 Feb 2020 15:37:03 -0500 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 1j4sZ8-0005cS-BQ; Thu, 20 Feb 2020 13:37:02 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1j4sZ8-0006yJ-47; Thu, 20 Feb 2020 13:36:58 -0700 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, 20 Feb 2020 13:36:48 -0700 Message-Id: <20200220203652.26734-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200220203652.26734-1-logang@deltatee.com> References: <20200220203652.26734-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 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH v11 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 | 9 +++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 219e24304b4e..756f8ee201d9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4227,6 +4227,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 1024fec7914c..196a0d38e19c 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -687,4 +687,13 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl); static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { } #endif +#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); +#endif /* CONFIG_NVME_TARGET_PASSTHRU */ + #endif /* _NVME_H */ -- 2.20.1