[PATCH 11/15] sysfs: Implement sysfs_delete_link and sysfs_rename_link

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric W. Biederman
Date: Thursday, July 3, 2008 - 6:18 pm

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>
Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
---
 fs/sysfs/symlink.c    |   31 +++++++++++++++++++++++++++++++
 include/linux/sysfs.h |   17 +++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index de9a5c0..ed9c52c 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -80,6 +80,21 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
 }
 
 /**
+ *	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 * kobj, const char * name)
 	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)
 {
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 8fa97f0..c3a30ce 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -112,6 +112,12 @@ int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
 				   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,
@@ -198,6 +204,17 @@ 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 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)
 {
-- 
1.5.3.rc6.17.g1911

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Thu Jun 26, 1:21 pm)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Mon Jun 30, 11:56 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Tue Jul 1, 12:50 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Tue Jul 1, 2:20 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Tue Jul 1, 5:30 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Tue Jul 1, 8:53 pm)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Wed Jul 2, 9:49 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Wed Jul 2, 10:11 pm)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Thu Jul 3, 5:27 am)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Thu Jul 3, 12:57 pm)
Re: [PATCH 06/11] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Thu Jul 3, 1:08 pm)
[PATCH 00/15] sysfs support for namespaces, Eric W. Biederman, (Thu Jul 3, 5:48 pm)
[PATCH 02/15] sysfs: Support for preventing unmounts., Eric W. Biederman, (Thu Jul 3, 6:07 pm)
[PATCH 03/15] sysfs: sysfs_get_dentry add a sb parameter, Eric W. Biederman, (Thu Jul 3, 6:08 pm)
[PATCH 04/15] sysfs: Implement __sysfs_get_dentry, Eric W. Biederman, (Thu Jul 3, 6:09 pm)
[PATCH 05/15] sysfs: Rename Support multiple superblocks, Eric W. Biederman, (Thu Jul 3, 6:10 pm)
[PATCH 06/15] Introduce sysfs_sd_setattr and fix sysfs_chmod, Eric W. Biederman, (Thu Jul 3, 6:11 pm)
[PATCH 08/15] sysfs: Make sysfs_mount static once again., Eric W. Biederman, (Thu Jul 3, 6:14 pm)
[PATCH 11/15] sysfs: Implement sysfs_delete_link and sysfs ..., Eric W. Biederman, (Thu Jul 3, 6:18 pm)
Re: [PATCH 00/15] sysfs support for namespaces, Eric W. Biederman, (Thu Jul 3, 6:27 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Fri Jul 4, 6:31 am)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Fri Jul 4, 2:49 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Fri Jul 4, 3:00 pm)
Re: [PATCH 00/15] sysfs support for namespaces, Eric W. Biederman, (Sat Jul 5, 9:42 pm)
Re: [PATCH 00/15] sysfs support for namespaces, Cornelia Huck, (Mon Jul 7, 4:41 am)
Re: [PATCH 00/15] sysfs support for namespaces, Eric W. Biederman, (Mon Jul 7, 5:22 am)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Sun Jul 13, 6:54 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Tue Jul 15, 10:41 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Tue Jul 15, 11:32 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Wed Jul 16, 12:07 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Wed Jul 16, 2:09 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Fri Jul 18, 1:19 pm)
Re: [PATCH 12/15] driver core: Implement tagged directory ..., Eric W. Biederman, (Sat Aug 2, 11:59 pm)
Re: [PATCH 09/15] sysfs: Implement sysfs tagged directory ..., Eric W. Biederman, (Tue Aug 19, 11:58 pm)
[PATCH 0/8] sysfs namespace support, Eric W. Biederman, (Wed Aug 20, 11:31 pm)
[PATCH 1/8] sysfs: Implement sysfs tagged directory support., Eric W. Biederman, (Wed Aug 20, 11:33 pm)
[PATCH 2/8] sysfs: Merge sysfs_rename_dir and sysfs_move_dir, Eric W. Biederman, (Wed Aug 20, 11:34 pm)
[PATCH 3/8] sysfs: Implement sysfs_delete_link and sysfs_r ..., Eric W. Biederman, (Wed Aug 20, 11:35 pm)
[PATCH 5/8] sysfs: Remove sysfs_create_link_nowarn, Eric W. Biederman, (Wed Aug 20, 11:36 pm)
Re: [PATCH 0/8] sysfs namespace support, David Miller, (Wed Aug 20, 11:37 pm)
[PATCH 4/8] driver core: Implement tagged directory suppor ..., Eric W. Biederman, (Wed Aug 20, 11:37 pm)
[PATCH 7/8] netns: Enable tagging for net_class directorie ..., Eric W. Biederman, (Wed Aug 20, 11:39 pm)
[PATCH 8/8] sysfs: user namespaces: fix bug with clone(CLO ..., Eric W. Biederman, (Wed Aug 20, 11:40 pm)
Re: [PATCH 1/8] sysfs: Implement sysfs tagged directory su ..., Eric W. Biederman, (Mon Oct 13, 8:20 pm)