From: Namhyung Kim <namhyung@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [for-next][PATCH 3/7] tracefs: Add new tracefs file system
Date: Mon, 9 Feb 2015 14:56:19 +0900 [thread overview]
Message-ID: <20150209055619.GA30788@sejong> (raw)
In-Reply-To: <20150204143755.373406887@goodmis.org>
Hi Steve,
On Wed, Feb 04, 2015 at 09:34:23AM -0500, Steven Rostedt wrote:
> From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
>
> Add a separate file system to handle the tracing directory. Currently it
> is part of debugfs, but that is starting to show its limits.
>
> One thing is that in order to access the tracing infrastructure, you need
> to mount debugfs. As that includes debugging from all sorts of sub systems
> in the kernel, it is not considered advisable to mount such an all
> encompassing debugging system.
>
> Having the tracing system in its own file systems gives access to the
> tracing sub system without needing to include all other systems.
>
> Another problem with tracing using the debugfs system is that the
> instances use mkdir to create sub buffers. debugfs does not support mkdir
> from userspace so to implement it, special hacks were used. By controlling
> the file system that the tracing infrastructure uses, this can be properly
> done without hacks.
>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
[SNIP]
> +/**
> + * tracefs_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, or a directory (if you want
> + * to create a directory, the tracefs_create_dir() function is
> + * recommended to be used instead.)
> + *
> + * 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.
I cannot find where it returns -ENODEV. AFAICS we cannot call tracefs
functions if tracing was not enabled.
> + */
> +struct dentry *tracefs_create_file(const char *name, umode_t mode,
> + struct dentry *parent, void *data,
> + const struct file_operations *fops)
> +{
> + struct dentry *dentry;
> + struct inode *inode;
> +
> + if (!(mode & S_IFMT))
> + mode |= S_IFREG;
> + BUG_ON(!S_ISREG(mode));
> + dentry = start_creating(name, parent);
> +
> + if (IS_ERR(dentry))
> + return NULL;
> +
> + inode = tracefs_get_inode(dentry->d_sb);
> + if (unlikely(!inode))
> + return failed_creating(dentry);
> +
> + inode->i_mode = mode;
> + inode->i_fop = fops ? fops : &tracefs_file_operations;
> + inode->i_private = data;
> + d_instantiate(dentry, inode);
> + fsnotify_create(dentry->d_parent->d_inode, dentry);
> + return end_creating(dentry);
> +}
> +
> +/**
> + * tracefs_create_dir - create a directory in the tracefs filesystem
> + * @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 a directory in tracefs with the given name.
> + *
> + * 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. If an error occurs, %NULL will be returned.
> + *
> + * If tracing is not enabled in the kernel, the value -%ENODEV will be
> + * returned.
Ditto.
Thanks,
Namhyung
> + */
> +struct dentry *tracefs_create_dir(const char *name, struct dentry *parent)
> +{
> + struct dentry *dentry = start_creating(name, parent);
> + struct inode *inode;
> +
> + if (IS_ERR(dentry))
> + return NULL;
> +
> + inode = tracefs_get_inode(dentry->d_sb);
> + if (unlikely(!inode))
> + return failed_creating(dentry);
> +
> + inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
> + inode->i_op = &simple_dir_inode_operations;
> + inode->i_fop = &simple_dir_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 end_creating(dentry);
> +}
next prev parent reply other threads:[~2015-02-09 5:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 14:34 [for-next][PATCH 0/7] tracing: Add new filesystem tracefs Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 1/7] tracing: Only create tracer options files if directory exists Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 2/7] tracing: Create cmdline tracer options on tracing fs init Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 3/7] tracefs: Add new tracefs file system Steven Rostedt
2015-02-09 5:56 ` Namhyung Kim [this message]
2015-02-09 15:04 ` Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 4/7] tracing: Convert the tracing facility over to use tracefs Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 5/7] tracing: Automatically mount tracefs on debugfs/tracing Steven Rostedt
2015-02-09 6:00 ` Namhyung Kim
2015-02-09 15:06 ` Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 6/7] tracefs: Add directory /sys/kernel/tracing Steven Rostedt
2015-02-04 14:34 ` [for-next][PATCH 7/7] tracing: Have mkdir and rmdir be part of tracefs Steven Rostedt
2015-02-09 6:07 ` Namhyung Kim
2015-02-09 15:07 ` Steven Rostedt
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=20150209055619.GA30788@sejong \
--to=namhyung@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
--cc=viro@ZenIV.linux.org.uk \
/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