linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	Kay Sievers <kay.sievers@vrfy.org>,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Benjamin LaHaise <bcrl@lhnet.ca>,
	Benjamin Thery <benjamin.thery@bull.net>,
	Daniel Lezcano <dlezcano@fr.ibm.com>,
	"Eric W. Biederman" <ebiederm@aristanetworks.com>
Subject: Re: [PATCH 4/7] sysfs: Implement sysfs_rename_link
Date: Tue, 12 Jan 2010 11:30:30 -0600	[thread overview]
Message-ID: <20100112173030.GA13506@us.ibm.com> (raw)
In-Reply-To: <1263241315-19499-4-git-send-email-ebiederm@xmission.com>

Quoting Eric W. Biederman (ebiederm@xmission.com):
> From: Eric W. Biederman <ebiederm@xmission.com>
> 
> Because of rename ordering problems we occassionally give false
> warnings about invalid sysfs operations.  So using sysfs_rename
> create a sysfs_rename_link function that doesn't need strange
> workarounds.

It looks nice and clean esp compared to the code you're replacing.
OTOH I do wonder whether your sysfs_type(sd) != SYSFS_KOBJ_LINK check
will catch unexpected ways that device_rename() was being called.
Shouldn't, I realize, since sysfs_create_link() always sets SYSFS_KOBJ_LINK,
but the check wasn't there before, so stranger things have happened.

> Cc: Benjamin Thery <benjamin.thery@bull.net>
> Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
> Cc: Tejun Heo <tj@kernel.org>
> Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>

Acked-by: Serge Hallyn <serue@us.ibm.com>

> ---
>  fs/sysfs/symlink.c    |   38 ++++++++++++++++++++++++++++++++++++++
>  include/linux/sysfs.h |    9 +++++++++
>  2 files changed, 47 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
> index c5eff49..1b9a3a1 100644
> --- a/fs/sysfs/symlink.c
> +++ b/fs/sysfs/symlink.c
> @@ -123,6 +123,44 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
>  	sysfs_hash_and_remove(parent_sd, name);
>  }
> 
> +/**
> + *	sysfs_rename_link - rename symlink in object's directory.
> + *	@kobj:	object we're acting for.
> + *	@targ:	object we're pointing to.
> + *	@old:	previous name of the symlink.
> + *	@new:	new name of the symlink.
> + *
> + *	A helper function for the common rename symlink idiom.
> + */
> +int sysfs_rename_link(struct kobject *kobj, struct kobject *targ,
> +			const char *old, const char *new)
> +{
> +	struct sysfs_dirent *parent_sd, *sd = NULL;
> +	int result;
> +
> +	if (!kobj)
> +		parent_sd = &sysfs_root;
> +	else
> +		parent_sd = kobj->sd;
> +
> +	result = -ENOENT;
> +	sd = sysfs_get_dirent(parent_sd, old);
> +	if (!sd)
> +		goto out;
> +
> +	result = -EINVAL;
> +	if (sysfs_type(sd) != SYSFS_KOBJ_LINK)
> +		goto out;
> +	if (sd->s_symlink.target_sd->s_dir.kobj != targ)
> +		goto out;
> +
> +	result = sysfs_rename(sd, parent_sd, new);
> +
> +out:
> +	sysfs_put(sd);
> +	return result;
> +}
> +
>  static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
>  				 struct sysfs_dirent *target_sd, char *path)
>  {
> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> index cfa8308..e322573 100644
> --- a/include/linux/sysfs.h
> +++ b/include/linux/sysfs.h
> @@ -110,6 +110,9 @@ int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
>  					  const char *name);
>  void sysfs_remove_link(struct kobject *kobj, const char *name);
> 
> +int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
> +			const char *old_name, const char *new_name);
> +
>  int __must_check sysfs_create_group(struct kobject *kobj,
>  				    const struct attribute_group *grp);
>  int sysfs_update_group(struct kobject *kobj,
> @@ -203,6 +206,12 @@ static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
>  {
>  }
> 
> +static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
> +				    const char *old_name, const char *new_name)
> +{
> +	return 0;
> +}
> +
>  static inline int sysfs_create_group(struct kobject *kobj,
>  				     const struct attribute_group *grp)
>  {
> -- 
> 1.6.5.2.143.g8cc62

  parent reply	other threads:[~2010-01-12 17:30 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 20:16 [PATCH 0/7] General sysfs enhancements Eric W. Biederman
2010-01-11 20:21 ` [PATCH 1/7] sysfs: Serialize updates to the vfs inode Eric W. Biederman
2010-01-12  5:41   ` Serge E. Hallyn
2010-01-11 20:21 ` [PATCH 2/7] sysfs: Pack sysfs_dirent more tightly Eric W. Biederman
2010-01-12  0:41   ` Tejun Heo
2010-01-11 20:21 ` [PATCH 3/7] sysfs: Keep an nlink count on sysfs directories Eric W. Biederman
2010-01-12  0:46   ` Tejun Heo
2010-01-12  0:53     ` Benjamin LaHaise
2010-01-12  1:06       ` Eric W. Biederman
2010-01-12  1:12         ` Benjamin LaHaise
2010-01-12  1:23           ` Eric W. Biederman
2010-01-12  6:22         ` Tejun Heo
2010-01-12 15:49       ` Valdis.Kletnieks
2010-01-12  1:02     ` Eric W. Biederman
2010-01-12  5:56   ` Serge E. Hallyn
2010-01-12  8:30     ` Eric W. Biederman
2010-01-12 12:41   ` Cornelia Huck
2010-01-12 15:34     ` Eric W. Biederman
2010-01-11 20:21 ` [PATCH 4/7] sysfs: Implement sysfs_rename_link Eric W. Biederman
2010-01-12  6:24   ` Tejun Heo
2010-01-12 17:30   ` Serge E. Hallyn [this message]
2010-01-11 20:21 ` [PATCH 5/7] driver core: Use sysfs_rename_link in device_rename Eric W. Biederman
2010-01-12  6:25   ` Tejun Heo
2010-01-12 17:34   ` Serge E. Hallyn
2010-01-11 20:21 ` [PATCH 6/7] sysfs: Pass super_block to sysfs_get_inode Eric W. Biederman
2010-01-12 17:43   ` Serge E. Hallyn
2010-01-11 20:21 ` [PATCH 7/7] sysfs: Kill unused sysfs_sb variable Eric W. Biederman
2010-01-12 17:43   ` Serge E. Hallyn
2010-01-15 21:37 ` [PATCH 0/7] General sysfs enhancements Greg KH
2010-02-13  3:20   ` [PATCH 0/6] " Eric W. Biederman
2010-02-13  3:22     ` [PATCH 1/6] sysfs: Serialize updates to the vfs inode Eric W. Biederman
2010-02-13  3:22     ` [PATCH 2/6] sysfs: Pack sysfs_dirent more tightly Eric W. Biederman
2010-02-13  3:22     ` [PATCH 3/6] sysfs: Implement sysfs_rename_link Eric W. Biederman
2010-02-13  3:22     ` [PATCH 4/6] driver core: Use sysfs_rename_link in device_rename Eric W. Biederman
2010-02-13  3:22     ` [PATCH 5/6] sysfs: Pass super_block to sysfs_get_inode Eric W. Biederman
2010-02-13  3:22     ` [PATCH 6/6] sysfs: Kill unused sysfs_sb variable Eric W. Biederman

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=20100112173030.GA13506@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=bcrl@lhnet.ca \
    --cc=benjamin.thery@bull.net \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dlezcano@fr.ibm.com \
    --cc=ebiederm@aristanetworks.com \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=gregkh@suse.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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).