aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-09-11 22:29:04 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 17:50:01 -0400
commit58292cbe6669d74498a5f08db13e57cb3bcfb81d (patch)
treebe6ed2b906a9796c58be9ff21251e124bf01ddcb /include
parentbcac3769ca6d6278f93afb6cc2b234d260ee5951 (diff)
sysfs: make attr namespace interface less convoluted
sysfs ns (namespace) implementation became more convoluted than necessary while trying to hide ns information from visible interface. The relatively recent attr ns support is a good example. * attr ns tag is determined by sysfs_ops->namespace() callback while dir tag is determined by kobj_type->namespace(). The placement is arbitrary. * Instead of performing operations with explicit ns tag, the namespace callback is routed through sysfs_attr_ns(), sysfs_ops->namespace(), class_attr_namespace(), class_attr->namespace(). It's not simpler in any sense. The only thing this convolution does is traversing the whole stack backwards. The namespace callbacks are unncessary because the operations involved are inherently synchronous. The information can be provided in in straight-forward top-down direction and reversing that direction is unnecessary and against basic design principles. This backward interface is unnecessarily convoluted and hinders properly separating out sysfs from driver model / kobject for proper layering. This patch updates attr ns support such that * sysfs_ops->namespace() and class_attr->namespace() are dropped. * sysfs_{create|remove}_file_ns(), which take explicit @ns param, are added and sysfs_{create|remove}_file() are now simple wrappers around the ns aware functions. * ns handling is dropped from sysfs_chmod_file(). Nobody uses it at this point. sysfs_chmod_file_ns() can be added later if necessary. * Explicit @ns is propagated through class_{create|remove}_file_ns() and netdev_class_{create|remove}_file_ns(). * driver/net/bonding which is currently the only user of attr namespace is updated to use netdev_class_{create|remove}_file_ns() with @bh->net as the ns tag instead of using the namespace callback. This patch should be an equivalent conversion without any functional difference. It makes the code easier to follow, reduces lines of code a bit and helps proper separation and layering. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/device.h24
-rw-r--r--include/linux/netdevice.h16
-rw-r--r--include/linux/sysfs.h31
3 files changed, 55 insertions, 16 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 2a9d6ed59579..ce690ea34547 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -427,8 +427,6 @@ struct class_attribute {
427 char *buf); 427 char *buf);
428 ssize_t (*store)(struct class *class, struct class_attribute *attr, 428 ssize_t (*store)(struct class *class, struct class_attribute *attr,
429 const char *buf, size_t count); 429 const char *buf, size_t count);
430 const void *(*namespace)(struct class *class,
431 const struct class_attribute *attr);
432}; 430};
433 431
434#define CLASS_ATTR(_name, _mode, _show, _store) \ 432#define CLASS_ATTR(_name, _mode, _show, _store) \
@@ -438,10 +436,24 @@ struct class_attribute {
438#define CLASS_ATTR_RO(_name) \ 436#define CLASS_ATTR_RO(_name) \
439 struct class_attribute class_attr_##_name = __ATTR_RO(_name) 437 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
440 438
441extern int __must_check class_create_file(struct class *class, 439extern int __must_check class_create_file_ns(struct class *class,
442 const struct class_attribute *attr); 440 const struct class_attribute *attr,
443extern void class_remove_file(struct class *class, 441 const void *ns);
444 const struct class_attribute *attr); 442extern void class_remove_file_ns(struct class *class,
443 const struct class_attribute *attr,
444 const void *ns);
445
446static inline int __must_check class_create_file(struct class *class,
447 const struct class_attribute *attr)
448{
449 return class_create_file_ns(class, attr, NULL);
450}
451
452static inline void class_remove_file(struct class *class,
453 const struct class_attribute *attr)
454{
455 return class_remove_file_ns(class, attr, NULL);
456}
445 457
446/* Simple class attribute that is just a static string */ 458/* Simple class attribute that is just a static string */
447struct class_attribute_string { 459struct class_attribute_string {
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3de49aca4519..42421ed49a47 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2873,8 +2873,20 @@ extern int __init dev_proc_init(void);
2873#define dev_proc_init() 0 2873#define dev_proc_init() 0
2874#endif 2874#endif
2875 2875
2876extern int netdev_class_create_file(struct class_attribute *class_attr); 2876extern int netdev_class_create_file_ns(struct class_attribute *class_attr,
2877extern void netdev_class_remove_file(struct class_attribute *class_attr); 2877 const void *ns);
2878extern void netdev_class_remove_file_ns(struct class_attribute *class_attr,
2879 const void *ns);
2880
2881static inline int netdev_class_create_file(struct class_attribute *class_attr)
2882{
2883 return netdev_class_create_file_ns(class_attr, NULL);
2884}
2885
2886static inline void netdev_class_remove_file(struct class_attribute *class_attr)
2887{
2888 netdev_class_remove_file_ns(class_attr, NULL);
2889}
2878 2890
2879extern struct kobj_ns_type_operations net_ns_type_operations; 2891extern struct kobj_ns_type_operations net_ns_type_operations;
2880 2892
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 11baec7c9b26..82f7fac78e77 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -173,7 +173,6 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
173struct sysfs_ops { 173struct sysfs_ops {
174 ssize_t (*show)(struct kobject *, struct attribute *, char *); 174 ssize_t (*show)(struct kobject *, struct attribute *, char *);
175 ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); 175 ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
176 const void *(*namespace)(struct kobject *, const struct attribute *);
177}; 176};
178 177
179struct sysfs_dirent; 178struct sysfs_dirent;
@@ -189,13 +188,15 @@ int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
189int __must_check sysfs_move_dir(struct kobject *kobj, 188int __must_check sysfs_move_dir(struct kobject *kobj,
190 struct kobject *new_parent_kobj); 189 struct kobject *new_parent_kobj);
191 190
192int __must_check sysfs_create_file(struct kobject *kobj, 191int __must_check sysfs_create_file_ns(struct kobject *kobj,
193 const struct attribute *attr); 192 const struct attribute *attr,
193 const void *ns);
194int __must_check sysfs_create_files(struct kobject *kobj, 194int __must_check sysfs_create_files(struct kobject *kobj,
195 const struct attribute **attr); 195 const struct attribute **attr);
196int __must_check sysfs_chmod_file(struct kobject *kobj, 196int __must_check sysfs_chmod_file(struct kobject *kobj,
197 const struct attribute *attr, umode_t mode); 197 const struct attribute *attr, umode_t mode);
198void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); 198void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
199 const void *ns);
199void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr); 200void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
200 201
201int __must_check sysfs_create_bin_file(struct kobject *kobj, 202int __must_check sysfs_create_bin_file(struct kobject *kobj,
@@ -277,8 +278,9 @@ static inline int sysfs_move_dir(struct kobject *kobj,
277 return 0; 278 return 0;
278} 279}
279 280
280static inline int sysfs_create_file(struct kobject *kobj, 281static inline int sysfs_create_file_ns(struct kobject *kobj,
281 const struct attribute *attr) 282 const struct attribute *attr,
283 const void *ns)
282{ 284{
283 return 0; 285 return 0;
284} 286}
@@ -295,8 +297,9 @@ static inline int sysfs_chmod_file(struct kobject *kobj,
295 return 0; 297 return 0;
296} 298}
297 299
298static inline void sysfs_remove_file(struct kobject *kobj, 300static inline void sysfs_remove_file_ns(struct kobject *kobj,
299 const struct attribute *attr) 301 const struct attribute *attr,
302 const void *ns)
300{ 303{
301} 304}
302 305
@@ -435,4 +438,16 @@ static inline int __must_check sysfs_init(void)
435 438
436#endif /* CONFIG_SYSFS */ 439#endif /* CONFIG_SYSFS */
437 440
441static inline int __must_check sysfs_create_file(struct kobject *kobj,
442 const struct attribute *attr)
443{
444 return sysfs_create_file_ns(kobj, attr, NULL);
445}
446
447static inline void sysfs_remove_file(struct kobject *kobj,
448 const struct attribute *attr)
449{
450 return sysfs_remove_file_ns(kobj, attr, NULL);
451}
452
438#endif /* _SYSFS_H_ */ 453#endif /* _SYSFS_H_ */