From patchwork Thu Jan 4 21:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 185157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5891633dyb; Thu, 4 Jan 2024 14:00:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf8fUdBdEo1AIA3CxQ+SJEIZAx6oPwgYI9fpAKt/Oq5oV7bo/lPIO55AugU311iXuaD0sZ X-Received: by 2002:a05:620a:5595:b0:77f:3db5:7b69 with SMTP id vq21-20020a05620a559500b0077f3db57b69mr1432305qkn.32.1704405652056; Thu, 04 Jan 2024 14:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704405652; cv=none; d=google.com; s=arc-20160816; b=fNkiwH0isWPh+tVKh6f2T+JcYORU8xg4NelrUvXskeBDsh01d9UFVw5yZg/n9gKJvC kjb8Kv2lDqdVFjb2OVuTuEmSZpA73LjD8W6SkpD24AjFS2ecC+Wz5oiKmcDRTGluAN+I NJHmJdwvX0FMoTq5JQAAc9Hl006QmLWYMjA+XWb0Ic5LXdMNvHZq4tNv8vUfpbhmj+tF jsX1brncDVlU8guRwzDWgmBauI01aaZqckEkJML1SBvYeEVOJnR2Zh96xW0KEXjfZKmd U9KolIAqHCFrWD3+jPWbZDFtiOVG6X3KcwwomsrZKeyh3UZmO+9x7K7/2ZXotRgj5piC 435Q== ARC-Message-Signature: i=1; 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=EbuEc+3+/dM6pxEHoHz7TMraZJmVVWSnEJNirB5z+G0=; fh=/+b36Kyncow8zkAf4U206kHBsn7X4TQclH3EtkME/8M=; b=gIA6b5GKj26jejf7WS9cuM4oyqSbOoOT04PyIkbUuFBdR6+xnM62S/OFSSZhrMlISF 0WtX9YF6EbCzvvIapDfuyoomzlfvqyOkwPcd5JwbyvWCgdiYkaKyG+DClJ7vxV+n5G08 zpgB/no5OULeGJcFFCqVEx4uAeamLBFNWYozVBb9l0u9P7R2YRAIvslxDUx2JDMlQDtI +fCQ1zE0YUNMoP5u3/X5ub9cKE2/SPhDeJGQRCRLER9XvWooqDmGYTwk0lccpgrpB5iw tn9oQtSwVw5mt3OJLvcaHYm7mOQpZ9VMoWcAgBA0YCM5csNAYaLTq3h5rxwNX/Mi+Yw1 anrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17268-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17268-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 18-20020a05620a049200b00781795d5badsi377634qkr.14.2024.01.04.14.00.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 14:00:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17268-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17268-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17268-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D2E591C22791 for ; Thu, 4 Jan 2024 22:00:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2A172D7AB; Thu, 4 Jan 2024 21:59:43 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org 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 3B7272C863; Thu, 4 Jan 2024 21:59:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6B59C433CC; Thu, 4 Jan 2024 21:59:41 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLVlg-00000000vhD-1zwl; Thu, 04 Jan 2024 17:00:48 -0500 Message-ID: <20240104220048.333115095@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 04 Jan 2024 16:57:14 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Al Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH 3/4] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240104215711.924088454@goodmis.org> 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: 1787198861310805795 X-GMAIL-MSGID: 1787198861310805795 From: "Steven Rostedt (Google)" In order to apply a shortcut to skip over the current ctx->pos immediately, by using the ei->entries array, the reading of that array should be first. Moving the array reading before the linked list reading will make the shortcut change diff nicer to read. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c73fb1f7ddbc..a1934e0eea3b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -752,8 +752,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) * Need to create the dentries and inodes to have a consistent * inode number. */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + for (i = 0; i < ei->nr_entries; i++) { + void *cdata = ei->data; if (c > 0) { c--; @@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - if (ei_child->is_freed) - continue; + entry = &ei->entries[i]; + name = entry->name; - name = ei_child->name; + mutex_lock(&eventfs_mutex); + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out_dec; + } + r = entry->callback(name, &mode, &cdata, &fops); + mutex_unlock(&eventfs_mutex); + if (r <= 0) + continue; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out_dec; } - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { if (c > 0) { c--; @@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - entry = &ei->entries[i]; - name = entry->name; - - mutex_lock(&eventfs_mutex); - /* If ei->is_freed then just bail here, nothing more to do */ - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - goto out_dec; - } - r = entry->callback(name, &mode, &cdata, &fops); - mutex_unlock(&eventfs_mutex); - if (r <= 0) + if (ei_child->is_freed) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; } ret = 1;