From patchwork Tue Jan 31 22:53:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9548751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B46160425 for ; Tue, 31 Jan 2017 22:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61ABD2832B for ; Tue, 31 Jan 2017 22:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56815283EC; Tue, 31 Jan 2017 22:54:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2DA2832B for ; Tue, 31 Jan 2017 22:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750830AbdAaWyI (ORCPT ); Tue, 31 Jan 2017 17:54:08 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:34367 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750796AbdAaWyH (ORCPT ); Tue, 31 Jan 2017 17:54:07 -0500 Received: by mail-pf0-f173.google.com with SMTP id e4so112113964pfg.1 for ; Tue, 31 Jan 2017 14:54:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jGa3uDdEgv6/3j2d5cgWvx8nKgsDh2gvmvx+bp4NuqU=; b=ZrOiW5MHs8gUHR+4OR/s5yMT6VynAW5agLqL6HCuRLBfRN0FaxLxjKv/h7pviNbdM4 kU31haw864FdahgUeQ2XIC7oUXYkqDYS/P0z6KaJtDrBJml/s2rS5xuBTRY0aTG2CLUk DSZ9F4vsIXVBR5CVWhqH1F95J74z5zIhfhZqxgrNUkqYWJ8fXBFX4lIKrWpMjSJWX/aG +mQhJIWRbzH/XCPMmRmFjInJHajnLajqAiBYZ7IRmdtYUU5Dv1vlnMBWDUdB1P7CHNF+ jAhaMqIBqFBoomPbwt/fo9V0jnEkPXMcIPRVdbnakmxUV0ZLPKnnbOORrwQQbbegnszg /5Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jGa3uDdEgv6/3j2d5cgWvx8nKgsDh2gvmvx+bp4NuqU=; b=A6x2UWKju8g8SoDtrb1NkfDFrIFNHaWVhhI9jw5vN3I9B6W55rYHRzQA19njqHNvDm WI1s65DC/qQBUVon5uy0J6vb6DtaZ055cjxjEnjI5TDKqj96LcI1HYShQGkiKYi4Tbf4 vllqG/nwV3mveEszCLjxlegta5d0PA9jBCirmPztrcyuwCcMKkcmFlqhQ0KxEi1c2IsF THsPoGrUXp3Vf3eET1ca7uIaMtw/Hbk6+s0IfmrvmVp0Uv5CKBEfI278HcHPDtsJqUd4 o86wfUaJgx7i3YFAYDbYAjR2TyjFV3W7ePacTIXkRsWx4+hxaKQQRLC3zbLYWsI+IW2J ukBA== X-Gm-Message-State: AIkVDXI/24AsyMMfuc+O0+a2ay02Hw3o7RUm8pvygB+BDPr0zvTE6fYKq+g2VV1HWG/r+J6Q X-Received: by 10.98.72.216 with SMTP id q85mr32595549pfi.75.1485903247004; Tue, 31 Jan 2017 14:54:07 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::b:7f05]) by smtp.gmail.com with ESMTPSA id e127sm43614618pfh.89.2017.01.31.14.54.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jan 2017 14:54:06 -0800 (PST) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: kernel-team@fb.com, Greg Kroah-Hartman Subject: [PATCH 1/6] debugfs: add debugfs_lookup() Date: Tue, 31 Jan 2017 14:53:17 -0800 Message-Id: <0b6ca2b7f686cd19177034ad26f96a86dd34009e.1485902856.git.osandov@fb.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval We don't always have easy access to the dentry of a file or directory we created in debugfs. Add a helper which allows us to get a dentry we previously created. The motivation for this change is a problem with blktrace and the blk-mq debugfs entries introduced in 07e4fead45e6 ("blk-mq: create debugfs directory tree"). Namely, in some cases, the directory that blktrace needs to create may already exist, but in other cases, it may not. We _could_ rely on a bunch of implied knowledge to decide whether to create the directory or not, but it's much cleaner on our end to just look it up. Cc: Greg Kroah-Hartman Signed-off-by: Omar Sandoval --- fs/debugfs/inode.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/debugfs.h | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index f17fcf89e18e..7fb1732a3630 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -248,6 +248,42 @@ static struct file_system_type debug_fs_type = { }; MODULE_ALIAS_FS("debugfs"); +/** + * debugfs_lookup() - look up an existing debugfs file + * @name: a pointer to a string containing the name of the file to look up. + * @parent: a pointer to the parent dentry of the file. + * + * This function will return a pointer to a dentry if it succeeds. If the file + * doesn't exist or an error occurs, %NULL will be returned. The returned + * dentry must be passed to dput() when it is no longer needed. + * + * If debugfs is not enabled in the kernel, the value -%ENODEV will be + * returned. + */ +struct dentry *debugfs_lookup(const char *name, struct dentry *parent) +{ + struct dentry *dentry; + + if (IS_ERR(parent)) + return NULL; + + if (!parent) + parent = debugfs_mount->mnt_root; + + inode_lock(d_inode(parent)); + dentry = lookup_one_len(name, parent, strlen(name)); + inode_unlock(d_inode(parent)); + + if (IS_ERR(dentry)) + return NULL; + if (!d_really_is_positive(dentry)) { + dput(dentry); + return NULL; + } + return dentry; +} +EXPORT_SYMBOL_GPL(debugfs_lookup); + static struct dentry *start_creating(const char *name, struct dentry *parent) { struct dentry *dentry; diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 014cc564d1c4..c0befcf41b58 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -80,6 +80,8 @@ static const struct file_operations __fops = { \ #if defined(CONFIG_DEBUG_FS) +struct dentry *debugfs_lookup(const char *name, struct dentry *parent); + struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); @@ -181,6 +183,12 @@ ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf, * want to duplicate the design decision mistakes of procfs and devfs again. */ +static inline struct dentry *debugfs_lookup(const char *name, + struct dentry *parent) +{ + return ERR_PTR(-ENODEV); +} + static inline struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops)