From patchwork Tue Feb 6 11:32:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482681dyb; Tue, 6 Feb 2024 03:53:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqIa5W0T3LMkoeEhF5ySLcGdFIdnVQA8gNgbcUbGGaV9JThLOK7nFySBrIEJZa1IDEZ23u X-Received: by 2002:a05:6214:2262:b0:68c:a7f6:12b2 with SMTP id gs2-20020a056214226200b0068ca7f612b2mr3051989qvb.8.1707220428312; Tue, 06 Feb 2024 03:53:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220428; cv=pass; d=google.com; s=arc-20160816; b=FEeCsiubcstUZj5Pr3WNChp1cqBctVkKEnIp5m0MIY7WT5LWI1OPix0+YDr2vXtHrT xptqia+kI0FgXbJWn0vFN9D9Pnjgh4nrXs1V9Sp+t1W7kOqyjRF6zmowtvJ8dHHdC5Tm oE6F+uHXJ0CVJxXZ3dIfCBonMF1MJJPqdkSXFV0EkRnK39gAXcumBN81Db3Wo4AVAL0/ con0L1xUdXDQ/AJqs2NqyH6Zv4ChixPxNod77oAa0MovzArJURGX3OCu8aixbmUsGU5C tE++99V61ED7Gc28Cu13wPhdksZMO/g68HtNnT+yZTADdJvp2I9wMaA/vJ1PIdZAkSY5 d6Gw== 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=3rg9wT42s0qbZ5O6GIg3gk9NLZhbRpGnQkxTjHAIRpw=; fh=8v+vbw1jqa24zdhVIP0NCwKXip8uAMfkbjswAD7cRGM=; b=cdPwhAzhMYIYSkTO9oWwY/+RXo/7MhHVeezcs+CpqLImS6pe/4Uofk91+fq5H2ptqF wC6VORaIiVHxJ3Dg7W/REs+Zy04I39DdJJrzBnuTm9B9QtdR23bFc1DO8d3iD0zbIVnH t4iNp9TwsyIab4B68qhUgGU6qotkQdGskWSaZLI9cPcMkj9SyA9zFfSciOJWAMVV7PSz bLJvb4BCb+LV7vwqUxTDL54+Bfv2NeUsCfGkX2FjQBHoApMhbuqzCaqkiSXdJ3Bcapuh hBlM5ZSkh0LLHbvv2xjKA7jiIVlt7jUmPcja6AmrZq0kXoUpByIEKC29YaZNbUSXoCUI IFpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUlqkYCzD+D+H3lLJibB2CPwjGUFhibHzP31mtQi2WHPKiFF/ilxMYmsWElDhiszhkYESArxSo4x7Ui1QTeKjz2wVcE2Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j2-20020a0ceb02000000b00688b198a444si2136928qvp.97.2024.02.06.03.53.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54809-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 1DB611C220AF for ; Tue, 6 Feb 2024 11:53:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A738113A276; Tue, 6 Feb 2024 11:33:39 +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 9948E1350D0; Tue, 6 Feb 2024 11:33:33 +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=1707219213; cv=none; b=qlnBMp8+kCeV4V1+Q62WxuIk+YD3hEzqzeHNUg8vPKTIPuTBBaDxJ8WhgqRXgCZd5OYXB5Sf+NnBMFVgCVYhSRM1iYi5uXGZPi6s93COdvfFakPpWBVZiY8+q1JVZ1IqYEB5fyVJJBpUplUtSVmOo6sL3RAOhjAlC1U7so2p/nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=K0Ph34GY80unDV6Wcvz0AavqMJytP5uSNCEE07y3Q00=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=R+YfVpntuY9rMvHY0L0Mo0ERrA38qXWVQ2UtCgSZFn5ZaDq+feRj6v+R6nGllm5NlVUMobZhhInF04QtlJV9j8EKIg0RJScD9Qu57Sn7UgGCxBhsPrT19491kTAs82UkvNrY5xenfkLCFUqSs5kwDqX53Q4jcp66hPqlIDq8fdA= 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 849F1C43141; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aRp-42bw; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.818811467@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:21 -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 , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.7][PATCH v2 23/23] eventfs: Keep all directory links at 1 References: <20240206113158.822006147@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: 1790150367935398712 X-GMAIL-MSGID: 1790150367935398712 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) (cherry picked from commit ca185770db914869ff9fe773bac5e0e5e4165b83) --- 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);