aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
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/linux/device.h
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/linux/device.h')
-rw-r--r--include/linux/device.h24
1 files changed, 18 insertions, 6 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 {