Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11172478ybi; Thu, 25 Jul 2019 11:13:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUwRCAxo1fw4DOPgIal3SmF6jtou/m5AmXMbsTbgb82RprUqJgAmb0goFwZX8qYdLSEXCW X-Received: by 2002:a17:902:9a84:: with SMTP id w4mr89806259plp.160.1564078424532; Thu, 25 Jul 2019 11:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564078424; cv=none; d=google.com; s=arc-20160816; b=SjAu6FonjMEfBRY3uE6M8OhbV4BT+5RRNfh8jI8Z0NPxUND2+xuqR9k0+c35mGgWuw zvIuq/KE16Y9cislDpgWJNmYLPajoBETzOegMrA8htV0BeqUIwcUf4aD4XzSiiXpMoU6 w260OWsaSbk+CxncvBQmlgLSY+kPKakCJCt5Rzwk445IUVUOszHvd6B2RuN8twIACEq5 EDRtR1/LiZUoWGUoii3/8wFquW1yIOInC51GKscbeStfDcchY2ipAw7Men11KENw2GO6 vlijG046XDejpApUNdG2sl1J8GRLxEoqA6LboEHQlJPp9TmwoyItnW06pyTTLQzb/TU8 7tuQ== 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=GRb4C+dlo9wt3N0rGK+F3b1ZoLI3nz9WPon/ZKBUawU=; b=r9HHofBD10SoQoWhuE4LsS77OBYJQRJWnvBvpUBmbkbIe4Ab1gZ1X7Pp4acVtLtwkz FPmSlKSMj/y4JTe6DwCamOpyJeKKlj569yKoLFvBUGjchLGrG8paLh7fMuDo5upT3EMg 3ppAnHk4b23pKWcFde64GKnyOr4TC+Wd+7vaIJqtZyIK2mrFCtARjkU0hY9SrFPKTbEj DMH6KPs9Th99Xb/1ioXemhzNtDw9gRh9oW8s0/pM7IPzmRST0Tts8QQmNQhtkZinRhUr Bcgm/jil5NwusqpCFsf0zmObuX+1sVHOaaKJensuhXG9k140eTxjq5u5ov0hirW27uoo tGXA== 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 a33si17887297pgl.436.2019.07.25.11.13.29; Thu, 25 Jul 2019 11:13:44 -0700 (PDT) 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 S2388137AbfGYRXr (ORCPT + 99 others); Thu, 25 Jul 2019 13:23:47 -0400 Received: from ale.deltatee.com ([207.54.116.67]:39620 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729870AbfGYRXq (ORCPT ); Thu, 25 Jul 2019 13:23:46 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hqhSv-0001JF-V8; Thu, 25 Jul 2019 11:23:45 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1hqhSv-0001n8-0Z; Thu, 25 Jul 2019 11:23:41 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Christoph Hellwig , Sagi Grimberg , Keith Busch , Jens Axboe , Chaitanya Kulkarni , Max Gurtovoy , Stephen Bates , Logan Gunthorpe , Greg Kroah-Hartman , Alexander Viro Date: Thu, 25 Jul 2019 11:23:21 -0600 Message-Id: <20190725172335.6825-3-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725172335.6825-1-logang@deltatee.com> References: <20190725172335.6825-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-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.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, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk 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=-8.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH v6 02/16] chardev: introduce cdev_get_by_path() X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +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 cdev_get_by_path() attempts to retrieve a struct cdev from a path name. It is analagous to blkdev_get_by_path(). This will be necessary to create a nvme_ctrl_get_by_path()to support NVMe-OF passthru. Signed-off-by: Logan Gunthorpe Cc: Greg Kroah-Hartman Cc: Alexander Viro --- fs/char_dev.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/cdev.h | 1 + 2 files changed, 35 insertions(+) diff --git a/fs/char_dev.c b/fs/char_dev.c index 5cc53bd5f654..25037d642ff8 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "internal.h" @@ -403,6 +404,38 @@ static struct cdev *cdev_lookup(struct inode *inode) return p; } +struct cdev *cdev_get_by_path(const char *pathname) +{ + struct inode *inode; + struct cdev *cdev; + struct path path; + int error; + + if (!pathname || !*pathname) + return ERR_PTR(-EINVAL); + + error = kern_path(pathname, LOOKUP_FOLLOW, &path); + if (error) + return ERR_PTR(error); + + if (!may_open_dev(&path)) { + cdev = ERR_PTR(-EACCES); + goto out; + } + + inode = d_backing_inode(path.dentry); + if (!S_ISCHR(inode->i_mode)) { + cdev = ERR_PTR(-EINVAL); + goto out; + } + + cdev = cdev_lookup(inode); + +out: + path_put(&path); + return cdev; +} + /* * Called every time a character special file is opened */ @@ -690,5 +723,6 @@ EXPORT_SYMBOL(cdev_add); EXPORT_SYMBOL(cdev_set_parent); EXPORT_SYMBOL(cdev_device_add); EXPORT_SYMBOL(cdev_device_del); +EXPORT_SYMBOL(cdev_get_by_path); EXPORT_SYMBOL(__register_chrdev); EXPORT_SYMBOL(__unregister_chrdev); diff --git a/include/linux/cdev.h b/include/linux/cdev.h index 0e8cd6293deb..c7f2df2ca69a 100644 --- a/include/linux/cdev.h +++ b/include/linux/cdev.h @@ -24,6 +24,7 @@ void cdev_init(struct cdev *, const struct file_operations *); struct cdev *cdev_alloc(void); +struct cdev *cdev_get_by_path(const char *pathname); void cdev_put(struct cdev *p); int cdev_add(struct cdev *, dev_t, unsigned); -- 2.20.1