From patchwork Wed Jan 31 22:11:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 194987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp54937dyc; Wed, 31 Jan 2024 14:11:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzV+dSkdhf0ovE5yRLdUdwnhDJmkvabFJgw19YKbOBV+BvN0x04888vKtxiZtVLDsWovPM X-Received: by 2002:a17:90a:12c7:b0:295:ab1d:e37e with SMTP id b7-20020a17090a12c700b00295ab1de37emr3105640pjg.39.1706739083407; Wed, 31 Jan 2024 14:11:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706739083; cv=pass; d=google.com; s=arc-20160816; b=TgCXSe0gE0b3Qyyx5rHK2/jRbKZT11196V6M4fp6j5LZgoRfAdgEF/JSs2E56Fgy4p 2+pHkeW8xls8QtnCp0h2UX5If1O0rmp6AfoYc2RlZF949L/KVlqiobIkf2L7OoR3gHR1 P6M8FjaeeHRXTJwIa8ngWJ4mGnZnwOhYCvP2yEyaODrEjRH2VVKBrEzvSS4Xdfj2sLV4 kRMXO5JNL9jy+fngBd0bjAvnDmte74FR/YUKqn8APibvzbEwbLBVMDpPh1fzBnL4pA1o 9eGh/Feac91Rr0m2DAuZgCf1eudCnz/3R4cZl+6n/tQSyUTjPkWjuIN68aQxwL10HlIN R3gg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date; bh=whLj1adPCk8qiw+k7LOi8E2A8liSpnCuV+xVUYSqG+g=; fh=cYwwZdIIBZ0ushGoeE8q2cjt8vQ7WLcR5MK9HN0FU3E=; b=Qy53xqTc4dmPVRp+XLpEYeMI8TtYSv07CSd9RJoe3mYGPV5pS0atyy6rS1vajcQ7jf ZRksvvr/1Kgl7lxSZCOefde1BALpLwURG13oleEsrul21TvleCgeNy2mBisa3Uaoxt6X kdDZ7GunOjPagrmuwt/lorKQxZpkTMxodxfVF8RcFxMmUOt+lYvYM9CV3uh05arRLr1B A1gYtXT9YyRs2xbinB4HDYhBbke3Sre3S2W9zOPPYDJp0yEv0IPPig5SVMSpKCvaNB3Y LOimr7sJNw8WMbtilzTCm8ib1MqhAfXPgWkAV0SLFSBUcfO9gfM7AHoycPCCSJ6sC/pq zc9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-47234-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47234-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVvMr1cVez8xllTtGAc+pdqYK5BJtPrbdpVbEQSlDQre+9ZFH04yWkzW0EgLUab845N3JUn/hEC9AcUTJvlt0G+KcQ3HA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cq6-20020a17090af98600b00290b31dbe77si2152416pjb.20.2024.01.31.14.11.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:11:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47234-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-47234-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47234-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 33DC7286AAC for ; Wed, 31 Jan 2024 22:11:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89D2F39FD4; Wed, 31 Jan 2024 22:11: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 5DBCF39FFB; Wed, 31 Jan 2024 22:11:07 +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=1706739067; cv=none; b=APhxINq/35JRlzCieVibVKEAUmcc/w0iyJ3Q7SEA6imClvaPghhDR/hRVC3QIheHypLjnAP0wP2cx404SVRqwVp+c3eCrJ8TSTvn1j1Bbbbt5QUuLLXAZq1h/jwpM6jd04aO9xeWTNH7TCEGzxSEXLEuZbLkJh1FVTKIJ+byBH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706739067; c=relaxed/simple; bh=TcJ0LtlwRMoHr5h77qmW67gE+n5AX8DYT/vIshYiA9Y=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=ifmAx9FWC+zwoKbLr7x/QF29tJClHRsO9ldzYUfTKNlDyS5ht8UKF6acm0zPS3M/I5wtzgrpOvPIgRdKg6KDZrcRn68dQS8Iu9XMwVbkf6oMQ9JAVsDGngVKSzNK2ADyjmfJjBg9HaI3G5U9buw2vJIloUcckk+cCgLiz5eAX7k= 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 3E985C433A6; Wed, 31 Jan 2024 22:11:06 +0000 (UTC) Date: Wed, 31 Jan 2024 17:11:20 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Linus Torvalds Subject: [PATCH] eventfs: Create eventfs_root_inode to store dentry Message-ID: <20240131171120.607cb71d@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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: 1789645641186935761 X-GMAIL-MSGID: 1789645641186935761 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 463920295237..126cbe62f142 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) @@ -412,19 +429,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; } @@ -718,6 +759,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; @@ -730,7 +772,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; @@ -739,10 +781,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;