linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Thery <benjamin.thery@bull.net>
To: linux-kernel@vger.kernel.org
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Tejun Heo <htejun@gmail.com>, Greg Kroah-Hartman <gregkh@suse.de>,
	Al Viro <viro@ftp.linux.org.uk>,
	Daniel Lezcano <dlezcano@fr.ibm.com>,
	"Serge E. Hallyn" <serue@us.ibm.com>,
	Pavel Emelyanov <xemul@openvz.org>,
	netdev@vger.kernel.org, Benjamin Thery <benjamin.thery@bull.net>
Subject: [PATCH 07/11] sysfs: Implement sysfs_delete_link and sysfs_rename_link
Date: Tue, 06 May 2008 19:31:40 +0200	[thread overview]
Message-ID: <20080506173335.460883711@theryb.frec.bull.fr> (raw)
In-Reply-To: 20080506173030.653828076@theryb.frec.bull.fr

sysfs: Implement sysfs_delete_link and sysfs_rename_link

When removing a symlink sysfs_remove_link does not provide
enough information to figure out which tagged directory the symlink
falls in.  So I need sysfs_delete_link which is passed the target
of the symlink to delete.

Further half the time when we are removing a symlink the code is
actually renaming the symlink but not doing so explicitly because
we don't have a symlink rename method. So I have added sysfs_rename_link
as well.

Both of these functions now have enough information to find a symlink
in a tagged directory.  The only restriction is that they must be called
before the target kobject is renamed or deleted.  If they are called
later I loose track of which tag the target kobject was marked with
and can no longer find the old symlink to remove it.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Acked-by: Benjamin Thery <benjamin.thery@bull.net>
---
 fs/sysfs/symlink.c    |   31 +++++++++++++++++++++++++++++++
 include/linux/sysfs.h |   17 +++++++++++++++++
 2 files changed, 48 insertions(+)

Index: linux-vanilla/fs/sysfs/symlink.c
===================================================================
--- linux-vanilla.orig/fs/sysfs/symlink.c
+++ linux-vanilla/fs/sysfs/symlink.c
@@ -80,6 +80,21 @@ int sysfs_create_link(struct kobject * k
 }
 
 /**
+ *	sysfs_delete_link - remove symlink in object's directory.
+ *	@kobj:	object we're acting for.
+ *	@targ:	object we're pointing to.
+ *	@name:	name of the symlink to remove.
+ *
+ *	Unlike sysfs_remove_link sysfs_delete_link has enough information
+ *	to successfully delete symlinks in tagged directories.
+ */
+void sysfs_delete_link(struct kobject *kobj, struct kobject *targ,
+			const char *name)
+{
+	sysfs_hash_and_remove(targ, kobj->sd, name);
+}
+
+/**
  *	sysfs_remove_link - remove symlink in object's directory.
  *	@kobj:	object we're acting for.
  *	@name:	name of the symlink to remove.
@@ -97,6 +112,22 @@ void sysfs_remove_link(struct kobject * 
 	sysfs_hash_and_remove(kobj, 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)
+{
+	sysfs_delete_link(kobj, targ, old);
+	return sysfs_create_link(kobj, targ, new);
+}
+
 static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
 				 struct sysfs_dirent *target_sd, char *path)
 {
Index: linux-vanilla/include/linux/sysfs.h
===================================================================
--- linux-vanilla.orig/include/linux/sysfs.h
+++ linux-vanilla/include/linux/sysfs.h
@@ -111,6 +111,12 @@ int __must_check sysfs_create_link(struc
 				   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);
+
+void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
+			const char *name);
+
 int __must_check sysfs_create_group(struct kobject *kobj,
 				    const struct attribute_group *grp);
 int sysfs_update_group(struct kobject *kobj,
@@ -195,6 +201,17 @@ static inline void sysfs_remove_link(str
 {
 }
 
+static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
+				    const char *old_name, const char *new_name)
+{
+	return 0;
+}
+
+static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
+				     const char *name)
+{
+}
+
 static inline int sysfs_create_group(struct kobject *kobj,
 				     const struct attribute_group *grp)
 {

-- 

  parent reply	other threads:[~2008-05-06 17:40 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-06 17:30 [RESEND][PATCH 00/11] sysfs tagged directories Benjamin Thery
2008-05-06 17:30 ` [PATCH 01/11] sysfs: Support for preventing unmounts Benjamin Thery
2008-05-06 17:30 ` [PATCH 02/11] sysfs: sysfs_get_dentry add a sb parameter Benjamin Thery
2008-05-06 17:31 ` [PATCH 03/11] sysfs: Implement __sysfs_get_dentry Benjamin Thery
2008-05-06 17:31 ` [PATCH 04/11] sysfs: Rename Support multiple superblocks Benjamin Thery
2008-05-06 17:31 ` [PATCH 05/11] sysfs: sysfs_chmod_file handle " Benjamin Thery
2008-05-06 17:31 ` [PATCH 06/11] sysfs: Implement sysfs tagged directory support Benjamin Thery
2008-05-06 17:31 ` Benjamin Thery [this message]
2008-05-06 17:31 ` [PATCH 08/11] driver core: Implement tagged directory support for device classes Benjamin Thery
2008-05-06 17:32 ` [PATCH 09/11] netns: Enable tagging for net_class directories in sysfs Benjamin Thery
2008-05-06 17:32 ` [PATCH 10/11] avoid kobject name conflict with different namespaces Benjamin Thery
2008-05-07 18:49   ` Eric W. Biederman
2008-05-07 19:08     ` Greg KH
2008-05-07 20:54       ` Eric W. Biederman
2008-05-08  8:28         ` Cornelia Huck
2008-05-08 19:28           ` Eric W. Biederman
2008-05-09  5:35             ` Cornelia Huck
2008-05-09 18:16               ` Eric W. Biederman
2008-05-08 19:25       ` Eric W. Biederman
2008-05-08 21:30       ` [PATCH] wireless: Add missing locking to cfg80211_dev_rename Eric W. Biederman
2008-05-08 22:12         ` Serge E. Hallyn
2008-05-08 22:18         ` Johannes Berg
2008-05-08 21:41       ` [PATCH] Fix kobject_rename and !CONFIG_SYSFS Eric W. Biederman
2008-05-12 22:02         ` kobject: " Greg KH
2008-05-13  7:00           ` Eric W. Biederman
2008-05-13 14:25             ` Benjamin Thery
2008-05-13 16:44               ` Greg KH
2008-05-13 17:55                 ` [PATCH] Fix kobject_rename and !CONFIG_SYSFS v2 Eric W. Biederman
2008-05-13 18:23                   ` Randy.Dunlap
2008-05-13 20:43                     ` Eric W. Biederman
2008-05-13 20:16                   ` Greg KH
2008-05-13 20:45                     ` [PATCH] Fix kobject_rename and !CONFIG_SYSFS v3 Eric W. Biederman
2008-05-13 21:18                       ` Randy Dunlap
2008-05-14  4:39                         ` [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4 Eric W. Biederman
2008-05-14  5:03                           ` Andrew Morton
2008-05-14  9:01                             ` Eric W. Biederman
2008-05-14  9:20                               ` Andrew Morton
2008-05-14  9:51                                 ` Benjamin Thery
2008-05-14  9:56                                   ` Andrew Morton
2008-05-13 19:33                 ` kobject: Fix kobject_rename and !CONFIG_SYSFS Benjamin Thery 
2008-05-13 20:42                   ` Eric W. Biederman
2008-05-06 17:32 ` [PATCH 11/11] sysfs: user namespaces: add ns to user_struct Benjamin Thery
2008-05-06 19:03   ` Serge E. Hallyn
2008-05-06 17:53 ` [RESEND][PATCH 00/11] sysfs tagged directories Greg KH
2008-05-06 18:41   ` Benjamin Thery
2008-05-07 13:19   ` Daniel Lezcano
2008-05-07 13:47     ` Benjamin Thery
2008-05-14 15:07     ` Benjamin Thery
2008-06-06 15:46 [PATCH 00/11] sysfs tagged directories V5 Benjamin Thery
2008-06-06 15:48 ` [PATCH 07/11] sysfs: Implement sysfs_delete_link and sysfs_rename_link Benjamin Thery
2008-06-18 17:07 [PATCH 00/11] sysfs tagged directories V6 Benjamin Thery
2008-06-18 17:08 ` [PATCH 07/11] sysfs: Implement sysfs_delete_link and sysfs_rename_link Benjamin Thery
2008-06-23  2:13   ` Tejun Heo
2008-06-26 20:24     ` Eric W. Biederman
2008-06-29  3:35       ` Tejun Heo
2008-06-30  3:02         ` 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=20080506173335.460883711@theryb.frec.bull.fr \
    --to=benjamin.thery@bull.net \
    --cc=dlezcano@fr.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=serue@us.ibm.com \
    --cc=viro@ftp.linux.org.uk \
    --cc=xemul@openvz.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).