]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
sysfs: Implement sysfs_rename_link
authorEric W. Biederman <ebiederm@xmission.com>
Sat, 13 Feb 2010 03:22:25 +0000 (19:22 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 8 Mar 2010 01:04:52 +0000 (17:04 -0800)
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.

Cc: Benjamin Thery <benjamin.thery@bull.net>
Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/sysfs/symlink.c
include/linux/sysfs.h

index c5eff49fa41beb9676992504d7ae37d46f0c16f4..1b9a3a1e8a17a1e3951980b3b4179d06a2b0a916 100644 (file)
@@ -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)
 {
index 5b8f80f5aca61dbd95c6bce2a3a96630d5463e64..d77cde6d049813ce50bb4c38e066faae6375bd95 100644 (file)
@@ -151,6 +151,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,
@@ -255,6 +258,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)
 {