From patchwork Fri Feb 2 02:30:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165550dyc; Thu, 1 Feb 2024 18:32:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVc9nOLEz7U+LgyUO5sURfBXKpWaWc10e+7inCc+XLufT56SGPOmRgJJWhXvGr5CaNRhEm X-Received: by 2002:a05:620a:158f:b0:783:f827:124 with SMTP id d15-20020a05620a158f00b00783f8270124mr4454439qkk.78.1706841175035; Thu, 01 Feb 2024 18:32:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841175; cv=pass; d=google.com; s=arc-20160816; b=rfJofww+Yg6G1qCXfYOwCUqYJxaqhGNO0/E4RIE9CB4ZMRwkuXp1KNbFEQMf4uur4M ZJLpfCziKmDnP5PZchRCNxBKXnNehVYZZfFtgmCnWzdlQ8CzHHL2eHLhddX1e6tvk0pv Q2x9s5AVa7fHu6g7kr0XuWXLuTO6ciLYJ8asCpi/TzUqAjOsTG/VcEA5e7PK19Tnq/z6 B5cnFKTe3jOyYp30se5dShjXvwc4LjqjBzemMlCb/TYdVXxMdtcvJFxxEUwb5t/wcG1P pf2HYFqcgdC4aIaNOQ4X/xHp/VP3kkbSPfObzfcYKXgfve58a70vH/VAVma6I+CTzS5B QMIw== 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=4GpbK88Sjv3E086VZC2iFw20VfSgG6CnwKNDusGLVJA=; fh=tnZqb9oZCmbjA9/ix03+k9/HbKVZ3gwhrkKMJ+pRi4U=; b=Qj7bBpSksUkVbl8j1nCt85jQZNQMpVr+vauA/jv+Gj9iPAiUtbCQlfNV8ggZyp+22m Bonztb5fjphcSp6jXrlUYj7IsAABvmxMRGe6YGJs/RR21TnemsW1OE8ksOKa1oHx+hmg Lzuk9GR4Cg33nzOXNWGlso7eKzU9LpD18TyKB01WFxgn/BoYW4LOP7aBskBgmfmwLrSJ sgvYU8//t/M06Z71cP3PkOJp8tSLpyNaLEQS0N5/AZYeqFJ9Dtzv2w24sJMHtXnc20rq 1fkexJZffWVvKGEvCay7v3XETN02BqZ3e/UIykMvRh/iZOh+GnncZwSIpo7lc8PkO+cY YMwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49106-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXeTMw6hgr+TRVr3g1IsxUF1cBuyqY9eVzLM4NAWHlIrzyjro6C5wL/0epf6mkLV6PRrslKTcbPNxuaUVl6nNSnS8g3sQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe18-20020a05620a851200b00785466d67ecsi978491qkn.66.2024.02.01.18.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49106-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49106-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 D039F1C22E24 for ; Fri, 2 Feb 2024 02:32:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C355617BDD; Fri, 2 Feb 2024 02:30:09 +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 970E6107A6; Fri, 2 Feb 2024 02:30:06 +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=1706841006; cv=none; b=uSamPuVTQn/gMC/IrMoibgFdB/sOeD4iCCzd02Bi2KWpBmEoJeZp9M3p8pbaRQbcauPpqwvi5gHVMcbu6bH20W9+Iw1WFloVPRwfUDUuUTE1AzEeB/ETY9DPgmFLYdAZ9CDb/DoLbLdEtiXhVC5LpYdUHrq23h3yRxhdZEN1SDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841006; c=relaxed/simple; bh=Dq6x99Zk/Vun27CnDuFYUGrU4i510huChkfoAHC46Jo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KMfbIYwRHCfQe0Pka7flpga/zIXxqzH5PIM7NXLJPf8voZRNqI9OGCmywBPrBcZcXU5trsEARi/j/eNU7OAwtWXMfu9/pcyyy7FNIm5rbb4vMMtQdwufbnKY/vDeNCi2Z93hHdA46IUeocgBr/k+bLsJD3muNtmaQTOi5oiKF5Y= 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 13BECC41679; Fri, 2 Feb 2024 02:30:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJw-00000005kC4-0a2m; Thu, 01 Feb 2024 21:30:24 -0500 Message-ID: <20240202023023.996375893@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:12 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [for-linus][PATCH 13/13] eventfs: Keep all directory links at 1 References: <20240202022959.515961549@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: 1789752691669299358 X-GMAIL-MSGID: 1789752691669299358 From: "Steven Rostedt (Google)" The directory link count in eventfs was somewhat bogus. It was only being updated when a directory child was being looked up and not on creation. One solution would be to update in get_attr() the link count by iterating the ei->children list and then adding 2. But that could slow down simple stat() calls, especially if it's done on all directories in eventfs. Another solution would be to add a parent pointer to the eventfs_inode and keep track of the number of sub directories it has on creation. But this adds overhead for something not really worthwhile. The solution decided upon is to keep all directory links in eventfs as 1. This tells user space not to rely on the hard links of directories. Which in this case it shouldn't. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.339968298@goodmis.org Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9e031e5a2713..110e8a272189 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -404,9 +404,7 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, dentry->d_fsdata = get_ei(ei); - inc_nlink(inode); d_add(dentry, inode); - inc_nlink(dentry->d_parent->d_inode); return NULL; } @@ -769,9 +767,17 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry dentry->d_fsdata = get_ei(ei); - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); + /* + * Keep all eventfs directories with i_nlink == 1. + * Due to the dynamic nature of the dentry creations and not + * wanting to add a pointer to the parent eventfs_inode in the + * eventfs_inode structure, keeping the i_nlink in sync with the + * number of directories would cause too much complexity for + * something not worth much. Keeping directory links at 1 + * tells userspace not to trust the link number. + */ d_instantiate(dentry, inode); + /* The dentry of the "events" parent does keep track though */ inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); tracefs_end_creating(dentry);