From patchwork Tue May 2 11:23:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228802 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 D7852C7EE21 for ; Tue, 2 May 2023 11:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233954AbjEBLYi (ORCPT ); Tue, 2 May 2023 07:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233946AbjEBLYc (ORCPT ); Tue, 2 May 2023 07:24:32 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013004.outbound.protection.outlook.com [52.101.54.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 130F540E6; Tue, 2 May 2023 04:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HLuKSVd9egv3WjILJJYz+3zOrLeNiCiq4L5nURxu6Zbo5K0doxbDwTquyPY2Fa+daIgj6ul6HPxALiFjOypcYi7jqGx61Yyte3fbwz9U1mOwiMzuLjxnMT81VycDancc1d4eQV0Z0OlfZ36Zh4yg7x7Bh8N2BgdQg1WrY027Pf4Oojq9m83/t7BHFqAYM48+TWfO5z18wZd5Cr5mIeppF3kTeiKJhy6lUatE9Nm+liryEhizX4TjCAWKs2qUGPxY1mi3Wj9YIXE+jNNpLCCLjOl5OB3dQUQUNEDgs5MJ5V0x/pltYn4v0dJqmymY9SWUooAH4aGZWMUojwIC4GOyag== 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=iDLRwQWnus2YNb0srng3/2Q1Dfsq3j8kFA+cW1Oponk=; b=A88GPfBEEiyeRc2fmLBjrLKkVW2iu+I3513UHNCocifGkarS9Ao2NRCESHEJ2qIEwCHVo/JKUPHLW2LPrrw6rUNcxN3BQlFU3la5Kjoavmiy73j7avbRkxRiSOuFSCM2UhumHl5LGTgETBjffhEcp/DBhRO+Toe0vkaKET7n9T/A9IdO+55g6jJl590HrQjDctVajwI7CJxOxCdvHLQqNldK9dqISxRN5cJx5lTCkMi7u1BNGMnta3reCC126YQcF0yb9fZCF25TEk6tU6BvM2yhOvNH21UT51K0yoye1wJYf22krymPIWKwTts2OZ79KEr+ILDy9mGBX8vPYFMqNg== 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=iDLRwQWnus2YNb0srng3/2Q1Dfsq3j8kFA+cW1Oponk=; b=Q++lEQsTgj1MeoRTwdjOt2tpHKDYF6ygt43aQN6QGDEGAkhb8gErPFk4qgy5PF0JAghWiuqOtsN9mUx7LBltaVj/TGv5OSaXwYQ4xiQJCQLNOKrALgG5v3iZrehTbM0NJSDxRlovIs+QCZcjL5miL9/JEmIsm33IWl72nVSJSOQ= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:15 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:15 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 1/9] eventfs: introducing struct tracefs_inode Date: Tue, 2 May 2023 16:53:12 +0530 Message-Id: <1683026600-13485-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: 52d37a4f-4bce-4c31-1098-08db4affc328 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: 5tYkGEHyF3TlWNm8HxsP7P1Ns+Rlst0ViSfpyXmmV4hl6MXaBYSvfENOpTnI6ZSwai2s2kdCd4+4UAnH7hKoCWFKyWRZWzkvbcRtVYQSq7lxEI7g66QrDw8VmPgszJw6GtsjYrSa+ApziFlFyFeNtTxKO4DKBCCvFlj+3eyS+FeqscoCLizpMBvJ05o0QCGkTJYIpGaFa6dCg6G261HT+h0xTrCb5ZZ9KG4bYk6nm2prr20T9HAI5YGIswZBWQEoDCx/EE4FQLQAC/N19x7pLVcKzcAgYijVDIJb97i3M3C87XO32aKaT6SuSpUpDt1oD46Snstff7Tut9DoLv4xnAD0ekOOaQmfXxcEtIZanOTOPB9dm021gPuvoUF2hMam5MTdgSa3hzvqi5SrLa6FFdAhhBMTXUSA7+Qz/em6XhtlvsUbib3LMk4lvZ8byho0DjJqG6VrSIsdzilMArdSosxgd0wtImr30MWh30/pZmOQCr2d1qc4eu7bfNHmtUbw/lLwxzCONZRzB4NheWezt5QOnNOMxYCg3pwEB86PsLIwhEtGHrP9xHTGmQbpMnAqvjIhOPUd7E6Y71DAjbsGAtUyTn6aq1fqUegUhojsZuSZbQsjBe2Dv+iUEw3V42Zj 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: quR2zWEidODZ9yMAUTL6SKANlfkOAVaS/tOqHJrx8hqsvNUBOU+x0Tky5TfpdCHDzpuxGxu7dkgMVwI2SH1l7HFsey50/88gSgCfp2dbXE3jVvq7kmBI4F3HN3x93/2acmhzAWSwRhtCH8BAvbJPIE4NZvNqk6p7qm3rKE9QorC21LMoE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0YNIUu/N3X39Z9TUB95zQQtl6n3Lt3/V4d/JW5k7lBl8AiaiWGN0wdrFstLzR/r4BVrxJKkTgp0mumDf3HwbMQX+jVQXg6uoOOaicm12xPViu4vwM68Li4teL+ioGovvm/3Ly5H4pjgiwNPcYbNF5AnpsnO4C+ONKfUUXFhJ7HYaO/c/uoxLVh0e9kpQaUsO4r8M+CspCrlC/Ym3xYIsZ4hMksXfkLu2EtDvNuorJ25ZVAvpiEu+qNQVcHDeZyHS8aHadggj/F/+P3uDDwch0lTDNPByWS8ypn9lwfobV1G1HEmggMVwaElVsPYoxNXptm0FEU2/yBTn6 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52d37a4f-4bce-4c31-1098-08db4affc328 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:15.6305 (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: ieqlPkxUB++FmhpM/qYIxG/HMR9tEb/hmlUwG3MUtd5cD7xbAHwUz9RAZxbkNDRJUuKPljeB/Av5wRSHcO7ArA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Introducing tracefs_inode structure, this will help eventfs to keep track of inode, flags and pointer to private date. Renaming, removing static property from some function name. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/inode.c | 21 +++++++++++---------- fs/tracefs/internal.h | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 fs/tracefs/internal.h diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 57ac8aa4a..7df1752e8 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -21,6 +21,7 @@ #include #include #include +#include "internal.h" #define TRACEFS_DEFAULT_MODE 0700 @@ -127,7 +128,7 @@ static const struct inode_operations tracefs_dir_inode_operations = { .rmdir = tracefs_syscall_rmdir, }; -static struct inode *tracefs_get_inode(struct super_block *sb) +struct inode *tracefs_get_inode(struct super_block *sb) { struct inode *inode = new_inode(sb); if (inode) { @@ -399,7 +400,7 @@ static struct file_system_type trace_fs_type = { }; MODULE_ALIAS_FS("tracefs"); -static struct dentry *start_creating(const char *name, struct dentry *parent) +struct dentry *tracefs_start_creating(const char *name, struct dentry *parent) { struct dentry *dentry; int error; @@ -437,7 +438,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) return dentry; } -static struct dentry *failed_creating(struct dentry *dentry) +struct dentry *tracefs_failed_creating(struct dentry *dentry) { inode_unlock(d_inode(dentry->d_parent)); dput(dentry); @@ -445,7 +446,7 @@ static struct dentry *failed_creating(struct dentry *dentry) return NULL; } -static struct dentry *end_creating(struct dentry *dentry) +struct dentry *tracefs_end_creating(struct dentry *dentry) { inode_unlock(d_inode(dentry->d_parent)); return dentry; @@ -490,14 +491,14 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, if (!(mode & S_IFMT)) mode |= S_IFREG; BUG_ON(!S_ISREG(mode)); - dentry = start_creating(name, parent); + dentry = tracefs_start_creating(name, parent); if (IS_ERR(dentry)) return NULL; inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return failed_creating(dentry); + return tracefs_failed_creating(dentry); inode->i_mode = mode; inode->i_fop = fops ? fops : &tracefs_file_operations; @@ -506,13 +507,13 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, inode->i_gid = d_inode(dentry->d_parent)->i_gid; d_instantiate(dentry, inode); fsnotify_create(d_inode(dentry->d_parent), dentry); - return end_creating(dentry); + return tracefs_end_creating(dentry); } static struct dentry *__create_dir(const char *name, struct dentry *parent, const struct inode_operations *ops) { - struct dentry *dentry = start_creating(name, parent); + struct dentry *dentry = tracefs_start_creating(name, parent); struct inode *inode; if (IS_ERR(dentry)) @@ -520,7 +521,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return failed_creating(dentry); + return tracefs_failed_creating(dentry); /* Do not set bits for OTH */ inode->i_mode = S_IFDIR | S_IRWXU | S_IRUSR| S_IRGRP | S_IXUSR | S_IXGRP; @@ -534,7 +535,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, d_instantiate(dentry, inode); inc_nlink(d_inode(dentry->d_parent)); fsnotify_mkdir(d_inode(dentry->d_parent), dentry); - return end_creating(dentry); + return tracefs_end_creating(dentry); } /** diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h new file mode 100644 index 000000000..6776b4693 --- /dev/null +++ b/fs/tracefs/internal.h @@ -0,0 +1,25 @@ +#ifndef _TRACEFS_INTERNAL_H +#define _TRACEFS_INTERNAL_H + +enum { + TRACEFS_EVENT_INODE = BIT(1), +}; + +struct tracefs_inode { + unsigned long flags; + void *private; + struct inode vfs_inode; +}; + +static inline struct tracefs_inode *get_tracefs(const struct inode *inode) +{ + return container_of(inode, struct tracefs_inode, vfs_inode); +} + +struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); +struct dentry *tracefs_end_creating(struct dentry *dentry); +struct dentry *tracefs_failed_creating(struct dentry *dentry); +struct inode *tracefs_get_inode(struct super_block *sb); + +#endif /* _TRACEFS_INTERNAL_H */ + From patchwork Tue May 2 11:23:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228804 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 CA0C4C7EE26 for ; Tue, 2 May 2023 11:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233973AbjEBLYm (ORCPT ); Tue, 2 May 2023 07:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjEBLYj (ORCPT ); Tue, 2 May 2023 07:24:39 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013011.outbound.protection.outlook.com [52.101.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A04F859F3; Tue, 2 May 2023 04:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EcPSRmRxRyltqxg32BYv9bN6EzceINDbdlipm4xz1r+A7SpRjh45lv8arUJXfJTFBruN0d0pNG3wwX7QdbPfYbchZcD/4eGYRa81vnZDbyAj8M+tES3KBNnF239m+2lZ8yY7ObDyMkZVd9VM9exTY2tlZh5tcSk6+v/XhG8uR3o80JFTDujHkvaI0rOOntNxjDpMUmaefuZ5+j6f2aNW9GZiNhu+91UFtxo+1J34ic8xa1tCNyWLxmX2jvMLFN8JURJLI+vWO9/mb8DsfmGGfBaVrQWDDnTewfhHkXFDsLjJC8+tq0wWV7+A1cfBj2bcXiW17cURnGmUeRoWAS7adA== 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=tb0M5jJA1d2NZBOTyENLsWq2jwdjAnZmR28h8eWoMl4=; b=jY46pK742t3yBJyCjZdffIgwABXyyHTRkufDr6BDOTsnd4PQldJxf9YGFGbZb63+PilgkLIw/I/1UbRj3uv/Xoq0jInG1v/1REK07Vtq3v2jJrzgu4KglcYcaCP7zPxSCvA273QnhiaSTPTjezdYkNFJA31Y1lPb3M7YGLoSaugRQKkXwBoKeodRMKezZVnVbN86cCU/wLmyP+1uh+bI3QM/UxzUqc3VS/rSvyhFbMghQQQzd6QD/k3RkT+R4CMUlIAFqiVrhRCrnxEwKu425jjO8mR2lqgJPOmWU95nWhqSkmZdCl/6askVf23GWGP0KO6YxHjZhPz6cQ78hXuSXw== 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=tb0M5jJA1d2NZBOTyENLsWq2jwdjAnZmR28h8eWoMl4=; b=0uk1YJtAW7la0jFLBGoemXvLb0DYYdJ+ssc+QV0rIf6eCH8FblEL2UF8lQQFww22oyC+OdfuWxK88TNfav/NsjnTmWtI+kOU4+Yr97p6t2H/W02/odE2nxNUXlF3VYR4HaOOKvvwcuKB8+2iTtTW5hg/vfIVWJmlRQaLUjzK6AM= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:17 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:17 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 2/9] eventfs: adding eventfs dir add functions Date: Tue, 2 May 2023 16:53:13 +0530 Message-Id: <1683026600-13485-3-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: e4d1098e-2944-4931-edd9-08db4affc3ce 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: qHj3FuXhgDi2gwWoZ2pDQi/0Eksezxs9ayHG/9wPbQ8Jlix67HVk6+9jt1dx82qqe1RpFYTWfdXESIlJn3MqVY28ISR074stxamF/fiP+EroD/Di8PrkC2ZyFDtgF6IOvziihOfuOGyfheA2BFagFXkb0mOurDcdnjDUUke7Q/dCfWwFi30doGrKTayeWruYmr/6/likE8idIhCXd/Q2m2hLahrsp6NqoKkEWijf26gG2MSaCzojBGTzfHL2pwXG321jgUk7H796+AMaXHgfZbTWD6A0w7nMKuBOb4NhvhRq+H0pi7gCQZIcqNRC4FdTic4vPBw+IvO2cAkwGbpt+jj03zF3O/X7Swvuh/H0MYEekbSYc6sYvFJ+P5hTUS1/z9LVW62WWT92NbvEHEm9Jb9o3KOcTfQgt5bnJyPBOGDPLGj4FTkpWGm8ctoacH/M+x/33mSZSoyRAPuGuYvx9an48jt1ZgOL+Zdbmy7Fkif73wk1M/y5Vr76hLjcIc+pEJDLxBwaTOZWROXu2/0qmAi6ysxvoHGqTd8KdWUz80F/ZaIolg3sJLFT09bj+jpHQFEJb41AuvssQk396UIhbrFhiRK1+OtC0VzfI24SeaCFGJT43yP4o+pHgblqEAzU 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(30864003)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NS3oFz0Vxp6P0kEl6s/g8DEMGl5EvFndBQtRmfODo7xjWbhknpxWnGTaR7zAEVOKeuLi7v6LqZplPasRaKTZixIC8/NMimohUDg5i2Uh4/Lf0Aa1YM58tn2cKl3EPX4wPZbgJDdl0nICN/cNY7UjyDcAs4/1BPNuysQuq2ENYRi9JOB4WKsmk2qqHhNvbPcKObBU+hlCGmubqhKQ2lFumxyZoU7BjWX5z69ZqDBUrkb0GRW/dubstxj4OZWJHY3hzVgDyIoqnGonSj5W9pTRJg1tQkp17xBwiY7H5XdODkYa+qTAJg7VQJVgkW4iufsovV4uIP7hxrYecZT/xabSKBqGhgv5ARD7hhii1269Oq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Mpz+RYtyUGSPvd5XhYstjMwDJHD7QJxHHZ0IMdfkDURdfYqYRYlvpaxET3YSZx8y5fEvCu3OcKbLQvSxWcpO3KJqmeGABOEXrKBADuYXz6bFlXvak/hOPbVtHdHSOjexBlhD5szvlEHiEcLnSziVoN1dAqH8cd X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4d1098e-2944-4931-edd9-08db4affc3ce X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:17.1260 (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: m/w6GVHIO9fKL04VoDqD2ktUmxIyCWl2peqa/3k/3vQEjgIT/cy/6W5fuD/lm5VoxXf1PLlMn8iQhudr+Ul6RQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Adding eventfs_file structure which will hold properties of file or dir. Adding following functions to add dir in eventfs: eventfs_create_events_dir() will directly create events dir with-in tracing folder. eventfs_add_subsystem_dir() will adds the info of subsystem_dir to eventfs and dynamically create subsystem_dir as and when requires. eventfs_add_dir() will add the info of dir (which is with-in subsystem_dir) to eventfs and dynamically create these dir as and when requires. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/Makefile | 1 + fs/tracefs/event_inode.c | 252 +++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 29 +++++ kernel/trace/trace.h | 1 + 4 files changed, 283 insertions(+) create mode 100644 fs/tracefs/event_inode.c diff --git a/fs/tracefs/Makefile b/fs/tracefs/Makefile index 7c35a282b..73c56da8e 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 000000000..82caba7e9 --- /dev/null +++ b/fs/tracefs/event_inode.c @@ -0,0 +1,252 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * event_inode.c - part of tracefs, a pseudo file system for activating tracing + * + * Copyright (C) 2020-22 VMware Inc, author: Steven Rostedt (VMware) + * Copyright (C) 2020-22 VMware Inc, author: Ajay Kaher + * + * eventfs is used to show trace events with one set of dentries + * + * eventfs stores meta-data of files/dirs and skip to create object of + * inodes/dentries. As and when requires, eventfs will create the + * inodes/dentries for only required files/directories. Also eventfs + * would delete the inodes/dentries once no more requires but preserve + * the meta data. + */ +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +/** + * eventfs_dentry_to_rwsem - Return corresponding eventfs_rwsem + * @dentry: a pointer to dentry + * + * helper function to return crossponding eventfs_rwsem for given dentry + */ +static struct rw_semaphore *eventfs_dentry_to_rwsem(struct dentry *dentry) +{ + if (S_ISDIR(dentry->d_inode->i_mode)) + return (struct rw_semaphore *)dentry->d_inode->i_private; + else + return (struct rw_semaphore *)dentry->d_parent->d_inode->i_private; +} + +/** + * eventfs_down_read - acquire read lock function + * @eventfs_rwsem: a pointer to rw_semaphore + * + * helper function to perform read lock, skip locking if caller task already + * own the lock. read lock requires for lookup(), release() and these also + * called with-in open(), remove() which already hold the read/write lock. + */ +static void eventfs_down_read(struct rw_semaphore *eventfs_rwsem) +{ + down_read_nested(eventfs_rwsem, SINGLE_DEPTH_NESTING); +} + +/** + * eventfs_up_read - release read lock function + * @eventfs_rwsem: a pointer to rw_semaphore + * + * helper function to release eventfs_rwsem lock if locked + */ +static void eventfs_up_read(struct rw_semaphore *eventfs_rwsem) +{ + up_read(eventfs_rwsem); +} + +/** + * eventfs_down_write - acquire write lock function + * @eventfs_rwsem: a pointer to rw_semaphore + * + * helper function to perform write lock on eventfs_rwsem + */ +static void eventfs_down_write(struct rw_semaphore *eventfs_rwsem) +{ + while (!down_write_trylock(eventfs_rwsem)) + msleep(10); +} + +/** + * eventfs_up_write - release write lock function + * @eventfs_rwsem: a pointer to rw_semaphore + * + * helper function to perform write lock on eventfs_rwsem + */ +static void eventfs_up_write(struct rw_semaphore *eventfs_rwsem) +{ + up_write(eventfs_rwsem); +} + +static const struct file_operations eventfs_file_operations = { +}; + +static const struct inode_operations eventfs_root_dir_inode_operations = { +}; + +/** + * eventfs_create_events_dir - create the trace event structure + * @name: a pointer to a string containing the name of the directory to + * create. + * @parent: a pointer to the 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. + * @eventfs_rwsem: a pointer to rw_semaphore + * + * This function creates the top of the trace event directory. + */ +struct dentry *eventfs_create_events_dir(const char *name, + struct dentry *parent, + struct rw_semaphore *eventfs_rwsem) +{ + 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_rwsem(eventfs_rwsem); + 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; + inode->i_private = eventfs_rwsem; + + /* 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: a pointer to a string containing the name of the file to create. + * @parent: a pointer to the parent dentry for this dir. + * @eventfs_rwsem: a pointer to rw_semaphore + * + * 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 rw_semaphore *eventfs_rwsem) +{ + 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 = kzalloc(sizeof(*ef), GFP_KERNEL); + if (!ef) + return ERR_PTR(-ENOMEM); + + ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL); + if (!ef->ei) { + kfree(ef); + return ERR_PTR(-ENOMEM); + } + + INIT_LIST_HEAD(&ef->ei->e_top_files); + + ef->name = kstrdup(name, GFP_KERNEL); + if (!ef->name) { + kfree(ef->ei); + kfree(ef); + return ERR_PTR(-ENOMEM); + } + + ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + ef->iop = &eventfs_root_dir_inode_operations; + ef->fop = &eventfs_file_operations; + ef->dentry = NULL; + ef->created = false; + ef->d_parent = parent; + ef->data = eventfs_rwsem; + + eventfs_down_write(eventfs_rwsem); + list_add_tail(&ef->list, &ei_parent->e_top_files); + eventfs_up_write(eventfs_rwsem); + return ef; +} + +/** + * eventfs_add_dir - add eventfs dir to list to create later + * @name: a pointer to a string containing the name of the file to create. + * @ef_parent: a pointer to the parent eventfs_file for this dir. + * @eventfs_rwsem: a pointer to rw_semaphore + * + * 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 rw_semaphore *eventfs_rwsem) +{ + struct eventfs_file *ef; + + if (!ef_parent) + return ERR_PTR(-EINVAL); + + ef = kzalloc(sizeof(*ef), GFP_KERNEL); + if (!ef) + return ERR_PTR(-ENOMEM); + + ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL); + if (!ef->ei) { + kfree(ef); + return ERR_PTR(-ENOMEM); + } + + INIT_LIST_HEAD(&ef->ei->e_top_files); + + ef->name = kstrdup(name, GFP_KERNEL); + if (!ef->name) { + kfree(ef->ei); + kfree(ef); + return ERR_PTR(-ENOMEM); + } + + ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + ef->iop = &eventfs_root_dir_inode_operations; + ef->fop = &eventfs_file_operations; + ef->created = false; + ef->dentry = NULL; + ef->d_parent = NULL; + ef->data = eventfs_rwsem; + + eventfs_down_write(eventfs_rwsem); + list_add_tail(&ef->list, &ef_parent->ei->e_top_files); + eventfs_up_write(eventfs_rwsem); + return ef; +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 999124459..aeca6761f 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -21,6 +21,35 @@ struct file_operations; #ifdef CONFIG_TRACING +struct eventfs_inode { + struct list_head e_top_files; +}; + +struct eventfs_file { + const char *name; + struct dentry *d_parent; + struct dentry *dentry; + struct list_head list; + struct eventfs_inode *ei; + const struct file_operations *fop; + const struct inode_operations *iop; + void *data; + umode_t mode; + bool created; +}; + +struct dentry *eventfs_create_events_dir(const char *name, + struct dentry *parent, + struct rw_semaphore *eventfs_rwsem); + +struct eventfs_file *eventfs_add_subsystem_dir(const char *name, + struct dentry *parent, + struct rw_semaphore *eventfs_rwsem); + +struct eventfs_file *eventfs_add_dir(const char *name, + struct eventfs_file *ef_parent, + struct rw_semaphore *eventfs_rwsem); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 616e1aa1c..3726725c8 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -359,6 +359,7 @@ struct trace_array { struct dentry *options; struct dentry *percpu_dir; struct dentry *event_dir; + struct rw_semaphore eventfs_rwsem; struct trace_options *topts; struct list_head systems; struct list_head events; From patchwork Tue May 2 11:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228801 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 4D383C77B7E for ; Tue, 2 May 2023 11:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233961AbjEBLYh (ORCPT ); Tue, 2 May 2023 07:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233669AbjEBLYb (ORCPT ); Tue, 2 May 2023 07:24:31 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013011.outbound.protection.outlook.com [52.101.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C1326BC; Tue, 2 May 2023 04:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XIcpvnKYcS5nIoTyXgp5re9TnI87RjrDOgzv6YHij0J8f4OFNQZrJaYdt/S0dzlQ9DuZF/gCE3VNGVCsbl2UYYWkKVCS3A3sBBEvUN+Gzf7ZaCfRs0EPyPuvFEh5vPEd1EHquKecOpqRiOx6K8TH7QKCeiC8i9bQTIJLvungElaqS65dtaDJK+LTUMcNqYEWoJvTglPI/DKsabhWlywerF9xdl5SNXaSLxSU3vcykhbcwAEUjRODztNGUtrLnHFBEFZxdgjTt5eNoDh6yKox9IH9CjktuOHZOH3XR2zCeMVg/gy1iIyDAUfVHgsNscyy34neE1VLhpWaP4A6hLQ5eg== 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=kkRu/CB8vMVQrWr2u8LNHjVjzlQsYbcCGubmZWaeChE=; b=WinxD9rKQ1AynDWymNqhJ7CH8da0Kobv2K7TXAnjdS9QCUxv4anh+W/G8ktGxtgmDuUuwmiAmkmKYLmw5At5lFR6GwcoeCTWwXDLahoebn3vaH6E4XYFg4nmy3I8Xs6bsrW4v6Gh7IH22hLOw6Xq+Qn4Flpi5M0xtHyeaDctjU8Vcf/Sz8nxkCTeGYxeRP9xU2MpyvxOb4Nw7u2rPwWDqZP3AcN1b8Cj4e66pK2F5fqLWx9FXEUk+zjq92hEOBugv5nTLMQhCVKAy5tVb1+BJhtObJ+6u706A9wyjXRK7Fl8jvvAb62zMMTDDU0szX3iQJvR4SxuhYNkFkp/ocp9fA== 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=kkRu/CB8vMVQrWr2u8LNHjVjzlQsYbcCGubmZWaeChE=; b=JHNb9lJ46bKGMGYuTNoGJR58o9iC0ImMccZAgT0Y1mvUFzmBHBMCO1t/RxoTBICjaS0iUg18cDk10xrC2MDpLw6+7iwZaWT9ZddoESORLtIufakpeRBXhYyVmaQ122eSmqc+xe0aUpNpSAi4v4GqRg9Qg5T3lJ6OyEiCA3JU5Ew= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:18 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:18 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 3/9] eventfs: adding eventfs file add functions Date: Tue, 2 May 2023 16:53:14 +0530 Message-Id: <1683026600-13485-4-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: f51eb987-cf43-406a-0108-08db4affc4af 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: OqqHCpICWtRJRbo3EKvDCbGgItYW2Ix0S3DwcfwYI/bsreMatYBO++VnKIZREUOEjT32I/s7WcfszNjUyirAkSmGSze6le303rkPYAZ2cR3ZF3bcYnDtfFJzZ8v+k5X+/5+2kssC7OFAVF4Td3uujJCNBN6V1kNRXkr6zNrq65VdUxdoqiwxk9PTDTp4GXa0pLueMPB1nicfPH2Qkzul5Oy4t3J0uSUgp/hgkKMEAY9YBEUF522lKmuZNUjlQmXNJu4ZmjLCUHEGpvYBcnhVmbuDjJI7d9bKKUDRzJ7ED2D+sL8SVLwthlFxG/EU4a0yI7T1Xrkw8KhS/Q/xY+nFRLmnIH1+ySSM46CVUk0OMooGt5dvqXjkxQTDDYNjIo+fgN8tMaTwajTTSanK0P5ZtYkkiFWwHBr5wm1jraGM6lCBzZvyzkLm2HwsbI6AaNEbzZbbUJUil9k6t84Nkeh8fB/9xmXXUDcd2MKMtjv+jF57AEh4v/pjRwYZN7sPF0WU1KDIVSFE3Pm2c1R4RajSJxz3AzQ2t80syZMZN1XVm09S6atHQy46iwgwJacVpQhguZUuGX+ZVcqdcR5Z7q+4lZK4t9N5vAj2b15MCCcSMRVa2zF4vtBfMl47TkECqaxK 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005);D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4aScKSguu4xxwBRn1El+oWAL2efEJLqiSh4ZSB//eqY6YZsRkBrVjMs8UjGKLqPyneQZuWmH0RLzolKD+bUUB2798xoWqF9WWVfL60GHol3qTKZnkstGP9PmreOOHS1+yZLdt5ppcJkMqYGdleHUfqijTuwhZGopeN3laN2z5vEZhdoLzkzC7DkI+e+4Hcd76UHgDqnPeWQDnWlduEykHcvI81M9Ae8gCKfEPQW3iyCKbybo+H1b2MVSP2C9la1FR/gcZm7iV/3tiNblIEkhLHB1yLQwLBcxadWgZkJz/9NqZUriwdX8TeKPcWyNUEnKF19207AXoDWNEef7KmAxT+sA6Jos4L3lZaPlf5fC/3xFugqQShswmzie4N853sPS1Wu+ZXwP5Z0DDBIiVR1ZsSX3y3sDWn9C7bazxGdNHWVqoYL05uWITzpH2wmucEv8UWnTaYCpQcoP4Fl+wOIsmZaDP3mtcbwMuZkSRfHLMmQ5ZV8hN9EcU9XdR/ubpa4IIccZw0bl9JR97ohrsLc7BCiH5QE1p+KJOexwOsV1CPn2j8w6DcBO0tldmkqIKwo+klHv/Y X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: f51eb987-cf43-406a-0108-08db4affc4af X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:18.1775 (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: QxMSKpf/0AX/Hs/TclOLGw3vWKJW/SS1DeSpqCj2yiR9Im8BzDx7zr8/RDb+vSpg0HJY8E+lAYatqWZpxCOCcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Adding following function to eventfs to add files: eventfs_add_top_file() will add the info of top file to eventfs and dynamically create these files as and when required. eventfs_add_file() will add the info of nested files to eventfs and dynamically create these dir as and when required. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/event_inode.c | 118 +++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 8 +++ 2 files changed, 126 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 82caba7e9..93134ae40 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -250,3 +250,121 @@ struct eventfs_file *eventfs_add_dir(const char *name, eventfs_up_write(eventfs_rwsem); return ef; } + +/** + * eventfs_add_top_file - add event top file to list to create later + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have. + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is NULL, then the + * file will be created in the root of the tracefs filesystem. + * @data: a pointer to 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. + * @fop: a pointer to a struct file_operations that should be used for + * this file. + * + * This function adds top files of event dir to list. + * And all these files are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +int eventfs_add_top_file(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fop) +{ + struct tracefs_inode *ti; + struct eventfs_inode *ei; + struct eventfs_file *ef; + struct rw_semaphore *eventfs_rwsem; + + if (!parent) + return -EINVAL; + + if (!(mode & S_IFMT)) + mode |= S_IFREG; + + if (!parent->d_inode) + return -EINVAL; + + ti = get_tracefs(parent->d_inode); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return -EINVAL; + + ei = ti->private; + ef = kzalloc(sizeof(*ef), GFP_KERNEL); + if (!ef) + return -ENOMEM; + + ef->name = kstrdup(name, GFP_KERNEL); + if (!ef->name) { + kfree(ef); + return -ENOMEM; + } + + ef->mode = mode; + ef->data = data; + ef->fop = fop; + ef->dentry = NULL; + ef->ei = NULL; + ef->created = false; + ef->d_parent = parent; + + eventfs_rwsem = (struct rw_semaphore *) parent->d_inode->i_private; + eventfs_down_write(eventfs_rwsem); + list_add_tail(&ef->list, &ei->e_top_files); + eventfs_up_write(eventfs_rwsem); + return 0; +} + +/** + * eventfs_add_file - add eventfs file to list to create later + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have. + * @ef_parent: a pointer to the parent eventfs_file for this file. + * @data: a pointer to 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. + * @fop: a pointer to a struct file_operations that should be used for + * this file. + * + * This function adds top files of event dir to list. + * And all these files are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +int eventfs_add_file(const char *name, umode_t mode, + struct eventfs_file *ef_parent, + void *data, + const struct file_operations *fop) +{ + struct eventfs_file *ef; + struct rw_semaphore *eventfs_rwsem; + + if (!ef_parent) + return -EINVAL; + + if (!(mode & S_IFMT)) + mode |= S_IFREG; + + ef = kzalloc(sizeof(*ef), GFP_KERNEL); + if (!ef) + return -ENOMEM; + + ef->name = kstrdup(name, GFP_KERNEL); + if (!ef->name) { + kfree(ef); + return -ENOMEM; + } + + ef->mode = mode; + ef->data = data; + ef->fop = fop; + ef->dentry = NULL; + ef->ei = NULL; + ef->created = false; + + eventfs_rwsem = (struct rw_semaphore *) ef_parent->data; + eventfs_down_write(eventfs_rwsem); + list_add_tail(&ef->list, &ef_parent->ei->e_top_files); + eventfs_up_write(eventfs_rwsem); + return 0; +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index aeca6761f..1e1780a61 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -50,6 +50,14 @@ struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_parent, struct rw_semaphore *eventfs_rwsem); +int eventfs_add_file(const char *name, umode_t mode, + struct eventfs_file *ef_parent, void *data, + const struct file_operations *fops); + +int eventfs_add_top_file(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); From patchwork Tue May 2 11:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228803 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 69E52C7EE24 for ; Tue, 2 May 2023 11:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233926AbjEBLYl (ORCPT ); Tue, 2 May 2023 07:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233956AbjEBLYi (ORCPT ); Tue, 2 May 2023 07:24:38 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013004.outbound.protection.outlook.com [52.101.54.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D0825B86; Tue, 2 May 2023 04:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJrJTWfyv8DjcSlEgH+nMymBrrICDb6iK37RmGorHQZwZbEJn3CTxIlSPATSMrC6Z8c7teUFWoSkPN6mz0XiVmCyZlVP//UM2Yi+1B1zOq4bR+3OjQ4/FCL6Lc1kwrDkWg7xQEbM1zDX4lNWlmSHashgGpYDjGKzoBkjwSX+KR9GqKnsvh97O2RyUxdaKPReQum4WA21U8tW/q2K+pHc2uKdHLtuPeODTRfu4F0lgUlriYFOX9RIXzOWYFFqHOXhoQisWqJxtNEqaFWj3NweZp5aXIGZgLXsubRmbxEZ8ViaPxT/Biotzg7LHM2L9w6DP+zYudV5gVfLNhazn9d4AA== 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=wvfFuAsOE7stLNyZRI4oiYGvViyfqeFGHzc2Wiwd68w=; b=JcjQ6lytUoL+MT7iozVzBxtaMuHdtI3fciPO5emZo/6QH5/BogxfmNmz9hLscITK5vIs8zUuy+BHYD9uqx+6UUG4bf5yteIaK6HYv/9jijk1bUvQdb3wpnpLW0mu5fj7o7w4TQqB9aRZ5FzM/eVs4ueQs7+1c5t5SvCz8/ymP4fbGAnBWZnurgxdrQLhSc21oSMdAHVkVQx/ogbh6kIYNuw5mzUSBEnQ4/H5ZCYWRMQllBL/ndKPhyw+ZB9Wn1zaZqNXBr/g+DZWt9m1gl6dUpdKbCUAKMhmKdBdZWzqykOEv+DxaTpOh0T7D7qjhHVPq0hxM4L+ECJnkB1duBR8Hg== 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=wvfFuAsOE7stLNyZRI4oiYGvViyfqeFGHzc2Wiwd68w=; b=zYX5XlwfyFiVhrIEKrpCvGYPQwRwez8Y1OaYphgez9oBbir9vGDr/721VOZZPQO+AUXXa0FQaKjQkMzCb7jg1BJ55KhBSL7NldmTNXFdh/qBrZGj40yy9nw+w+KMe79JuVhpGjMWeZ3tG11Nnq7HFIqo+qDmt/BgDSuspRewlXI= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:19 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:19 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 4/9] eventfs: adding eventfs file, directory remove function Date: Tue, 2 May 2023 16:53:15 +0530 Message-Id: <1683026600-13485-5-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: 58a58413-62f0-4e4a-7c12-08db4affc553 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: OlFc6e8jJ5fJqjAOHCg71Lx6azV0Yb+FKVM98RcWDchnlLZxFY5VmjcQzP52xvR29fcj4vHwj5og/8W3BQragXnQx4AbukiRYpCkVy26T9aelKtkcP8CtK0ecyq7aIuTn375oy5MhR34ZXosbk2cYJWRnuDvil2MAr+cJphKXYhO7cXhXgtpgZlgUgQaawHTu9tvijLH5k24lw5iiUuwI1FStse17yv41wwRzeKTZU6eeVcrK33RRKreIPaWVHewq5amBokF2pQVAaexwt7gywaYXr8hfqSRBfp5WeHM8xln8PULvYoCvsydidPJ0M9N5ET2HYT8PyTRf1hlrQ+/8zHR3IQuqmWplDyJYKO4KiypcNc7UP9C9ldvDoABZpGZEvxrTXD148DjIvJ01xENsoX71X6UKbXA8E1oRXMSbkIjPUamcvAew0SnsKe7GB5wvsFAiK/h3OF5tYyZT1gKD1LUc2+urNy0C1EU91rAejsquUMAEjU5Ud3gCBoXjZ6zhLlr/jua2HgUSyekit8hCpAzsKIcOxg+kOi52T6UIv/Ml/z40jqzWX3nwwvCzurmS1r2Ew6B1D+0WEmFy7jfTNmD+C5/T6Ni0g8UI9HjXE0cZFB5HPN+qz5lVeT2p+p9 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vuFNDgYy3aXuWjopTuseHS2CdaB8XA7FHEx3chg30tYeSCDEMUrPyh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5lb1gzOWbPQSbs6q/jGNyYoeUPmoCkAaM8fCMAK/PCkErxq23tsP3NnhtmDD83prjzu8dPL9AosODVLlDz/OAkjjBvWo51i5G+dfByn+4q5X16eDeSKvGPaXzfqR+dPhY3DQ6ZBAFkZ/5QRt6xkIcQb7mwkKIYBGhiUqs7wKUNHAt8n872oAoaxy6xxdcTthUVBvb4T6WPe257VsrhWbigKycWECrikvJoLHi8G8T3bJrsdufX9pD0N5rwGFOY7w2LqmN30QfKl31EU0Z3qdkpMnJV4xpktGzWQ9bIoA4h08w2TyNGAnRS17FvedddMpVtwGtqYcB6VJk5dwTLOebn6q7EYmHP3sPPnC8Uh5d4AHtPK6msif31fQSYSUrOM8hvu81dt5wismsDzQlqru9ATlUUwNl1uqQmdgoIa1DC4iLvdyeiuO/Ckl++nV8gd/PmtSKonDHPMl525ox X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58a58413-62f0-4e4a-7c12-08db4affc553 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:19.2640 (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: uXWYDeg3UOhud4U+XnkDgYShi56A/IyLiXkFeDxZklFD3wKYnCv2Lzs1BpNqDKRUtkuzOHjTva5r6ON8xIIARg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Adding eventfs_remove(), this function will recursively remove dir or file info from eventfs. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/event_inode.c | 78 ++++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 4 +++ 2 files changed, 82 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 93134ae40..9ab675edf 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -368,3 +368,81 @@ int eventfs_add_file(const char *name, umode_t mode, eventfs_up_write(eventfs_rwsem); return 0; } + +/** + * eventfs_remove_rec - remove eventfs dir or file from list + * @ef: a pointer to eventfs_file to be removed. + * + * This function recursively remove eventfs_file which + * contains info of file or dir. + */ +void eventfs_remove_rec(struct eventfs_file *ef) +{ + struct eventfs_file *ef_child, *n; + + if (!ef) + return; + + if (ef->ei) { + /* search for nested folders or files */ + list_for_each_entry_safe(ef_child, n, &ef->ei->e_top_files, list) { + eventfs_remove_rec(ef_child); + } + kfree(ef->ei); + } + + if (ef->created && ef->dentry) { + d_invalidate(ef->dentry); + dput(ef->dentry); + } + list_del(&ef->list); + kfree(ef->name); + kfree(ef); +} + +/** + * eventfs_remove - remove eventfs dir or file from list + * @ef: a pointer to eventfs_file to be removed. + * + * This function acquire the eventfs_rwsem lock and call eventfs_remove_rec() + */ +void eventfs_remove(struct eventfs_file *ef) +{ + struct rw_semaphore *eventfs_rwsem; + + if (!ef) + return; + + if (ef->ei) + eventfs_rwsem = (struct rw_semaphore *) ef->data; + else + eventfs_rwsem = (struct rw_semaphore *) ef->d_parent->d_inode->i_private; + + eventfs_down_write(eventfs_rwsem); + eventfs_remove_rec(ef); + eventfs_up_write(eventfs_rwsem); +} + +/** + * eventfs_remove_events_dir - remove eventfs dir or file from list + * @dentry: a pointer to events's dentry to be removed. + * + * This function remove events main directory + */ +void eventfs_remove_events_dir(struct dentry *dentry) +{ + struct tracefs_inode *ti; + struct eventfs_inode *ei; + + if (!dentry || !dentry->d_inode) + return; + + ti = get_tracefs(dentry->d_inode); + if (!ti || !(ti->flags & TRACEFS_EVENT_INODE)) + return; + + ei = ti->private; + d_invalidate(dentry); + dput(dentry); + kfree(ei); +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 1e1780a61..ea10ccc87 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -58,6 +58,10 @@ int eventfs_add_top_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); +void eventfs_remove(struct eventfs_file *ef); + +void eventfs_remove_events_dir(struct dentry *dentry); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); From patchwork Tue May 2 11:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228806 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 144F7C77B7E for ; Tue, 2 May 2023 11:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233968AbjEBLZE (ORCPT ); Tue, 2 May 2023 07:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbjEBLYr (ORCPT ); Tue, 2 May 2023 07:24:47 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013004.outbound.protection.outlook.com [52.101.54.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4D115241; Tue, 2 May 2023 04:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oY+5fzu/iAcKHLmaHUUXehCI3BBYXVvpBgCuMj3t51zyFScZXUFJVUn37GkQ0B2UcriPBTjqAHUOFdRARykb3qLqe4RwVZ5qhQO8TPxr8tMs75VlwDhL4oloTj9vucABRGIK1baqOv4HY9dG5Bc3lXkO1LhlpTLE5hrbVjnitgFiohifL8wORD4Z6pIVJUdasvEw/8PRp1Itwm/acqvp8b752U9gQwpdz8HiunJUpalcf3n8gBhK0xlHhgPdZf4HSC0Zh3CnY38EpPUEp9M3/Qw03ngWhU3DZ/2/cRLnzA1U8K9VcyzsiFhFuthEwnatxQR2Htt98SSlkA4T+0FQtg== 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=gHID1jxyIqha3NrAukk48LnTgeOjGeMGMwy8PE6DaoA=; b=OsdcmzyA8EQ8oR0plspJyCQCyfIQ1Ghm64PUkOmm8AeegreU50ZnLq6I2S/LUKHHJyR1a2mBJQMJsJiFkgrzWwsJrk/npNaYP6q7ilb7IPiPZwE+yUv3L+Yxl4zHrpn96uIPOJ4KDy4KOd7HfTbbqU66U4Nsb5jH5szLG6JdP3EUswm4RHLe5Bo4RRKL7wfp/dAprvc0Wl9FfIcZH+dD4DmifEHQJuqoATel17Ups5JgVe0t9/Wmx5cAYHM7aWAkPjqcBry+LVWP9pl3N1ZWaLsl8E/eP3D6lTjDzTIrnxORoAIIyvnO8SeE0NAVYzZdNdVpROSV71lky+hukAfg6w== 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=gHID1jxyIqha3NrAukk48LnTgeOjGeMGMwy8PE6DaoA=; b=nQD6e7ni0yzPwo7uekio5fu+9yhEQAwm5dXzHIQGsD4rvdIxCmCIPH4WEIVgE8cp/K7UMfzsvNgBIIGwlUZR6Ic5YSD2ykB8IUx9EfZP0Fi5lcEs+UQwjgy+S/c4JAbClYqtZVRWn8uMtW4TXEV7iJBpfpWa3OufJ4faAHT1Z/w= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:20 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:20 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 5/9] eventfs: adding functions to create eventfs files and directories Date: Tue, 2 May 2023 16:53:16 +0530 Message-Id: <1683026600-13485-6-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: 21ba7af8-2ade-4659-5964-08db4affc5fa 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: rkUVedR+NiBRdf3DEftLJql2SjOi2eCUa4uX7VCmTJIGuDuv5zdWulcbR+Rp8oAnuQWuB1/kohNX8F3eXw14V7HenhUZYd3oQHMElslM3mnScnNPI6bi0l8O+TFH8n2G/f0fe/cmoE0SA8c+q4Xdc2H3SOB9pTbypIroo0KlVc9Mau26zz7Ynmp0xEcs9EWFOOTo5+nXo21v6Ph3hlrb2wRRMPe1BB1wEX3sS2nZAw358e37cB3LEb/rBau5VqgLq08TUAWk/vZiOCPj5DHqhxmfihNB4kTd8aVyUN+fpcsz5oGfjXNduZTiB7EReYxVyh+G7Z1tSC/1cJdw4qzQDY5wNOZ0JMxwvqfpFr2Ov8+Lwee9fRwSv9D7H9cbxCiZKw1PKahC2E7YJ91VZVWBQpXmFzqwk6Lb+1/IykCXRMI/nTqUnMfbCdLl0ujrnVdHjIqZV2LbLLo+AtQQEhHAkRFXozI2eXlHl69VQ32DMRola59uqBK5CG/kphG6BmQ6OpWdPhgMopOPWGA3COIU7MLbuEoDCVPQCXkUHgL3qhsEtEKgEw8HdgUzh2pc5ka3qOe3spfAQ5Buhw7dsyWB9nEfAptI7GfeqvQyW7W6fn17FaNFF7EgD7b6/ZkHGsRz 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b/k7D+rjMwlNQfJs/2qPHoPTQWjrD8eDByl5rdrwhB92kLf2sCFuxHyCF7oLKvDG8/M34f5DlRud5646nhfCaqs9DUm2YzpYwM5I5PicVv7yH31MPuHSf7YL4bWzYmutgHcmkd8TTyVz+y8SQ0JQgQZuL+J5y4O8zGQB/4lUhM0rhRmADFkkio3BDj3qtxDVpnuc77qECzIHe72uqEUaikHYhEPhig7gESyYZ924s7yuzMXu0hYztYbrZfMsV6faHxCBvE7ldZke2g8PHsqofMsmo1zSxnrXy+GqyJP6o6kIYBNVzK3d8CA9Umqkny1WQPF0V69sS9X+3la1kOPcSQymVVxRjVTVOQxjEgUKnH7NHCv0Dz22YR5K0myWcO6W9gqjIXl+WZRXtz+i0lRDI+YE19jQzru+5yId8PIfXhQopMs3CtDk8A/id9PDCIXjXIx+j1HtWoEtluGrtWlvu5E0Hgm57EP06rmoyAG4yJwQyWaO9Q5OXNbS5BUaHUbjaAH+XLvs7v0VJ1yzsYNQ3UhIqPqxPqKk/fV595y39UDH31zlOi6rFgQ0exZbpEIlbiKmImmPrCuPsToZNwJ71WtMEqYDNe61xyQIrnu/MfwDqOHW7Jbt13ntFOG2T22s95Hy2hi3cMpwUcG2tJZD2lz7qzGJTdSaAKZIqrFw15p2Ue1Ku/o23dZWVDc/8vK6wB7U8kGVadBm+oxkphZ60x7YfxJJJNIERGQ/+HggApUg1LabOxGrl2era+qbZ/yPHJuDS7iAXiThERcMAT0v4te7dDdjv3XLEHT1KcTqwLqd2DZgLCnMOZb2Jf8TVnU9Z6JQ3MwHPKx87D5xDs1u9LEgpuQj3kjL5ZGux9fPzE84mioDBxbhsHkDgAe3ibMvXL0Lx/cR30YE8diy1WQN6qr5EiDhrFqDD5exZquC8NFi639A6YIeYBZ82ONT4sNGUJm3Kj/FgWuKtn69Zi9Mj19FnkT078T2OE2FanxCZH+PKnz240R+TNcfx38hmPuqhd9gJeyQnGAL++M1+cAP0zWhKBIDN0Tsk08n1VOcSeJB5zEoGf5C9FvnwNkLwUTn/rPBHRzvTYcgVMjvw+IZG71Y91cQ73fzX/H/Cd30QPHXXwoQgnQlptzMq9IUsH2l2aBPlS/j+Sb3oDB6kMHPpj7ufoizG6c+kSIxOv72ooPKHhfjchaMPdlSysy8s9zPznmPKrLpX/WIA530SaOgEsL7rS1taWNVnPTlrtulmnLoIk/RsaozSF1ZZEZ1xjClxqYOJfoFXf3bg7ngU6cm3bKLnmKf4bF7sZlSl/3CKFsBtFtX2qGtLGTsChVIriDBwmoeutoedyZmgM7vpEXZTFn6Jrdcclc1Kx831l1VbQQP2TTRLje2Ww1FQoxtXgQHBLSXfjHXL8V98jRc0zU2su0anjexlSW0VqKHlfDjKebxVjbV/t2j2Mi6nloL1X19K5THYYSsF+WkgREwt+OBkwgOFsx1nsNkzKdA7yAsbOkBy4BGROV51I+dGwFJs8rY0gbkwQF1Nhx38PHe14bkK7jEouLcSHMp/Tq4/AivZ53w6/ADe4cpDFbndoWjSzCC X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21ba7af8-2ade-4659-5964-08db4affc5fa X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:20.3514 (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: GvPaM7/xUFOh6V+9UtJo9W0WXLJ3+7+zIEzhWhNHTGABE+fYJAS9aa8oWGROScQ70dkBFVjx0IUzD87bfAdbJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Adding eventfs_create_file(), eventfs_create_dir() to create file, dir at runtime as and when requires. These function will be called either from lookup of inode_operations or open of file_operations. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/event_inode.c | 125 +++++++++++++++++++++++++++++++++++++++ fs/tracefs/inode.c | 47 +++++++++++++++ include/linux/tracefs.h | 6 ++ 3 files changed, 178 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9ab675edf..0ee27f7c8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -83,6 +83,131 @@ static void eventfs_up_write(struct rw_semaphore *eventfs_rwsem) up_write(eventfs_rwsem); } +/** + * eventfs_create_file - create a file in the tracefs filesystem + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have. + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is NULL, then the + * file will be created in the root of the tracefs filesystem. + * @data: a pointer to 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. + * @fop: a pointer to a struct file_operations that should be used for + * this file. + * + * This is the basic "create a file" function for tracefs. It allows for a + * wide range of flexibility in creating a file. + * + * This function will return a pointer to a dentry if it succeeds. This + * pointer must be passed to the tracefs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here.) If an error occurs, %NULL will be returned. + * + * If tracefs is not enabled in the kernel, the value -%ENODEV will be + * returned. + */ +static struct dentry *eventfs_create_file(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fop) +{ + struct tracefs_inode *ti; + struct dentry *dentry; + struct inode *inode; + + if (security_locked_down(LOCKDOWN_TRACEFS)) + return NULL; + + if (!(mode & S_IFMT)) + mode |= S_IFREG; + + if (WARN_ON_ONCE(!S_ISREG(mode))) + return NULL; + + dentry = eventfs_start_creating(name, parent); + + if (IS_ERR(dentry)) + return dentry; + + inode = tracefs_get_inode(dentry->d_sb); + if (unlikely(!inode)) + return eventfs_failed_creating(dentry); + + inode->i_mode = mode; + inode->i_fop = fop; + inode->i_private = data; + + ti = get_tracefs(inode); + ti->flags |= TRACEFS_EVENT_INODE; + d_instantiate(dentry, inode); + fsnotify_create(dentry->d_parent->d_inode, dentry); + return eventfs_end_creating(dentry); +} + +/** + * eventfs_create_dir - create a dir in the tracefs filesystem + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have. + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is NULL, then the + * file will be created in the root of the tracefs filesystem. + * @data: a pointer to 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. + * @fop: a pointer to a struct file_operations that should be used for + * this dir. + * @iop: a pointer to a struct inode_operations that should be used for + * this dir. + * + * This is the basic "create a dir" function for eventfs. It allows for a + * wide range of flexibility in creating a dir. + * + * This function will return a pointer to a dentry if it succeeds. This + * pointer must be passed to the tracefs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here.) If an error occurs, %NULL will be returned. + * + * If tracefs is not enabled in the kernel, the value -%ENODEV will be + * returned. + */ +static struct dentry *eventfs_create_dir(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fop, + const struct inode_operations *iop) +{ + struct tracefs_inode *ti; + struct dentry *dentry; + struct inode *inode; + + if (security_locked_down(LOCKDOWN_TRACEFS)) + return NULL; + + WARN_ON(!S_ISDIR(mode)); + + dentry = eventfs_start_creating(name, parent); + + if (IS_ERR(dentry)) + return dentry; + + inode = tracefs_get_inode(dentry->d_sb); + if (unlikely(!inode)) + return eventfs_failed_creating(dentry); + + inode->i_mode = mode; + inode->i_op = iop; + inode->i_fop = fop; + inode->i_private = data; + + ti = get_tracefs(inode); + ti->flags |= TRACEFS_EVENT_INODE; + + inc_nlink(inode); + d_instantiate(dentry, inode); + inc_nlink(dentry->d_parent->d_inode); + fsnotify_mkdir(dentry->d_parent->d_inode, dentry); + return eventfs_end_creating(dentry); +} + static const struct file_operations eventfs_file_operations = { }; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7df1752e8..66c4df734 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -452,6 +452,53 @@ struct dentry *tracefs_end_creating(struct dentry *dentry) return dentry; } +struct dentry *eventfs_start_creating(const char *name, struct dentry *parent) +{ + struct dentry *dentry; + int error; + + error = simple_pin_fs(&trace_fs_type, &tracefs_mount, + &tracefs_mount_count); + if (error) + return ERR_PTR(error); + + /* + * If the parent is not specified, we create it in the root. + * We need the root dentry to do this, which is in the super + * block. A pointer to that is in the struct vfsmount that we + * have around. + */ + if (!parent) + parent = tracefs_mount->mnt_root; + + if (unlikely(IS_DEADDIR(parent->d_inode))) + dentry = ERR_PTR(-ENOENT); + else + dentry = lookup_one_len(name, parent, strlen(name)); + + if (!IS_ERR(dentry) && dentry->d_inode) { + dput(dentry); + dentry = ERR_PTR(-EEXIST); + } + + if (IS_ERR(dentry)) + simple_release_fs(&tracefs_mount, &tracefs_mount_count); + + return dentry; +} + +struct dentry *eventfs_failed_creating(struct dentry *dentry) +{ + dput(dentry); + simple_release_fs(&tracefs_mount, &tracefs_mount_count); + return NULL; +} + +struct dentry *eventfs_end_creating(struct dentry *dentry) +{ + return dentry; +} + /** * tracefs_create_file - create a file in the tracefs filesystem * @name: a pointer to a string containing the name of the file to create. diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index ea10ccc87..57bfd1322 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -38,6 +38,12 @@ struct eventfs_file { bool created; }; +struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); + +struct dentry *eventfs_failed_creating(struct dentry *dentry); + +struct dentry *eventfs_end_creating(struct dentry *dentry); + struct dentry *eventfs_create_events_dir(const char *name, struct dentry *parent, struct rw_semaphore *eventfs_rwsem); From patchwork Tue May 2 11:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228805 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 40F6AC7EE24 for ; Tue, 2 May 2023 11:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233367AbjEBLZQ (ORCPT ); Tue, 2 May 2023 07:25:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbjEBLYt (ORCPT ); Tue, 2 May 2023 07:24:49 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013011.outbound.protection.outlook.com [52.101.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 040B1558B; Tue, 2 May 2023 04:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LNoQEm3RKfrh9RSSrIhgUKZ25URb74WvBhLXBSFJQoSy7kBvEWLGC3ZtupnbKxp6fPqLfCv8/A6kPB5DgrlSscu6GIsNg2iU8lSb9QBnZIbZ8zXri8af6ARF/5ISBdAkS+iUtaB5U6bgK55Y/tB0XTuoHZdca6Z92PonunTGCCFfnloiU53fyttBjcTkFZv1zFTiVwf3IVhLCchyQ3gaS3Go1/ISPHP1dWagkuvEs9HcBsZvn4CS2VA/cU38gLgq9HgpWqObCke8p19uOKlfXdlkTN3yOQr3nk4fX9bVYgLk5iK/+cvhelZEeZcKyZkH0okcvn3WJF0ZO7GrXEcJPQ== 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=Z2ct1Q7hesDl4mZGK7qLPhrph4joBS9Y2AklBElPvBc=; b=LumKODwxaiiH3ktjXFZwQVEwklTwYhYClROhRlTZQMg5uxy37azq6zPnPEUJ/cjEnAP/cQnSIL3MTt57rGzZmShMHjnKx8bYbT81MCR9sUhZOfAsVaefesbm63M+JRTW/DmSjGAliZR0SIFeR7SJ+JHHSTRrY2Km+P6BRTtIsRfdoVifQgYKjUSrK+326/RwfeCTqdgVFHW+k+P+PjPA3Ugh97Ez+SBmu7GDYjmE7/8iUAtSbXdBGgOXkR074pVziaJA4852mzkRmEcBEMyvU3MkzxhIj4MpceE271fepw71s4WH+aAh9nM+zQHn612VKIjF2UIx4Byj6uR27JGO1Q== 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=Z2ct1Q7hesDl4mZGK7qLPhrph4joBS9Y2AklBElPvBc=; b=u+lZp4PLS2SdxR/9/5LpSEW+c2+IbADsYbkcaEpPsKANIOis2ufl+i6U5LnBDe1kmkMa5LsGwTKNZgv49VDB5vIXzmu30yGOwobjOd0rjQ6rozQkI+LNjsoTWDBcdbhJ162O28/63ZCTkc92Nw5vhNx2zIx91j4sJTPhadAZEus= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:21 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:21 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 6/9] eventfs: adding eventfs lookup, read, open functions Date: Tue, 2 May 2023 16:53:17 +0530 Message-Id: <1683026600-13485-7-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: 0cb7a781-b404-4597-e14a-08db4affc69e 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: djkVQmksS74IpI1N80kjWLqsghZ18trtsbazlo5w59mjvFSdCh50IuCe9c1f804wYaHM0aPOP1HiheAZTji0AdMh2FSJqkvdn6tR02YdGDnxnaNPGS5KMi3Zzzhy8U1dkYqmVuw3PV75Tr3nZgPSesXxbU3vPKDCWiB8pDbmgdOnP+aQ9WPQQD5mMFW2IHKTVX40GTMCYqDfq77zBWnrP1js34XNkmH9MJznLTrWvF0+m0gAi/p4vxbxXrzoyIYi2g9S4XaHgKfzoEy0gtxtG2AzV38jp7jIMW8ZXDT8a/Iwv836pprssr5ojLq+yyGRnK/sapOxCwRIo5aQNRc9JktytiPzTtUB8AP+TGGGi5294kg3B38m9wjj1aDPqlfQlegOb3oL3Zc/mObLCzQuzg7PU0bpHOqGOBPemR8AKu528q8OMCd/evO7vQKqhWaEjE6h/ZPcMMn2VonepcrT40OjCBHaTI1sYyNUAmg7cRI5XI5zw8L5itDk/yguoULzU0C1YqoEUrmOu/ZpeiORyBzg9FV43xNarWaO7OVgfvrqx9qOya2zvouZbCfqyHWoeiYzMMUNilmya3qlWhwcLipG+exG5YeDADa8cfuZxnBdBuSi7QdBxotKSR7IRkWN 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YD1J5puj+Z+eSkss/+6/bdD8x5vpKGbefe+lXQZyLYgFFBHG7X+hRWtyId8wmgcJw21MClXArJbgZ7mySJlAA+QDAznpwWnj92vsejH+w3V31jjRRaOdi7b9JwSqTuX83R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FRmo0MWo+r0dNt4wb0nxGxnLCYMBQ07hX+9TJLn0tnTmegPrr2HqDqpH26pc5ZLw8nA5AG5nhS5vgKbRKVwB5WTk2GCJjenPur0mS0OTpUg0KT7oJ64MXZzi/WyWcDGo6QfigZLWXVNlY9zSKZH51BZv8tC8J8fRKNKhl9a2eyI4TMASbf+bXBLnNHr3S3c0tbGLvOXWFu9FevxchlX/g+OyIn01giTTJ6i88F+6mDFKjbi7iOVsbJk5mne+DWCoaqHP+Hs1NoiPPjd59vKEa7hdoeTU4gN2l/2Gead0Nh7ngJOdyKIqAPzoJrhxIlBjsDsEngCC3DJxXeCjtjOluGUQHdLP8bmY+sM6fwX1QniE0vqysVBIHLtebHvnHgW8xZH9g7NlFb8r+kHQ X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0cb7a781-b404-4597-e14a-08db4affc69e X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:21.4169 (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: vsu75w6Omb8JCAXsAl5P6usgcIpeXLRVcP/1SkpMbNfMVn/FeM6pt2fJpRYhp37MNmuOSUTfK7UROpac8jmmgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Adding following functions to eventfs: eventfs_set_ef_status_free() eventfs_post_create_dir() eventfs_root_lookup() eventfs_release() dcache_dir_open_wrapper() Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/event_inode.c | 188 +++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 2 + 2 files changed, 190 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0ee27f7c8..f047e45ed 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -208,10 +208,198 @@ static struct dentry *eventfs_create_dir(const char *name, umode_t mode, return eventfs_end_creating(dentry); } +/** + * eventfs_set_ef_status_free - set the ef->status to free + * @dentry: dentry who's status to be freed + * + * eventfs_set_ef_status_free will be called if no more + * reference remains + */ +void eventfs_set_ef_status_free(struct dentry *dentry) +{ + struct tracefs_inode *ti_parent; + struct eventfs_file *ef; + + ti_parent = get_tracefs(dentry->d_parent->d_inode); + if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE)) + return; + + ef = dentry->d_fsdata; + if (!ef) + return; + ef->created = false; + ef->dentry = NULL; +} + +/** + * eventfs_post_create_dir - post create dir routine + * @ef: eventfs_file of recently created dir + * + * Files with-in eventfs dir should know dentry of parent dir + */ +static void eventfs_post_create_dir(struct eventfs_file *ef) +{ + struct eventfs_file *ef_child; + struct tracefs_inode *ti; + + eventfs_down_read((struct rw_semaphore *) ef->data); + /* fill parent-child relation */ + list_for_each_entry(ef_child, &ef->ei->e_top_files, list) { + ef_child->d_parent = ef->dentry; + } + eventfs_up_read((struct rw_semaphore *) ef->data); + + ti = get_tracefs(ef->dentry->d_inode); + ti->private = ef->ei; +} + +/** + * eventfs_root_lookup - lookup routine to create file/dir + * @dir: directory in which lookup to be done + * @dentry: file/dir dentry + * @flags: + * + * Used to create dynamic file/dir with-in @dir, search with-in ei + * list, if @dentry found go ahead and create the file/dir + */ + +static struct dentry *eventfs_root_lookup(struct inode *dir, + struct dentry *dentry, + unsigned int flags) +{ + struct tracefs_inode *ti; + struct eventfs_inode *ei; + struct eventfs_file *ef; + struct dentry *ret = NULL; + struct rw_semaphore *eventfs_rwsem; + + ti = get_tracefs(dir); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return NULL; + + ei = ti->private; + eventfs_rwsem = (struct rw_semaphore *) dir->i_private; + eventfs_down_read(eventfs_rwsem); + list_for_each_entry(ef, &ei->e_top_files, list) { + if (strcmp(ef->name, dentry->d_name.name)) + continue; + ret = simple_lookup(dir, dentry, flags); + if (ef->created) + continue; + ef->created = true; + if (ef->ei) + ef->dentry = eventfs_create_dir(ef->name, ef->mode, ef->d_parent, + ef->data, ef->fop, ef->iop); + else + ef->dentry = eventfs_create_file(ef->name, ef->mode, ef->d_parent, + ef->data, ef->fop); + + if (IS_ERR_OR_NULL(ef->dentry)) { + ef->created = false; + } else { + if (ef->ei) + eventfs_post_create_dir(ef); + ef->dentry->d_fsdata = ef; + dput(ef->dentry); + } + break; + } + eventfs_up_read(eventfs_rwsem); + return ret; +} + +/** + * eventfs_release - called to release eventfs file/dir + * @inode: inode to be released + * @file: file to be released (not used) + */ +static int eventfs_release(struct inode *inode, struct file *file) +{ + struct tracefs_inode *ti; + struct eventfs_inode *ei; + struct eventfs_file *ef; + struct dentry *dentry = file_dentry(file); + struct rw_semaphore *eventfs_rwsem; + + ti = get_tracefs(inode); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return -EINVAL; + + ei = ti->private; + eventfs_rwsem = eventfs_dentry_to_rwsem(dentry); + eventfs_down_read(eventfs_rwsem); + list_for_each_entry(ef, &ei->e_top_files, list) { + if (ef->created) + dput(ef->dentry); + } + eventfs_up_read(eventfs_rwsem); + return dcache_dir_close(inode, file); +} + +/** + * dcache_dir_open_wrapper - eventfs open wrapper + * @inode: not used + * @file: dir to be opened (to create it's child) + * + * Used to dynamic create file/dir with-in @file, all the + * file/dir will be created. If already created then reference + * will be increased + */ +static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) +{ + struct tracefs_inode *ti; + struct eventfs_inode *ei; + struct eventfs_file *ef; + struct inode *f_inode = file_inode(file); + struct dentry *dentry = file_dentry(file); + struct rw_semaphore *eventfs_rwsem; + + ti = get_tracefs(f_inode); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return -EINVAL; + + ei = ti->private; + eventfs_rwsem = eventfs_dentry_to_rwsem(dentry); + eventfs_down_read(eventfs_rwsem); + list_for_each_entry(ef, &ei->e_top_files, list) { + if (ef->created) { + dget(ef->dentry); + continue; + } + + ef->created = true; + + inode_lock(dentry->d_inode); + if (ef->ei) + ef->dentry = eventfs_create_dir(ef->name, ef->mode, dentry, + ef->data, ef->fop, ef->iop); + else + ef->dentry = eventfs_create_file(ef->name, ef->mode, dentry, + ef->data, ef->fop); + inode_unlock(dentry->d_inode); + + if (IS_ERR_OR_NULL(ef->dentry)) { + ef->created = false; + } else { + if (ef->ei) + eventfs_post_create_dir(ef); + ef->dentry->d_fsdata = ef; + } + } + eventfs_up_read(eventfs_rwsem); + return dcache_dir_open(inode, file); +} + static const struct file_operations eventfs_file_operations = { + .open = dcache_dir_open_wrapper, + .read = generic_read_dir, + .iterate_shared = dcache_readdir, + .llseek = generic_file_llseek, + .release = eventfs_release, }; static const struct inode_operations eventfs_root_dir_inode_operations = { + .lookup = eventfs_root_lookup, }; /** diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 57bfd1322..268450d60 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -68,6 +68,8 @@ void eventfs_remove(struct eventfs_file *ef); void eventfs_remove_events_dir(struct dentry *dentry); +void eventfs_set_ef_status_free(struct dentry *dentry); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); From patchwork Tue May 2 11:23:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228808 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 1AA89C7EE24 for ; Tue, 2 May 2023 11:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbjEBL0p (ORCPT ); Tue, 2 May 2023 07:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjEBLZG (ORCPT ); Tue, 2 May 2023 07:25:06 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013004.outbound.protection.outlook.com [52.101.54.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D935FC8; Tue, 2 May 2023 04:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NYqEaCUmQH0jYH7IpFcQlQz2ccx57hLYwRmnB92KBOm3sD6yAZjde7kp8t4DC48upmkkXtgmVJTbFAVM8sElUWR8bLTmp9CT1yKvnzZZ1aa5Tkx2xtkJCIxIwHuuau5Mv7i4Cj5Q6r822syXE8lbiQOn4S45zOAedlX7hSI8ZzdFxB3zjVf7HLaHxeEy+rEDGk6agZKZ0H0vp6120/c2RSjdyLOiRiHKFNYee//NxKSlfOtRSFtXYBmoEDEjs79Hz2EDpZWJHw+o6EGpe/aYQ1RzeMx0olifyWOmf38M/T04GKFkaGivdcC/3p468gFZTJvf3U9DRsdJCX/T4AtVCQ== 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=uInKmho4B1o98gZBl2Y1AdyjuUqybZlbhrWd2mDIjDI=; b=DzttNHlFtRU5n7ZEwSkuVy21H+G83AZ6TS9qYOxS8OJ7rcX1dLgB5QPOlGhHbhUJybROBnMPHMyhptdrqqXaVhXQWvCIzzJkY93jgQRro7G0kAj0jFRDf3dZjy6J/WH7BV7e9w3Y9pFEg6Bp9/mkqWpOn+AgdRcmmZW7kEwMtDjNHHjJH8jzSA0eZa3O7+5r0fwtlpDb9sr0zHKuLKqNwARylNzTKdpO4etIhVKL14+J6C4sEFLVZ/WhvubnIpTvpKqXc3c89lzdNE9Q/KQ1diFEaU4rVmgiDJM8yZpjOIotarfCy+YbXGAgTUHcZFc/bqWqBotWk/tPPwJLlBCo6A== 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=uInKmho4B1o98gZBl2Y1AdyjuUqybZlbhrWd2mDIjDI=; b=Beu7G/VxNRosAgKEWT+qpzD5BHqZqqYdaEKf+uAsC2nONvn8vehgkrb0tUYJ96RjtPC82/P9b0ZH9f+ePix/8vrbkNaf3HixIlsUoOIlJFJvxRFm59JY6fBtUYLfIMXzqs+OxB9ovy9hcq7VhRis2Y1y6S1g80f0fwaBWZjJy4g= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:22 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:22 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 7/9] eventfs: creating tracefs_inode_cache Date: Tue, 2 May 2023 16:53:18 +0530 Message-Id: <1683026600-13485-8-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: cc1e70b2-96d4-471b-ed67-08db4affc740 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: PLypwlOTLCrY4O2skGwn5uBcDjjpz0SGzTLvDk287+BD4+Phsvbokqg0prPmg9oFwpUVSUcexD5qlYhMPQyGUJKUwO1sA2QFbLZqMKZwUCSkMN9AnaHp4xeXXB2iWKT8h92vzwVfSvzCQZ9+eImKrkhEW88ak6eUF+w6f70fAOjpt3fnQjCMt6PX5b9DVZsnSJGWZA/5l/rv6UIGgkG+rrpSWapHcGxGNHv/PLxhV8hw6CWaq11QYVYV3qdB9dV2Jr80iFEOMU53jzPUtY2grEHApsWLY7SZdWcb7re4lLCSmq8lg4BhNHu7zR+zzPKa0TQh4fccPagMVMrQxn8FtFTWWWulXt2Sv1GoZ5MWVzG+sJj7SITygj8a8uij0gPlGcBlv2p0xyjSEMMIa6JhH6y3PlxGEarWyQB7XXdS0eE7F0ukFz1YWudCMg0ikegItK/QpA32u6LVh+Q/boHTyGZTqCzW0Mxn8UY+eQcIGd5FuEGQmQ3fNH1uqsuUkOmczm/jibEBc3v91jsy/ukiP7UI0M2XMIH+27pL81D5Va60uPuRUxKvJkB+39/8NhRUHELYxgz51f0OJ+DqAOQv3hMtpEjtehS+3CXuhqU4ewz+D+d1iixaIgVz5SV46Xpg 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FAX4z+vI5hd737vvWi1urWDf6Nj8cJ9p/D8k6r6bm2NP/TGlLkfgrB7yjpUKXWEmHkz8hjDoQNpBLT8UQgsRSGT2TDcdN4X70Ha7pAISUuaTvtInKjg2kpNQZ9fO+Y62vHiw0jGzUldkh714mk8VexmRpkb9ZMA9A1qlSfF5M9lxGS2uU981EClLsYxnVkv5Xx4mUoJLL1QvIQvsniS3Jp9PqkcpPHONIQ2MVwPaDmZZ9MwBzb4rSe6HoBLrduOTB977DRhAYv4aDJp8fE+hkyg6mLZbzbsd87WJYss0mp9E4LAhOqWheweyUWMfvOkM/hJIblanDJ2LOKPAw6mPvl535Y+GRHfXWBZKjhvvvtdUsG95qm4se/iG5f5nl4SmbHGsMbwCqz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BuDfUuAfRexh0FcpB2tMF4cTwriqYvY2nZw6S8h7Yvj80x9a7yDXxsScU258upFFVx+yM1W5GF8SMkqUlkoC+qNePxhXHT8XnQV/lls+vsUAse7RJxusdTYfGm2ay8h+LG3s4fFgkA8KKA X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc1e70b2-96d4-471b-ed67-08db4affc740 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:22.4737 (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: oJlYoaGXw4hTISy/15RLsLMjRIIFoSsVjYwmC/YFB3KYHnY/BkqDXLjpByqrk/dN4SUuVcksNr7bPqcpNcnscA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Creating tracefs_inode_cache which is a cache of tracefs_inode. Adding helping functions: tracefs_alloc_inode() tracefs_free_inode() Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- fs/tracefs/inode.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 66c4df734..76820d3e9 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -24,11 +24,30 @@ #include "internal.h" #define TRACEFS_DEFAULT_MODE 0700 +static struct kmem_cache *tracefs_inode_cachep __ro_after_init; static struct vfsmount *tracefs_mount; static int tracefs_mount_count; static bool tracefs_registered; +static struct inode *tracefs_alloc_inode(struct super_block *sb) +{ + struct tracefs_inode *ti; + + ti = kmem_cache_alloc(tracefs_inode_cachep, GFP_KERNEL); + if (!ti) + return NULL; + + ti->flags = 0; + + return &ti->vfs_inode; +} + +static void tracefs_free_inode(struct inode *inode) +{ + kmem_cache_free(tracefs_inode_cachep, get_tracefs(inode)); +} + static ssize_t default_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -347,6 +366,9 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root) } static const struct super_operations tracefs_super_operations = { + .alloc_inode = tracefs_alloc_inode, + .free_inode = tracefs_free_inode, + .drop_inode = generic_delete_inode, .statfs = simple_statfs, .remount_fs = tracefs_remount, .show_options = tracefs_show_options, @@ -676,10 +698,26 @@ bool tracefs_initialized(void) return tracefs_registered; } +static void init_once(void *foo) +{ + struct tracefs_inode *ti = (struct tracefs_inode *) foo; + + inode_init_once(&ti->vfs_inode); +} + static int __init tracefs_init(void) { int retval; + tracefs_inode_cachep = kmem_cache_create("tracefs_inode_cache", + sizeof(struct tracefs_inode), + 0, (SLAB_RECLAIM_ACCOUNT| + SLAB_MEM_SPREAD| + SLAB_ACCOUNT), + init_once); + if (!tracefs_inode_cachep) + return -ENOMEM; + retval = sysfs_create_mount_point(kernel_kobj, "tracing"); if (retval) return -EINVAL; From patchwork Tue May 2 11:23:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228809 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 D6739C7EE26 for ; Tue, 2 May 2023 11:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233964AbjEBL0q (ORCPT ); Tue, 2 May 2023 07:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234104AbjEBLZK (ORCPT ); Tue, 2 May 2023 07:25:10 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013011.outbound.protection.outlook.com [52.101.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9297E5FC7; Tue, 2 May 2023 04:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HU5P3g9R9Q/lgiXNVsKHUl824kFC7CGzNaVXgXCWK9vuvEorYKXJRV7k/+DVQE1YxJe10k6hn+my7dHwI9cLJ1VpQmiHQmqmktIVjU4R84rIka/WbtEnW5Ikz+McBcxYNpIXj3ylOWJv2sKtMXvdS5LqENWIa3Awop425ccLyZKgnt37+KqySNdwe5vP3DMIfvFQnRsvBAlw2klKrlJcnOigYKF0NEkp2qTulRXDnVeLI6Bd5seKSEDdA6oYcVrIUPC79aShRdr1+U6cMcQc1H1Pz+kDAk7I1gBw97KSuLTj3my0pCknUmBHsgiHqWOp1JYcPYGCMGcW3BPjYEdk9w== 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=ERQimYWkxEJ0rbIEpqK/pcQLku99de6QyaNoG0OzoWw=; b=Xs7Fbxhm40IC2Yd44EPpVOHhgDntIBkPQhkuGjzKpDM5GNWRkIE3vDTzMv828ULB/D/jYJpGH8PqXhqge8ogZqjoc+lk38Nxub/ACPxl3SYGjhChKOe1QD41oZQwpM94/m5ESeyuScq6on3xOxZT8YdqhWpK1dNVgz6LikNSw3ry5Q0Jqf8092JmuEfI4cNcOiXMH/FDgs9rR/C1vOd9J+A6jZh/Mawj2yPTz9RRnYsxMSLvxAfc843pyK+rcY+27wSHDV4nhKMaQRM5xz/VO3dxSSbRdK/J+CQHrct8IkP9se0ZkmrIndXoQ4D2XP0yX73tYJZrMCgRMfsg8wfN3w== 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=ERQimYWkxEJ0rbIEpqK/pcQLku99de6QyaNoG0OzoWw=; b=2hMnw5LyjAkIYO5YnBTXQ1KfQaGJj0v/M47lowlsjHUsnESjL91vOYF4kJAEBYJ8YYZ8lkWQT2KCnishL4pBRaN82VyU8MHc9KBIG+VQUMcLG1fWmYAFs0ZP3zGKndvKQF+rSW0H2uRRR0Zf1JsnLk0EPPnJM30ikALQssCBPFM= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:23 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:23 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 8/9] eventfs: moving tracing/events to eventfs Date: Tue, 2 May 2023 16:53:19 +0530 Message-Id: <1683026600-13485-9-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: cedb92c1-bd7a-4e11-681d-08db4affc7e5 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: 1xCfLuXhXfeoaAj8mTIxnJDfY2jV+MBGlS2pc+4YKBp5fhbvTa+1fEAnoh4W3yUIviUx8C4jgJeFfmR/FNTFPFxatqcqsv41nbWTKF3ItIYDgdbFkx5tV98b1z5zJGiZpcM9zUaxZ4yuJqcjkOJscK/Cdbv2ZulLG7UuyLYplBb9wZ7wrMrnIAWr3qDm3S0JmDVKkU1zGKLFc0+v09XDGe9BnoVRWqDHwbnaIjiBoliMKHbKKxTexg4Um6ALJkMFcDjkQI3b4A2qbkzRQyapVmNaN+PZMoM5WyyGAsJgwpYfuz4ZjiTGMAJmaKVilrJclU3+qEq1/clRivIqSxq9W0oajQLsVAecTkDONj6Nts8Vz69GRpEv1zwgHj/g3JMtZWlRPU8bSXrtopGIOFb311e9I7qfYt3mVxbMMHi6cc5VlNAU1NYE4zcfSTm4ShQ3ajJr+kdoC088kZ0brYPFcAXKtaqa6RrzkpZCuosGOlYEQ4ONJSMJPtHODP6SXaM8lYm5VE3NXhWbbjRVrHSmjsAV+r+Lfba6dYqW+RZj+EZVMV4lMuqXy7vaqCDmLpUv2N/CHDBSQpKPUFg+612a8Ks+GVxUreRuJaGWaYj53YEJB8YInOOV0jHfQodE50Xb 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JY6MxwQDC1VvJnbV+bVTFDse4SCWRMPULs13QkVken9ZHcr0TUhmrGWZrQxZoZymtVA8olAZDLo7M3Ybv5xI5xiRuKABoxERFFMAPwdZ/9ZC9DwdxGdgJ8NW+dUryWH2t/cGjNcqyul2ZwZs4EAQ+mTvdWljuUdPmNZV1BTKU6MxpYjXJUjV7FLpsBkf8lgLc1eyLyNcGNuOX4BKp0LHPdrvV4TYgfcYoNqcBZVxEknS+mfyBTdF40kdsDsyQumz3NtHed4QojJIbfpUSkPvXu/DJu32MGksLDDDDDDonwQ841Iq8X6EUNnkzxnfxdYjYclQwXOkWfovrYpt6s6hiA/QtJVDh1il2CoOOjuh8o1NkX89LqVMd3lpkwMTcEgVSvIh3jx8hAhXFMT6+W/zNWCrWqrGlLlQnStatupnsLAfXiDC6MDM8ehVVU78iIPgQWFInF2Cr8TAP+oM+7V3fEphR7Hr6QuiY0LmlL4r53Dx/ubnHEAAuaP+2Bi53nvAm2DmR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X-MS-Exchange-CrossTenant-Network-Message-Id: cedb92c1-bd7a-4e11-681d-08db4affc7e5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:23.5440 (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: a5gIZDYEyRxegddG5/QeH1oiNb/ftwAvogcBOgikDXaVe9N427Tl7rKsqZ9GFgEPCGZdvlRWJyKnckEkSJ3E1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Till now /sys/kernel/debug/tracing/events is a part of tracefs, with-in this patch creating 'events' and it's sub-dir as eventfs. Basically replacing tracefs calls with eventfs calls for 'events'. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/inode.c | 18 ++++++++++ include/linux/trace_events.h | 1 + kernel/trace/trace.h | 2 +- kernel/trace/trace_events.c | 66 +++++++++++++++++++----------------- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 76820d3e9..a098d7153 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -374,6 +374,23 @@ static const struct super_operations tracefs_super_operations = { .show_options = tracefs_show_options, }; +static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) +{ + struct tracefs_inode *ti; + + if (!dentry || !inode) + return; + + ti = get_tracefs(inode); + if (ti && ti->flags & TRACEFS_EVENT_INODE) + eventfs_set_ef_status_free(dentry); + iput(inode); +} + +static const struct dentry_operations tracefs_dentry_operations = { + .d_iput = tracefs_dentry_iput, +}; + static int trace_fill_super(struct super_block *sb, void *data, int silent) { static const struct tree_descr trace_files[] = {{""}}; @@ -396,6 +413,7 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent) goto fail; sb->s_op = &tracefs_super_operations; + sb->s_d_op = &tracefs_dentry_operations; tracefs_apply_options(sb, false); diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 0e373222a..696843d46 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -635,6 +635,7 @@ struct trace_event_file { struct list_head list; struct trace_event_call *event_call; struct event_filter __rcu *filter; + struct eventfs_file *ef; struct dentry *dir; struct trace_array *tr; struct trace_subsystem_dir *system; diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 3726725c8..ee9002852 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1308,7 +1308,7 @@ struct trace_subsystem_dir { struct list_head list; struct event_subsystem *subsystem; struct trace_array *tr; - struct dentry *entry; + struct eventfs_file *ef; int ref_count; int nr_events; }; diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 654ffa404..01bd3dda6 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -988,7 +988,8 @@ static void remove_subsystem(struct trace_subsystem_dir *dir) return; if (!--dir->nr_events) { - tracefs_remove(dir->entry); + if (dir->ef) + eventfs_remove(dir->ef); list_del(&dir->list); __put_system_dir(dir); } @@ -1009,7 +1010,8 @@ static void remove_event_file_dir(struct trace_event_file *file) tracefs_remove(dir); } - + if (file->ef) + eventfs_remove(file->ef); list_del(&file->list); remove_subsystem(file->system); free_event_filter(file->filter); @@ -2295,13 +2297,13 @@ create_new_subsystem(const char *name) return NULL; } -static struct dentry * +static struct eventfs_file * event_subsystem_dir(struct trace_array *tr, const char *name, struct trace_event_file *file, struct dentry *parent) { struct event_subsystem *system, *iter; struct trace_subsystem_dir *dir; - struct dentry *entry; + int res; /* First see if we did not already create this dir */ list_for_each_entry(dir, &tr->systems, list) { @@ -2309,7 +2311,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name, if (strcmp(system->name, name) == 0) { dir->nr_events++; file->system = dir; - return dir->entry; + return dir->ef; } } @@ -2333,8 +2335,8 @@ event_subsystem_dir(struct trace_array *tr, const char *name, } else __get_system(system); - dir->entry = tracefs_create_dir(name, parent); - if (!dir->entry) { + dir->ef = eventfs_add_subsystem_dir(name, parent, &tr->eventfs_rwsem); + if (IS_ERR(dir->ef)) { pr_warn("Failed to create system directory %s\n", name); __put_system(system); goto out_free; @@ -2349,22 +2351,22 @@ event_subsystem_dir(struct trace_array *tr, const char *name, /* the ftrace system is special, do not create enable or filter files */ if (strcmp(name, "ftrace") != 0) { - entry = tracefs_create_file("filter", TRACE_MODE_WRITE, - dir->entry, dir, + res = eventfs_add_file("filter", TRACE_MODE_WRITE, + dir->ef, dir, &ftrace_subsystem_filter_fops); - if (!entry) { + if (res) { kfree(system->filter); system->filter = NULL; pr_warn("Could not create tracefs '%s/filter' entry\n", name); } - trace_create_file("enable", TRACE_MODE_WRITE, dir->entry, dir, + eventfs_add_file("enable", TRACE_MODE_WRITE, dir->ef, dir, &ftrace_system_enable_fops); } list_add(&dir->list, &tr->systems); - return dir->entry; + return dir->ef; out_free: kfree(dir); @@ -2418,6 +2420,7 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) { struct trace_event_call *call = file->event_call; struct trace_array *tr = file->tr; + struct eventfs_file *ef_subsystem = NULL; struct dentry *d_events; const char *name; int ret; @@ -2427,26 +2430,26 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) * then the system would be called "TRACE_SYSTEM". */ if (strcmp(call->class->system, TRACE_SYSTEM) != 0) { - d_events = event_subsystem_dir(tr, call->class->system, file, parent); - if (!d_events) + ef_subsystem = event_subsystem_dir(tr, call->class->system, file, parent); + if (!ef_subsystem) return -ENOMEM; } else d_events = parent; name = trace_event_name(call); - file->dir = tracefs_create_dir(name, d_events); - if (!file->dir) { + file->ef = eventfs_add_dir(name, ef_subsystem, &tr->eventfs_rwsem); + if (IS_ERR(file->ef)) { pr_warn("Could not create tracefs '%s' directory\n", name); return -1; } if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) - trace_create_file("enable", TRACE_MODE_WRITE, file->dir, file, + eventfs_add_file("enable", TRACE_MODE_WRITE, file->ef, file, &ftrace_enable_fops); #ifdef CONFIG_PERF_EVENTS if (call->event.type && call->class->reg) - trace_create_file("id", TRACE_MODE_READ, file->dir, + eventfs_add_file("id", TRACE_MODE_READ, file->ef, (void *)(long)call->event.type, &ftrace_event_id_fops); #endif @@ -2462,27 +2465,27 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) * triggers or filters. */ if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) { - trace_create_file("filter", TRACE_MODE_WRITE, file->dir, + eventfs_add_file("filter", TRACE_MODE_WRITE, file->ef, file, &ftrace_event_filter_fops); - trace_create_file("trigger", TRACE_MODE_WRITE, file->dir, + eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef, file, &event_trigger_fops); } #ifdef CONFIG_HIST_TRIGGERS - trace_create_file("hist", TRACE_MODE_READ, file->dir, file, + eventfs_add_file("hist", TRACE_MODE_READ, file->ef, file, &event_hist_fops); #endif #ifdef CONFIG_HIST_TRIGGERS_DEBUG - trace_create_file("hist_debug", TRACE_MODE_READ, file->dir, file, + eventfs_add_file("hist_debug", TRACE_MODE_READ, file->ef, file, &event_hist_debug_fops); #endif - trace_create_file("format", TRACE_MODE_READ, file->dir, call, + eventfs_add_file("format", TRACE_MODE_READ, file->ef, call, &ftrace_event_format_fops); #ifdef CONFIG_TRACE_EVENT_INJECT if (call->event.type && call->class->reg) - trace_create_file("inject", 0200, file->dir, file, + eventfs_add_file("inject", 0200, file->ef, file, &event_inject_fops); #endif @@ -3635,21 +3638,22 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) { struct dentry *d_events; struct dentry *entry; + int error = 0; entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent, tr, &ftrace_set_event_fops); if (!entry) return -ENOMEM; - d_events = tracefs_create_dir("events", parent); - if (!d_events) { + d_events = eventfs_create_events_dir("events", parent, &tr->eventfs_rwsem); + if (IS_ERR(d_events)) { pr_warn("Could not create tracefs 'events' directory\n"); return -ENOMEM; } - entry = trace_create_file("enable", TRACE_MODE_WRITE, d_events, + error = eventfs_add_top_file("enable", TRACE_MODE_WRITE, d_events, tr, &ftrace_tr_enable_fops); - if (!entry) + if (error) return -ENOMEM; /* There are not as crucial, just warn if they are not created */ @@ -3662,11 +3666,11 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) &ftrace_set_event_notrace_pid_fops); /* ring buffer internal formats */ - trace_create_file("header_page", TRACE_MODE_READ, d_events, + eventfs_add_top_file("header_page", TRACE_MODE_READ, d_events, ring_buffer_print_page_header, &ftrace_show_header_fops); - trace_create_file("header_event", TRACE_MODE_READ, d_events, + eventfs_add_top_file("header_event", TRACE_MODE_READ, d_events, ring_buffer_print_entry_header, &ftrace_show_header_fops); @@ -3754,7 +3758,7 @@ int event_trace_del_tracer(struct trace_array *tr) down_write(&trace_event_sem); __trace_remove_event_dirs(tr); - tracefs_remove(tr->event_dir); + eventfs_remove_events_dir(tr->event_dir); up_write(&trace_event_sem); tr->event_dir = NULL; From patchwork Tue May 2 11:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13228807 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 2DE9FC77B7E for ; Tue, 2 May 2023 11:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbjEBLZf (ORCPT ); Tue, 2 May 2023 07:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233120AbjEBLZe (ORCPT ); Tue, 2 May 2023 07:25:34 -0400 Received: from BL0PR02CU006.outbound.protection.outlook.com (mail-eastusazon11013004.outbound.protection.outlook.com [52.101.54.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216475B86; Tue, 2 May 2023 04:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c32n8RWlgLBOctTwXSzDnWh0V8HcfETJlgMUoslQjiMcS+1fLBiE18z73dF4T3YPhIcXoeJkaN7YDlZgetxjCiupFb3jxwkF3fy1QllkH5FcBZujirq2wmvn55Z1MnVNA5+KE/6RxUSXnjM7sZDRnV9O7P2SnmmiFsGSCCZUDzajBuebNpxUyl912L6qgRkNvGapDEsA+h/gVfoI1Rhf13ilV+heBYplSPYQMK4TyZJ5fxcDGdXRZ3CV+K2dtEyopzco/0nyP88KoOEFeVKLMEgl1IIpyA3lDHZOFb7Nc4VfSiOOKVY4UreW48VsdJNj8bxA6+AQ0mVcwyAbneeM6Q== 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=T6LeVy+ZuzuUY3j8ve9mKvLGhEC8Cn/MDZMbvsf0rDQ=; b=ciqe70q92mSCPv5GPxuO2S/81hNRpO4mh20+4/3u2rbiGakjA4/t/rh2EBScqT9WvkNQvnfS75xVejtglyz90EElAFl0nQlc/KKAIrPidPA81OsAEC36PJOxzotGz0Hy44Wc/vaPWpiMM9n8YhpQD0QpQOqNBFKXOL2Tjir0W0zWcal1ZqF6Xc5Xef1NsFeWlBEejNwK05hDezxcOUmCwbgbqwDG4pbF3SY29oMhVO/b3EnxbClZ+bljE8LHNyvBdB0UVOI5gPRYngpFXThnRxAfGXDePhZcmE1QSI2xUqak493U+dTrdK/ZeDJa7yGH5hkb12/tSpT0G3yAxg0aQQ== 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=T6LeVy+ZuzuUY3j8ve9mKvLGhEC8Cn/MDZMbvsf0rDQ=; b=JMfQtMApgxU93CHDJxrXet69/vZ9rme8v8pzTZLbCrgB+BCPGRH/0e108rOQaCpU0VTtCgAE4aQuotrMnbeDM1c5AHIn5M9jxt9dHwCtY0iOgkCGOd2AmnJ+tY1PDent8ZAhl0A/skMGa3YB65YicC5M4S4yu/3Y0uX2Pjm3am0= 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 BYAPR05MB6648.namprd05.prod.outlook.com (2603:10b6:a03:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 11:24:24 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::5631:475a:58d4:cf66%7]) with mapi id 15.20.6363.020; Tue, 2 May 2023 11:24:24 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, chinglinyu@google.com, namit@vmware.com, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, vsirnapalli@vmware.com, tkundu@vmware.com, er.ajay.kaher@gmail.com, Ajay Kaher Subject: [PATCH v2 9/9] test: ftrace: fix kprobe test for eventfs Date: Tue, 2 May 2023 16:53:20 +0530 Message-Id: <1683026600-13485-10-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1683026600-13485-1-git-send-email-akaher@vmware.com> References: <1683026600-13485-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|BYAPR05MB6648:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a6746aa-54c0-49be-ce83-08db4affc895 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: Cs3+N0liCpU2sEOzRHftbriHjm54AQuyTkdkfg3+quMu5JuJlMh4NvHim5fuHnwHTgY67MILUmI9QilD6KICq3WT+sy2ICQ89B39Nlm5QQP3hUnPwgk8T6VpYS1IX+CtXaiHjD+1NpaTt+rHDzpqNXtbFtFSS+/ZK8A3hhuIEsI5F6MCCw3MkFpfNZmXtfDc5g0ZOrYymrxl+VhCGegzCtZa35NRqzeQgH7tQPHxe6UUMABHMk1knQ24TUa8hFBZ3nYF3mZWdS5E4F7Rq6dxeWPzq4oZrovetGGS64j3myPsV6kSl2Y77VCpQ0nlpiMpC8ew0mBFzGS8664HBm3/N8QRtCym5/ed7rkQ/wproblUK+dYjCt/HKy2cYQYd2g+rHiCoedP9VH5WnM7Hukq6EvWj7kIrdRnT8JgOxXYme93FOQMLpFfkfGDdveSPYT10RFqDAYxFRHJZhiR2Qr55T70R/3omrrY+wTnNNk1L5bNZRwlqqycFrGO3ppgcT42oefjHEqb3S6j2/tyycjdoX/wfMMdfOKLMgS5UKZ+G8wRe/Gcfgbwfh/i2hNl7e5HApQVIIS1ZCrak5Xq9U8qQDzu6xMDgg28XbBvn61NoflhH0x5KIDjuy22rdCKTGrH 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(451199021)(6486002)(6666004)(52116002)(107886003)(38100700002)(38350700002)(2906002)(86362001)(41300700001)(66946007)(66556008)(66476007)(4326008)(478600001)(316002)(5660300002)(8676002)(8936002)(36756003)(6506007)(26005)(6512007)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zek7Zunu5LU0cuDL8o33LlUYlFD4pGQoqdQDDzl9gzcRXKP3f7fF62h2hebhV6r3U+U5JwgODmx6X9nqpZr4JOs4xQLwt7rMXnGk/wZa8lkC2en4pN41FFOE9QWNPVCbKGg4ySkTKev0hDhkeRG/+dcc9xedY/lQWA+djTtozRuCAUvzRqos0O32l/BHZkt9gbL/FqpHUJqa8bBUoBePOMR0ui53h69B0CNzrUUFNeh2tn7R6GoZCb4GF0ZNIXrp/V3OQq9VpT43qLCDHqn+W4AbtmpS6D2gf74lLIb6xQsy4IgrlVqhHAKZnouYHVKd/kpnSYzdObV0dS9Pl0ChPogFRuNvR//TJ7pjsveBR8QvngZ+akCbanltCp5mzVpLUpgNEhy3uGuw5wd6Sn5gdgbd9H1ccdp/9FOnilnW2V4n8IVfS2j7oBavISV5CL8gwNrr/bVnA6BXSo8BqDwvRBWUf8qcCWy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9YOVLxBUX+6NRwBoT9fyE61jt5r2u X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a6746aa-54c0-49be-ce83-08db4affc895 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 11:24:24.7009 (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: ggrkawaY3Kn3bYMabsXP4Up592d5MzrPNpyRTebkUbhu64W9dP8MEn4bFAZDxGwcriIEoDlgv3CdyZfJbRKzOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB6648 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org kprobe_args_char.tc, kprobe_args_string.tc has validation check for tracefs_create_dir, for eventfs it should be eventfs_create_dir. Signed-off-by: Ajay Kaher Co-developed-by: Steven Rostedt (VMware) Signed-off-by: Steven Rostedt (VMware) Tested-by: Ching-lin Yu --- .../selftests/ftrace/test.d/kprobe/kprobe_args_char.tc | 4 ++-- .../selftests/ftrace/test.d/kprobe/kprobe_args_string.tc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_char.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_char.tc index 285b4770e..523cfb645 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_char.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_char.tc @@ -34,14 +34,14 @@ mips*) esac : "Test get argument (1)" -echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):char" > kprobe_events +echo "p:testprobe eventfs_add_dir arg1=+0(${ARG1}):char" > kprobe_events echo 1 > events/kprobes/testprobe/enable echo "p:test $FUNCTION_FORK" >> kprobe_events grep -qe "testprobe.* arg1='t'" trace echo 0 > events/kprobes/testprobe/enable : "Test get argument (2)" -echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):char arg2=+0(${ARG1}):char[4]" > kprobe_events +echo "p:testprobe eventfs_add_dir arg1=+0(${ARG1}):char arg2=+0(${ARG1}):char[4]" > kprobe_events echo 1 > events/kprobes/testprobe/enable echo "p:test $FUNCTION_FORK" >> kprobe_events grep -qe "testprobe.* arg1='t' arg2={'t','e','s','t'}" trace diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc index a4f8e7c53..b9f8c3f8b 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc @@ -37,14 +37,14 @@ loongarch*) esac : "Test get argument (1)" -echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events +echo "p:testprobe eventfs_add_dir arg1=+0(${ARG1}):string" > kprobe_events echo 1 > events/kprobes/testprobe/enable echo "p:test $FUNCTION_FORK" >> kprobe_events grep -qe "testprobe.* arg1=\"test\"" trace echo 0 > events/kprobes/testprobe/enable : "Test get argument (2)" -echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events +echo "p:testprobe eventfs_add_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events echo 1 > events/kprobes/testprobe/enable echo "p:test $FUNCTION_FORK" >> kprobe_events grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace