From patchwork Thu Feb 1 15:34:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp299119dyb; Thu, 1 Feb 2024 09:03:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvqBX6v7sgypZUtSaNWsyTNiSP+8TVfyhkeAqUUe0oPVXGHW/+Fzt9lyYhiP9z84rYRglQ X-Received: by 2002:a17:903:26d5:b0:1d9:4643:65b6 with SMTP id jg21-20020a17090326d500b001d9464365b6mr2880342plb.1.1706807025400; Thu, 01 Feb 2024 09:03:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706807025; cv=pass; d=google.com; s=arc-20160816; b=YQ4DvuN2ZbqTEv8NkhK4BCy8PnHhf36Cv8eYQm+HSVtEM6Poqjua60vZP/+SZPMXOx LM/pd//xLcYDvnDVj/KwyZLuC5SspAT4MMBYohxKoT+rUWRigIBLjWSZWnotfQsoItu8 lg04TJBsUCLh58c6MLR203eRJvvJmML2D9dvkjKbzpND4erfRBjL5gxqeraIC99+KwB4 5twbEj/8u2vr9Tgm2+OY8ldMlesFDE2y3n/T3mdyIEPO/zbuZNQgP6zyrVv3iPYnAs65 pIXarqhQS94EZDaJ/XwABGok3/ZcMR6tpECbqWDXpkUYKmM1iuV1Vjv8PpaBjr+dYzAE iMjg== 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=r5Z1FqaXl8/gr59fvr5vlw2KNofRCpUUOX4Vr/5tKdE=; fh=jQeHReCxMvqfp4PWEpreRLKQ+UF5yoUhI6sVXiqtGR4=; b=MFMlwqDmsGxRPnA97DoiU8FD70FFWzETsEl2iq2n/hiCkCxjyL9vH4tLVWI4xEDISO LOchucXBOCrrV4KaC2pa4AVyYyM1eXFLDOrVBgDKpNaabDl/TqaFnSEJ4vkhbdVje+WB q+JJy+9NdToxqGAbEo70yD3WX3qPhOhypIkGVFg/gabrAXdlmutTEEQSykSOa1AtLVVr saivmPouzb6Ke7BOYfuW6IehjOzLZ1O6eg/FqSoKPVF6HTM0xQIznw8jCFtHm3Vr5PS5 lQtkCz0Lci3Z7P/8zamo643qELMLJ3ffzHfCF1chDvdyT2UAGXd3busWDBXKhgFOuiz6 lSyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWjuHGqn2UNEATalQN94mAd0Cmnt3hg974HVYzsBWHBU37ZF04mqVeEqRS+ETGbNLKkCH/A2nP/c37tqIuef38vRGrnZA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id v12-20020a170902f0cc00b001d88b4759c5si117135pla.19.2024.02.01.09.03.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:03:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48504-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 A6AB7B2C00E for ; Thu, 1 Feb 2024 16:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3F5D7DC85; Thu, 1 Feb 2024 16:16:02 +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 A5865160894; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=GDVjlxYkZtc+HS4w0BAJNhXQa3XTlLft+OApsQLoAfYs2pX4OPGY2DhFWGK696fE8ix0OnLujqS3W3KnAUEgAmQLUPT7k7Ko3wQStPXBFBkqTk0swp2Pto6B9gy+e3PCNdpyg+s9SatOv3DWv6Kqt1dQlKKhU8nfZANOvvxpbxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=aYQmR4grRcJrLfjdmABWmdW24Zibr5d0HrWyIDxBXt8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=L+4y6w0Y2Ydtbi02X7/i10xoUKaeoj3ZxuXjzsvUnS8d1Bndiek7CWxdsZY3TGeLZOaPndXuh3HbGePzk0GwqSpS8DXx/CLWDbQaGjPE5ZVMsjjibROye0fC7h11ZCDn+r2YfUbEpVnm93sSGeos+B874kqFimQlXLwujkstqUU= 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 56772C43141; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005TkC-20gX; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.339968298@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:50 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , stable@vger.kernel.org, Al Viro Subject: [PATCH 4/6] eventfs: Keep all directory links at 1 References: <20240201153446.138990674@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: 1789716883508561961 X-GMAIL-MSGID: 1789716883508561961 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/ Cc: stable@vger.kernel.org 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);