public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ajay Kaher <akaher@vmware.com>
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 <akaher@vmware.com>
Subject: [PATCH 3/8] eventfs: adding eventfs file add functions
Date: Sun, 22 Jan 2023 22:37:02 +0530	[thread overview]
Message-ID: <1674407228-49109-3-git-send-email-akaher@vmware.com> (raw)
In-Reply-To: <1674407228-49109-1-git-send-email-akaher@vmware.com>

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 <akaher@vmware.com>
Co-developed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Tested-by: Ching-lin Yu <chinglinyu@google.com>
---
 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);
-- 
2.7.4


  parent reply	other threads:[~2023-01-22 17:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22 17:07 [PATCH 1/8] eventfs: introducing struct tracefs_inode Ajay Kaher
2023-01-22 17:07 ` [PATCH 2/8] eventfs: adding eventfs dir add functions Ajay Kaher
2023-01-23  2:06   ` kernel test robot
2023-01-23  7:44   ` kernel test robot
2023-01-23 12:04   ` Dan Carpenter
2023-01-22 17:07 ` Ajay Kaher [this message]
2023-01-22 17:07 ` [PATCH 4/8] eventfs: adding eventfs file, directory remove function Ajay Kaher
2023-01-22 17:07 ` [PATCH 5/8] eventfs: adding functions to create eventfs files and directories Ajay Kaher
2023-01-22 18:45   ` kernel test robot
2023-01-22 20:09   ` kernel test robot
2023-01-23  9:26   ` kernel test robot
2023-01-22 17:07 ` [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions Ajay Kaher
2023-01-22 19:38   ` kernel test robot
2023-01-23 11:49   ` kernel test robot
2023-01-23 16:54   ` Steven Rostedt
2023-01-22 17:07 ` [PATCH 7/8] eventfs: creating tracefs_inode_cache Ajay Kaher
2023-01-22 17:07 ` [PATCH 8/8] eventfs: moving tracing/events to eventfs Ajay Kaher
2023-01-22 21:00   ` kernel test robot
2023-01-23 14:14   ` kernel test robot
2023-01-31  8:08   ` kernel test robot
2023-01-22 17:07 ` [PATCH 0/8] tracing: introducing eventfs Ajay Kaher
2023-01-23 16:51   ` Steven Rostedt
2023-01-29 18:07     ` Ajay Kaher
2023-01-30  6:43       ` Nadav Amit
2023-03-28 22:47   ` Steven Rostedt
2023-03-29 18:00     ` Ajay Kaher
2023-01-23  5:41 ` [PATCH 1/8] eventfs: introducing struct tracefs_inode kernel test robot
2023-01-23  6:01 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1674407228-49109-3-git-send-email-akaher@vmware.com \
    --to=akaher@vmware.com \
    --cc=amakhalov@vmware.com \
    --cc=chinglinyu@google.com \
    --cc=er.ajay.kaher@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namit@vmware.com \
    --cc=rostedt@goodmis.org \
    --cc=srivatsa@csail.mit.edu \
    --cc=srivatsab@vmware.com \
    --cc=tkundu@vmware.com \
    --cc=vsirnapalli@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox