aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kobject.h')
-rw-r--r--include/linux/kobject.h125
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 */
34extern char uevent_helper[]; 38extern 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 */
60extern const char *kobject_actions[];
61
62struct kobject { 63struct 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
74extern int kobject_set_name(struct kobject *, const char *, ...) 73extern int kobject_set_name(struct kobject *, const char *, ...)
@@ -83,14 +82,9 @@ extern void kobject_init(struct kobject *);
83extern void kobject_cleanup(struct kobject *); 82extern void kobject_cleanup(struct kobject *);
84 83
85extern int __must_check kobject_add(struct kobject *); 84extern int __must_check kobject_add(struct kobject *);
86extern int __must_check kobject_shadow_add(struct kobject *kobj,
87 struct sysfs_dirent *shadow_parent);
88extern void kobject_del(struct kobject *); 85extern void kobject_del(struct kobject *);
89 86
90extern int __must_check kobject_rename(struct kobject *, const char *new_name); 87extern int __must_check kobject_rename(struct kobject *, const char *new_name);
91extern int __must_check kobject_shadow_rename(struct kobject *kobj,
92 struct sysfs_dirent *new_parent,
93 const char *new_name);
94extern int __must_check kobject_move(struct kobject *, struct kobject *); 88extern int __must_check kobject_move(struct kobject *, struct kobject *);
95 89
96extern int __must_check kobject_register(struct kobject *); 90extern 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
108struct kobj_uevent_env {
109 char *envp[UEVENT_NUM_ENVP];
110 int envp_idx;
111 char buf[UEVENT_BUFFER_SIZE];
112 int buflen;
113};
114
114struct kset_uevent_ops { 115struct 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 */
138struct kset { 140struct 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) \
186struct kset _name##_subsys = { \ 188struct 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) \
192struct kset _varname##_subsys = { \ 194struct 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
248extern void subsystem_init(struct kset *);
249extern int __must_check subsystem_register(struct kset *); 223extern int __must_check subsystem_register(struct kset *);
250extern void subsystem_unregister(struct kset *); 224extern void subsystem_unregister(struct kset *);
251 225
252static inline struct kset *subsys_get(struct kset *s)
253{
254 if (s)
255 return kset_get(s);
256 return NULL;
257}
258
259static inline void subsys_put(struct kset *s)
260{
261 kset_put(s);
262}
263
264struct subsys_attribute { 226struct 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);
275int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, 237int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
276 char *envp[]); 238 char *envp[]);
277 239
278int add_uevent_var(char **envp, int num_envp, int *cur_index, 240int 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))); 243int kobject_action_type(const char *buf, size_t count,
244 enum kobject_action *type);
282#else 245#else
283static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) 246static 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
290static inline int add_uevent_var(char **envp, int num_envp, int *cur_index, 253static 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
256static 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__ */