Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp724965ybt; Fri, 26 Jun 2020 10:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIumcRK316A8MEyCeTRHOv+LEs8LOHSqIM7cXpjIpZjzMhD8+JN1WdLzbJyKT06E3GwP6v X-Received: by 2002:a17:906:9387:: with SMTP id l7mr3312184ejx.274.1593190913459; Fri, 26 Jun 2020 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593190913; cv=none; d=google.com; s=arc-20160816; b=ov1yAyFWbCPoNP70UOrEFxh5PBmEM2wg7Q6XoW0GG8T4W5RPGx52LctmvAoZGp0lXz xL6DzXXHZ12kmW0sNfjh/10hY2pu+LdmWkcFy1Y4VdvxJtx9G5at+1lRsTUYGict5rOP 5jT8oYUwBLbj9SVNxZTG248o+8qk9oa66pXopLMb80DbLBy52HwD5ZB27ozKNFkNlkD3 l+LwwBM9O1fJYfYn3MK56co2KIlYVuqmG5ZHmhShH4lTH1sLG6PU2EIin7Ep0r1VgIiw VSRIkxKWLPcaQrw/p7o/JZBRdUN+B7stO2S9dcKp0ehwPNPfBRovwejRy/HlAuV+IvpA 6E0A== 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 :dkim-signature; bh=0P+V/GA6kjnmOazXS4i5E7J/ATNToBo60mTEbmyeGr4=; b=rbgZBILh1MicdpfNPAmY5J1cBlbgG7C7SULHbm/5AnZ7m0GNs/qrdVuu6ieYLYmOnv 3xCxQusKSGaWK5T7jMfau4P6dB1ppUXfayyc4IFYGLWnjxYoUWXohZYtYUjNUVd9IddV LrX1UTZ6xyY4OIe5C5/8/1uHUvo78oflISlau11OQ5mCZ8mIVRbVK+w066x+Pp0gNtiw x10t2AnQHeJ8n3fCwwmtgMtTAm/5ltPTI+kPEAIGzl5Xl5l09p9FR7VurxJ9SpFl2CIs Rfv1QKteRfce19zNkNcB8AAu6b3cSBl4PAnJS3gjfXcVCsaG0SHx2xkmhfyiGGfINHNz 7y5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=A27IIaLX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kq13si17374482ejb.276.2020.06.26.10.01.30; Fri, 26 Jun 2020 10:01:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=A27IIaLX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729834AbgFZPkZ (ORCPT + 99 others); Fri, 26 Jun 2020 11:40:25 -0400 Received: from ale.deltatee.com ([207.54.116.67]:34856 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729714AbgFZPjh (ORCPT ); Fri, 26 Jun 2020 11:39:37 -0400 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=0P+V/GA6kjnmOazXS4i5E7J/ATNToBo60mTEbmyeGr4=; b=A27IIaLXnyNF8UdImF34dOisAD x9pkO7HyLOHEDFoGFKlfYZ+2APXPAkFEDxvdw2KKLpAVHbbcullx51P6C4uixlDQCyVsefvOPHkLr LssN7jKTRz/0HSqTAVQkx6w3FV4lkTlHpaEXUQeIYx/VVb3jdxqxhcDOEo63ya96HbAYuuur3sgSe Z3RS4+99DneUgj+mu8vYhQBrMYRNHKhCK4UVCCrg1s27cbUHGo1vmZmmagq1PY663ucw+mijd22RB jy5P6svwJ8m6tVxfj9T2UijyhS1xqYl+pXh4u52bitU5QrAIKIOO1cpU2crl/VFQQgWNC4vJnt6Jo qTrBV8ow==; 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 1joqRu-0000oS-43; Fri, 26 Jun 2020 09:39:34 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1joqRn-0007HZ-92; Fri, 26 Jun 2020 09:39:23 -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: Fri, 26 Jun 2020 09:39:14 -0600 Message-Id: <20200626153918.27929-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200626153918.27929-1-logang@deltatee.com> References: <20200626153918.27929-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 v14 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 4171e07f1fc9..acd5af305f4b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4361,6 +4361,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 2ef8d501e2a8..e7074afadb5f 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -712,4 +712,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