From patchwork Tue Feb 6 12:10:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502029dyb; Tue, 6 Feb 2024 04:28:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMGjY6NXl7TiR1rsRgLOzW84MHSJtbMqSSYCLeMdVKYVoJdfcT+2S3JpvlLMVy56kgoC99 X-Received: by 2002:a05:6214:5096:b0:68c:66d4:374e with SMTP id kk22-20020a056214509600b0068c66d4374emr2813460qvb.48.1707222529140; Tue, 06 Feb 2024 04:28:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222529; cv=pass; d=google.com; s=arc-20160816; b=P2RIwj2E7OW+vcof/jPg3CriZ54PCnmHJGGFcbEZc3s0lrFzc0HfS5pw9LvQX0KV2l HyEUEIxIZvRrxnzOQLSPOs4UgH/oC0ETBPmFmxWJwJE4ii3QtO0H3yge2A5ZTuNNxbQ8 qCgIM0GGy/XDs9S4JOL/nUPNAVu4yOW6zQObGRngg+FEimREl7CGvOR8+FyDRu4SXtJ9 AMXQHUc8KaHW3GhkOnjmVknZNvT1231S67u0Yk97ITB62SsNbEQ86IGor09ufHh/ywUP LskQxW/fd/+Qih1uyuTOfJ4Ac9zCP8nK9/+TUrWfSZAcOUVdbKHwoCnxmWnb8E+/wf4b 4hhw== 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=STVGsk3UzsxWDN/vxsRZwcaGBEAOiygLkiqOdSdRYv4=; b=Cs+/qPUy/RYLaa3tm6AEa8rypiPHyTFVBp6RO8Q6n8HgZs48LN8A9BpklsNEDOG3R3 Bm4ZhAlJUGb/Govu9uiaHh6pUQ3mW4EDAj/kW6l0XdeIuzEvwy7lDAEXeAw0OfED6A4N 9VmpEXUy2FN95d1db3WJsFjk3ltgP6Oa76amXIoZ1sN+RCyMQP2Mj0DVSBtDr1umkcGZ ZBEF20LxksqczKjLZr8M4i7/L6ZXXPIuhkZDxkJeBUry/Po8xSM8CRTRUF2nqF6jYO/l ZLukOu6OXQqROeltC3U/27ctML6s9PU2vhJCemGAsqOP1chWxr6d0AFGpVKUi5SIMp6G FYlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWbzIUhhTRMhZEAoh76rh15KdX7yroGL2T4S8FC0uGi/Wyp6aGqNyTVLlIJBjpf/WiEiEfNOpb9SU5zj2x2dlgIPEm0nw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j5-20020a05620a0a4500b007858da6db88si1380477qka.741.2024.02.06.04.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54931-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-54931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54931-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 BE3B01C243EF for ; Tue, 6 Feb 2024 12:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72FB4152E02; Tue, 6 Feb 2024 12:09:43 +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 6531F1353F6; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=soyWUGiiqs46RukQ4Po+1fluBQRbtz15mVeq7RjJAFTNURX8MOg+cw3kHYamAsSev2ww0uvgkLVaX+dCGvH3SNJHNEmiWR6VeoJHJjPUqvn7skkHT9M9janw00ExNCl7PnsNplBqbAsEdtxL8lIg1EMKERVKbu2BfQ9W6cj8OAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=K0Ph34GY80unDV6Wcvz0AavqMJytP5uSNCEE07y3Q00=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=vCmHioN24qOTIxnFGZPSjyWnAXfZ4rW9jaErtt49iJDlLZtLiGMegAz65nefRlxcSJZT5O3BABvtVV6MBbIYGNdr15Lh/ZOd3CdLMkar0v1H4FTEWa/fnX8hnKprAF4DMQbSh2wmS2Tyx8UCHgB/NMMsId1SKzRDzIwQ5JSZoOM= 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 50B13C433A6; Tue, 6 Feb 2024 12:09:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bTp-3PR9; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.665411833@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:10:02 -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.6][PATCH 57/57] eventfs: Keep all directory links at 1 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: 1790152570820108981 X-GMAIL-MSGID: 1790152570820108981 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);