Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1499314ybk; Thu, 14 May 2020 10:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS2L6ydEuIodP/Y4NL3bBpxfNj54ZEMLRUUh75NX2CGTEVTvpBZCWKm41uObU9Em60ab/i X-Received: by 2002:a17:906:5e41:: with SMTP id b1mr4688678eju.278.1589477163311; Thu, 14 May 2020 10:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589477163; cv=none; d=google.com; s=arc-20160816; b=IcuTvWnf7Jo9X5HJyGgEB7GIspafiBX7YusmzcJaKUh6hRtUuGn96Ksu5/7JLd+ows moDPG+CgXIp3hBv0ZSqpDqrXcyubOQCScxqq6KuHQp0svglRRWBEHOMhaYgcMa9ZiL4X +MQJF8zHqj0WKxkNWlwIo0CHvVocoyUEB/ndGQQfNpQVZOhpRbxiJ3oa7GF6M7iLLCMV Oc7+nFnXp5wo56f2KZ/udYesfVD+/M2/TkjompX3LQ2LfgC+Cv3EPdF4u+hP4Io0yq58 kWcNlrmTgfeVaiYNVJ1+JpmUIzd39/sfreOnsdTvNxCbFnCvMA8rye1+8XAfG5JjpD0B wrAw== 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=u3G2qDcytQi1y6uglruWIcOM7CnzhC3c80wjX9aephI=; b=JKsnU6SsYt6TVI3hSnsyS9xnd8DU7Jynh9hovdqeYcP5XiXwl8X4QTtHpVKHL7bPi/ rr1TC6F0GBE5RFwLRPhA+SX160O1dh//oils7QtvDQbCL1T6rP8vCL6ZHR6aLIgynIul QqUe0aq148vySmNLwzLhnePHiPluieEYGL3vVIyiYpj51h9NxNp6K6Bh64JzHiCNQW3P AeHQfqc1zGGQ57gXjqTaOIOlOrruDllBDGH2/+5tbRINZ/vsmehbhIU57iyeldqXEn9d XZUaDXFZ3LuHa6PA/9PJlBJ317CN1qJJ8WH330IIpRzly7azUPh0KxrBhpLoZStiZxSk MNJA== 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 q10si2307919eju.123.2020.05.14.10.25.39; Thu, 14 May 2020 10:26:03 -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 S1726171AbgENRXN (ORCPT + 99 others); Thu, 14 May 2020 13:23:13 -0400 Received: from ale.deltatee.com ([207.54.116.67]:46912 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbgENRXK (ORCPT ); Thu, 14 May 2020 13:23:10 -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 1jZHZV-00021r-Ty; Thu, 14 May 2020 11:23:06 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1jZHZU-0001h3-MM; Thu, 14 May 2020 11:23:00 -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, 14 May 2020 11:22:49 -0600 Message-Id: <20200514172253.6445-6-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514172253.6445-1-logang@deltatee.com> References: <20200514172253.6445-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 v13 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 2ead7ad45a9d..2604971362d8 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4305,6 +4305,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