From patchwork Thu Feb 1 15:34:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp273647dyb; Thu, 1 Feb 2024 08:26:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5VgHCGtL4sbaEDAT/LnMzzX272ED0bCp/zEi94Sir7Mf9am+CpDMPwFApZfg6t0Qe/HdS X-Received: by 2002:a17:90b:3555:b0:295:fe86:ad1f with SMTP id lt21-20020a17090b355500b00295fe86ad1fmr4261915pjb.46.1706804768725; Thu, 01 Feb 2024 08:26:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706804768; cv=pass; d=google.com; s=arc-20160816; b=ebW/GU20ed9nAXGHkRKzhl8RNSBOrnyLSvQX7A1xh9Voh2wVxTQTLkfZfoy3ruVpQd 0oLBwQkDEkIvrSawu0rhcQI8jG8Ok41C81SBTbtv1Lug9dg41O6F9r+1rZL60lnhE2S0 ziK2YRQex2kFzw31p+D2U9FxU9AOfIGw8X4tolSnnpjpe3OXuZUuc9QqjC/1TSjC2bJc 3gli5LK4CYwc4p8cADEVuMRAIoN9+0/tIGUd1H0wv8e7CpbNvZEliiNfA8qTev1QuvMw Peb+/tKIrjeVYw2vy8FzRLBbLqJmNYUuadzEonRXcVFXl9wRTE1Lx9s61SHxjkqDMQOu p3BQ== 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=h5PeeVnruYM6GCNxsaFwAUXfYiwycBHir/IgjQ4Fv8w=; fh=ipnE+k3/UyBSxjLi/s1BjTfKge68MX+NXvlwRJk9m7A=; b=QMDeqUhjOEqj9JGNAcFaxe1psO17s2HnC3OSJO0yJCHXcmH2mNwb5os6I/n98Rs9Ji iqA1N/XmyQ0lAxG1yTEkQFxqH4LAwnNUPSP5YrpgEsjXVfDy3Fy4GhBB5J0JXVs93UvD lpWSeR9Vg+g21TbZmKTn3OB3lQS3k9EjlTqRqQpITmqvoXiKVZ6F+6TuuOPfn5Ltpy8C IdoNXX+6oFR7DHB9hjPX66AsIainHz0Nw8mEwF5SssxjoaiG96cp3yfsWBjoffds9NyS DwO+asPTxDPYQOrNzw1zHevYApI/8ClMSHbgWcIW6z8vH+h5/J8BaoTPFOSJyUKp2DmU v22A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWJ9HNy89+2HilEeMyfeCOVPC0cNuaTx8F90baqXTn4DnlkDYR5EZ0j9osiS/zc6pPZxR495sVew30yUwH4zL0lzHC4KA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e5-20020a17090a728500b00295e171ceebsi3939266pjg.68.2024.02.01.08.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 08:26:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48505-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 928352861C1 for ; Thu, 1 Feb 2024 16:21:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48B427DCB7; Thu, 1 Feb 2024 16:16:04 +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 DA164161B5A; 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=VB8ysJzuZqpiRNu5wDwSEVM69UmeC57KQZuwsfTvqcGO8jeNiaCdVzUXPwsP4RC8Ruy2c5HMC/jRCxQiX2Ty6EtKR21qjyAY5yYfGkYa4ZL4zoGL9/eXtw6wlPy1nN7hj4BPzorSr4g4qOEAF8Mwbf7ulnf4ykNWpwFB2iyLn2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=TwXMBgsYj3cjkDRxSyydgTaD5Knftq7Y2tB5Ttzmt/o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aMcvm0WCz0C/QiDVpqjkRugXULfZ6vYDjO8AM+gB36+R+xEOlOeCxMCCMdgaHER5K5Q/gDcoY+/r7cngwLRZHzB1OQ0TBw5oYAqDWpg1wMg4UflApcPXxjDWyYUiT3E6KOB3RwevXJDiVZt4EhYFg/rT/43KHN4vbEIBcXs2+gU= 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 A0DDFC4166C; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005TlA-3MFD; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.658992558@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:52 -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 Subject: [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry 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: 1789714517122553024 X-GMAIL-MSGID: 1789714517122553024 From: "Steven Rostedt (Google)" Only the root "events" directory stores a dentry. There's no reason to hold a dentry pointer for every eventfs_inode as it is never set except for the root "events" eventfs_inode. Create a eventfs_root_inode structure that holds the events_dir dentry. The "events" eventfs_inode *is* special, let it have its own descriptor. Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 65 +++++++++++++++++++++++++++++++++------- fs/tracefs/internal.h | 2 -- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1a831ba1042b..c50d089c9a7f 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -35,6 +35,17 @@ static DEFINE_MUTEX(eventfs_mutex); /* Choose something "unique" ;-) */ #define EVENTFS_FILE_INODE_INO 0x12c4e37 +struct eventfs_root_inode { + struct eventfs_inode ei; + struct dentry *events_dir; +}; + +static struct eventfs_root_inode *get_root_inode(struct eventfs_inode *ei) +{ + WARN_ON_ONCE(!ei->is_events); + return container_of(ei, struct eventfs_root_inode, ei); +} + /* Just try to make something consistent and unique */ static int eventfs_dir_ino(struct eventfs_inode *ei) { @@ -73,12 +84,18 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + struct eventfs_root_inode *rei; WARN_ON_ONCE(!ei->is_freed); kfree(ei->entry_attrs); kfree_const(ei->name); - kfree_rcu(ei, rcu); + if (ei->is_events) { + rei = get_root_inode(ei); + kfree_rcu(rei, ei.rcu); + } else { + kfree_rcu(ei, rcu); + } } static inline void put_ei(struct eventfs_inode *ei) @@ -408,19 +425,43 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, return NULL; } +static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char *name) +{ + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) + return NULL; + kref_init(&ei->kref); + return ei; +} + static inline struct eventfs_inode *alloc_ei(const char *name) { struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL); + struct eventfs_inode *result; if (!ei) return NULL; - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) { + result = init_ei(ei, name); + if (!result) kfree(ei); + + return result; +} + +static inline struct eventfs_inode *alloc_root_ei(const char *name) +{ + struct eventfs_root_inode *rei = kzalloc(sizeof(*rei), GFP_KERNEL); + struct eventfs_inode *ei; + + if (!rei) return NULL; - } - kref_init(&ei->kref); + + rei->ei.is_events = 1; + ei = init_ei(&rei->ei, name); + if (!ei) + kfree(rei); + return ei; } @@ -710,6 +751,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry int size, void *data) { struct dentry *dentry = tracefs_start_creating(name, parent); + struct eventfs_root_inode *rei; struct eventfs_inode *ei; struct tracefs_inode *ti; struct inode *inode; @@ -722,7 +764,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry if (IS_ERR(dentry)) return ERR_CAST(dentry); - ei = alloc_ei(name); + ei = alloc_root_ei(name); if (!ei) goto fail; @@ -731,10 +773,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry goto fail; // Note: we have a ref to the dentry from tracefs_start_creating() - ei->events_dir = dentry; + rei = get_root_inode(ei); + rei->events_dir = dentry; + ei->entries = entries; ei->nr_entries = size; - ei->is_events = 1; ei->data = data; /* Save the ownership of this directory */ @@ -845,13 +888,15 @@ void eventfs_remove_dir(struct eventfs_inode *ei) */ void eventfs_remove_events_dir(struct eventfs_inode *ei) { + struct eventfs_root_inode *rei; struct dentry *dentry; - dentry = ei->events_dir; + rei = get_root_inode(ei); + dentry = rei->events_dir; if (!dentry) return; - ei->events_dir = NULL; + rei->events_dir = NULL; eventfs_remove_dir(ei); /* diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index beb3dcd0e434..15c26f9aaad4 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -36,7 +36,6 @@ struct eventfs_attr { * @children: link list into the child eventfs_inode * @entries: the array of entries representing the files in the directory * @name: the name of the directory to create - * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children * @data: The private data to pass to the callbacks * @attr: Saved mode and ownership of eventfs_inode itself @@ -54,7 +53,6 @@ struct eventfs_inode { struct list_head children; const struct eventfs_entry *entries; const char *name; - struct dentry *events_dir; struct eventfs_attr *entry_attrs; void *data; struct eventfs_attr attr;