aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-09-11 22:29:06 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 18:30:22 -0400
commit4b30ee58ee64c64f59fd876e4afa6ed82caef3a4 (patch)
tree52d26225aec86ae39ed559882a30bec10fdb2031
parente34ff4906199d2ebd248ae897ae34f52bea151c9 (diff)
sysfs: remove ktype->namespace() invocations in symlink code
There's no reason for sysfs to be calling ktype->namespace(). It is backwards, obfuscates what's going on and unnecessarily tangles two separate layers. There are two places where symlink code calls ktype->namespace(). * sysfs_do_create_link_sd() calls it to find out the namespace tag of the target directory. Unless symlinking races with cross-namespace renaming, this equals @target_sd->s_ns. * sysfs_rename_link() uses it to find out the new namespace to rename to and the new namespace can be different from the existing one. The function is renamed to sysfs_rename_link_ns() with an explicit @ns argument and the ktype->namespace() invocation is shifted to the device layer. While this patch replaces ktype->namespace() invocation with the recorded result in @target_sd, this shouldn't result in any behvior difference. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/base/core.c8
-rw-r--r--fs/sysfs/symlink.c16
-rw-r--r--include/linux/sysfs.h16
3 files changed, 24 insertions, 16 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c7cfadcf6752..3335000be2dc 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1881,6 +1881,7 @@ EXPORT_SYMBOL_GPL(device_destroy);
1881 */ 1881 */
1882int device_rename(struct device *dev, const char *new_name) 1882int device_rename(struct device *dev, const char *new_name)
1883{ 1883{
1884 struct kobject *kobj = &dev->kobj;
1884 char *old_device_name = NULL; 1885 char *old_device_name = NULL;
1885 int error; 1886 int error;
1886 1887
@@ -1898,13 +1899,14 @@ int device_rename(struct device *dev, const char *new_name)
1898 } 1899 }
1899 1900
1900 if (dev->class) { 1901 if (dev->class) {
1901 error = sysfs_rename_link(&dev->class->p->subsys.kobj, 1902 error = sysfs_rename_link_ns(&dev->class->p->subsys.kobj,
1902 &dev->kobj, old_device_name, new_name); 1903 kobj, old_device_name,
1904 new_name, kobject_namespace(kobj));
1903 if (error) 1905 if (error)
1904 goto out; 1906 goto out;
1905 } 1907 }
1906 1908
1907 error = kobject_rename(&dev->kobj, new_name); 1909 error = kobject_rename(kobj, new_name);
1908 if (error) 1910 if (error)
1909 goto out; 1911 goto out;
1910 1912
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 2dd4507d9edd..12d58ada3e6d 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -52,7 +52,7 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
52 52
53 ns_type = sysfs_ns_type(parent_sd); 53 ns_type = sysfs_ns_type(parent_sd);
54 if (ns_type) 54 if (ns_type)
55 sd->s_ns = target->ktype->namespace(target); 55 sd->s_ns = target_sd->s_ns;
56 sd->s_symlink.target_sd = target_sd; 56 sd->s_symlink.target_sd = target_sd;
57 target_sd = NULL; /* reference is now owned by the symlink */ 57 target_sd = NULL; /* reference is now owned by the symlink */
58 58
@@ -181,19 +181,20 @@ void sysfs_remove_link(struct kobject *kobj, const char *name)
181EXPORT_SYMBOL_GPL(sysfs_remove_link); 181EXPORT_SYMBOL_GPL(sysfs_remove_link);
182 182
183/** 183/**
184 * sysfs_rename_link - rename symlink in object's directory. 184 * sysfs_rename_link_ns - rename symlink in object's directory.
185 * @kobj: object we're acting for. 185 * @kobj: object we're acting for.
186 * @targ: object we're pointing to. 186 * @targ: object we're pointing to.
187 * @old: previous name of the symlink. 187 * @old: previous name of the symlink.
188 * @new: new name of the symlink. 188 * @new: new name of the symlink.
189 * @new_ns: new namespace of the symlink.
189 * 190 *
190 * A helper function for the common rename symlink idiom. 191 * A helper function for the common rename symlink idiom.
191 */ 192 */
192int sysfs_rename_link(struct kobject *kobj, struct kobject *targ, 193int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
193 const char *old, const char *new) 194 const char *old, const char *new, const void *new_ns)
194{ 195{
195 struct sysfs_dirent *parent_sd, *sd = NULL; 196 struct sysfs_dirent *parent_sd, *sd = NULL;
196 const void *old_ns = NULL, *new_ns = NULL; 197 const void *old_ns = NULL;
197 int result; 198 int result;
198 199
199 if (!kobj) 200 if (!kobj)
@@ -215,16 +216,13 @@ int sysfs_rename_link(struct kobject *kobj, struct kobject *targ,
215 if (sd->s_symlink.target_sd->s_dir.kobj != targ) 216 if (sd->s_symlink.target_sd->s_dir.kobj != targ)
216 goto out; 217 goto out;
217 218
218 if (sysfs_ns_type(parent_sd))
219 new_ns = targ->ktype->namespace(targ);
220
221 result = sysfs_rename(sd, parent_sd, new_ns, new); 219 result = sysfs_rename(sd, parent_sd, new_ns, new);
222 220
223out: 221out:
224 sysfs_put(sd); 222 sysfs_put(sd);
225 return result; 223 return result;
226} 224}
227EXPORT_SYMBOL_GPL(sysfs_rename_link); 225EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
228 226
229static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, 227static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
230 struct sysfs_dirent *target_sd, char *path) 228 struct sysfs_dirent *target_sd, char *path)
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 7f56bad3be82..c792f73ac7fa 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -213,8 +213,9 @@ int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
213 const char *name); 213 const char *name);
214void sysfs_remove_link(struct kobject *kobj, const char *name); 214void sysfs_remove_link(struct kobject *kobj, const char *name);
215 215
216int sysfs_rename_link(struct kobject *kobj, struct kobject *target, 216int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
217 const char *old_name, const char *new_name); 217 const char *old_name, const char *new_name,
218 const void *new_ns);
218 219
219void sysfs_delete_link(struct kobject *dir, struct kobject *targ, 220void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
220 const char *name); 221 const char *name);
@@ -340,8 +341,9 @@ static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
340{ 341{
341} 342}
342 343
343static inline int sysfs_rename_link(struct kobject *k, struct kobject *t, 344static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t,
344 const char *old_name, const char *new_name) 345 const char *old_name,
346 const char *new_name, const void *ns)
345{ 347{
346 return 0; 348 return 0;
347} 349}
@@ -454,4 +456,10 @@ static inline void sysfs_remove_file(struct kobject *kobj,
454 return sysfs_remove_file_ns(kobj, attr, NULL); 456 return sysfs_remove_file_ns(kobj, attr, NULL);
455} 457}
456 458
459static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
460 const char *old_name, const char *new_name)
461{
462 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
463}
464
457#endif /* _SYSFS_H_ */ 465#endif /* _SYSFS_H_ */