linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 7/7] tracing: Have mkdir and rmdir be part of tracefs
Date: Mon, 9 Feb 2015 15:07:22 +0900	[thread overview]
Message-ID: <20150209060722.GC30788@sejong> (raw)
In-Reply-To: <20150204143756.006343748@goodmis.org>

On Wed, Feb 04, 2015 at 09:34:27AM -0500, Steven Rostedt wrote:
> +static int tracefs_syscall_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode)
> +{
> +	char *name;
> +	int ret;
> +
> +	name = get_dname(dentry);
> +	if (!name)
> +		return -ENOMEM;
> +
> +	/*
> +	 * The mkdir call can call the generic functions that create

	   The mkdir can call ... ?


> +	 * the files within the tracefs system. It is up to the individual
> +	 * mkdir routine to handle races.
> +	 */
> +	mutex_unlock(&inode->i_mutex);
> +	ret = tracefs_ops.mkdir(name);
> +	mutex_lock(&inode->i_mutex);
> +
> +	kfree(name);
> +
> +	return ret;
> +}
> +
> +static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentry)
> +{
> +	char *name;
> +	int ret;
> +
> +	name = get_dname(dentry);
> +	if (!name)
> +		return -ENOMEM;
> +
> +	/*
> +	 * The rmdir call can call the generic functions that create

Ditto.


> +	 * the files within the tracefs system. It is up to the individual
> +	 * rmdir routine to handle races.
> +	 * This time we need to unlock not only the parent (inode) but
> +	 * also the directory that is being deleted.
> +	 */
> +	mutex_unlock(&inode->i_mutex);
> +	mutex_unlock(&dentry->d_inode->i_mutex);
> +
> +	ret = tracefs_ops.rmdir(name);
> +
> +	mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
> +	mutex_lock(&dentry->d_inode->i_mutex);
> +
> +	kfree(name);
> +
> +	return ret;
> +}
> +

[SNIP]
> +/**
> + * tracefs_create_instance_dir - create the tracing instances directory
> + * @name: The name of the instances directory to create
> + * @parent: The parent directory that the instances directory will exist
> + * @mkdir: The function to call when a mkdir is performed.
> + * @rmdir: The function to call when a rmdir is performed.
> + *
> + * Only one instances directory is allowed.
> + *
> + * The instances directory is special as it allows for mkdir and rmdir to
> + * to be done by userspace. When a mkdir or rmdir is performed, the inode
> + * locks are released and the methhods passed in (@mkdir and @rmdir) are

s/methhods/methods/

Thanks,
Namhyung


> + * called without locks and with the name of the directory being created
> + * within the instances directory.
> + *
> + * Returns the dentry of the instances directory.
> + */
> +struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent,
> +					  int (*mkdir)(const char *name),
> +					  int (*rmdir)(const char *name))
> +{
> +	struct dentry *dentry;
> +
> +	/* Only allow one instance of the instances directory. */
> +	if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir))
>  		return NULL;
>  
> -	inode = tracefs_get_inode(dentry->d_sb);
> -	if (unlikely(!inode))
> -		return failed_creating(dentry);
> +	dentry = __create_dir(name, parent, &tracefs_dir_inode_operations);
> +	if (!dentry)
> +		return NULL;
>  
> -	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
> -	inode->i_op = &simple_dir_inode_operations;
> -	inode->i_fop = &simple_dir_operations;
> +	tracefs_ops.mkdir = mkdir;
> +	tracefs_ops.rmdir = rmdir;
>  
> -	/* 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);
> +	return dentry;
>  }

  reply	other threads:[~2015-02-09  6:09 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
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 [this message]
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=20150209060722.GC30788@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;
as well as URLs for NNTP newsgroup(s).