Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3811720ybz; Mon, 20 Apr 2020 09:52:51 -0700 (PDT) X-Google-Smtp-Source: APiQypJTk+cVbZDDDDs8gotazXaggin2uZOmByXAWwticICG0YUUoOkdgdk9+IUpLlFvny491rl4 X-Received: by 2002:a05:6402:22ed:: with SMTP id dn13mr14844578edb.212.1587401571639; Mon, 20 Apr 2020 09:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587401571; cv=none; d=google.com; s=arc-20160816; b=cId0mc0CLfJ7oCLdTlBriA76EuaCogoCuWxnHn7SwAOUVioNn7ifRa+PLzlWYKgdUj 9TkYy4TdYejZkEP2pLOOunXrgXCuIgoHUmJxOs7allbnB8u5WQwVt7LS7RyjOiEzwfsP duesj13M2DcN+Bz7wS2z4jAOt58T1oPnr81mNaoUc5THoyzTy20WqHFJ1ks2lM3rFR1+ BTMCo9P2wsvCtZLYjup+/iW8zIoOXQBXzwkfGaZatsgXo7jsohu/4PiU4M4Kd9Z7tU1l hr3oWuYeLAv1wRw3O5iHZZyX/Q1etJhfDdqR/rIa7uQS4S+kFiH9id9zCxVIgqXiJaki hKAg== 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=F13bE3JnUVykUH0QhYaSUE3m6XTPLwgi8lHpEiDCX5Q=; b=i05qfAWf/2R9vQ1YL73baC3mjdg75GRqDkZH4YHojYJTfxRiAO1gh8DxdxBClcBPwS f6Twl5czJDwhyxpLs2N7Cqkp6GlLhqU5fuFdD3ETKUzStTzcabTGiEFBb3j5klztQwK8 O8v+c/emIcshtIGYi3y5XdXrrTNBtvTZgEAdmhqqmM8UIlO9LF2MqTJlAeOmTs+PDQ+I elZnZuGW52yQ9euSrdFRKr6yGcun5R3xHcbbNlw1aO6CiYAq6Lhyfq7/dNoTVsdWTDXT fzUJLlBqyf5stQ1hh5pLQfOgV2cif4kL0Tvd48FmBlm4wqKyuokO+MsqmIvI6jsD84e2 RNaQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d17si868607ejh.334.2020.04.20.09.52.27; Mon, 20 Apr 2020 09:52:51 -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; 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 S1726232AbgDTQrL (ORCPT + 99 others); Mon, 20 Apr 2020 12:47:11 -0400 Received: from ale.deltatee.com ([207.54.116.67]:43038 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgDTQrL (ORCPT ); Mon, 20 Apr 2020 12:47:11 -0400 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 1jQZZb-0008F5-BL; Mon, 20 Apr 2020 10:47:08 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1jQZZa-0005do-92; Mon, 20 Apr 2020 10:47:06 -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: Mon, 20 Apr 2020 10:46:56 -0600 Message-Id: <20200420164700.21620-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200420164700.21620-1-logang@deltatee.com> References: <20200420164700.21620-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 autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH v12 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 1e2062c341c5..1f3ef53bb8b4 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4303,6 +4303,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 2e04a36296d9..9195dd97b61b 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -689,4 +689,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