diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-23 18:01:46 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-27 16:01:03 -0500 |
commit | c84a3b27798dfce928b867fa1c9f3c3fd66f0a31 (patch) | |
tree | 87a706232ee20ce8262b4a34bbf9eaf06b3ddfe6 /lib/kobject.c | |
parent | 6ce4eac1f600b34f2f7f58f9cd8f0503d79e42ae (diff) |
sysfs: drop kobj_ns_type handling, take #2
The way namespace tags are implemented in sysfs is more complicated
than necessary. As each tag is a pointer value and required to be
non-NULL under a namespace enabled parent, there's no need to record
separately what type each tag is. If multiple namespace types are
needed, which currently aren't, we can simply compare the tag to a set
of allowed tags in the superblock assuming that the tags, being
pointers, won't have the same value across multiple types.
This patch rips out kobj_ns_type handling from sysfs. sysfs now has
an enable switch to turn on namespace under a node. If enabled, all
children are required to have non-NULL namespace tags and filtered
against the super_block's tag.
kobject namespace determination is now performed in
lib/kobject.c::create_dir() making sysfs_read_ns_type() unnecessary.
The sanity checks are also moved. create_dir() is restructured to
ease such addition. This removes most kobject namespace knowledge
from sysfs proper which will enable proper separation and layering of
sysfs.
This is the second try. The first one was cb26a311578e ("sysfs: drop
kobj_ns_type handling") which tried to automatically enable namespace
if there are children with non-NULL namespace tags; however, it was
broken for symlinks as they should inherit the target's tag iff
namespace is enabled in the parent. This led to namespace filtering
enabled incorrectly for wireless net class devices through phy80211
symlinks and thus network configuration failure. a1212d278c05
("Revert "sysfs: drop kobj_ns_type handling"") reverted the commit.
This shouldn't introduce any behavior changes, for real.
v2: Dummy implementation of sysfs_enable_ns() for !CONFIG_SYSFS was
missing and caused build failure. Reported by kbuild test robot.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/kobject.c')
-rw-r--r-- | lib/kobject.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 5b4b8886435e..16e9335b32d3 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -65,13 +65,17 @@ static int populate_dir(struct kobject *kobj) | |||
65 | 65 | ||
66 | static int create_dir(struct kobject *kobj) | 66 | static int create_dir(struct kobject *kobj) |
67 | { | 67 | { |
68 | const struct kobj_ns_type_operations *ops; | ||
68 | int error; | 69 | int error; |
69 | 70 | ||
70 | error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj)); | 71 | error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj)); |
71 | if (!error) { | 72 | if (error) |
72 | error = populate_dir(kobj); | 73 | return error; |
73 | if (error) | 74 | |
74 | sysfs_remove_dir(kobj); | 75 | error = populate_dir(kobj); |
76 | if (error) { | ||
77 | sysfs_remove_dir(kobj); | ||
78 | return error; | ||
75 | } | 79 | } |
76 | 80 | ||
77 | /* | 81 | /* |
@@ -80,7 +84,20 @@ static int create_dir(struct kobject *kobj) | |||
80 | */ | 84 | */ |
81 | sysfs_get(kobj->sd); | 85 | sysfs_get(kobj->sd); |
82 | 86 | ||
83 | return error; | 87 | /* |
88 | * If @kobj has ns_ops, its children need to be filtered based on | ||
89 | * their namespace tags. Enable namespace support on @kobj->sd. | ||
90 | */ | ||
91 | ops = kobj_child_ns_ops(kobj); | ||
92 | if (ops) { | ||
93 | BUG_ON(ops->type <= KOBJ_NS_TYPE_NONE); | ||
94 | BUG_ON(ops->type >= KOBJ_NS_TYPES); | ||
95 | BUG_ON(!kobj_ns_type_registered(ops->type)); | ||
96 | |||
97 | sysfs_enable_ns(kobj->sd); | ||
98 | } | ||
99 | |||
100 | return 0; | ||
84 | } | 101 | } |
85 | 102 | ||
86 | static int get_kobj_path_length(struct kobject *kobj) | 103 | static int get_kobj_path_length(struct kobject *kobj) |