From patchwork Fri Jul 28 18:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 707769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D7AC001E0 for ; Fri, 28 Jul 2023 18:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236070AbjG1SV2 (ORCPT ); Fri, 28 Jul 2023 14:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235989AbjG1SVZ (ORCPT ); Fri, 28 Jul 2023 14:21:25 -0400 Received: from CY4PR02CU008.outbound.protection.outlook.com (mail-westcentralusazon11012009.outbound.protection.outlook.com [40.93.200.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D53C9422A; Fri, 28 Jul 2023 11:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JAbCn5x4cxl9ahUDoklJ/nVln2T2hokyHmSUBv/dZYP60YSkBjWDZbSZGMF53kbtBv7IcJY3aoTbiehnvs9brwUfmUbondmbhL/Grpz3k2eXUJzEpQFql7/scExiH+iaJWbq4WhfDTqV26r7E9klVtqFnT3uJilparEqxOemQ27VGuMimuNqUsxcpNXZhGV9MeNzGafxy59iwGeX7gQqslay81UUtOvaqqfFVTvFYNkja9ZC58c6Ww+iK9Yhor0T9gDeYYsGliaH6bbRrGmDkgjkltvQZUmKng7a9F+DxhhAkwSdc45oP1JA5KDWoGI3k77sAAL5/Z50x6f9DtRryQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pDvwg1P4xmQElgMzF3qShwdTNxBZYbqmBfS4jTzgkyI=; b=WU2Pcc3FNIKdEhKFsz0482ykID+pDbDZFCtKJhcK5ozY9oeOfcT4/PahjLd2VGhuP6n/t2pAaK8ZK0/Achwlu6G1Ri1lQ5tFaMVc8ditSQHNBeaaxszrm7XtEJcOfCD/5xZdQ+umMgMS5gbm5XN6Nc62ruZp6f0LBGyjC6U2AC+U7CV+5P/8TjHTAY6iD/H5IZ14k0MQI8lCeqfQZ7ug7B2Quee2FoTWv9tnGMCkKtX+zkzl7qaZ13zfCn6zhKoEkutaQOLjmKwWj4ZGnOt0wOpWUX2H8vBAZJpL65CNZten+JUlE0Tz6B5xDScbA2nstzPRv2uhIsxB3UZBWVdCTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pDvwg1P4xmQElgMzF3qShwdTNxBZYbqmBfS4jTzgkyI=; b=QDtrTegGEq5HK4aCaMsu32D5VS5SEEDPTGRazmHe7bjHvKP3xH07oOoQBbdfNWrBJ6Gp5VahWgztkCsC7O3dNUMRZwg8erhRjjN/h5AtGpx50SRPmwCPmgF5klG76Ku+S8pEJbLWS8f9l30dKHEZYpgiDJfpybPqeOxbKVIgKOQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) by SN7PR05MB9264.namprd05.prod.outlook.com (2603:10b6:806:26c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 18:21:21 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::b5d8:98b9:6ca7:94f0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::b5d8:98b9:6ca7:94f0%6]) with mapi id 15.20.6631.026; Fri, 28 Jul 2023 18:21:21 +0000 From: Ajay Kaher To: rostedt@goodmis.org, shuah@kernel.org, mhiramat@kernel.org Cc: chinglinyu@google.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org, lkp@intel.com, namit@vmware.com, oe-lkp@lists.linux.dev, akaher@vmware.com, amakhalov@vmware.com, er.ajay.kaher@gmail.com, srivatsa@csail.mit.edu, tkundu@vmware.com, vsirnapalli@vmware.com Subject: [PATCH v6 04/10] eventfs: Implement eventfs dir creation functions Date: Fri, 28 Jul 2023 23:50:46 +0530 Message-Id: <1690568452-46553-5-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1690568452-46553-1-git-send-email-akaher@vmware.com> References: <1690568452-46553-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0090.namprd11.prod.outlook.com (2603:10b6:a03:f4::31) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|SN7PR05MB9264:EE_ X-MS-Office365-Filtering-Correlation-Id: 924ed8dc-6989-4012-f484-08db8f97716d X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B62boKZSBGYM1u0UehmQC+FAzeFkaQUTOACtIF9igRduVS3akKk1lQgY/lzF/7BjwjIMcLaGc0oxfwVdJYLwNQTn17010KL+Uj15xyjH+AbvvripzGsh3Xb7pVCHDYHw6RDnEnwfcDmAMdAMTseaB8GNvapwTgKVOq6aoyjrEaRANmU6+9upoCps9pVDH3RMuqPJD2fjtPr8+6EjNFZebGoaimGcyK5hP90+m9NqA6dbVPMY7uiLRWTyJdkTcI88eTR/5g4fllbyIquiw/N6Xy/0/QxYbnpc0WAsm2aM2XXCcfWC8ZvSzdqlOl/9a1SnOExATvLWX2t1jzE6penHU1TYQtVoLMGeXl8TfYWYUdXP+bhNiQmFdhsbWtZSX6P+EVzDkGo9RLp+yDBob9pPV8LawCJ6aUfFONOcKqW2vvbXPn6v1yP7D1nMl4ABDNlsMi+Ty+Ca9XtIGd1qa78FNo3Q1AyhZ+5ozlEosUiKBzhvGplbNop0DtwW34ffHoszYZehypxcgzG6IY5lvbS1HstF3j7LHRsCSmUVLXagl/rVXvrVMVYdt2q1JTTewsessBoIrDhIc6RRdt6cTn48z8WXCgPGUUAa/8o0Z0qz/tgYnv2RRa4qYP0qudv6nKOmRYJ9VOAL57SYfHBdb39oiYRCTEluNtONf83euCuIXqjOe8bq+aeS7JollblvbnnJmWaFbmMX49XzXXfYF6F1ZQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR05MB8703.namprd05.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(396003)(346002)(136003)(366004)(451199021)(2906002)(316002)(7416002)(8676002)(86362001)(8936002)(41300700001)(36756003)(6512007)(5660300002)(966005)(107886003)(26005)(6506007)(6666004)(6486002)(52116002)(83380400001)(478600001)(38350700002)(186003)(38100700002)(4326008)(66556008)(66946007)(66476007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GJtRE3avbmPr7rFo+ARLsEdcoBAp7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muAMtSzFpw94e24kWR+sp9pPDH69QUlrV5XtphdmBPp/QM+3PPMRm3NNCrMfbkj8Tynl0E4IQ9UAuIa2UnW67QnoRWIPDBuOnsJ4cr+nT0Sgnr36++bgpMdTfq0e2HGE+AoOwsF88JMFjTvk1W8CcDcv2ad1PcvnMIhAMUPEw+/keNDG5oyEaRCu1mwJ+slR2eraMCS5XroUiS6QYx5GslEnMGQWMxjyS4sqRqQVfbqJZZpGB5KbzDg4uzH0OijGp8X7CJupBc90bCfPv5Dl40hTlL7uwXSq2lyBnuw5qiJPIB+5sg9m+kJ84V1e7Qneh+mkNrFdJx2dS6dCpsLzyHt06Hk/PAE+sOqjr0WCo6axjPNMVkqf5UTr206P+uxcCyJPmxgivC9qFfOboIIfj+y7h+qv9ghgTQJ13bw+R6GiKQvzikVdoppvqxgBM5ZFy/K6w8PmTdLTVEyf6h0VZIpzJmUIXGmQoBGqbhT X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 924ed8dc-6989-4012-f484-08db8f97716d X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 18:21:21.0476 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8OLh2rceS+0LIrdUzdyaTHYS9fVbxoERGnRsMsceA8QKAN/sq2MruZP9LC++5NrM8kUbeI60EUbbqVfSG5T3fQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR05MB9264 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add eventfs_file structure which will hold the properties of the eventfs files and directories. Add following functions to create the directories in eventfs: eventfs_create_events_dir() will create the top level "events" directory within the tracefs file system. eventfs_add_subsystem_dir() creates an eventfs_file descriptor with the given name of the subsystem. eventfs_add_dir() creates an eventfs_file descriptor with the given name of the directory and attached to a eventfs_file of a subsystem. Add tracefs_inode structure to hold the inodes, flags and pointers to private data used by eventfs. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202305051619.9a469a9a-yujie.liu@intel.com --- fs/tracefs/Makefile | 1 + fs/tracefs/event_inode.c | 211 +++++++++++++++++++++++++++++++++++++++ fs/tracefs/internal.h | 4 + include/linux/tracefs.h | 11 ++ 4 files changed, 227 insertions(+) create mode 100644 fs/tracefs/event_inode.c diff --git a/fs/tracefs/Makefile b/fs/tracefs/Makefile index 7c35a282b484..73c56da8e284 100644 --- a/fs/tracefs/Makefile +++ b/fs/tracefs/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only tracefs-objs := inode.o +tracefs-objs += event_inode.o obj-$(CONFIG_TRACING) += tracefs.o diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c new file mode 100644 index 000000000000..8f334b122e46 --- /dev/null +++ b/fs/tracefs/event_inode.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * event_inode.c - part of tracefs, a pseudo file system for activating tracing + * + * Copyright (C) 2020-23 VMware Inc, author: Steven Rostedt (VMware) + * Copyright (C) 2020-23 VMware Inc, author: Ajay Kaher + * + * eventfs is used to dynamically create inodes and dentries based on the + * meta data provided by the tracing system. + * + * eventfs stores the meta-data of files/dirs and holds off on creating + * inodes/dentries of the files. When accessed, the eventfs will create the + * inodes/dentries in a just-in-time (JIT) manner. The eventfs will clean up + * and delete the inodes/dentries when they are no longer referenced. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +struct eventfs_inode { + struct list_head e_top_files; +}; + +/** + * struct eventfs_file - hold the properties of the eventfs files and + * directories. + * @name: the name of the file or directory to create + * @list: file or directory to be added to parent directory + * @ei: list of files and directories within directory + * @fop: file_operations for file or directory + * @iop: inode_operations for file or directory + * @data: something that the caller will want to get to later on + * @mode: the permission that the file or directory should have + */ +struct eventfs_file { + const char *name; + struct list_head list; + struct eventfs_inode *ei; + const struct file_operations *fop; + const struct inode_operations *iop; + void *data; + umode_t mode; +}; + +static DEFINE_MUTEX(eventfs_mutex); + +static const struct inode_operations eventfs_root_dir_inode_operations = { +}; + +static const struct file_operations eventfs_file_operations = { +}; + +/** + * eventfs_prepare_ef - helper function to prepare eventfs_file + * @name: the name of the file/directory to create. + * @mode: the permission that the file should have. + * @fop: struct file_operations that should be used for this file/directory. + * @iop: struct inode_operations that should be used for this file/directory. + * @data: something that the caller will want to get to later on. The + * inode.i_private pointer will point to this value on the open() call. + * + * This function allocates and fills the eventfs_file structure. + */ +static struct eventfs_file *eventfs_prepare_ef(const char *name, umode_t mode, + const struct file_operations *fop, + const struct inode_operations *iop, + void *data) +{ + struct eventfs_file *ef; + + ef = kzalloc(sizeof(*ef), GFP_KERNEL); + if (!ef) + return ERR_PTR(-ENOMEM); + + ef->name = kstrdup(name, GFP_KERNEL); + if (!ef->name) { + kfree(ef); + return ERR_PTR(-ENOMEM); + } + + if (S_ISDIR(mode)) { + ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL); + if (!ef->ei) { + kfree(ef->name); + kfree(ef); + return ERR_PTR(-ENOMEM); + } + INIT_LIST_HEAD(&ef->ei->e_top_files); + } else { + ef->ei = NULL; + } + + ef->iop = iop; + ef->fop = fop; + ef->mode = mode; + ef->data = data; + return ef; +} + +/** + * eventfs_create_events_dir - create the trace event structure + * @name: the name of the directory to create. + * @parent: parent dentry for this file. This should be a directory dentry + * if set. If this parameter is NULL, then the directory will be + * created in the root of the tracefs filesystem. + * + * This function creates the top of the trace event directory. + */ +struct dentry *eventfs_create_events_dir(const char *name, + struct dentry *parent) +{ + struct dentry *dentry = tracefs_start_creating(name, parent); + struct eventfs_inode *ei; + struct tracefs_inode *ti; + struct inode *inode; + + if (IS_ERR(dentry)) + return dentry; + + ei = kzalloc(sizeof(*ei), GFP_KERNEL); + if (!ei) + return ERR_PTR(-ENOMEM); + inode = tracefs_get_inode(dentry->d_sb); + if (unlikely(!inode)) { + kfree(ei); + tracefs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); + } + + INIT_LIST_HEAD(&ei->e_top_files); + + ti = get_tracefs(inode); + ti->flags |= TRACEFS_EVENT_INODE; + ti->private = ei; + + inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + inode->i_op = &eventfs_root_dir_inode_operations; + inode->i_fop = &eventfs_file_operations; + + /* directory inodes start off with i_nlink == 2 (for "." entry) */ + inc_nlink(inode); + d_instantiate(dentry, inode); + inc_nlink(dentry->d_parent->d_inode); + fsnotify_mkdir(dentry->d_parent->d_inode, dentry); + return tracefs_end_creating(dentry); +} + +/** + * eventfs_add_subsystem_dir - add eventfs subsystem_dir to list to create later + * @name: the name of the file to create. + * @parent: parent dentry for this dir. + * + * This function adds eventfs subsystem dir to list. + * And all these dirs are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +struct eventfs_file *eventfs_add_subsystem_dir(const char *name, + struct dentry *parent) +{ + struct tracefs_inode *ti_parent; + struct eventfs_inode *ei_parent; + struct eventfs_file *ef; + + if (!parent) + return ERR_PTR(-EINVAL); + + ti_parent = get_tracefs(parent->d_inode); + ei_parent = ti_parent->private; + + ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL); + if (IS_ERR(ef)) + return ef; + + mutex_lock(&eventfs_mutex); + list_add_tail(&ef->list, &ei_parent->e_top_files); + mutex_unlock(&eventfs_mutex); + return ef; +} + +/** + * eventfs_add_dir - add eventfs dir to list to create later + * @name: the name of the file to create. + * @ef_parent: parent eventfs_file for this dir. + * + * This function adds eventfs dir to list. + * And all these dirs are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +struct eventfs_file *eventfs_add_dir(const char *name, + struct eventfs_file *ef_parent) +{ + struct eventfs_file *ef; + + if (!ef_parent) + return ERR_PTR(-EINVAL); + + ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL); + if (IS_ERR(ef)) + return ef; + + mutex_lock(&eventfs_mutex); + list_add_tail(&ef->list, &ef_parent->ei->e_top_files); + mutex_unlock(&eventfs_mutex); + return ef; +} diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 7dfb7ebc1c3f..f0fd565d59ec 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -2,6 +2,10 @@ #ifndef _TRACEFS_INTERNAL_H #define _TRACEFS_INTERNAL_H +enum { + TRACEFS_EVENT_INODE = BIT(1), +}; + struct tracefs_inode { unsigned long flags; void *private; diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 99912445974c..432e5e6f7901 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -21,6 +21,17 @@ struct file_operations; #ifdef CONFIG_TRACING +struct eventfs_file; + +struct dentry *eventfs_create_events_dir(const char *name, + struct dentry *parent); + +struct eventfs_file *eventfs_add_subsystem_dir(const char *name, + struct dentry *parent); + +struct eventfs_file *eventfs_add_dir(const char *name, + struct eventfs_file *ef_parent); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops);