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.h156
1 files changed, 66 insertions, 90 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 06cbf41d32d2..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[];
@@ -36,27 +40,34 @@ extern char uevent_helper[];
36/* counter to tag the uevent, read only except for the kobject core */ 40/* counter to tag the uevent, read only except for the kobject core */
37extern u64 uevent_seqnum; 41extern u64 uevent_seqnum;
38 42
39/* the actions here must match the proper string in lib/kobject_uevent.c */ 43/*
40typedef int __bitwise kobject_action_t; 44 * The actions here must match the index to the string array
45 * in lib/kobject_uevent.c
46 *
47 * Do not add new actions here without checking with the driver-core
48 * maintainers. Action strings are not meant to express subsystem
49 * or device specific properties. In most cases you want to send a
50 * kobject_uevent_env(kobj, KOBJ_CHANGE, env) with additional event
51 * specific variables added to the event environment.
52 */
41enum kobject_action { 53enum kobject_action {
42 KOBJ_ADD = (__force kobject_action_t) 0x01, /* exclusive to core */ 54 KOBJ_ADD,
43 KOBJ_REMOVE = (__force kobject_action_t) 0x02, /* exclusive to core */ 55 KOBJ_REMOVE,
44 KOBJ_CHANGE = (__force kobject_action_t) 0x03, /* device state change */ 56 KOBJ_CHANGE,
45 KOBJ_OFFLINE = (__force kobject_action_t) 0x04, /* device offline */ 57 KOBJ_MOVE,
46 KOBJ_ONLINE = (__force kobject_action_t) 0x05, /* device online */ 58 KOBJ_ONLINE,
47 KOBJ_MOVE = (__force kobject_action_t) 0x06, /* device move */ 59 KOBJ_OFFLINE,
60 KOBJ_MAX
48}; 61};
49 62
50struct kobject { 63struct kobject {
51 const char * k_name; 64 const char * k_name;
52 char name[KOBJ_NAME_LEN];
53 struct kref kref; 65 struct kref kref;
54 struct list_head entry; 66 struct list_head entry;
55 struct kobject * parent; 67 struct kobject * parent;
56 struct kset * kset; 68 struct kset * kset;
57 struct kobj_type * ktype; 69 struct kobj_type * ktype;
58 struct sysfs_dirent * sd; 70 struct sysfs_dirent * sd;
59 wait_queue_head_t poll;
60}; 71};
61 72
62extern int kobject_set_name(struct kobject *, const char *, ...) 73extern int kobject_set_name(struct kobject *, const char *, ...)
@@ -71,14 +82,9 @@ extern void kobject_init(struct kobject *);
71extern void kobject_cleanup(struct kobject *); 82extern void kobject_cleanup(struct kobject *);
72 83
73extern int __must_check kobject_add(struct kobject *); 84extern int __must_check kobject_add(struct kobject *);
74extern int __must_check kobject_shadow_add(struct kobject *kobj,
75 struct sysfs_dirent *shadow_parent);
76extern void kobject_del(struct kobject *); 85extern void kobject_del(struct kobject *);
77 86
78extern int __must_check kobject_rename(struct kobject *, const char *new_name); 87extern int __must_check kobject_rename(struct kobject *, const char *new_name);
79extern int __must_check kobject_shadow_rename(struct kobject *kobj,
80 struct sysfs_dirent *new_parent,
81 const char *new_name);
82extern int __must_check kobject_move(struct kobject *, struct kobject *); 88extern int __must_check kobject_move(struct kobject *, struct kobject *);
83 89
84extern int __must_check kobject_register(struct kobject *); 90extern int __must_check kobject_register(struct kobject *);
@@ -99,37 +105,44 @@ struct kobj_type {
99 struct attribute ** default_attrs; 105 struct attribute ** default_attrs;
100}; 106};
101 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};
102 114
103/**
104 * kset - a set of kobjects of a specific type, belonging
105 * to a specific subsystem.
106 *
107 * All kobjects of a kset should be embedded in an identical
108 * type. This type may have a descriptor, which the kset points
109 * to. This allows there to exist sets of objects of the same
110 * type in different subsystems.
111 *
112 * A subsystem does not have to be a list of only one type
113 * of object; multiple ksets can belong to one subsystem. All
114 * ksets of a subsystem share the subsystem's lock.
115 *
116 * Each kset can support specific event variables; it can
117 * supress the event generation or add subsystem specific
118 * variables carried with the event.
119 */
120struct kset_uevent_ops { 115struct kset_uevent_ops {
121 int (*filter)(struct kset *kset, struct kobject *kobj); 116 int (*filter)(struct kset *kset, struct kobject *kobj);
122 const char *(*name)(struct kset *kset, struct kobject *kobj); 117 const char *(*name)(struct kset *kset, struct kobject *kobj);
123 int (*uevent)(struct kset *kset, struct kobject *kobj, char **envp, 118 int (*uevent)(struct kset *kset, struct kobject *kobj,
124 int num_envp, char *buffer, int buffer_size); 119 struct kobj_uevent_env *env);
125}; 120};
126 121
122/**
123 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
124 *
125 * A kset defines a group of kobjects. They can be individually
126 * different "types" but overall these kobjects all want to be grouped
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.
130 *
131 * @ktype: the struct kobj_type for this specific kset
132 * @list: the list of all kobjects for this kset
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.
139 */
127struct kset { 140struct kset {
128 struct kobj_type * ktype; 141 struct kobj_type *ktype;
129 struct list_head list; 142 struct list_head list;
130 spinlock_t list_lock; 143 spinlock_t list_lock;
131 struct kobject kobj; 144 struct kobject kobj;
132 struct kset_uevent_ops * uevent_ops; 145 struct kset_uevent_ops *uevent_ops;
133}; 146};
134 147
135 148
@@ -164,22 +177,22 @@ static inline struct kobj_type * get_ktype(struct kobject * k)
164extern struct kobject * kset_find_obj(struct kset *, const char *); 177extern struct kobject * kset_find_obj(struct kset *, const char *);
165 178
166 179
167/** 180/*
168 * Use this when initializing an embedded kset with no other 181 * Use this when initializing an embedded kset with no other
169 * fields to initialize. 182 * fields to initialize.
170 */ 183 */
171#define set_kset_name(str) .kset = { .kobj = { .name = str } } 184#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }
172 185
173 186
174#define decl_subsys(_name,_type,_uevent_ops) \ 187#define decl_subsys(_name,_type,_uevent_ops) \
175struct kset _name##_subsys = { \ 188struct kset _name##_subsys = { \
176 .kobj = { .name = __stringify(_name) }, \ 189 .kobj = { .k_name = __stringify(_name) }, \
177 .ktype = _type, \ 190 .ktype = _type, \
178 .uevent_ops =_uevent_ops, \ 191 .uevent_ops =_uevent_ops, \
179} 192}
180#define decl_subsys_name(_varname,_name,_type,_uevent_ops) \ 193#define decl_subsys_name(_varname,_name,_type,_uevent_ops) \
181struct kset _varname##_subsys = { \ 194struct kset _varname##_subsys = { \
182 .kobj = { .name = __stringify(_name) }, \ 195 .kobj = { .k_name = __stringify(_name) }, \
183 .ktype = _type, \ 196 .ktype = _type, \
184 .uevent_ops =_uevent_ops, \ 197 .uevent_ops =_uevent_ops, \
185} 198}
@@ -189,7 +202,7 @@ extern struct kset kernel_subsys;
189/* The global /sys/hypervisor/ subsystem */ 202/* The global /sys/hypervisor/ subsystem */
190extern struct kset hypervisor_subsys; 203extern struct kset hypervisor_subsys;
191 204
192/** 205/*
193 * Helpers for setting the kset of registered objects. 206 * Helpers for setting the kset of registered objects.
194 * Often, a registered object belongs to a kset embedded in a 207 * Often, a registered object belongs to a kset embedded in a
195 * subsystem. These do no magic, just make the resulting code 208 * subsystem. These do no magic, just make the resulting code
@@ -207,49 +220,9 @@ extern struct kset hypervisor_subsys;
207#define kobj_set_kset_s(obj,subsys) \ 220#define kobj_set_kset_s(obj,subsys) \
208 (obj)->kobj.kset = &(subsys) 221 (obj)->kobj.kset = &(subsys)
209 222
210/**
211 * kset_set_kset_s(obj,subsys) - set kset for embedded kset.
212 * @obj: ptr to some object type.
213 * @subsys: a subsystem object (not a ptr).
214 *
215 * Can be used for any object type with an embedded ->kset.
216 * Sets the kset of @obj's embedded kobject (via its embedded
217 * kset) to @subsys.kset. This makes @obj a member of that
218 * kset.
219 */
220
221#define kset_set_kset_s(obj,subsys) \
222 (obj)->kset.kobj.kset = &(subsys)
223
224/**
225 * subsys_set_kset(obj,subsys) - set kset for subsystem
226 * @obj: ptr to some object type.
227 * @subsys: a subsystem object (not a ptr).
228 *
229 * Can be used for any object type with an embedded ->subsys.
230 * Sets the kset of @obj's kobject to @subsys.kset. This makes
231 * the object a member of that kset.
232 */
233
234#define subsys_set_kset(obj,_subsys) \
235 (obj)->subsys.kobj.kset = &(_subsys)
236
237extern void subsystem_init(struct kset *);
238extern int __must_check subsystem_register(struct kset *); 223extern int __must_check subsystem_register(struct kset *);
239extern void subsystem_unregister(struct kset *); 224extern void subsystem_unregister(struct kset *);
240 225
241static inline struct kset *subsys_get(struct kset *s)
242{
243 if (s)
244 return kset_get(s);
245 return NULL;
246}
247
248static inline void subsys_put(struct kset *s)
249{
250 kset_put(s);
251}
252
253struct subsys_attribute { 226struct subsys_attribute {
254 struct attribute attr; 227 struct attribute attr;
255 ssize_t (*show)(struct kset *, char *); 228 ssize_t (*show)(struct kset *, char *);
@@ -264,10 +237,11 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action);
264int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, 237int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
265 char *envp[]); 238 char *envp[]);
266 239
267int add_uevent_var(char **envp, int num_envp, int *cur_index, 240int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
268 char *buffer, int buffer_size, int *cur_len, 241 __attribute__((format (printf, 2, 3)));
269 const char *format, ...) 242
270 __attribute__((format (printf, 7, 8))); 243int kobject_action_type(const char *buf, size_t count,
244 enum kobject_action *type);
271#else 245#else
272static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) 246static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
273{ return 0; } 247{ return 0; }
@@ -276,10 +250,12 @@ static inline int kobject_uevent_env(struct kobject *kobj,
276 char *envp[]) 250 char *envp[])
277{ return 0; } 251{ return 0; }
278 252
279static 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, ...)
280 char *buffer, int buffer_size, int *cur_len,
281 const char *format, ...)
282{ 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; }
283#endif 259#endif
284 260
285#endif /* __KERNEL__ */ 261#endif /* __KERNEL__ */