From patchwork Tue Feb 6 12:09:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1505013dyb; Tue, 6 Feb 2024 04:33:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHe3/2DuFN+08Z+WOb76Mk4ugWYYODt1dUVXtBspSdaiyaEYe/707rUoF+HhL2JD4HN0It3 X-Received: by 2002:a17:90b:1a88:b0:296:21dc:488c with SMTP id ng8-20020a17090b1a8800b0029621dc488cmr2131753pjb.41.1707222834552; Tue, 06 Feb 2024 04:33:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222834; cv=pass; d=google.com; s=arc-20160816; b=SbgKxl/AqYhqcH9fbb+7AQUGiqvBx+Fvg8yXZKo/W87DdEDuRehf6fN9szuN6WdLDj YuAnCWGylShSduGNd8E20sXhmwqT7NHaR16SSANULoc5goFe/Z+VqV9UEPRo23F7UeGj tD8NCuXexJ76ZBIT2PpwjHmVCPKwUy6N8vxwxW7YWobzzLW7Zfeby3hb84XlP9w5thRl RXZ118RR8MlGZdPAeS1waIGGvIfWkxpd+eE3pp+oPrJ6ooVVrqhsrlwBBWrkz9jpRieA ERqKylrx0e9lM388asFk7wZivkOhGiz+9xUq8daDuPFznOOVlqAFifUPdUeXkTm1orRm iMNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=uXyNTi+hcecekKn8pb9kUZDns5PCP3zA+0J9cysBCZk=; fh=1W5b7BHlcOzQn+3B+IsaHelm7966lbw47qGVOpoHitk=; b=sQImWM5nONtwJhHqBjhvPeXlQ3SQ2wyH6nHG9ykVFH/+wc/eUdC6OcV/u4wYSq6V+x h+8Q7/aM2FGCn7p/RqbeC9ZJLEnCHqvR2qJHYt9PjRYZSoHWqEsIyZmqywKPUGNhRxjX PXGUakzGplSvW5S0ETwbvpf+BBOgNGHE9T5OgWlw987cgxWNYyme0bVffaDJ7MrYEtEh fgc6XV3yFCU+cgDc8PoUoIF8lCJzMfKrfUXyq/NuSJqvmHNUBEXP6xwf1GMKbm9qcRy6 AQ9FmOvUVTQ7aLFYXj6Ze3/SuSNMJTZAhjONQKu5qp35RYr2jYOi6KcCzXYRyYJF75Jc RUlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCX7IW1sZ/G6SRzhmeGpgqmkJxbNTBFpcSf70yspR5lTeOgDBsCv7rNvefpr3rtnhBFZ1NxOJ3vnen+LPhHYhS3xQ85L1g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gl1-20020a17090b120100b00295efecceaasi1072708pjb.91.2024.02.06.04.33.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:33:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 05537B2669F for ; Tue, 6 Feb 2024 12:24:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5ED6714C58A; Tue, 6 Feb 2024 12:09:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40AA513341E; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; cv=none; b=LjndCWVw8yK+dmWm2AZaNIx7H1NV8ynLq8Oftd1XyJuSE8UmOfFSUDSDF7MrsLdCZSAZCpXAe3h4aj4JbvyrkjjUiZoeQwO7BKc8SbGTGeXclKyHFmlhi+JqzNri8SAQ4MCJD5UzjH8lW5+k6kwbElM0FmZE2bd40sWg2qloAck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=k2T8+mfZwwC/SEoIfiKTy8FA9wi/cqLxT6cnp0Xwewc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dOw/DXcSVf2fUKVot4J3P4BeJByJKM7oMj05RHxnKkpoFuXITuT1BcgEezCyoK7YpJX9vKUQKxh19YjJDtGTE7ItRfRWkZdNb4fnnU1YwJHUSiplJ57dn2jc7YM7tKGvufXmi5kR4vfKA3A0kekm3ocOvalQe5AuXn1/UwCuaFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFC2DC433A6; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bIq-0uEe; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.069546514@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:40 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.6][PATCH 35/57] eventfs: Remove "lookup" parameter from create_dir/file_dentry() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152890690715696 X-GMAIL-MSGID: 1790152890690715696 From: "Steven Rostedt (Google)" The "lookup" parameter is a way to differentiate the call to create_file/dir_dentry() from when it's just a lookup (no need to up the dentry refcount) and accessed via a readdir (need to up the refcount). But reality, it just makes the code more complex. Just up the refcount and let the caller decide to dput() the result or not. Link: https://lore.kernel.org/linux-trace-kernel/20240103102553.17a19cea@gandalf.local.home Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.517502710@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Ajay Kaher Cc: Al Viro Cc: Christian Brauner Signed-off-by: Steven Rostedt (Google) (cherry picked from commit b0f7e2d739b4aac131ea1662d086a07775097b05) --- fs/tracefs/event_inode.c | 55 +++++++++++++++------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f0677ea0ec24..c360300fb866 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -390,16 +390,14 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * @mode: The mode of the file. * @data: The data to use to set the inode of the file with on open() * @fops: The fops of the file to be created. - * @lookup: If called by the lookup routine, in which case, dput() the created dentry. * * Create a dentry for a file of an eventfs_inode @ei and place it into the - * address located at @e_dentry. If the @e_dentry already has a dentry, then - * just do a dget() on it and return. Otherwise create the dentry and attach it. + * address located at @e_dentry. */ static struct dentry * create_file_dentry(struct eventfs_inode *ei, int idx, struct dentry *parent, const char *name, umode_t mode, void *data, - const struct file_operations *fops, bool lookup) + const struct file_operations *fops) { struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; @@ -414,9 +412,7 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } /* If the e_dentry already has a dentry, use it */ if (*e_dentry) { - /* lookup does not need to up the ref count */ - if (!lookup) - dget(*e_dentry); + dget(*e_dentry); mutex_unlock(&eventfs_mutex); return *e_dentry; } @@ -441,13 +437,12 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * way to being freed, don't return it. If e_dentry is NULL * it means it was already freed. */ - if (ei->is_freed) + if (ei->is_freed) { dentry = NULL; - else + } else { dentry = *e_dentry; - /* The lookup does not need to up the dentry refcount */ - if (dentry && !lookup) dget(dentry); + } mutex_unlock(&eventfs_mutex); return dentry; } @@ -465,9 +460,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -500,13 +492,12 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) * @pei: The eventfs_inode parent of ei. * @ei: The eventfs_inode to create the directory for * @parent: The dentry of the parent of this directory - * @lookup: True if this is called by the lookup code * * This creates and attaches a directory dentry to the eventfs_inode @ei. */ static struct dentry * create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, - struct dentry *parent, bool lookup) + struct dentry *parent) { struct dentry *dentry = NULL; @@ -518,11 +509,9 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, return NULL; } if (ei->dentry) { - /* If the dentry already has a dentry, use it */ + /* If the eventfs_inode already has a dentry, use it */ dentry = ei->dentry; - /* lookup does not need to up the ref count */ - if (!lookup) - dget(dentry); + dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; } @@ -542,7 +531,7 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * way to being freed. */ dentry = ei->dentry; - if (dentry && !lookup) + if (dentry) dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; @@ -562,9 +551,6 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -589,8 +575,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct eventfs_inode *ei; struct dentry *ei_dentry = NULL; struct dentry *ret = NULL; + struct dentry *d; const char *name = dentry->d_name.name; - bool created = false; umode_t mode; void *data; int idx; @@ -626,13 +612,10 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_dir_dentry(ei, ei_child, ei_dentry, true); - created = true; - break; - } - - if (created) + d = create_dir_dentry(ei, ei_child, ei_dentry); + dput(d); goto out; + } for (i = 0; i < ei->nr_entries; i++) { entry = &ei->entries[i]; @@ -650,8 +633,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_file_dentry(ei, i, ei_dentry, name, mode, cdata, - fops, true); + d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + dput(d); break; } } @@ -768,9 +751,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) inode_lock(parent->d_inode); list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei, ei_child, parent, false); + d = create_dir_dentry(ei, ei_child, parent); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++; @@ -790,9 +774,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) mutex_unlock(&eventfs_mutex); if (r <= 0) continue; - d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false); + d = create_file_dentry(ei, i, parent, name, mode, cdata, fops); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++;