diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2007-01-24 14:35:52 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-02-07 13:37:14 -0500 |
commit | b592fcfe7f06c15ec11774b5be7ce0de3aa86e73 (patch) | |
tree | 13f2cb344f8871edd30dc15007534405197d8480 /include | |
parent | 2f65168de7d68a5795e945e781d85b313bdc97b9 (diff) |
sysfs: Shadow directory support
The problem. When implementing a network namespace I need to be able
to have multiple network devices with the same name. Currently this
is a problem for /sys/class/net/*.
What I want is a separate /sys/class/net directory in sysfs for each
network namespace, and I want to name each of them /sys/class/net.
I looked and the VFS actually allows that. All that is needed is
for /sys/class/net to implement a follow link method to redirect
lookups to the real directory you want.
Implementing a follow link method that is sensitive to the current
network namespace turns out to be 3 lines of code so it looks like a
clean approach. Modifying sysfs so it doesn't get in my was is a bit
trickier.
I am calling the concept of multiple directories all at the same path
in the filesystem shadow directories. With the directory entry really
at that location the shadow master.
The following patch modifies sysfs so it can handle a directory
structure slightly different from the kobject tree so I can implement
the shadow directories for handling /sys/class/net/.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Cc: Maneesh Soni <maneesh@in.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/kobject.h | 4 | ||||
-rw-r--r-- | include/linux/sysfs.h | 23 |
2 files changed, 23 insertions, 4 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 76538fcf2c4e..b850e0310538 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
@@ -74,9 +74,13 @@ extern void kobject_init(struct kobject *); | |||
74 | extern void kobject_cleanup(struct kobject *); | 74 | extern void kobject_cleanup(struct kobject *); |
75 | 75 | ||
76 | extern int __must_check kobject_add(struct kobject *); | 76 | extern int __must_check kobject_add(struct kobject *); |
77 | extern int __must_check kobject_shadow_add(struct kobject *, struct dentry *); | ||
77 | extern void kobject_del(struct kobject *); | 78 | extern void kobject_del(struct kobject *); |
78 | 79 | ||
79 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); | 80 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); |
81 | extern int __must_check kobject_shadow_rename(struct kobject *kobj, | ||
82 | struct dentry *new_parent, | ||
83 | const char *new_name); | ||
80 | extern int __must_check kobject_move(struct kobject *, struct kobject *); | 84 | extern int __must_check kobject_move(struct kobject *, struct kobject *); |
81 | 85 | ||
82 | extern int __must_check kobject_register(struct kobject *); | 86 | extern int __must_check kobject_register(struct kobject *); |
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index eee485957c0c..192de3afa96b 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | struct kobject; | 17 | struct kobject; |
18 | struct module; | 18 | struct module; |
19 | struct nameidata; | ||
19 | 20 | ||
20 | struct attribute { | 21 | struct attribute { |
21 | const char * name; | 22 | const char * name; |
@@ -89,13 +90,13 @@ struct sysfs_dirent { | |||
89 | #ifdef CONFIG_SYSFS | 90 | #ifdef CONFIG_SYSFS |
90 | 91 | ||
91 | extern int __must_check | 92 | extern int __must_check |
92 | sysfs_create_dir(struct kobject *); | 93 | sysfs_create_dir(struct kobject *, struct dentry *); |
93 | 94 | ||
94 | extern void | 95 | extern void |
95 | sysfs_remove_dir(struct kobject *); | 96 | sysfs_remove_dir(struct kobject *); |
96 | 97 | ||
97 | extern int __must_check | 98 | extern int __must_check |
98 | sysfs_rename_dir(struct kobject *, const char *new_name); | 99 | sysfs_rename_dir(struct kobject *, struct dentry *, const char *new_name); |
99 | 100 | ||
100 | extern int __must_check | 101 | extern int __must_check |
101 | sysfs_move_dir(struct kobject *, struct kobject *); | 102 | sysfs_move_dir(struct kobject *, struct kobject *); |
@@ -127,11 +128,17 @@ int __must_check sysfs_create_group(struct kobject *, | |||
127 | void sysfs_remove_group(struct kobject *, const struct attribute_group *); | 128 | void sysfs_remove_group(struct kobject *, const struct attribute_group *); |
128 | void sysfs_notify(struct kobject * k, char *dir, char *attr); | 129 | void sysfs_notify(struct kobject * k, char *dir, char *attr); |
129 | 130 | ||
131 | |||
132 | extern int sysfs_make_shadowed_dir(struct kobject *kobj, | ||
133 | void * (*follow_link)(struct dentry *, struct nameidata *)); | ||
134 | extern struct dentry *sysfs_create_shadow_dir(struct kobject *kobj); | ||
135 | extern void sysfs_remove_shadow_dir(struct dentry *dir); | ||
136 | |||
130 | extern int __must_check sysfs_init(void); | 137 | extern int __must_check sysfs_init(void); |
131 | 138 | ||
132 | #else /* CONFIG_SYSFS */ | 139 | #else /* CONFIG_SYSFS */ |
133 | 140 | ||
134 | static inline int sysfs_create_dir(struct kobject * k) | 141 | static inline int sysfs_create_dir(struct kobject * k, struct dentry *shadow) |
135 | { | 142 | { |
136 | return 0; | 143 | return 0; |
137 | } | 144 | } |
@@ -141,7 +148,9 @@ static inline void sysfs_remove_dir(struct kobject * k) | |||
141 | ; | 148 | ; |
142 | } | 149 | } |
143 | 150 | ||
144 | static inline int sysfs_rename_dir(struct kobject * k, const char *new_name) | 151 | static inline int sysfs_rename_dir(struct kobject * k, |
152 | struct dentry *new_parent, | ||
153 | const char *new_name) | ||
145 | { | 154 | { |
146 | return 0; | 155 | return 0; |
147 | } | 156 | } |
@@ -205,6 +214,12 @@ static inline void sysfs_notify(struct kobject * k, char *dir, char *attr) | |||
205 | { | 214 | { |
206 | } | 215 | } |
207 | 216 | ||
217 | static inline int sysfs_make_shadowed_dir(struct kobject *kobj, | ||
218 | void * (*follow_link)(struct dentry *, struct nameidata *)) | ||
219 | { | ||
220 | return 0; | ||
221 | } | ||
222 | |||
208 | static inline int __must_check sysfs_init(void) | 223 | static inline int __must_check sysfs_init(void) |
209 | { | 224 | { |
210 | return 0; | 225 | return 0; |