From patchwork Sun Jan 22 17:07:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111531 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 13BB9C38142 for ; Sun, 22 Jan 2023 17:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbjAVRHg (ORCPT ); Sun, 22 Jan 2023 12:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbjAVRHf (ORCPT ); Sun, 22 Jan 2023 12:07:35 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67C4F21948; Sun, 22 Jan 2023 09:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SMlM5ZrLeI3JU68X3ESZYGy2+UMF8XKdydYvGWGkIvM0pIwO9BgMlsnjvmb39/qVjdUxml1EnQu66d2gIYJ6y7VkyX2O5NZF4CJaCu4u79AM1x18hkiaIjd4TVcwaKIp9OyAo+FtYASMYfjgAk/XIQ/9eSIzh2I+7iwCBkMXDvYr/Tqm2uKS/6KZ0QmuM//LtdDk99shbr6eDKXe6srAmKfV/SpE1T92Cf+CcMUBiGGGFCGArGhbHCHtDGzj2cUwc0WaMe0IXzl51OUBcE4nFVKtpo5pAcb0x71sxR9dnh+YaL669wK2xMgrwWalZuW3fnfoELEk9oPII5gN57cUuw== 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=Nsgy9MSvqSmYf0Yl6yn9+RruwGgucaqbm0UKDXWEAos=; b=DyvtF0vaqRqIGLYg/PkZdQ/yQiJDJQQg1dixjPp6Zyl/Oe5yueNDVAs6L3fKUFrqlOptnEiSxin3msK4PhnyH4gb6vM4JyjgrCXhPoyiLS73/T++BrCIzE3c66mSOr8fDuR7ECnNWn9ATEq4YBD/gOFZOuIx3v+GlMwVuyyQWfztNIg1/ZojySJcRy2zbxm+Wg7A+226vpYwZlJJazD87TjZu1m8nNr/0DIQH7gVQdcVOrMv3anAyHH7mAtot0RD3T0CVLKn4CojVYPOH2n7uNhL2pBIODC+AQNoBr45TOlh/KVUUoXsOc3XcC58DA7eZxkh23h+X0RINzMp5VWIYw== 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=Nsgy9MSvqSmYf0Yl6yn9+RruwGgucaqbm0UKDXWEAos=; b=PA5UDriVn8EMBePaWeuGVhloRzUPBB6yKnT/qToedW7nb1tBieI3kRnu3MLOhvDpbqkdn2fsU4oBfI57KtuO4qFnYeiVBsBHwIhJwuFuZVt+04kRuF5GEWeie112p8Sn3zMIJ2r4XCr2VZFmtPP0S82bzPNn7w3A/2PnEpi/eak= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:30 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:29 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 1/8] eventfs: introducing struct tracefs_inode Date: Sun, 22 Jan 2023 22:37:00 +0530 Message-Id: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f133675-de79-4b42-7d08-08dafc9b24bb 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: STg34hM8EOLTC20C+wUrIZv6NYCaKwT9Bv67CeMEtxwf2FzflHetm5KRuCjmjBjqJJWWR9mXR5aA99xAySTRexizmgFYAaUdqxig1h0oTGwuRKw4dk+sF6LV+UtPAKu3D/m63GTerVGtCJFvN1KgY85EQbq9HtkhtyfErK1wvxiWuoATqgv3wOgkJeiYR9IBvvDXsztjNipihLPuxafiSzsFQhjssbS1hyQjY8nz5itoPjwtBHa+siWaTh46WhEH6xOvhWZYEjsA3TEL2g+9hKPJ2eEQkKtF7rYYOwwyc4gzYidkddZ0y5vxgIqwAhu4KgWIN5BmxK2u5uZBiow7y0rIRko05lgk7CTNZR3Su1jMDIi97o54vX7n/70lUTCFM4K+ApjkfIRKIhDiKPkLK+ya33rSh/r9SFHyEmcqhzppxPBpkb7FpTntNErB23MTAhyskqOJO66KjMLKNvNABE06vcxi5EKXU0puvsSNKBuglRrIQXNRX5wMrp+ri1E6Ybp/UzuTggdBFMt4P93IrmtXB/zdjT6u+0S2nEFZ4OjwGkiXimxBR4s/6sNbX8gfEAqJffr95UukK+iNezRHrSnQXa3dEN+a5X9nMFE0LDNdXY7DXU+czctN2dLjCraaEzmajd2SuI0/R4Qk/5MJnviOC0nIErvjdwfnaxoZummkPnDRUpOPUfc35i3yw/6Oz8nOK4D2NRIguFJsIE3j9A== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nSOmtP2Oak5uvklnn2QIgABqxncSYziUtuLFsKTW7lbPWjDR/Qh4VURlq77CiJppAy0T4kWFIlhNOGFvYXh1Ajq/qnXaMug2opFrrcYPQU3trxFSw3DAylNDic2jv/XvstRp708wZDbtoRIiuu8V3sTMG2ySKWjbvlNQOCz0c/oJqFNviGs+bmYDBWwkLWxPImKR+AiLfw9wGGI4Zva6AeBECDBzL8n4/m8ZeG0KNEozZdw9OlB3Nvy9vCkKcZQPufOedun9Rq5TBJxKdwKARNe2GaVHJAU7Ykg9IAqkz1ScXXMdd2DVOlfWjRWG7pYLqJZP9+6zwruaC7nHhEYGeYOrvMcUjGBqBhFBBiJLA0LhDwX2T1+cslegec5qW4twelLchxAoUbwpCtZUTIS0pLoGa71kA9EBrQY4HBNojJ0C1grtoxv5Brs0OSGeoQA6zGUTbgWqFV0JsDaxdAGtTDGmbBg0nelqvGpdeI56d1PLH2aYpk1VI1G9cWsZJT3Iqm81MAksAftxWVZmz3kHQfPd401XwlTCWb46LBJMkBVpdGPNnrm0IDN+dorSXTKjZI3jQee1nsPQCXhBYNBZwBD0K8T169am1Wt89zHW0++OhHRm8y/8g6/Zy3qsNmg7N/WucfDh5c7CCikwJosdNin6a28Yh6uSPqvPeWHreCLdovXT3ZUs0zPtlnJs4ZXhaWlUAC6BoJghWVuSHeamrztNDzbAXFASQo3dGwIJyL9JYl7s0JMblsdm594sf6HYHew9ZtMjrLavMNPn/ggjmyebFYaWGALaz7vezD2oiuMi+tQdBj7CVwh1t5WfvGq4lEPHXeEbCa9XYTuncnO/IX4Z4CV9zKhApMV/W7D2d++KF7RgmYgMB5XGLuO0/5FNjuZqinjcqnfqXJrDyDjZjCFHRRLJ08yJCdW5z4Oags1Su4st9yjnS4bZqRWN9yv8kXuAn346KTCFQqna8knhIB8UJfRsa0PfUzAveHbZs661ERcmkWwZZy1ghxqrtEQgNDPpPfgBuNmK1ERMsNZIJEOOgKCYG3VzgP9lF6uMJfQmrjC4tr9OinmgNiTogwYTLeNg+98aJIn0Kt/SCTFyqcMwoW7i3YN/7GYWv2CEkdUQb4TO083Pnpazv2weZ7r3ObLZIi4K9d+WuKol7RGV0l009rJpLAlzyXXYKEcdeSNfkm6iDmN2iZFB4KWhQ8HjuMo41gDnEcAqgrCLDBzegaP5ZyBEK6I9SZEWDrlud3sw3byoRScNJzLd4gMMi07gGrPCsy2ypszHaVAgwMBqD0VP0QTpT94/KcnFL3MfO/qiOkbLVkPx+IkJC42v++vej77tdaE+RA7Npo4mnE/r8HTNlPdcvSaWuAyWGqAg1q1GWSLJzTvDRDYDUdjQ/DCoDFOBhxd0MAtQ7VFVVy01w6f8tVxrp19mqgBfomjHtv5zX2AnjBEx9YW2AWir4hhvK0UtHKhS9bZSvTCouk0hScq4nSr7YYxFh3sXpqvnOde/kKca2+LMbjwKh9cS0p7S3lMJ7ugW78sJyTrFqKrmf4whz55CO0FQc/Blpk6M7vHk2G86cviXTa9iHpOCe2Z/ X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f133675-de79-4b42-7d08-08dafc9b24bb X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:29.4774 (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: zmGo+efjmdmrSmjnQ8iM4SbKRa750WIIbRKkCako6Yny0J7JXr0+kTgYTuCpIL25jgPOSlHlPoI+HFG6NhbD9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 20 ++++++++++---------- fs/tracefs/internal.h | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 fs/tracefs/internal.h diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index da85b39..015b7b8 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -127,7 +127,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 +399,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 +437,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 +445,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 +490,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 +506,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 +520,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 +534,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 0000000..27869ea --- /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 + From patchwork Sun Jan 22 17:07:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111532 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 31233C38142 for ; Sun, 22 Jan 2023 17:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbjAVRHo (ORCPT ); Sun, 22 Jan 2023 12:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbjAVRHj (ORCPT ); Sun, 22 Jan 2023 12:07:39 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0951B55A; Sun, 22 Jan 2023 09:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JDtSLlXXvQVfEV1gK6rToHprAtJN7ZvWiPAQrLj9UBGBp2ret2P/AaX1W8/HUZ/9wnwskwGEn/V0v1eV6v8Qimn9bU0nv5tTPYsaZ0HD41SSyxLIoBGgBWpAyCMVIYtWPPBjoDGiESCCpWJiIUz4NYNoVHN1GJvndhwNdySqJbtaRk69rb+LmoXSca3dFcqX5KFoQ+G8Vomixsvl7/oQA1nlgRQEkyFCnUp0cowgrwzW07nwZApO9gQb0lBGRR+pAoFBXRNywxEKCIU4flIu81DpqmK0EJCxuing81xgo+5n4bLCUOnSk9RWQOa2/Cb1JX3YB62oobwBcKOePVSbvA== 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=cFoLdhfObTl7nJsHCOSs0v1zTfDsS6wMCzu59YkD/YM=; b=nnJz1ZfOuIUxGjyO3os6G7K28BmZNq00YN5YOcsNDaA46d3jcyxSCcmPnex5AbRpeDfEek5pSfHFNzMLSk6/C9Q4WFiib2KHqsDfqjfmYrCFQkyrgsNHhviIZNT/Xx4dLUk4g42Qo1ZRn1BEexcuAWsWZeMZCBEIYERXuTCDtXcPgiiwlHFuf2wfo0n+d4nTCvfiDpb1TaVEHQsZSDL0nLv2CwMNsbFGiSPHpm8ohVxwOdjlThgw+JZKj7XYfhop4B1TfAVFu0atygrx+DmaevMyj8wum1jEv1EOKywhn+i039A9Tivk80ZmC2N/DEOfimPTaKdXtK3tnxp3HzDSyw== 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=cFoLdhfObTl7nJsHCOSs0v1zTfDsS6wMCzu59YkD/YM=; b=zjG0hcm2xAtAgU2auGxbqTslWI3BZPEQvAR1iXNXWIMKJu0oR2aqrDw9HKJO8VaE7MWw6AQ62HSZaVjXm5S0KdQGaPcNUoiW9ck15qKNizbuCBF6mdwpG362xAAjSknQpbbGHuquj+F7a5hSL0ohHWnpB6Gx0oeHBowfDE8xAU4= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:31 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:31 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 2/8] eventfs: adding eventfs dir add functions Date: Sun, 22 Jan 2023 22:37:01 +0530 Message-Id: <1674407228-49109-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e67f590-2446-4e87-ab95-08dafc9b25ea 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: kMluHMUCWxRjHyvDwfmmM9hBiqPQFLRNobqY2XRLYCeFMogtuoJ+op465QXe6v2FIYD93OO5+eZmWy+65zxcwFKI1sKC9WRUHDkmyu3sVcSnKTfpWrUMdeKYVTo0OhkNZd7kpLGRjCuNRKZyskGxTJdtDLV5/Vp4qsBSTjhYfbegNroqcbtBVToAdtLzpKdqri9XQu3t9X1D2Q5QaxoD1N56WJ8+MgZqdz5bpBYmQWqFKo3ixmvvt2AlabJqou8/rSXu7cPPjHfzs03+24J2+k5aMdopOW0utlJ3B6u+6j0ka6uP6HlPnxlB6o8HAjLEjBS8j0FEziADmbxDiJyV/4YbrTIbrDiXKZTH0tWcW1RP8qU58s3UbGbWtz/qmQgLbSJKplpfccvM0q7bcYKABCli+LRFNC+yJuXHkoMLCMCwdTUhcr9ShHqInCTU39QSppOioxoX2A1EzrR1h1bjFrh+5W0u1Jj/uJtPYameWFiBbRw9M474bUvO0kUfo8VYfB6GuuWlT1g0BPjnNTsCZc3kuNiqgMyigSv4g/TuaiBJ3YygGGbocamGsbTCvjkw5oLfBVFc8rRYAKK5GJhtUAe6zRS4jDWwKV6+gQveGInAuVmu8v2EIqA3LE28gCQoaSNC/pT+px4XnhHSSDtfMqqflJmqeMlSi/JKnjDyeRTKSGbUcPqlt/rsFhMaX6oI22kbXZY8BWr9zEVGRLmOCw== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Od/1J922DSN3niyWy1ml8aSBtvwa51HBUu8ip8EQ8Npvyo5uDiFveulohfJ6EJEDYjTC8tRHKgDRuCtFyMBjUYBqFeITjRsoANpeXTXzb96ReyZrRRg4X5V7FDv83Zf277V4K+Mceu2uEy+0L+rbZFBdHb4d4odyshtF+mfqlF0AzBfVr2bw2uPX7jf2NbIJ3FBZMYw00us4q4KR/ySbvqpcSqocyLMeDv10ts/nddiTmTzj7KopMBkYLHK1WsX+zOakNvIRom8T4X/64ewzoPmC3p73ctEF71hvzUgSVnd+WQ3pQtW1OBic+pxHTKcvRBMZhtUA88rSsR5zeP+xZN7g2HJBo2UYlgvyxB9/iDZKOXpkmsGjGSmnOuuW/60xko4rNQpmsg8JCh98fvesaVGpNEc/i/jJYhy+ifI/IU7YTTicotwrBt2nzkb/ckI9JusqNN0ji6j9Rtn7rjAq751XSlaW4mgER4O03gjehEXqfBxlFVfXTExHZa7rRK48dZw7YgR4QVx53Rg/zfgLMhCK9quzT5/Xf8gdkDXVur+nVewYk90x34E0Yns1q+gBnzBioEzOS7tdG/CQdYFpsDniOtjv6sZXj3w4j/ry4gsWKE75WOmiMbhBrmmBZd8NC6btcLItdZJA3rs7yinCBbBRGlngDOXm9hC2CBYJlR1cNcfRfJdQ36E98BjLMNet7qxghXdOsEfwQyCg0bkBe5K/XXmroOqsrYw+f7UHZbHcp7l42r/eAmg/dcAEMUAxR7gvi0Gm2wnVxLnvHJazNn5PnAYvEjiXMDj8vwcW4XqD+AXbNzNaQs8R0vsf3CkIhMSmKY9K/MQB2MIa9lY1k3vL6g+cYn/bqBtTtKdOI3JRWLVLvJekUwFf3LPcXpD58FF5zsPww/W7vHSRuxoLk19H5tLUlwdS9HJcev40X+4136Zg8OChAiXKbk2wYHI4vSe8C0X/QzryEImsh4JgK9HLRskmPneUclwUA+3lsfU0xUSLQc5JHpm6Hk8pxDRsU3dyQq3lwuyfsqecJgp9WOrY9S8cjHFfdrpRvEzXiDYiDM81QNbkHL9wcDjemNaM46Gel/gd138P1Fzn0mO9F8D0fVxGPfUioC1y0bmpk3KZ/VEAfs3yVY56mj4lsrzpDEXrfxmlcFj55xbGGz5hCUCVaFTWLIpwgNLuDB5J6czmmW+3D+ffkTY/RU3HsyjxaWWk63Kz0i1bxh9wWJoY26T288FuxHLJILSzDhnuo6Z8Gp+A6Yeqycpeghav58+CgaopDiGVhxmDoXFqKFSx9I+Cu54iZgN8YWoPPQwpahbvhO5++LjigBwoNKTImPC1t3eNPexbQLyfRbLT/+ERxEws+SdzsUAqMUk/7hLP1Pa8vn4ScHsWJ99G8B9aVhB+kcstfnWLrGaJWHZW080ba1XNGAjvaMVY2qUMS3dsSzMQnsMad/A7HItmrfvnGgM74yby3X9kCmbeNaQmU93ObihzwzFZBQx5NMiWqQvWaDyxq7ONsHcV0+KeDXi9uqnnCbehso6OCgBGqsY7pVGj/ptZvx86b9iBz4vhDHdasY3pkW55NVcl/TxH7ihf9OYS X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e67f590-2446-4e87-ab95-08dafc9b25ea X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:31.4800 (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: NK9jDm2Flcbe4qGwZtgbi3L385Js0paeVanhpp8js7WCYAwHuE1H1ySH1VU0cskd0tkoplwdQIlDbVT1E7S3bA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 173 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 26 +++++++ 3 files changed, 200 insertions(+) create mode 100644 fs/tracefs/event_inode.c diff --git a/fs/tracefs/Makefile b/fs/tracefs/Makefile index 7c35a28..73c56da 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 0000000..ef3b435 --- /dev/null +++ b/fs/tracefs/event_inode.c @@ -0,0 +1,173 @@ +// 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 "internal.h" + +static const struct file_operations eventfs_file_operations = { +}; + +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. + * + * This function creates the top of the trace event directory. + */ +struct dentry *eventfs_create_events_dir(const char *name, struct dentry *parent) +{ + struct dentry *dentry = tracefs_start_creating(name, parent); + struct eventfs_inode *ei; + struct tracefs_inode *ti; + struct inode *inode; + + if (IS_ERR(dentry)) + return dentry; + + ei = kzalloc(sizeof(*ei), GFP_KERNEL); + if (!ei) + return ERR_PTR(-ENOMEM); + inode = tracefs_get_inode(dentry->d_sb); + if (unlikely(!inode)) { + kfree(ei); + tracefs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); + } + + INIT_LIST_HEAD(&ei->e_top_files); + + ti = get_tracefs(inode); + ti->flags |= TRACEFS_EVENT_INODE; + ti->private = ei; + + inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + inode->i_op = &eventfs_root_dir_inode_operations; + inode->i_fop = &eventfs_file_operations; + + /* directory inodes start off with i_nlink == 2 (for "." entry) */ + inc_nlink(inode); + d_instantiate(dentry, inode); + inc_nlink(dentry->d_parent->d_inode); + fsnotify_mkdir(dentry->d_parent->d_inode, dentry); + return tracefs_end_creating(dentry); +} + +/** + * eventfs_add_subsystem_dir - add eventfs subsystem_dir to list to create later + * @name: a pointer to a string containing the name of the file to create. + * @parent: a pointer to the parent dentry for this dir. + * + * This function adds eventfs subsystem dir to list. + * And all these dirs are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct dentry *parent) +{ + struct eventfs_file *ef; + struct tracefs_inode *ti_parent; + struct eventfs_inode *ei_parent; + + 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); + kfree(ef->ei); + 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; + + list_add_tail(&ef->list, &ei_parent->e_top_files); + 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. + * @eventfs_file: a pointer to the parent eventfs_file for this dir. + * + * This function adds eventfs dir to list. + * And all these dirs are created on the fly when they are looked up, + * and the dentry and inodes will be removed when they are done. + */ +struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_parent) +{ + struct eventfs_file *ef; + + if (!ef_parent) + return ERR_PTR(-EINVAL); + + ef = 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; + + list_add_tail(&ef->list, &ef_parent->ei->e_top_files); + return ef; +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 9991244..6983409 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -21,6 +21,32 @@ 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 eventfs_file *eventfs_add_subsystem_dir(const char *name, + struct dentry *parent); + +struct eventfs_file *eventfs_add_dir(const char *name, + struct eventfs_file *ef_parent); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); From patchwork Sun Jan 22 17:07:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111533 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 36C48C25B4E for ; Sun, 22 Jan 2023 17:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjAVRHp (ORCPT ); Sun, 22 Jan 2023 12:07:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbjAVRHn (ORCPT ); Sun, 22 Jan 2023 12:07:43 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4D96184; Sun, 22 Jan 2023 09:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f8tDABeXQjGsPQPsfC080rzha4U39IycX51Ke5tf8zzjWV6N8eBYPK0hVRsI7qdiiYBltaSGmahO8Xr+zg1Lsv7TtV49vQMYmzPZev9uGry8wYeYz1+xZe9MFtxjHFDNa0/O5L+vIfTlnoWX90ltB9kapN9aAEhxdbkHay7Xhtrc0YHvKxTQ37zTc/h/BZh2BM4uks2GJwPeMi63UIvPMtzvUMtBm/nWaJW8faO9Ym+LkAE4Njoo0ha3y/wsTuXiv163OAKjEGWK0fD7g3tv6c+e9Y8sFbhThVbXumwQt2V9d7Z07ZBuxiNPEiFnfG2mKR0qaTuJaIk/JNEkTHAw+A== 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=604SRayyklRpjImVlk5PCVvyMeRL/ZrQj0Vsxb+9jwU=; b=GNXMMnLwroyNQX4O95uPSMHmb7OWyRwe7sGji5v5O8hLl9iAhhF0C73Tru+gBVfGUzPsONDDItLThxoD1faUA0poY9BBoNJ+ebm2vyES721hQNLYqu1RWAlOV1sWHooKXIHPynCCdwaDGKiyQdRRnOJDAzB/vRQn+6oMhPLCu769CCTSVpXycbSv1Oj1QXXaNsfGviLUr01RFwr3EdPlYIZYcx7NsKQm9v3sLvY9xlSXvmmWyY46C0LrsRQsFZUApTBpkKPa+cg2i+hU8iYiyzwQAvL+nr2yYpbhfYIfNitnrFm6hIuOVVXOx73GBnBCDBykBrvgcVtOwNJSi/5D3A== 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=604SRayyklRpjImVlk5PCVvyMeRL/ZrQj0Vsxb+9jwU=; b=rYcaPJBad9XjXh1iLoSS5okCWDUOAPqqATHpXdZrLfyT6Rbym1CktJBPKVUuJgBFQUINGF3x5OwXk9mONUOcz89AU4wkFnMI3Rc5tjc6Y20Ihh3TZbBQh9DZboIJWxL0RrBBepn9bvn/zuMOPwHtYrbdwndypyj2ouQcppJacBE= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:32 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:32 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 3/8] eventfs: adding eventfs file add functions Date: Sun, 22 Jan 2023 22:37:02 +0530 Message-Id: <1674407228-49109-3-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d2d3b81-beb6-4a58-d09a-08dafc9b2685 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: OvckA4iy0neXLBSk9HT9GHiWcbSFkmCeP7RKSWOL4wnyTo9dr1Skc2aRDwOY4nzSYGg0+OBW4dEumifbCbebbRm2rPoTk4Z2ExxywM1Wdy3DQe3lVNTYiysIuHI+Feu6Ah8Tw2C16pTxZYFU1edzJo2Zm1BhyCgYWYaFti9T97T9JGdow+kjoNiZ/11J1gygk91QEeZT4sfFva0pse4WS1Qzw6VgT+pgz7NbBVkeE513LJqsD8e4RvbMxHZXn0P99O68pQgis+w/FW1AxUZdibeAkvflkfPI9WAM4fDHSneYKIS44LvekzBHv1f6Jbmdurn3x6FJQArgYMQGZJxMcN/Vbc/nKKyb/L8Jn85mW/AcTV8IrSVKsWcoS2QeBQezCUCXzt4ltYiyvbdA+eID+IvjH3Wq0M6wDQRl2y08ecmDfUOziAJRj9BPPYl6sTHDlDo85RVHA3Cj5sUIkPFSMpvRbL95a4YySQlbbZnDDtgUrXhftSAvcsM7xITMUVd+prNXYvejG3KyolGjW4DDj0yi23qvT2N4w1t38z8Gh4l6WBrnVx/7qlknN5Cen0MH9VbexdPWy+oR5T0ppeQqzf121Rx7Ee2W/GlnkOYUNHKmlfhHdsrLO8FEEOYcY5apU7f4cmHl3l8J/fpm3wxbilqE290RzO/6HtYmL+ik6xScLKvX+QujIOEUtWGNsh2xfka9giLEgrvvPU7Mbt96MA== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OLIgZGWFZiDZw+1zC+tLj/tOzDy7kgbPqbTBrq2YUMnLoVOcDjwymhQOzCvV3KIkRaBeyAq2MP0qdRedP9d7wnP/XJ453DfBeVgT/VU4qVwsDT7KmZYNH3PQudxDmLDWgDAlvcnBhxpKbXmYuV2xhIvlXoIgCUceLDWTbVjAWCDq6Iri5q82ZnPpImEEG0nyD8P2dwx3oEKBGw3ML2JKkUeyBzlxTLeYfmD2fZraqBbb69UViNON4fcAJVJvBPzY1VGb7SKIsHsIVn8DpkEUj45T5vZsuOB76KOexMW+hDVH/0FXfOEVHmAf5kEmyosVoFvWVej7V31VBHmjafzslliyIIsd4Iyk35dP/qQB2DRYBWsPYD3oI+gM7IzbC3F5AnLrsy8MPImgvZVMvjQ777cifyT2TjEI4EZw5AqOveyX7fxCu2GvHWvdUyCPOT0l7V7JMVPwyZGRlLc0hIFGRVGF+pZodRW3z1y/uyUUkz4kkyheAgF5v7Cci5e5hhV8hazfel+HPVUP8uyKcaOan+pnE7mTT2H3JHCKLWCp/RZiteGLsxXqrHrg8Z4ipwcgvwS8hCE9rOJ8D9tEA+km/p7JkHduqhB3p6Z/IXm7FdHNt9iQj1xP/NU5ZSTcYF0uHq5i1r3uA/q+CA7ncR/Af6kr/r266n+4WRzXuPEiRV6h+Y1Xqdr90SZygWd1FpxX75zcVcEXiTcqZYjtRY/utcUGgP+gnFmXdnIOnULIUElbFf+LX83y2X5dkjfHmnqJiHWPZSOuTBttxIrisdSF3l8AyMDJlPlQRaLGwKu8CGbVk4855pHT8w9jKA4BX4gtnTPrUkGmn5LNILR9scyzVEKhYKIrDALmWjl9E5XpaH6OtvrdAQMRO9qUtiwZ3SkyrD3FhXjBPdVhkomCmiIq2pLE27LO8brK90mb0dnP0SmptEG2sKS67U5PHOg1NCFH50Fk39uN1xd3f08cgZMCSfN0jJ591n2lI8NZ/LySIUezWFLwPs1q7PHBn+k2IdusG7b8rUGfXITtUbKc6csNxlj02g91TB3DojY+WMiXYovZSCWiKuW2rrLgh6XwXbuz0Goso7d47bpGEAqmVLSbcMjUZm78vbryTcQpe+7wk69J5uE6etfJ/0NO/59LfSKijFnmeIkviz0WWf5MHdiDhMOSVIikRj7RcKDRNJeXksxWS9tgk4+aKJju54w3PV7h3CwgbtCd7oQtpGKgYNSOO74E/n1sQGiBGyETC8yvmBV7L9rCWKZR4ecvhSgKyhaaSYrc4hJvIr2kHiKS71YNwzLbwbO2adkc0AyPhPeGNZX5v2ssCchoX8Z1DfqMmupE3+odJYJyNZJFaesJUmsBMJZjsfo8PJK2JQ2mS9Nz9R+Wmv0SEuoF+6b3B7mGZhIH4KZytu2BB2faShdDaMqTKoGc8AxIbBT5SRCE3UwUNGn18b+Yxx7Wqt7YJqYp9POZprk+GfPKQQ7wQFhZB1twbzhPDDWUOmvnjDcKPOtk6W2VtwPQfguB6FNbnFEiKdEJojYtLI1VkRplV99snlYvb1V+kYBHnNFj77Y6I34M0HyiHYEzj8+UTdwfaBBKXrXy X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d2d3b81-beb6-4a58-d09a-08dafc9b2685 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:32.4186 (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: OfeYe15TceNChNai1aiIE8MHuB/SDLhhBJZZYRBxF+3LkIf+3GeDYxV5IUqR+gFUoFRF1JmRh/1R8m9FtmyA6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 108 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 8 ++++ 2 files changed, 116 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index ef3b435..e479712 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -171,3 +171,111 @@ struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_p list_add_tail(&ef->list, &ef_parent->ei->e_top_files); 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; + + 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; + list_add_tail(&ef->list, &ei->e_top_files); + 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; + + 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; + list_add_tail(&ef->list, &ef_parent->ei->e_top_files); + return 0; +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 6983409..7d390d2 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -47,6 +47,14 @@ struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_parent); +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 Sun Jan 22 17:07:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111535 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 2C4D6C38142 for ; Sun, 22 Jan 2023 17:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjAVRHq (ORCPT ); Sun, 22 Jan 2023 12:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbjAVRHo (ORCPT ); Sun, 22 Jan 2023 12:07:44 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012002.outbound.protection.outlook.com [52.101.63.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008472108; Sun, 22 Jan 2023 09:07:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NJ8IkvuyuOP+KNpkcjx9A3IbLl5fh/sOG1Xi/tzW+54oaY6p+YfdMUwUJxHqYsKbEC36/4ZcL/fkG4cKfSEbtbZVS8bwiprpDQpPyX7wLvAyIgjbFHD78HGuAQ54X+opvNGaCXWnkoZUm/GWvDhGUQVmDYSgUWZrUYrZum+JYoMGIaBMVqRo+uSRcHR0KAJug2C0wTmi+Z2wC1ytx1aUqW3RSvj0Xngp+KS9BRVWaAqmfOiHhOnV8t1ZwK/w/aA5PpPp5KYUizbTnfBVEDaRMMiI0ppL24tN/REOHDmEKUe5T7LcMZ0/VKms1i3Da+/I5Hr53MhkmQL4fNXj344inw== 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=jyDNKM3Qh6uMTvjpuakktS3MnTqjCFxaQhzDiFnt/eQ=; b=cI6Mvy9ug2WtjXqI1s4asoqb0CTWBhXKI+kxUj3t3iLQ95wddtEDogS0mhuUGXVkCQtzqegiLRhlowQ87QR93I/m2i22Ki2ADf43sStEsOUOdiCWWvDCFCVPnwpBlByZr8PhV7yoFRXAO4OSJYUNDxcVT3r6CYlp9P9uY9hw9qvOC8B5tFyVmmuCZsGbg7gKx2tj26yl2mcoJcSEHY2NY/l2j6YL3wBD11u9Ami1bCRYAvLwOsrQidlUu14zdZ5YGlbABo69BonxyGXXG3PT7hfXdPWNdMxDjpwZEMXbR2x2qjc7ZK9RE5Zgw2TTk1ZB4dN9P7i7pvGYlRslFUxyaw== 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=jyDNKM3Qh6uMTvjpuakktS3MnTqjCFxaQhzDiFnt/eQ=; b=GBIMQ9jdKVSohdjSdEmZNfKTj0fkKlcDobY6n79Q9ZGGZZhc9QS2m++Lj/pyih27UO+YEmGZ0IXDjc3dcZRabg106BOQ0bEprZ9qtwVf3OKyO4N7K8AIiTBPIEw7DwvF313rQtxMu1Qcb5tqyrdQoSv3Uoexjam0aArwsLXKqkw= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:33 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:33 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 4/8] eventfs: adding eventfs file, directory remove function Date: Sun, 22 Jan 2023 22:37:03 +0530 Message-Id: <1674407228-49109-4-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: f4d02316-262a-4a93-749f-08dafc9b2712 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: RkUCLZxFI7SqXsqoB/20ZFobNzYVBa5UXm6yIU2iAzFeUeRffuHERPKCqwj//AEjXXB6UXY1wuGiSt/3ouInBLZchP9XUSrxxKqhKE0qzIzKSdBlcw9Ni3Vad9ZweOp+a0ecB8OY+Ip4MbO/QBi0H5ZIlPft1hRlodW5MTd4ax4COUyKIwvAKxTJ2tVdgsz0xWZgag6n+PZUSL1BJDaRX0Y77FjoLfkJPypGdIUshK3a40ZVi5B+NM9P/B9BSgmRoQ2MStUBgfKCk+1d+DajS3zZHVHB8Zb6xwafz57Dt/clusEdgfnUlTvZjag8U9s9jwJ/TpCPvVo4dZ6wtUNyBuUtQmofFPk3tP3Is7mVBXuoz0eIayJ2lMLgnrY7MbLAa7tDJfgRf1kZeqzkj1vChMy1LzVYotwN1PwvdEdPART1U3WeDUdh1b7DssNmher2TVmg2oZz0rBgyg+kid4hVCzKXJX7D6/ydud8l3XgLruRL37fjvLbcggonDbTNwKqGKrk+T91LAn7Dxh2tobt5tSdMwe08ILTTmKB2xArp4bwK2Q/ocjDsxiIc0VeyPoLeUpcOJC0Hc/9sjd+WjClhh85jssBkB+jaKZQwYtlk8TmM9q64nwpnmSZwD5e6rVbY5ObTdR/LEQ4FOaAcPbxfGG6lGZeD6K89xif7RswZzSr6ajBuMCy/n8u/3tESw5WgcKDWsS36L6FjYrGMT5hbQ== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ys1VBaf8zlOAbJDvXn2Vwbd/uuyjF5rn0gCvKJC8JrSkz6LGJQzs6//znfSkDh1itiZD6B5tZiRlpZ1KfKcdggL6qrq3tv9dP7sOhjvyt3n92roQnb1JmoRG2ANS3/GlBp2b8C8MBFQm0De95UfCd82eQ3BNDZDaHbKvVDyw0n4NKRyNq0Ifuk2MeTr/KExUs2ek69SHeR13bcaYL4HnKZ+dIMH3k1YI40BzwOXSdeRxWQc859D6CDOonExseK0F+ZYDA8O53Ui8RC6f+nVqo975XSptBPZZqqeVM/LreV2RH3wWA9Dnl/+Yk0DwpjueF4dus8gpp9UWexZaR01jowE3jLzoyqgLPXMh31DK2dQrVYJv1YSWZNUSco9PbNprnf0UQ2l7rFMNSOyxToqEOfqChvpN25CowhmDUNYjaguyTwzCwRToQgntrfocWjhiN1j/OIIAlAuiXgGrUz5BwxECBCZ1/g8+OugE/lbk4sQN0lHU+czcGHq/LclY7nIAtoPwkjKQ47Ec0bhUHyAnkDai5gs2oYOUoCiavlSHg61coc5lr/aojd+rYqzSolhBy3yCC3JsTyCJaaYxS60rr7rwM440zQUx/YstcMBGUqgR6qW5prdlTYqkBSNGiBGCUHOstYCmjdH0fgB2oKe7KR2CzjJTb4ncoRtHxGg3sDHaY5BssPWJsoTeRtbfwUTdSZQjGbAY0wQx0puWyUQMKmBslWSl1YmgNQxL660gjeyd4zcEUG3fYjU2ZMP1KRIZXJHQ+CHQ5p7GnKHdjUcPXaOA+o9iNNrFcJdO3mhNaduMiRt07FbbeG7Ht5MSpmK73jVDND57mMTi6AGjC3Bux/7kGHiDx0b40d65VI3n8pHaSfn2ePW7E/H8UeFVRX4Dh8VlReqZuXpFoE6Irto61kmpVlJQz64UsrG1suOEYHjy202uUEClNe1CERlmxkiGkZdxTOL0SIx4ojkiSm0hYXhLD56CG31xSDWNDVUhHoRZqp5MheRE0vW9Tg/WWtjvQ2yIc2B8j33fvWBcXG1wCAtBqfgnNtqV4qjhcqkss6JyFde7YN+E5q+hpX45BK/McNdR294arCykMSl8jwLzsonX7eqKUyoblUp7++ZnZ+x56lvcmKJ9gSbyuJweYSJBNKNiuWmIRUEiuXkvYXhudh/6Q5ZQG/g10f9+ccfxHeQTOD8SZ3TROvUSLxvxAaoxeqwsQstiK21FuEPWLSmg7NiMNY0+qM/+7KWSeeyPAiE83ZvEF1Sl5EZXv+zhwZ7t0fbjd+YMSW6aOfo6GN7QUMa2EgrhfbY4z6stDdmCDDE1eCLdvM6cNkBSpbX1lBFzlSDL/4dPSRobRJ46Iv8HMYsrJDpgplaQQJbmPWqYeAnNkzWvLiRRNcya/4Eyr0EDVe0mlI/dRkRFT5Uh+pFWDfzucrNYTZA3BDNeuD0WQm4DldXVgmS/N8rScVySXx+96DpcrXCh0Z8giU05MySl0arHTXXwDsyroHUeBfncLOMdGE9eUEaI2sE4z5+hBd1lPSddpq/vAfEGYS0DloM/zmKFnyQ/njavj9gHNaYLFFfDjh236L4REQ5sBerD82Ib X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4d02316-262a-4a93-749f-08dafc9b2712 X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:33.3383 (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: jkqwtsL/RwGvuqCXVy8EmaeE+61BujO4FSk6AIUylfaJ02pdio9s0OyZRkri5AVGQhF1jkdkrHiuP1kjTX5C6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 26 ++++++++++++++++++++++++++ include/linux/tracefs.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index e479712..4d47da0 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -279,3 +279,29 @@ int eventfs_add_file(const char *name, umode_t mode, list_add_tail(&ef->list, &ef_parent->ei->e_top_files); return 0; } + +/** + * eventfs_remove - remove eventfs dir or file from list + * @eventfs_file: a pointer to eventfs_file to be removed. + * + * This function recursively remove eventfs_file which + * contains info of file or dir. + */ +void eventfs_remove(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(ef_child); + } + kfree(ef->ei); + } + list_del(&ef->list); + kfree(ef->name); + kfree(ef); +} diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 7d390d2..b02cbba 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -55,6 +55,8 @@ 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); + struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); From patchwork Sun Jan 22 17:07:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111534 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 72308C54E94 for ; Sun, 22 Jan 2023 17:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbjAVRHp (ORCPT ); Sun, 22 Jan 2023 12:07:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbjAVRHo (ORCPT ); Sun, 22 Jan 2023 12:07:44 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D4BAD31; Sun, 22 Jan 2023 09:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JLYn9CSVPfbXPR3w0fI842O7t4Jc5JhDKAlN0iw34fojFLpBe6iEZn8KggkDLxJnoNPeTyKp5sw47XRezspLjbMP4jQWu2mNXhmAV83deCYKbnJn2Fzt5AbHlxcVDuCOaFiEWwpWFyUd/ny9Ed4l0vcu/Om0vbrDfRo+EqOoJvTlw1jYTJ30BIt3+sFaXD2+MXM1PHrUANDPP/dfIeb3BTMtM849PB/KGK8HU0hseDl9Rybz0+YoOAKRuhK7TilsDICbhDhiYuS+NZ0qoNhnY8/jg4SNZ5YH37UPUT1KmAyeP663w4hFLOpDgEBu5u8Z3McwV7ZHAOZfE5zVY6s+mw== 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=xfcd1wBT3ZdZtwiJ0ROpaSaeazj8fSJNBjMNY4QMyII=; b=fpvyLnAxct35EGoIjwNFixUKAI0QQpHIDU6F1iozbJ0vRk4nCV2nW/jw1k7NSH+wg8epOYSTXj6zZPzSjjUEa/lb6DT2GWy7ish4OoaIBX8a6oGqWIp5SWJ6jFRk+CAQX0AyI11w78W+F/4lf69O4xzcL37jlnZfWZq5P0b0yHpFhY3m7pZ/URKAAC2vSPqH0iIJdSGjae70BJvp3FxVisLnvo9uZ3SsQcykhci2IpOJT4VqlE89GKn1MATW8MWePvY3PRbw9rCs7OuJf4TUEOhD8moeHbNUIYawEy0awA1wpXuAYEYSTVNNB82YpFJoCN0u8WCCdwQLHq3DJpyxYQ== 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=xfcd1wBT3ZdZtwiJ0ROpaSaeazj8fSJNBjMNY4QMyII=; b=hzZJ1XyXDev68RnjaWg4ANbiONobdhWRr5Ty+0cNS9ZQnC2TCznqxibkyCsoDVH3JbJf6Hs0zBih1VwQJiUcAgv0QX/gJ8K4tNuNdPptGMV7YSwG9Kug2F/3h9kvleg6/7nb6fZW88ncmtrfm9UPB50YIhrf+PNwwlm26BzVLis= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:34 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:34 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 5/8] eventfs: adding functions to create eventfs files and directories Date: Sun, 22 Jan 2023 22:37:04 +0530 Message-Id: <1674407228-49109-5-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 941b4f42-33c8-4314-b94d-08dafc9b279c 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: XprIsvCxxe1Dq4jd5Nz2s2el42md8685ZAqvSgwpWMDd4DnAtcdXujDUFUckLULkSjcZbS/3tLiGAOw3X7NpZ0rOb3Raahu1qmBJ9Iq/ztE1dr+4dgNkUcvV4iYg1EMfMxZeJHiXimSUw1ifLCtcMPdUDCCFvFoQ2z4pB6B38ZTcDCOT6d2XArTwktGthwPqxSk/F7/Un89UL4w5PYgmf2uXgKV/RS760asImRCtLX2DqkJIXhL68JAs8vTGdraOaQKiPQSVPLN1lM3VGOv3ivRcwQoCDwP8BVzhmfkwqJ466hlWe7Q9rZJkrI1/DGfhP2Uq1a3zhtugt8DMVUWyJTxfSzDWGgsN0n7lzigjkCwbyzjn76rRpZlDWLD2Os78T/hVJd6fkjNKB1zgHkf+8UdSDTPcItJWHIyg+WcAxehdxsMDMBmTpK+zzk6mVWM37TEu5ICcGt3XUGimHdF7meyu5jnJTH7nF7yzmX/b552OR8gAAS+CO9EM/vPPdbhbkTDC+zKeW+o8DnYQ11fhSdpOWed/t851ocIumLQVW0YcDj0OXo/d7gRoei/ftnsY5nkSDENZEWgsJ5+nWYBp6JN0FxfbQNw8N0cqJjd3INUkUcqKfTcprn/lJwTOsE7QGbvxsaXmUpKA2N1zna7vhFxZ/JmtA8Ry0Lh7qjj7mKRAKE5a1WFLnkkyEvetocZOZ37unfTk35JErGZrjfYYiQ== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +Svz/LjoKRODvq6kYz3R19IQxqmJuj4xkoMpZDPNUB2IVNO5DQswx/RHz/rsnYjnbZihe4cIqjRfhWK8TaDv3StvxdOQj2dhwGUs1BB25K9rD5Kg9eyv4t6SgYQpDXqzoQIc2MhFe7vn40CPcBRJayqzS3dRgUXYYYnmyymhuq75yCtISSKL8fEo/Rkk2IUh3oKM4syyyZB2w1Kl45OCxVE39FbhmlnK49ti2Ql7lTba4eC9PUlaixrECEFbhuQGGBpBQgelXDS0j2I7lk+pBU1TrxMTCniXOM4GjoyyrkIg0m2cCVdLyv9g4J1dKh/Vd5HHRzWpQsMnN4GdFbQFM7qrJM2W6Td4974oHB0kL3Ct01Qdc/M+25srgEXlFD5lkkTSjPD7nFs1Zp8HYAPcBrdKry8rzPHl8qsIskIASw6fSn0fKmLTZOcr1LZbCTMu2F5Z2nIKHFk4h654tDX2KfkcwGRRmOv/maX1NstxxFJKSEglWe+pNQocYnNuIcdulVdlIkIWAu5wruYgpg0C2nNdnipoBKMQFxYaNJC8225FLelU2Xq5lvjphTNqos65gLZ50cOe3jBMFs88raREsfern7j7wNIogQYkP28yf0oIO/ccSLUNM6IdsNepFOrfP2gMv/fOVos4fFYbqvn3rIiKLIH/p++HwJjL2A6h5Lz88Zo42+aDnk8CCVssU3GcpssXKn2n98fXJkceYcZJ+BlbfA1VDo6jy0yjFCLLw45AolAi4Zw3EahmH3mprK87b/r61JIqhEEndtqQT5D6+Y1omRe/h62pMqpbTzQ8ZTBQNQ98X5CNbYNIXMC1+g0bMP/e3jTD9XSClADAvTeYox0tzj8xbTE+AvalvZz3lmHGJoc3pumhjpclo2nPFC7VrzwoziZ19IWZc/7nl481Sxsr062xqEuubu5NDrKLK7vYzOunMIHdkzlrY5Xypdr+nd95fpRElXctfY01Pjs/3CfhriL8wQQc/Oqdm1b5m7j9rsOB0Q5wSVNvMJiknwg9cqpBojgkBJAr+39DyQd6RabiMnYdZAeuUanZ64+aoQlZ8YfkeVh+Fem+bX6PT2Qqh5L2cX7eUo99vpkGOhk2fIjk3UpJtohURTOdThzZtcQxb9Mou1To16AUH5qAH84xEAMLg9+MVeIVrGOeADB1clHKZpWJBLOUi+J8N0Tw32Dp0zBfsZYn6lmp6qnNIord9XHhUUGAfpMSAqrmf6IQT5K8UZQapwBwJrgFUcd5s2ZCjQuU3QUCdZcMgsEP4mHL3hc6bL4jUaccglXxxeg4ew6bZOWUyLQ6eHZtR0C6+GTkt5Nz4A72hJuEfuSTHmDrwdlHhPyubNesibkS4zWEBnKtFTdhKVa4oa1QV60okFEvmF00Gqb/ZlRqNV3/w5uCV4I9uDOXZo4ziREkB5yRCw2gFoeI/EfBsGV133uaagovwV4rWp3fS10KYzlfLSx5LIQGKYEz9v56w0W3oVofb6/Oj5MMR4mWojyB7o1jI4RkbDgJveF/kWMT1t8ga5cgo14+wPzurHs4uA6un1upQGjcbspBdPRotkHrS/Hn8dkwbLSzRXzqSwNclPKp5I+b X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 941b4f42-33c8-4314-b94d-08dafc9b279c X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:34.3715 (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: JV8sP5rYu9hhnET97cbOzAfm1baSOLOEQwD9NLe/FNNiei40ghhpE8DvybwwG/N+aXQv1YlQBvDaDwlZJI+kxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 137 ++++++++++++++++++++++++++++++++++++++++++++++- fs/tracefs/inode.c | 47 ++++++++++++++++ include/linux/tracefs.h | 6 +++ 3 files changed, 189 insertions(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 4d47da0..28866c0 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -21,6 +21,141 @@ #include #include "internal.h" +/** + * 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. + * @fops: 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. + */ +struct dentry *eventfs_create_file(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fop, + bool anon) +{ + 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; + + if (anon) + d_instantiate_anon(dentry, inode); + else + 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. + */ +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, + bool anon) +{ + 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); + if (anon) + d_instantiate_anon(dentry, inode); + else + 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 = { }; @@ -86,9 +221,9 @@ struct dentry *eventfs_create_events_dir(const char *name, struct dentry *parent */ struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct dentry *parent) { - struct eventfs_file *ef; struct tracefs_inode *ti_parent; struct eventfs_inode *ei_parent; + struct eventfs_file *ef; if (!parent) return ERR_PTR(-EINVAL); diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 015b7b8..6d950d1 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -451,6 +451,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 b02cbba..52201f3 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); From patchwork Sun Jan 22 17:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111536 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 218D4C54E94 for ; Sun, 22 Jan 2023 17:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbjAVRHs (ORCPT ); Sun, 22 Jan 2023 12:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbjAVRHq (ORCPT ); Sun, 22 Jan 2023 12:07:46 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4304CEB44; Sun, 22 Jan 2023 09:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZXEUT3egUPRvDrBDe6rzdV1r5r3V3eyhQCX0SvScopxSSOLe7McM5cvJdJ33gaZmAa9XTBAr/ahwlsVFOtjtsZ/nq/5toL8CckQ0RneBDD/F/iYMmU5og3ju8RJcZE7F9gbffyraY9iMXvyhOI+Q7a+vM4cAIKcpOp9aqvTmOmvqymoIf8FovFhrDWf4kO+1557zFGImisYUrbut/h4roXxxa9cBxNn2tbhgcJmkie3uZJdyYlllDVGsZYsdKuEXCXdsp9RhmKP+c3iNvaQbMrU1rRR7yjwgIse9Ixci7xx3JQIlsB7X9O/YQzHYKvs/+lqJbPkJSvDuXMpv7CX/A== 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=F33NeSakApfkP80lHUYIJtHnBNU8aDyUnI8b3FY0DHg=; b=nVWXUs6n5HD2ht9Ma4bw3BLeLarcWMpkh1t1Srf+5CsxeTrabBlCECekZ0RZrukAEbSpiphnjLRRvcp/61sjDfnB5PZM3LrsioairzO21KopgmzETsMJs0NZNFB6PZcJNaT2VvbMF4CKeoONgOG8D9YuDEYqZqs7hQm3us2jGDy+FbsB6sXiLwcf6E5zjeuC+BfDIspZTQMHIR31HctsV3VAPaEnfp+LewciZ40R1RNmhtFkkoqQWh5Jcg+B63kWLqvd1RCOUIRhCV8efx03Aw2u2IeH8jFlf7HXwqfZAqDtwljhb2MtOffPanP8eiOLtF2JbVxGXlh1EYWHmsTvZA== 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=F33NeSakApfkP80lHUYIJtHnBNU8aDyUnI8b3FY0DHg=; b=XvLFERo6ZlRiJhOiG3ns+bk1scnRxPtUKOLhgPFN/tMhA6XKOcbKJl4Pg8qAgCb4VlIp9r2CgULFRLFWIq+CfyL5AH6qqo292jRb/qHOp9TkZr8qOtzpj8STfCEjni1dYGMzA/1oSoWem1sVp0ggLj8F1ABK72bWcGzROY53aEw= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:36 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:35 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 6/8] eventfs: adding eventfs lookup, read, open functions Date: Sun, 22 Jan 2023 22:37:05 +0530 Message-Id: <1674407228-49109-6-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a47975e-5562-4199-6f4c-08dafc9b283c 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: wCmdregk46XGjMCnE9yb40gExWNcgPiUukMuLPZxv5foNDzCUVwCCJT1aIB9HoG9YV53s15bZUlOq+Atc5E8NNMHPqBDtofgue7TCDFi50t+eGAuuUuJzVlYKSWsBSc8qvIRkcSUhm/ans6aH3WRmAVlvOqeGFLWirkMkSSXWy+Vp1IUGzAnNg7x4ddLB7SgYKm/KpZQ7ia8yyu5pLR8j1NgCo16lnmMJRuYkIzxS7YHJmbV70e3hODXJMJZmwp601sIpHUNo48kbLCKu3ZlohlLV9bKbY5H3KH/kHYuOPHN+ioZV/7HdiTLwCP/W8RLG61umg0j4+fqf/Hp4/YuQw0aHqOqyWlaRFGB95sWA6gifhFsPrsjDqJhqCIShUtkLYJ4oWVz9YABN3xf8wKRwUOnEyDxHHVudCXqSWvtCEzIZIVu9LxRcuWRGfru3s14zqtiDWD+khv331CtFC3MIbVPJ5YjcsL9iZ53KqWL3naULbYebj7MoM31lXVka2wVZiDpqthcqQQ3WN4F9nsqu0FqEURzYE9snru9Pu8DxFtAqdyWwwlMCT9kwerxQkjszZHyEDR1n0+UQL8W3t3PPicJzz+arZkLLnhr5sJJw/gXDHY4C1kN3N9lKTWlC/zq3iv6HR3+GHx9jDhgCIyCxyOEexdq6yguwY1I28xQT17mwL5wBitrDqop8UwfvjjOSBDs+RgFpYccL5JfvGa39w== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UdMM+GLL0Q0ed4SJazLtbRI4l6JqAB7P1J7U9Ezr0Iv1+MjnI3LWbs1Gr0KBOBLQvPzDGKL5XU/N+vcYsCN0TX5Nr0d45a14vcFcAeA4YUQmJta4KDCnbPL0ctWCgISWgB3MyMWABYswkx0hywAzSwmxhtGAFi9KI4T6ieryAxze2BIDB2i3QaSE0GljiHX0Bx9F72vD1iJ9cNlHCSYI+sbjb//62Tpo//J4yaT0czkgsuzuHMddAOEj2nWAAJgQt6/q67Qk2chlvBXCupRZVRmR9kmuGD0iKc9ANzFTwRNoK96kdb4TxI3vZ7mlPRtcn/sdaCMaEM8378XqCtbPU87WeSyf0FV4fb4CzDzfxKWGkgVY5HhiDUltiCTWm0hQ+vsNxtrLPCrX5w/x4hCjkptkFw1R9Qw3kL1y4u53n8FOxxeFNSi1U/NWOuLni00YAcMjxkwO1fYZxQXbKKebBMROhR+5f5Drxbnof3ULa3GgAredsyPe8FOanofKIZFCD/IWpZG/wpZJi0RP5b/fmYXWKi8WcTr9KpCbd6efBeuvLHPdUyKPBdIgwL17SMQ1AtH966iQTT98z/+r1Oypw5Kt6oA5vYOZJewg2v3ybeyyWjRzi5e4vC1hh9kdYxY3Rtvr/SQ39aH3Z/xiMnOz3kj3i6hr9Z1/QqxDaXIjSGotEck21gL1sLBm05DU5zami7qOJ51ASPsyQfJN1XmQC75RVbvWCQmNHkNRibEUaFGCzWjXJqAV1Ih32MHEiaK3wWnFmAkyYD/ILS0F2SMWU0xb02kLff+r40f+U+TynhmpX915zuRz0awzc+OLAdCpVZ+rlKBU3g6WlANgvI+7Ss7VB37x6g4KlWxjiUMxz81pHfHQcV+A7Hvk79M61aTzTfyDPjFZGyLoMlykb00+QBBkElDFuEWcASKJdZLzKcxSkkqRl6kg0W2rXqTlxJNPwtw+y5NWK39ACHj/9tGu6bqVKXCEsq/HHc30WdIbsSgZ/XJxJCCrrVMnR2qHrmRdQnc5p2MGf/OlFhGFaCFdujXwW8JKjBKagHKB7g1e8ep8HnzlNzpPkuBAS2MMzSVgceFLvMbRTsGAHjntvNNqEHdxMbacQElxZ//21iF5YrxXfwXR4Bpt8Nc6n+SMsLBh33iKyTu14AOZEq2k7tb+nliIjSemgL4U4VoqgVwr+sJ0zUxlUlPUt9P6Cv+ChCLTsh8gkFoCgv3hfA0/jniuaayMJz6LaNZ0zxSrYRGBQA+H4gxFfOKAMkMU0az4+9/JnZTCwjeo2fi5UfSli+dXoKSsrOZm/Hy8tYRaUD+Oi4YPnWOAgHpnKfnqOX98bmnv4i49+8STBlGZ6ThOwgcApiD62vArCBW3KFjJAdBGlKBIeQyUXnTxF1Hj3XmLa0XevkxZDXitlHpf3LLLHiXiRUen8bnWdsDto+ZRAcFlBBSqX1IXslSi7WD16ja1flGF6TWrIWUMBqFF+FpCPuDK08+RRR2tNslARQ11en9O+iDYkchikXTJs1coieDMnnP2iqUqsNpUv0uaqcFkdzgYSZBv1l2W85kb9tnZcy5SlIubOD1lnDoUXyK0kL2fAFj4 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a47975e-5562-4199-6f4c-08dafc9b283c X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:35.3088 (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: W8SkbL9LW7AIQm5P1n5GIgNQuYJq3RkEJ7gGjWHufbA3gTVAROBCS0R6QZeBX+oR2B27Zkwg+gFbSrr40jA7Og== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 179 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/tracefs.h | 2 + 2 files changed, 181 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 28866c0..bcee34e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -156,10 +156,189 @@ 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_inode *ei_parent; + struct eventfs_file *ef; + + ti_parent = get_tracefs(dentry->d_parent->d_inode); + if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE)) + return; + ei_parent = ti_parent->private; + + list_for_each_entry(ef, &ei_parent->e_top_files, list) { + if (!strcmp(ef->name, dentry->d_name.name)) { + ef->created = false; + ef->dentry = NULL; + break; + } + } +} + +/** + * eventfs_post_create_dir - post create dir routine + * @eventfs_file: eventfs_file of recently created dir + * + * Files with-in eventfs dir should know dentry of parent dir + */ +void eventfs_post_create_dir(struct eventfs_file *ef) +{ + struct eventfs_file *ef_child; + struct tracefs_inode *ti; + + /* fill parent-child relation */ + list_for_each_entry(ef_child, &ef->ei->e_top_files, list) { + ef_child->d_parent = ef->dentry; + } + + 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 = simple_lookup(dir, dentry, flags); + + ti = get_tracefs(dir); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return NULL; + + ei = ti->private; + list_for_each_entry(ef, &ei->e_top_files, list) { + if (strcmp(ef->name, dentry->d_name.name)) + continue; + + 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, 0); + else + ef->dentry = eventfs_create_file(ef->name, ef->mode, ef->d_parent, + ef->data, ef->fop, 0); + + 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; + } + 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; + + ti = get_tracefs(inode); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return -EINVAL; + + ei = ti->private; + list_for_each_entry(ef, &ei->e_top_files, list) { + if (ef->created) + dput(ef->dentry); + } + 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 + */ +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); + + ti = get_tracefs(f_inode); + if (!(ti->flags & TRACEFS_EVENT_INODE)) + return -EINVAL; + + ei = ti->private; + 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, 1); + else + ef->dentry = eventfs_create_file(ef->name, ef->mode, dentry, + ef->data, ef->fop, 1); + 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; + } + } + 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, }; 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 52201f3..952d248 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -63,6 +63,8 @@ int eventfs_add_top_file(const char *name, umode_t mode, void eventfs_remove(struct eventfs_file *ef); +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 Sun Jan 22 17:07:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111537 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 8E8FAC54E94 for ; Sun, 22 Jan 2023 17:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbjAVRH6 (ORCPT ); Sun, 22 Jan 2023 12:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbjAVRHu (ORCPT ); Sun, 22 Jan 2023 12:07:50 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012002.outbound.protection.outlook.com [52.101.63.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1ABEEFB0; Sun, 22 Jan 2023 09:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sx+c8KvKmtm6widRcvLyOr1nmSuPNrIoLAgZUvHLF4j3JtrBOWu6LfDz6ZGm7Ns+Oi0onblXCVikp3GD8hldOAJj7i/nTJylUx4pj5X0o3CsUF8QEUIOI+zWOL5X/PmTQWGRUD2iFp/vFU86sV2b2XKbdasA7vkIz13g54BMOkP2ZANcfF0tLeRXYZ9ZWFdBG/CaL10MeO9HN5d4u7BCezc8cs2X5m8Ix/6Ra+RPScL+LWNVGptVWGl4OqKRuZQ3w/87rWyNy14Xxc7iyIG7BEsHsO5YZgPAPndOEk8IGi64q/pfv/eKjxq+hmjoP+MdL8/MW2iTr0snC0oKmIHGGw== 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=rIBdJsxCUmdswEgQ7f80fp1KQeiWBLq6UZqSGbOF+LY=; b=oT2VkxlTKa36ZEyg5ApYT2ifUpk0YgSVtORlj3nDA9hzEPVEjFEbhCXx2KLgfdB7ctpzJodWwhnY7ss+DlpGviuRCWmMS6jN/gVXsTN/l+BLGiMf2EL2FIdKzdXEtra0noMQBP7Sk3K9Vx/zfb2cHGOqXeCIgJtznLKwDANVUGAValBCEt4T3cQTQwAVPTtGNw9V4B09FXzjWx6QcrWgDbPCYWKVFogk9qw4fw71lF/QSY1ONB5i2XEStvO7FLjQxVUG3uWtwNRe4TfpLWtlD+1YO8sfEcA8MKUC/8mJo79gZ3Lt4T2fwRznC7UYzdAC3/UiZGarsGjNTJcQyrmROw== 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=rIBdJsxCUmdswEgQ7f80fp1KQeiWBLq6UZqSGbOF+LY=; b=09QMIGI+ojFBRbw3ZRg35HZ4Xg4xZCqmgswhBHxH+I/V7I09dX+Vdj+ZZvP8vZjpxwmqmXVMEwpYHonpaWuX3idTdekhcH6dGgesj3TtNxd965nf7yaAc6fyQRu6SaNx8wOU60X87jEYM+Q1YOgP9Z9y8lgRAU/H/zep3F+XHBA= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:36 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:36 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 7/8] eventfs: creating tracefs_inode_cache Date: Sun, 22 Jan 2023 22:37:06 +0530 Message-Id: <1674407228-49109-7-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 98364896-cc4b-41fb-0dfb-08dafc9b28ce 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: I/Otofv8srmNB6hAW+otLKZ9CNNe9GeVnkUPzYx1kWcj/730/8REwJLJ1TXfpkr0/HXRqCocUK8d92ouI8moD/vAmhDBTk1JSKbzpe7rPvY/Us2c9SoizY7P3QXVeB6hKvlbZvXCEYrBDEv4YG9j4cAsx4bLNwPV2WMw0Wu8VCRkhnW0+0olRFaRi9UNUNsXaApFYPByjn4gZB/bvJkkFH2trcmmJ4lK9ZHFNVux0FcyMBI7xmBisBXLESQpvhgXAfkYTUEYtguxNDOi5ii0ybIQfio63Xh253GtoXNmkIdycolESZYynTJ3UsBN9dyUXlponlZtB8rS5kqyGGMZq7RIb7bCDdBmbl2KqT084rC6WRFRMXDWn1ojcRR+vmohfKx7W/DvbnGPy+NPx8Qv6OJd4fcM/eEZgPSDoAI0fiLcTh4u7Q4DQoOztYrB1vHl+vobyqugLYkk0nLD9JCB8jMv5l6rmBHY8uKmAeEc7bYd8Oo6CAX4MVT+lHgWBjnhRMjv8+rCZTWfCs83p1nFgiErxJav2LK4Mg32c2uJVjiiZNBJ28+mPfGDFnd5neDqcwBteTOzaiBTYwjYuCaz4Qd23JtZI5uwweGSOgYQK5drueLR6xnSCXXENaPN8twrCO5O3N8oYPRBaks4sTr6Jqto7DS+tm4EBkxyYWpChL5HqqOrYC+pF+g9eqSTbBPgl9tQ1V/Bn04LSTzQQAomQA== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sHMVVb0uCUTVVdiTVJd6RJjbsjo748lDlpoBuWEUunIgpNVfjtfkNHHb27AS2nU0qA2ZI2kZ4rZ4O5ESgwT7GPQEdnkg8ABNIA7/0qRfVHgyW8DNpmU8fbA58rgtoTTMXqLBPnHma4aJB5vQnABM7XbhwvdKkjJELHuzkdlqS7Rf247MlAWG+FFuWKtYrsIXjcI/fxgnUsG0uwtCmBQuKm8epxoJGzFDYUDVyaA1Lvn4+WeB9YIUUTNUeHvDHZWdC+omKnNlmjIumczjbrVdCAET8PrtL1gOyOU+PaRKONDOOxHW49MatAvZ04RrDX924vnzzO6zz/OwZipTkqwUZ3ObIUQ9OG4hruZAhkOTRxDtWQ6UC7oYBs4OlZ9zU3Yq3MhEmhFQmue7a17L3jSHTqCcXEmjNd/YewES485WArv5ORxoh+Ik4H/XQpjZRdemggjKd8acVW3u5PBGbzb9Y/OgaXTI/uNlinDekRkYNlcb3MczPYLFXM9Jl3V8dkWIGBIX6BtHHFutjYQi3PrVfeH3AGk/Xr9IzbP2oYzgLqjPnfcfDlWhXa/aBc5dnIO1npIuddL89vSJJqTQ6NTaxikA7fte7/EDUewWKXYycxBiVXEBdfoUcVBbWgMYB1gTNKXa4Mx1rvdjeJp/KcNAB+StdURFu0fJOj10g0bVZ2ZfiXQwulikE3+kHrK0ufl8ujAh9xBm4Zeedr5BtwtBkATlLduLdLHWym2ty3ynmFTKoHWZ2JLEHltJZrHSWUHo474qYhnglTHJmKUy0pxr62CnZx56FPBtSXAsJf2h6dYsJB+Ias+lkwP+r9ot21pP57xVNTIrmKvYXBehXFTRy9qTcrgYQwcNwT+R5dgDB9UCSR7zZRAEx1EKOpHUNP7y/1jW4J56Tjqdombzj7T9DizQP/a76oNfbBYCowMon1oSsJ94F1hRLQxYyWF7SFh+HF3ojgClztba2ZSGCuCtvMBcAAAuGZMLaC+8An3XUQtxQyl5x/pZze/7v28rJ/tINOJSIZOJJIR/c6BOKObK02VB+c0e+9eYO6SFsH8wAykwIdWnA8844I5zlcBv9wEAGPmmVSTXuMXBFMDibyVotKkxscZ/MMrPI6+kFXwXPObTDTthEYzi6kFwUGfUMFIGilus8i5fG9JwfgkPChoZmvJ9B8Msrpfqc+9vhiEHltRvOt5mkNjMfWMH7YzsXR4Yy1/TWAHRbgRq8KqphmISCl6fvmUvOSQ4HdUSI1mbi39lBYMRUTEH6j0adfNf8F5NWt8ypfgCIU2rQW3AYOlsFYl/5EFo6NIi/baV+rob+NrV1SiXXkHyToqh0GNDOYe94jOorwfFTW0nYR+de5q9w9ZgeF5Pz8VXPYcBT4XtRBBwe+tJZJtetgECHvhNcNzlkSYdjXdPhfs1RXJWeFiprVynHevqAoX+SMxS6vAMTurQza98P3FjHzG+MkfzEUI7UPoHMNaM8k3iEzl1wJw8ffMbaOGRwX0sfd4X5Tzh+NPv9aRY/DSOiP5oWKa3eLa/KjaCmuOiRNjQh/LsEwHJKDEXj8G+WKejYaIsBFQHXBOfExiea+dKm/QiJgyatxJZ X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98364896-cc4b-41fb-0dfb-08dafc9b28ce X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:36.2319 (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: cuREX2HtdDCE2JMoM/5Bfi/p68W0poRGWYpLumIMFAzElM+2tjZjzRlfs6uZLr5aHnVVs/5vbwDBeO5p3hDP7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 6d950d1..8fdbd81 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -21,13 +21,33 @@ #include #include #include +#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) { @@ -346,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, @@ -675,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 Sun Jan 22 17:07:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kaher X-Patchwork-Id: 13111538 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 E942FC25B4E for ; Sun, 22 Jan 2023 17:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231528AbjAVRIJ (ORCPT ); Sun, 22 Jan 2023 12:08:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbjAVRIH (ORCPT ); Sun, 22 Jan 2023 12:08:07 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11012003.outbound.protection.outlook.com [52.101.63.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC24126EE; Sun, 22 Jan 2023 09:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O8ugY3d/xroG5esZm9hCwsKpl2JBkfGvuS8cESE/58s71TbqJ2pp/Rnfz+K5XFvamKCGFZCP87Z94GjBxHiSL/ctb0dmtzfNSvCOu57CeDPY3WDK8WH95vb9Fsc6gSbsjquf1oEUqdaVw5i2Jlad7IV7X2p+wdPYG9oE1yo8gU5b8pC/PvuFWXZ8HJWOJt+nbwE8Mr7Vn1dT9HR+2RuM65kwSOqgkR/be25QwH2MrPcQZXuSsrKiUx/gqyvBoeWZhHn6Z6VZyOxdx5klwoQUA5ubj7va7DhAe1m0O3G/asZ6ojtiHAH34JfJqusD21jaiMxoDI74JOMwrDVp47xfuw== 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=NXZMDF8bnMkUbDpMzT7eWhMiDEY+Fcv0O10N/nhU984=; b=H2mE/5SphUzVlGAyd9OgVqsyeNZvNikEnJde/zIH9tsFx6AJ4hK+XcezaNmGMIKC61ne5NFBAPN4Zhayn1twCBfQOYyu/w28GZT2diCk3g6OfAMWUtqv8I7MgYqa/D4dnZE6suioPJ5L0wPc0JTFZEkVHm4bskJ9z9zTASCoikNyYHwZuYBY9D94TRpiJSIQcvaWGueod7qvXL6ID1bpl2BeP1N4rMmDRnWrglwZf1ypo4fbXO+1agZseAgwliescZaTQS6t3exrNIC2Obf8JmSGamzGPaXgQRTwgQ6OM6U/ivtt5nROd24ZekfnqC5bmAZUyjsKWmKgkBV7OWOFrw== 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=NXZMDF8bnMkUbDpMzT7eWhMiDEY+Fcv0O10N/nhU984=; b=sxdRRXQV9aTd/AMPT10nKpHuhAmUGJ+F9tbWWuUSdszzC8m/NoTBbqgQ0bcT9K9Y4AQZhTCFYBKKqncPb54aVEQnaRvkt3+7SvznN/UYmw36iHqS2Byav38eaLTU4gCdOLXbTW/t3KLsvhFx+ixW0IfUFgDWzQDg90KSrju+bx4= 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 MW4PR05MB9322.namprd05.prod.outlook.com (2603:10b6:303:1ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Sun, 22 Jan 2023 17:07:37 +0000 Received: from PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0]) by PH0PR05MB8703.namprd05.prod.outlook.com ([fe80::e710:a9a8:3bc8:d0b0%3]) with mapi id 15.20.6002.031; Sun, 22 Jan 2023 17:07:37 +0000 From: Ajay Kaher To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@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 8/8] eventfs: moving tracing/events to eventfs Date: Sun, 22 Jan 2023 22:37:07 +0530 Message-Id: <1674407228-49109-8-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com> References: <1674407228-49109-1-git-send-email-akaher@vmware.com> X-ClientProxiedBy: SJ0PR05CA0074.namprd05.prod.outlook.com (2603:10b6:a03:332::19) To PH0PR05MB8703.namprd05.prod.outlook.com (2603:10b6:510:bd::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB8703:EE_|MW4PR05MB9322:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b7aafc8-6cfb-4577-b204-08dafc9b295a 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: 0Gad1UteF6BsLvJzcc7RyZy9jBechqmWa4oh5Hjm++v+Ul5mdEMS1MrMufnYm+y2U5eTO4firkNRC+epYYoBN3PFYLW3Kr38hpoUfNJ+dZtfxnygHerXCu7jAI/dfcQHJ1EEKb6/uParEeiYf+M4dLwl9mqGIwQmfis9GFrUiTCt5EAQbQkr9f2Hwq0ft2QZHV2/1ow8t0yrii2SAsa4Pr1F7c9ZeNL2BmM2ydD4qUk8V8CfF5T1znGNCvcjdHYzel3fdK8lcx1bW14Tnk9ofUwdOMalt/dtkM4yVtmZuOGSG+S/nP/5ijSKGNkRMceJtTMsPUH/x1XZh/R7MKVz7n9704Gc62vKezZYFTa/Ip7bEORLjI0oyA8CB03JmUJmN+2tY4eCKtKwq7KyxwyVntpMMduRrf5XqUwpU/GF8A4BbQVkSxZpUzeuqofW5EoQ6tP95+PxAtGaM3d9wv4Iax8rrAS4ld7mCaYdrd7X9pp7upAOe0fYOTWk8lkuy12ypl/SZQCqBD6sj9gHE2PteGeTBti0IslxBfPyVl+PiN+9tvdCnO3h4yESwEdweJyoGvIZ/9pP9Im/GCuKlqcBaMZ5pNY01G2xDLh6947mS/vcnsBl6XymOjXE9+t0ap/E9EOS1bwd9V/TfupXVXJtnlmCMZljOOP7Tfy+Bv1FHDuYf7KYv6VEvv6JMMKCM/9xQ7jREch6dlQ+/BRI1T4D+A== 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(366004)(451199015)(36756003)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(6512007)(41300700001)(186003)(66946007)(26005)(2906002)(86362001)(83380400001)(6506007)(107886003)(316002)(6666004)(52116002)(6486002)(5660300002)(8936002)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l2j5hCA1ww9oXQiU/kM7TzoGe6GnLB6z9Z8bF7S0rvKbhcWKj8zEzKIaac4gCbhO4EmhjCqMN33DNC3Rmrf9b4i/3Tm2q5y9JPG3QIp0N01JNvUgXuDjVo8kDf7DlCRA1lL4/1P4kKbe3VUNpsX2uPy/bUsYsO1D1ZD/ey+XGQJjNIljsnozPK/GW/Z9AMtl7Yvc1fLaKLScD2w9RwBMGSjFqj4zT65SvIc7TjnQSYR+H1C0ai0vzphVY261YJQq5gKAXd6NJrPxyfv27ZNOoa4OLOdO6oN7eUT4GTj9jwCLIok/vVD1EGEu57U31gu17zZGtzhhGNCdVicMFHiwZxtNXoIL8ZK/c4oTJrzjvpOFUsAFOKs4Uq4x2tME07NJ9q4EUpjvoh8UCr+uq74hRV7L4i5yOjQ01i0Vu71YUsYBx1te/ETKmNXc2CEsDrZkcUaew6dnafuls60IrhYb4ndLzpY5r1ueoJrS9FmzhFD9nmRVUuzGfQwEXtxt8u8QWWp/68r3O2bP2t56sgxNeRcNcZ24AXFK7tuYuBhJf0ZIExCHXUJQRylgA+63tC/B8AUzqHqEl8pfhx3tKaPaKAhvooIsUXEkVKUJKBycukzIly5Wlc6GoDbC0IcPb3ij9YRxik2uVuDsJp3KojsxfsZiLzX/x9YJY1lVhBpEduYz/77SPI0Z6tJWA0a5YTsDl5GcRJ+vj5aFPHYodE+RMwBI+olfRnhtbifF8wthKC9EeWDHGc6+gqi/liuCvRdHDNwaOqQRD0avMqHSujjoDVY74JxURQDGAMO7HBOn2n4U3DDpMQzR8UzHMJMmHZztSPKdrIYKoV+EDKqZ9d6O1UbZGu5go6sh1LT91ciDLQqEg5CeqQ/wpH9rFpKEBAdJPNtJ8DIyD1cpCaFb/J0WEya8VeKMYwpiqHfOv27DgXSKBPnvSrAz1//Yzme7kx3GhqZ9aRsqIFFomloNZm2z9SHt0npu0hLyxFvQ7Lbb1YfiYz+a4br9uqk3jQQZlSJzd/QMEOjdJycDO2Sx/rB7WMq9AxnAVmygE8rSS8Ktt26a2PwHR0Ec8JrNafWVOY9z5uxrUpneyJ981xMoV5Kpgj/Y51vvoqaakVm0t1MB+3MnoEhfzwu4os2z8ByYT8AGj1pENy1M9w+RY/4nGZATiKDlJRHzHBh40UJ2U3xmTCfXxd9o0YSIQotmyIAILJWaUHWzMBwG2b/bl589puoIKq4Cvo05HvCa0/XL8+VKtbh8Ew57hDgaGfsDBPBL4BuPRKtf8Dm1r42GUY7P3UpiKx7ZM3Cy24ODBjQb0agt3vkV+FIfT8YA8j5ok3YxdAlcZb3A5Rr2rzleEa2LR2/WS84IgCUHkiNoaS4rxN6nZRgSDp3683XpBpXq9/T5iKcfJog5u2C4PZa26AEDTMMBEGzLQXg9ExtUcEPUkVIEt4wI0RF2io/nj2g2FJj6xMu6Xx0NJp6J8+K9qb2cJkGjIAqkpJDgQLIb2ImPlfwCGTdwBSKULmt0/CaPgQeidGGgRyMMGiSmYyiS3xVhzeL7nyDVH1xOjogQxizQB9qE+BYqgvAFGi0CmmEb+/UavIwd X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b7aafc8-6cfb-4577-b204-08dafc9b295a X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8703.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 17:07:37.2942 (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: 7fSD3B+sKD52gA7+z37eoJMCQVAtM/x+uvAwhxwRCAjRH+lBaDI4IGgbCed0g1KtdnIVXc54ix7+f3oq6DapNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR05MB9322 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 --- fs/tracefs/inode.c | 18 +++++++++++++ include/linux/trace_events.h | 1 + kernel/trace/trace.h | 2 +- kernel/trace/trace_events.c | 64 +++++++++++++++++++++++--------------------- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 8fdbd81..44b4344 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); +} + +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 4342e99..0a810ab 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -634,6 +634,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 e46a492..97d2e35 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1302,7 +1302,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 33e0b4f..b441f6a 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -973,7 +973,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); } @@ -994,7 +995,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); @@ -2277,13 +2279,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) { @@ -2291,7 +2293,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; } } @@ -2315,8 +2317,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); + if (IS_ERR(dir->ef)) { pr_warn("Failed to create system directory %s\n", name); __put_system(system); goto out_free; @@ -2331,22 +2333,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); @@ -2399,6 +2401,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; @@ -2408,26 +2411,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); + 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 @@ -2443,27 +2446,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 @@ -3616,21 +3619,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); + 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 */ @@ -3643,11 +3647,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);