2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _LINUX_KOBJECT_H_
29 #define _LINUX_KOBJECT_H_
31 #include <machine/stdarg.h>
33 #include <linux/kernel.h>
34 #include <linux/kref.h>
35 #include <linux/slab.h>
41 void (*release)(struct kobject *kobj);
42 const struct sysfs_ops *sysfs_ops;
43 struct attribute **default_attrs;
46 extern struct kobj_type kfree_type;
49 struct kobject *parent;
52 struct kobj_type *ktype;
53 struct list_head entry;
54 struct sysctl_oid *oidp;
58 kobject_init(struct kobject *kobj, struct kobj_type *ktype)
61 kref_init(&kobj->kref);
62 INIT_LIST_HEAD(&kobj->entry);
67 static inline void kobject_put(struct kobject *kobj);
68 void kobject_release(struct kref *kref);
71 kobject_put(struct kobject *kobj)
75 kref_put(&kobj->kref, kobject_release);
78 static inline struct kobject *
79 kobject_get(struct kobject *kobj)
83 kref_get(&kobj->kref);
88 kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
98 name = kzalloc(MAXPATHLEN, GFP_KERNEL);
101 vsnprintf(name, MAXPATHLEN, fmt, args);
104 for (; *name != '\0'; name++)
110 int kobject_add(struct kobject *kobj, struct kobject *parent,
111 const char *fmt, ...);
113 static inline struct kobject *
116 struct kobject *kobj;
118 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
121 kobject_init(kobj, &kfree_type);
126 static inline struct kobject *
127 kobject_create_and_add(const char *name, struct kobject *parent)
129 struct kobject *kobj;
131 kobj = kobject_create();
134 if (kobject_add(kobj, parent, "%s", name) == 0)
143 kobject_name(const struct kobject *kobj)
149 int kobject_set_name(struct kobject *kobj, const char *fmt, ...);
150 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
151 struct kobject *parent, const char *fmt, ...);
153 #endif /* _LINUX_KOBJECT_H_ */