[PATCH 24/25] sysfs: Implement sysfs_delete_link and sysfs_rename_link

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric W. Biederman
Date: Tuesday, August 7, 2007 - 2:36 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>
---
 fs/sysfs/symlink.c    |   31 +++++++++++++++++++++++++++++++
 include/linux/sysfs.h |   18 ++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 99aaf6f..6476b8f 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -106,6 +106,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.
@@ -116,6 +131,22 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
 	sysfs_hash_and_remove(kobj, kobj->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 28c497e..90eb35e 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -129,6 +129,13 @@ sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * n
 extern void
 sysfs_remove_link(struct kobject *, const char * name);
 
+extern int
+sysfs_rename_link(struct kobject *kobj, struct kobject *target,
+			const char *old_name, const char *new_name);
+
+extern void
+sysfs_delete_link(struct kobject *dir, struct kobject *targ, const char *name);
+
 int __must_check sysfs_create_bin_file(struct kobject *kobj,
 					struct bin_attribute *attr);
 void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
@@ -204,6 +211,17 @@ static inline void sysfs_remove_link(struct kobject * k, 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_bin_file(struct kobject * k, struct bin_attribute * a)
 {
-- 
1.5.1.1.181.g2de0

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

Messages in current thread:
[PATCH 2/5] sysfs: simplify sysfs_rename_dir(), Tejun Heo, (Thu Aug 2, 5:38 am)
[PATCH 0/25] Sysfs cleanups &amp; tagged directory support, Eric W. Biederman, (Tue Aug 7, 2:06 pm)
[PATCH 02/25] sysfs: Remove sysfs_instantiate, Eric W. Biederman, (Tue Aug 7, 2:08 pm)
[PATCH 03/25] sysfs: Use kill_anon_super, Eric W. Biederman, (Tue Aug 7, 2:10 pm)
[PATCH 04/25] sysfs: Make sysfs_mount static, Eric W. Biederman, (Tue Aug 7, 2:11 pm)
[PATCH 06/25] sysfs: Simplify readdir., Eric W. Biederman, (Tue Aug 7, 2:13 pm)
[PATCH 07/25] sysfs: Rewrite sysfs_drop_dentry., Eric W. Biederman, (Tue Aug 7, 2:14 pm)
[PATCH 08/25] sysfs: Implement __sysfs_get_dentry, Eric W. Biederman, (Tue Aug 7, 2:16 pm)
[PATCH 10/25] sysfs: Rewrite sysfs_get_dentry in terms of ..., Eric W. Biederman, (Tue Aug 7, 2:18 pm)
[PATCH 11/25] sysfs: Remove s_dentry, Eric W. Biederman, (Tue Aug 7, 2:19 pm)
[PATCH 12/25] sysfs: Introduce sysfs_rename_mutex, Eric W. Biederman, (Tue Aug 7, 2:21 pm)
[PATCH 13/25] sysfs: Simply sysfs_get_dentry, Eric W. Biederman, (Tue Aug 7, 2:22 pm)
[PATCH 14/25] sysfs: Don't use lookup_one_len_kern, Eric W. Biederman, (Tue Aug 7, 2:23 pm)
[PATCH 15/25] vfs: Remove lookup_one_len_kern, Eric W. Biederman, (Tue Aug 7, 2:25 pm)
[PATCH 16/25] sysfs: Support for preventing unmounts., Eric W. Biederman, (Tue Aug 7, 2:26 pm)
[PATCH 17/25] sysfs: Rewrite rename in terms of sysfs dirents, Eric W. Biederman, (Tue Aug 7, 2:27 pm)
[PATCH 19/25] sysfs: sysfs_get_dentry add a sb parameter, Eric W. Biederman, (Tue Aug 7, 2:29 pm)
[PATCH 20/25] sysfs: Rename Support multiple superblocks, Eric W. Biederman, (Tue Aug 7, 2:31 pm)
[PATCH 24/25] sysfs: Implement sysfs_delete_link and sysfs ..., Eric W. Biederman, (Tue Aug 7, 2:36 pm)
Re: [PATCH 02/25] sysfs: Remove sysfs_instantiate, Tejun Heo, (Tue Aug 7, 11:37 pm)
Re: [PATCH 03/25] sysfs: Use kill_anon_super, Tejun Heo, (Tue Aug 7, 11:50 pm)
Re: [PATCH 04/25] sysfs: Make sysfs_mount static, Tejun Heo, (Tue Aug 7, 11:51 pm)
Re: [PATCH 06/25] sysfs: Simplify readdir., Tejun Heo, (Wed Aug 8, 12:12 am)
Re: [PATCH 07/25] sysfs: Rewrite sysfs_drop_dentry., Tejun Heo, (Wed Aug 8, 12:35 am)
Re: [PATCH 11/25] sysfs: Remove s_dentry, Tejun Heo, (Wed Aug 8, 12:46 am)
Re: [PATCH 0/25] Sysfs cleanups &amp; tagged directory support, Eric W. Biederman, (Wed Aug 8, 12:47 am)
Re: [PATCH 0/25] Sysfs cleanups &amp; tagged directory support, Eric W. Biederman, (Wed Aug 8, 12:57 am)
Re: [PATCH 13/25] sysfs: Simply sysfs_get_dentry, Tejun Heo, (Wed Aug 8, 1:24 am)
Re: [PATCH 12/25] sysfs: Introduce sysfs_rename_mutex, Eric W. Biederman, (Wed Aug 8, 1:28 am)
Re: [PATCH 15/25] vfs: Remove lookup_one_len_kern, Tejun Heo, (Wed Aug 8, 1:39 am)
Re: [PATCH 14/25] sysfs: Don't use lookup_one_len_kern, Eric W. Biederman, (Wed Aug 8, 8:26 am)
Re: [PATCH 17/25] sysfs: Rewrite rename in terms of sysfs ..., Eric W. Biederman, (Wed Aug 8, 8:32 am)
Re: [PATCH 19/25] sysfs: sysfs_get_dentry add a sb parameter, Eric W. Biederman, (Wed Aug 8, 8:34 am)
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks, Eric W. Biederman, (Wed Aug 8, 8:45 am)
Re: alternative approached at tagged nodes, Tejun Heo, (Wed Aug 8, 9:31 am)
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks, Eric W. Biederman, (Wed Aug 8, 9:35 am)
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks, Eric W. Biederman, (Wed Aug 8, 9:55 am)