diff options
Diffstat (limited to 'include/linux/kobject.h')
-rw-r--r-- | include/linux/kobject.h | 125 |
1 files changed, 45 insertions, 80 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 949706c33622..4a0d27f475d7 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
@@ -1,8 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * kobject.h - generic kernel object infrastructure. | 2 | * kobject.h - generic kernel object infrastructure. |
3 | * | 3 | * |
4 | * Copyright (c) 2002-2003 Patrick Mochel | 4 | * Copyright (c) 2002-2003 Patrick Mochel |
5 | * Copyright (c) 2002-2003 Open Source Development Labs | 5 | * Copyright (c) 2002-2003 Open Source Development Labs |
6 | * Copyright (c) 2006-2007 Greg Kroah-Hartman <greg@kroah.com> | ||
7 | * Copyright (c) 2006-2007 Novell Inc. | ||
6 | * | 8 | * |
7 | * This file is released under the GPLv2. | 9 | * This file is released under the GPLv2. |
8 | * | 10 | * |
@@ -29,6 +31,8 @@ | |||
29 | 31 | ||
30 | #define KOBJ_NAME_LEN 20 | 32 | #define KOBJ_NAME_LEN 20 |
31 | #define UEVENT_HELPER_PATH_LEN 256 | 33 | #define UEVENT_HELPER_PATH_LEN 256 |
34 | #define UEVENT_NUM_ENVP 32 /* number of env pointers */ | ||
35 | #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ | ||
32 | 36 | ||
33 | /* path to the userspace helper executed on an event */ | 37 | /* path to the userspace helper executed on an event */ |
34 | extern char uevent_helper[]; | 38 | extern char uevent_helper[]; |
@@ -56,19 +60,14 @@ enum kobject_action { | |||
56 | KOBJ_MAX | 60 | KOBJ_MAX |
57 | }; | 61 | }; |
58 | 62 | ||
59 | /* The list of strings defining the valid kobject actions as specified above */ | ||
60 | extern const char *kobject_actions[]; | ||
61 | |||
62 | struct kobject { | 63 | struct kobject { |
63 | const char * k_name; | 64 | const char * k_name; |
64 | char name[KOBJ_NAME_LEN]; | ||
65 | struct kref kref; | 65 | struct kref kref; |
66 | struct list_head entry; | 66 | struct list_head entry; |
67 | struct kobject * parent; | 67 | struct kobject * parent; |
68 | struct kset * kset; | 68 | struct kset * kset; |
69 | struct kobj_type * ktype; | 69 | struct kobj_type * ktype; |
70 | struct sysfs_dirent * sd; | 70 | struct sysfs_dirent * sd; |
71 | wait_queue_head_t poll; | ||
72 | }; | 71 | }; |
73 | 72 | ||
74 | extern int kobject_set_name(struct kobject *, const char *, ...) | 73 | extern int kobject_set_name(struct kobject *, const char *, ...) |
@@ -83,14 +82,9 @@ extern void kobject_init(struct kobject *); | |||
83 | extern void kobject_cleanup(struct kobject *); | 82 | extern void kobject_cleanup(struct kobject *); |
84 | 83 | ||
85 | extern int __must_check kobject_add(struct kobject *); | 84 | extern int __must_check kobject_add(struct kobject *); |
86 | extern int __must_check kobject_shadow_add(struct kobject *kobj, | ||
87 | struct sysfs_dirent *shadow_parent); | ||
88 | extern void kobject_del(struct kobject *); | 85 | extern void kobject_del(struct kobject *); |
89 | 86 | ||
90 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); | 87 | extern int __must_check kobject_rename(struct kobject *, const char *new_name); |
91 | extern int __must_check kobject_shadow_rename(struct kobject *kobj, | ||
92 | struct sysfs_dirent *new_parent, | ||
93 | const char *new_name); | ||
94 | extern int __must_check kobject_move(struct kobject *, struct kobject *); | 88 | extern int __must_check kobject_move(struct kobject *, struct kobject *); |
95 | 89 | ||
96 | extern int __must_check kobject_register(struct kobject *); | 90 | extern int __must_check kobject_register(struct kobject *); |
@@ -111,36 +105,44 @@ struct kobj_type { | |||
111 | struct attribute ** default_attrs; | 105 | struct attribute ** default_attrs; |
112 | }; | 106 | }; |
113 | 107 | ||
108 | struct kobj_uevent_env { | ||
109 | char *envp[UEVENT_NUM_ENVP]; | ||
110 | int envp_idx; | ||
111 | char buf[UEVENT_BUFFER_SIZE]; | ||
112 | int buflen; | ||
113 | }; | ||
114 | |||
114 | struct kset_uevent_ops { | 115 | struct kset_uevent_ops { |
115 | int (*filter)(struct kset *kset, struct kobject *kobj); | 116 | int (*filter)(struct kset *kset, struct kobject *kobj); |
116 | const char *(*name)(struct kset *kset, struct kobject *kobj); | 117 | const char *(*name)(struct kset *kset, struct kobject *kobj); |
117 | int (*uevent)(struct kset *kset, struct kobject *kobj, char **envp, | 118 | int (*uevent)(struct kset *kset, struct kobject *kobj, |
118 | int num_envp, char *buffer, int buffer_size); | 119 | struct kobj_uevent_env *env); |
119 | }; | 120 | }; |
120 | 121 | ||
121 | /* | 122 | /** |
122 | * struct kset - a set of kobjects of a specific type, belonging | 123 | * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. |
123 | * to a specific subsystem. | ||
124 | * | ||
125 | * All kobjects of a kset should be embedded in an identical | ||
126 | * type. This type may have a descriptor, which the kset points | ||
127 | * to. This allows there to exist sets of objects of the same | ||
128 | * type in different subsystems. | ||
129 | * | 124 | * |
130 | * A subsystem does not have to be a list of only one type | 125 | * A kset defines a group of kobjects. They can be individually |
131 | * of object; multiple ksets can belong to one subsystem. All | 126 | * different "types" but overall these kobjects all want to be grouped |
132 | * ksets of a subsystem share the subsystem's lock. | 127 | * together and operated on in the same manner. ksets are used to |
128 | * define the attribute callbacks and other common events that happen to | ||
129 | * a kobject. | ||
133 | * | 130 | * |
134 | * Each kset can support specific event variables; it can | 131 | * @ktype: the struct kobj_type for this specific kset |
135 | * supress the event generation or add subsystem specific | 132 | * @list: the list of all kobjects for this kset |
136 | * variables carried with the event. | 133 | * @list_lock: a lock for iterating over the kobjects |
134 | * @kobj: the embedded kobject for this kset (recursion, isn't it fun...) | ||
135 | * @uevent_ops: the set of uevent operations for this kset. These are | ||
136 | * called whenever a kobject has something happen to it so that the kset | ||
137 | * can add new environment variables, or filter out the uevents if so | ||
138 | * desired. | ||
137 | */ | 139 | */ |
138 | struct kset { | 140 | struct kset { |
139 | struct kobj_type * ktype; | 141 | struct kobj_type *ktype; |
140 | struct list_head list; | 142 | struct list_head list; |
141 | spinlock_t list_lock; | 143 | spinlock_t list_lock; |
142 | struct kobject kobj; | 144 | struct kobject kobj; |
143 | struct kset_uevent_ops * uevent_ops; | 145 | struct kset_uevent_ops *uevent_ops; |
144 | }; | 146 | }; |
145 | 147 | ||
146 | 148 | ||
@@ -179,18 +181,18 @@ extern struct kobject * kset_find_obj(struct kset *, const char *); | |||
179 | * Use this when initializing an embedded kset with no other | 181 | * Use this when initializing an embedded kset with no other |
180 | * fields to initialize. | 182 | * fields to initialize. |
181 | */ | 183 | */ |
182 | #define set_kset_name(str) .kset = { .kobj = { .name = str } } | 184 | #define set_kset_name(str) .kset = { .kobj = { .k_name = str } } |
183 | 185 | ||
184 | 186 | ||
185 | #define decl_subsys(_name,_type,_uevent_ops) \ | 187 | #define decl_subsys(_name,_type,_uevent_ops) \ |
186 | struct kset _name##_subsys = { \ | 188 | struct kset _name##_subsys = { \ |
187 | .kobj = { .name = __stringify(_name) }, \ | 189 | .kobj = { .k_name = __stringify(_name) }, \ |
188 | .ktype = _type, \ | 190 | .ktype = _type, \ |
189 | .uevent_ops =_uevent_ops, \ | 191 | .uevent_ops =_uevent_ops, \ |
190 | } | 192 | } |
191 | #define decl_subsys_name(_varname,_name,_type,_uevent_ops) \ | 193 | #define decl_subsys_name(_varname,_name,_type,_uevent_ops) \ |
192 | struct kset _varname##_subsys = { \ | 194 | struct kset _varname##_subsys = { \ |
193 | .kobj = { .name = __stringify(_name) }, \ | 195 | .kobj = { .k_name = __stringify(_name) }, \ |
194 | .ktype = _type, \ | 196 | .ktype = _type, \ |
195 | .uevent_ops =_uevent_ops, \ | 197 | .uevent_ops =_uevent_ops, \ |
196 | } | 198 | } |
@@ -218,49 +220,9 @@ extern struct kset hypervisor_subsys; | |||
218 | #define kobj_set_kset_s(obj,subsys) \ | 220 | #define kobj_set_kset_s(obj,subsys) \ |
219 | (obj)->kobj.kset = &(subsys) | 221 | (obj)->kobj.kset = &(subsys) |
220 | 222 | ||
221 | /** | ||
222 | * kset_set_kset_s(obj,subsys) - set kset for embedded kset. | ||
223 | * @obj: ptr to some object type. | ||
224 | * @subsys: a subsystem object (not a ptr). | ||
225 | * | ||
226 | * Can be used for any object type with an embedded ->kset. | ||
227 | * Sets the kset of @obj's embedded kobject (via its embedded | ||
228 | * kset) to @subsys.kset. This makes @obj a member of that | ||
229 | * kset. | ||
230 | */ | ||
231 | |||
232 | #define kset_set_kset_s(obj,subsys) \ | ||
233 | (obj)->kset.kobj.kset = &(subsys) | ||
234 | |||
235 | /** | ||
236 | * subsys_set_kset(obj,subsys) - set kset for subsystem | ||
237 | * @obj: ptr to some object type. | ||
238 | * @_subsys: a subsystem object (not a ptr). | ||
239 | * | ||
240 | * Can be used for any object type with an embedded ->subsys. | ||
241 | * Sets the kset of @obj's kobject to @subsys.kset. This makes | ||
242 | * the object a member of that kset. | ||
243 | */ | ||
244 | |||
245 | #define subsys_set_kset(obj,_subsys) \ | ||
246 | (obj)->subsys.kobj.kset = &(_subsys) | ||
247 | |||
248 | extern void subsystem_init(struct kset *); | ||
249 | extern int __must_check subsystem_register(struct kset *); | 223 | extern int __must_check subsystem_register(struct kset *); |
250 | extern void subsystem_unregister(struct kset *); | 224 | extern void subsystem_unregister(struct kset *); |
251 | 225 | ||
252 | static inline struct kset *subsys_get(struct kset *s) | ||
253 | { | ||
254 | if (s) | ||
255 | return kset_get(s); | ||
256 | return NULL; | ||
257 | } | ||
258 | |||
259 | static inline void subsys_put(struct kset *s) | ||
260 | { | ||
261 | kset_put(s); | ||
262 | } | ||
263 | |||
264 | struct subsys_attribute { | 226 | struct subsys_attribute { |
265 | struct attribute attr; | 227 | struct attribute attr; |
266 | ssize_t (*show)(struct kset *, char *); | 228 | ssize_t (*show)(struct kset *, char *); |
@@ -275,10 +237,11 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action); | |||
275 | int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | 237 | int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, |
276 | char *envp[]); | 238 | char *envp[]); |
277 | 239 | ||
278 | int add_uevent_var(char **envp, int num_envp, int *cur_index, | 240 | int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) |
279 | char *buffer, int buffer_size, int *cur_len, | 241 | __attribute__((format (printf, 2, 3))); |
280 | const char *format, ...) | 242 | |
281 | __attribute__((format (printf, 7, 8))); | 243 | int kobject_action_type(const char *buf, size_t count, |
244 | enum kobject_action *type); | ||
282 | #else | 245 | #else |
283 | static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) | 246 | static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) |
284 | { return 0; } | 247 | { return 0; } |
@@ -287,10 +250,12 @@ static inline int kobject_uevent_env(struct kobject *kobj, | |||
287 | char *envp[]) | 250 | char *envp[]) |
288 | { return 0; } | 251 | { return 0; } |
289 | 252 | ||
290 | static inline int add_uevent_var(char **envp, int num_envp, int *cur_index, | 253 | static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) |
291 | char *buffer, int buffer_size, int *cur_len, | ||
292 | const char *format, ...) | ||
293 | { return 0; } | 254 | { return 0; } |
255 | |||
256 | static inline int kobject_action_type(const char *buf, size_t count, | ||
257 | enum kobject_action *type) | ||
258 | { return -EINVAL; } | ||
294 | #endif | 259 | #endif |
295 | 260 | ||
296 | #endif /* __KERNEL__ */ | 261 | #endif /* __KERNEL__ */ |