12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- #include <linux/kobject.h>
- #include <linux/string.h>
- #include <linux/export.h>
- #include <linux/stat.h>
- #include <linux/slab.h>
- #include <linux/random.h>
- const void *kobject_namespace(struct kobject *kobj)
- {
- const struct kobj_ns_type_operations *ns_ops = kobj_ns_ops(kobj);
- if (!ns_ops || ns_ops->type == KOBJ_NS_TYPE_NONE)
- return NULL;
- return kobj->ktype->namespace(kobj);
- }
- static int populate_dir(struct kobject *kobj)
- {
- struct kobj_type *t = get_ktype(kobj);
- struct attribute *attr;
- int error = 0;
- int i;
- if (t && t->default_attrs) {
- for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) {
- error = sysfs_create_file(kobj, attr);
- if (error)
- break;
- }
- }
- return error;
- }
- static int create_dir(struct kobject *kobj)
- {
- const struct kobj_ns_type_operations *ops;
- int error;
- error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj));
- if (error)
- return error;
- error = populate_dir(kobj);
- if (error) {
- sysfs_remove_dir(kobj);
- return error;
- }
-
- sysfs_get(kobj->sd);
-
- ops = kobj_child_ns_ops(kobj);
- if (ops) {
- BUG_ON(ops->type <= KOBJ_NS_TYPE_NONE);
- BUG_ON(ops->type >= KOBJ_NS_TYPES);
- BUG_ON(!kobj_ns_type_registered(ops->type));
- sysfs_enable_ns(kobj->sd);
- }
- return 0;
- }
- static int get_kobj_path_length(struct kobject *kobj)
- {
- int length = 1;
- struct kobject *parent = kobj;
-
- do {
- if (kobject_name(parent) == NULL)
- return 0;
- length += strlen(kobject_name(parent)) + 1;
- parent = parent->parent;
- } while (parent);
- return length;
- }
- static void fill_kobj_path(struct kobject *kobj, char *path, int length)
- {
- struct kobject *parent;
- --length;
- for (parent = kobj; parent; parent = parent->parent) {
- int cur = strlen(kobject_name(parent));
-
- length -= cur;
- strncpy(path + length, kobject_name(parent), cur);
- *(path + --length) = '/';
- }
- pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
- kobj, __func__, path);
- }
- char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
- {
- char *path;
- int len;
- len = get_kobj_path_length(kobj);
- if (len == 0)
- return NULL;
- path = kzalloc(len, gfp_mask);
- if (!path)
- return NULL;
- fill_kobj_path(kobj, path, len);
- return path;
- }
- EXPORT_SYMBOL_GPL(kobject_get_path);
- static void kobj_kset_join(struct kobject *kobj)
- {
- if (!kobj->kset)
- return;
- kset_get(kobj->kset);
- spin_lock(&kobj->kset->list_lock);
- list_add_tail(&kobj->entry, &kobj->kset->list);
- spin_unlock(&kobj->kset->list_lock);
- }
- static void kobj_kset_leave(struct kobject *kobj)
- {
- if (!kobj->kset)
- return;
- spin_lock(&kobj->kset->list_lock);
- list_del_init(&kobj->entry);
- spin_unlock(&kobj->kset->list_lock);
- kset_put(kobj->kset);
- }
- static void kobject_init_internal(struct kobject *kobj)
- {
- if (!kobj)
- return;
- kref_init(&kobj->kref);
- INIT_LIST_HEAD(&kobj->entry);
- kobj->state_in_sysfs = 0;
- kobj->state_add_uevent_sent = 0;
- kobj->state_remove_uevent_sent = 0;
- kobj->state_initialized = 1;
- }
- static int kobject_add_internal(struct kobject *kobj)
- {
- int error = 0;
- struct kobject *parent;
- if (!kobj)
- return -ENOENT;
- if (!kobj->name || !kobj->name[0]) {
- WARN(1, "kobject: (%p): attempted to be registered with empty "
- "name!\n", kobj);
- return -EINVAL;
- }
- parent = kobject_get(kobj->parent);
-
- if (kobj->kset) {
- if (!parent)
- parent = kobject_get(&kobj->kset->kobj);
- kobj_kset_join(kobj);
- kobj->parent = parent;
- }
- pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
- kobject_name(kobj), kobj, __func__,
- parent ? kobject_name(parent) : "<NULL>",
- kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
- error = create_dir(kobj);
- if (error) {
- kobj_kset_leave(kobj);
- kobject_put(parent);
- kobj->parent = NULL;
-
- if (error == -EEXIST)
- WARN(1, "%s failed for %s with "
- "-EEXIST, don't try to register things with "
- "the same name in the same directory.\n",
- __func__, kobject_name(kobj));
- else
- WARN(1, "%s failed for %s (error: %d parent: %s)\n",
- __func__, kobject_name(kobj), error,
- parent ? kobject_name(parent) : "'none'");
- } else
- kobj->state_in_sysfs = 1;
- return error;
- }
- int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
- va_list vargs)
- {
- const char *s;
- if (kobj->name && !fmt)
- return 0;
- s = kvasprintf_const(GFP_KERNEL, fmt, vargs);
- if (!s)
- return -ENOMEM;
-
- if (strchr(s, '/')) {
- char *t;
- t = kstrdup(s, GFP_KERNEL);
- kfree_const(s);
- if (!t)
- return -ENOMEM;
- strreplace(t, '/', '!');
- s = t;
- }
- kfree_const(kobj->name);
- kobj->name = s;
- return 0;
- }
- int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
- {
- va_list vargs;
- int retval;
- va_start(vargs, fmt);
- retval = kobject_set_name_vargs(kobj, fmt, vargs);
- va_end(vargs);
- return retval;
- }
- EXPORT_SYMBOL(kobject_set_name);
- void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
- {
- char *err_str;
- if (!kobj) {
- err_str = "invalid kobject pointer!";
- goto error;
- }
- if (!ktype) {
- err_str = "must have a ktype to be initialized properly!\n";
- goto error;
- }
- if (kobj->state_initialized) {
-
- printk(KERN_ERR "kobject (%p): tried to init an initialized "
- "object, something is seriously wrong.\n", kobj);
- dump_stack();
- }
- kobject_init_internal(kobj);
- kobj->ktype = ktype;
- return;
- error:
- printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
- dump_stack();
- }
- EXPORT_SYMBOL(kobject_init);
- static __printf(3, 0) int kobject_add_varg(struct kobject *kobj,
- struct kobject *parent,
- const char *fmt, va_list vargs)
- {
- int retval;
- retval = kobject_set_name_vargs(kobj, fmt, vargs);
- if (retval) {
- printk(KERN_ERR "kobject: can not set name properly!\n");
- return retval;
- }
- kobj->parent = parent;
- return kobject_add_internal(kobj);
- }
- int kobject_add(struct kobject *kobj, struct kobject *parent,
- const char *fmt, ...)
- {
- va_list args;
- int retval;
- if (!kobj)
- return -EINVAL;
- if (!kobj->state_initialized) {
- printk(KERN_ERR "kobject '%s' (%p): tried to add an "
- "uninitialized object, something is seriously wrong.\n",
- kobject_name(kobj), kobj);
- dump_stack();
- return -EINVAL;
- }
- va_start(args, fmt);
- retval = kobject_add_varg(kobj, parent, fmt, args);
- va_end(args);
- return retval;
- }
- EXPORT_SYMBOL(kobject_add);
- int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
- struct kobject *parent, const char *fmt, ...)
- {
- va_list args;
- int retval;
- kobject_init(kobj, ktype);
- va_start(args, fmt);
- retval = kobject_add_varg(kobj, parent, fmt, args);
- va_end(args);
- return retval;
- }
- EXPORT_SYMBOL_GPL(kobject_init_and_add);
- int kobject_rename(struct kobject *kobj, const char *new_name)
- {
- int error = 0;
- const char *devpath = NULL;
- const char *dup_name = NULL, *name;
- char *devpath_string = NULL;
- char *envp[2];
- kobj = kobject_get(kobj);
- if (!kobj)
- return -EINVAL;
- if (!kobj->parent)
- return -EINVAL;
- devpath = kobject_get_path(kobj, GFP_KERNEL);
- if (!devpath) {
- error = -ENOMEM;
- goto out;
- }
- devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
- if (!devpath_string) {
- error = -ENOMEM;
- goto out;
- }
- sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
- envp[0] = devpath_string;
- envp[1] = NULL;
- name = dup_name = kstrdup_const(new_name, GFP_KERNEL);
- if (!name) {
- error = -ENOMEM;
- goto out;
- }
- error = sysfs_rename_dir_ns(kobj, new_name, kobject_namespace(kobj));
- if (error)
- goto out;
-
- dup_name = kobj->name;
- kobj->name = name;
-
- kobject_uevent_env(kobj, KOBJ_MOVE, envp);
- out:
- kfree_const(dup_name);
- kfree(devpath_string);
- kfree(devpath);
- kobject_put(kobj);
- return error;
- }
- EXPORT_SYMBOL_GPL(kobject_rename);
- int kobject_move(struct kobject *kobj, struct kobject *new_parent)
- {
- int error;
- struct kobject *old_parent;
- const char *devpath = NULL;
- char *devpath_string = NULL;
- char *envp[2];
- kobj = kobject_get(kobj);
- if (!kobj)
- return -EINVAL;
- new_parent = kobject_get(new_parent);
- if (!new_parent) {
- if (kobj->kset)
- new_parent = kobject_get(&kobj->kset->kobj);
- }
-
- devpath = kobject_get_path(kobj, GFP_KERNEL);
- if (!devpath) {
- error = -ENOMEM;
- goto out;
- }
- devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
- if (!devpath_string) {
- error = -ENOMEM;
- goto out;
- }
- sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
- envp[0] = devpath_string;
- envp[1] = NULL;
- error = sysfs_move_dir_ns(kobj, new_parent, kobject_namespace(kobj));
- if (error)
- goto out;
- old_parent = kobj->parent;
- kobj->parent = new_parent;
- new_parent = NULL;
- kobject_put(old_parent);
- kobject_uevent_env(kobj, KOBJ_MOVE, envp);
- out:
- kobject_put(new_parent);
- kobject_put(kobj);
- kfree(devpath_string);
- kfree(devpath);
- return error;
- }
- EXPORT_SYMBOL_GPL(kobject_move);
- void kobject_del(struct kobject *kobj)
- {
- struct kernfs_node *sd;
- if (!kobj)
- return;
- sd = kobj->sd;
- sysfs_remove_dir(kobj);
- sysfs_put(sd);
- kobj->state_in_sysfs = 0;
- kobj_kset_leave(kobj);
- kobject_put(kobj->parent);
- kobj->parent = NULL;
- }
- EXPORT_SYMBOL(kobject_del);
- struct kobject *kobject_get(struct kobject *kobj)
- {
- if (kobj) {
- if (!kobj->state_initialized)
- WARN(1, KERN_WARNING "kobject: '%s' (%p): is not "
- "initialized, yet kobject_get() is being "
- "called.\n", kobject_name(kobj), kobj);
- kref_get(&kobj->kref);
- }
- return kobj;
- }
- EXPORT_SYMBOL(kobject_get);
- static struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj)
- {
- if (!kref_get_unless_zero(&kobj->kref))
- kobj = NULL;
- return kobj;
- }
- static void kobject_cleanup(struct kobject *kobj)
- {
- struct kobj_type *t = get_ktype(kobj);
- const char *name = kobj->name;
- pr_debug("kobject: '%s' (%p): %s, parent %p\n",
- kobject_name(kobj), kobj, __func__, kobj->parent);
- if (t && !t->release)
- pr_debug("kobject: '%s' (%p): does not have a release() "
- "function, it is broken and must be fixed.\n",
- kobject_name(kobj), kobj);
-
- if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) {
- pr_debug("kobject: '%s' (%p): auto cleanup 'remove' event\n",
- kobject_name(kobj), kobj);
- kobject_uevent(kobj, KOBJ_REMOVE);
- }
-
- if (kobj->state_in_sysfs) {
- pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
- kobject_name(kobj), kobj);
- kobject_del(kobj);
- }
- if (t && t->release) {
- pr_debug("kobject: '%s' (%p): calling ktype release\n",
- kobject_name(kobj), kobj);
- t->release(kobj);
- }
-
- if (name) {
- pr_debug("kobject: '%s': free name\n", name);
- kfree_const(name);
- }
- }
- #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
- static void kobject_delayed_cleanup(struct work_struct *work)
- {
- kobject_cleanup(container_of(to_delayed_work(work),
- struct kobject, release));
- }
- #endif
- static void kobject_release(struct kref *kref)
- {
- struct kobject *kobj = container_of(kref, struct kobject, kref);
- #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
- unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
- pr_info("kobject: '%s' (%p): %s, parent %p (delayed %ld)\n",
- kobject_name(kobj), kobj, __func__, kobj->parent, delay);
- INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup);
- schedule_delayed_work(&kobj->release, delay);
- #else
- kobject_cleanup(kobj);
- #endif
- }
- void kobject_put(struct kobject *kobj)
- {
- if (kobj) {
- if (!kobj->state_initialized)
- WARN(1, KERN_WARNING "kobject: '%s' (%p): is not "
- "initialized, yet kobject_put() is being "
- "called.\n", kobject_name(kobj), kobj);
- kref_put(&kobj->kref, kobject_release);
- }
- }
- EXPORT_SYMBOL(kobject_put);
- static void dynamic_kobj_release(struct kobject *kobj)
- {
- pr_debug("kobject: (%p): %s\n", kobj, __func__);
- kfree(kobj);
- }
- static struct kobj_type dynamic_kobj_ktype = {
- .release = dynamic_kobj_release,
- .sysfs_ops = &kobj_sysfs_ops,
- };
- struct kobject *kobject_create(void)
- {
- struct kobject *kobj;
- kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
- if (!kobj)
- return NULL;
- kobject_init(kobj, &dynamic_kobj_ktype);
- return kobj;
- }
- struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
- {
- struct kobject *kobj;
- int retval;
- kobj = kobject_create();
- if (!kobj)
- return NULL;
- retval = kobject_add(kobj, parent, "%s", name);
- if (retval) {
- printk(KERN_WARNING "%s: kobject_add error: %d\n",
- __func__, retval);
- kobject_put(kobj);
- kobj = NULL;
- }
- return kobj;
- }
- EXPORT_SYMBOL_GPL(kobject_create_and_add);
- void kset_init(struct kset *k)
- {
- kobject_init_internal(&k->kobj);
- INIT_LIST_HEAD(&k->list);
- spin_lock_init(&k->list_lock);
- }
- static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
- {
- struct kobj_attribute *kattr;
- ssize_t ret = -EIO;
- kattr = container_of(attr, struct kobj_attribute, attr);
- if (kattr->show)
- ret = kattr->show(kobj, kattr, buf);
- return ret;
- }
- static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
- const char *buf, size_t count)
- {
- struct kobj_attribute *kattr;
- ssize_t ret = -EIO;
- kattr = container_of(attr, struct kobj_attribute, attr);
- if (kattr->store)
- ret = kattr->store(kobj, kattr, buf, count);
- return ret;
- }
- const struct sysfs_ops kobj_sysfs_ops = {
- .show = kobj_attr_show,
- .store = kobj_attr_store,
- };
- EXPORT_SYMBOL_GPL(kobj_sysfs_ops);
- int kset_register(struct kset *k)
- {
- int err;
- if (!k)
- return -EINVAL;
- kset_init(k);
- err = kobject_add_internal(&k->kobj);
- if (err)
- return err;
- kobject_uevent(&k->kobj, KOBJ_ADD);
- return 0;
- }
- EXPORT_SYMBOL(kset_register);
- void kset_unregister(struct kset *k)
- {
- if (!k)
- return;
- kobject_del(&k->kobj);
- kobject_put(&k->kobj);
- }
- EXPORT_SYMBOL(kset_unregister);
- struct kobject *kset_find_obj(struct kset *kset, const char *name)
- {
- struct kobject *k;
- struct kobject *ret = NULL;
- spin_lock(&kset->list_lock);
- list_for_each_entry(k, &kset->list, entry) {
- if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
- ret = kobject_get_unless_zero(k);
- break;
- }
- }
- spin_unlock(&kset->list_lock);
- return ret;
- }
- EXPORT_SYMBOL_GPL(kset_find_obj);
- static void kset_release(struct kobject *kobj)
- {
- struct kset *kset = container_of(kobj, struct kset, kobj);
- pr_debug("kobject: '%s' (%p): %s\n",
- kobject_name(kobj), kobj, __func__);
- kfree(kset);
- }
- static struct kobj_type kset_ktype = {
- .sysfs_ops = &kobj_sysfs_ops,
- .release = kset_release,
- };
- static struct kset *kset_create(const char *name,
- const struct kset_uevent_ops *uevent_ops,
- struct kobject *parent_kobj)
- {
- struct kset *kset;
- int retval;
- kset = kzalloc(sizeof(*kset), GFP_KERNEL);
- if (!kset)
- return NULL;
- retval = kobject_set_name(&kset->kobj, "%s", name);
- if (retval) {
- kfree(kset);
- return NULL;
- }
- kset->uevent_ops = uevent_ops;
- kset->kobj.parent = parent_kobj;
-
- kset->kobj.ktype = &kset_ktype;
- kset->kobj.kset = NULL;
- return kset;
- }
- struct kset *kset_create_and_add(const char *name,
- const struct kset_uevent_ops *uevent_ops,
- struct kobject *parent_kobj)
- {
- struct kset *kset;
- int error;
- kset = kset_create(name, uevent_ops, parent_kobj);
- if (!kset)
- return NULL;
- error = kset_register(kset);
- if (error) {
- kfree(kset);
- return NULL;
- }
- return kset;
- }
- EXPORT_SYMBOL_GPL(kset_create_and_add);
- static DEFINE_SPINLOCK(kobj_ns_type_lock);
- static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
- int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
- {
- enum kobj_ns_type type = ops->type;
- int error;
- spin_lock(&kobj_ns_type_lock);
- error = -EINVAL;
- if (type >= KOBJ_NS_TYPES)
- goto out;
- error = -EINVAL;
- if (type <= KOBJ_NS_TYPE_NONE)
- goto out;
- error = -EBUSY;
- if (kobj_ns_ops_tbl[type])
- goto out;
- error = 0;
- kobj_ns_ops_tbl[type] = ops;
- out:
- spin_unlock(&kobj_ns_type_lock);
- return error;
- }
- int kobj_ns_type_registered(enum kobj_ns_type type)
- {
- int registered = 0;
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES))
- registered = kobj_ns_ops_tbl[type] != NULL;
- spin_unlock(&kobj_ns_type_lock);
- return registered;
- }
- const struct kobj_ns_type_operations *kobj_child_ns_ops(struct kobject *parent)
- {
- const struct kobj_ns_type_operations *ops = NULL;
- if (parent && parent->ktype && parent->ktype->child_ns_type)
- ops = parent->ktype->child_ns_type(parent);
- return ops;
- }
- const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj)
- {
- return kobj_child_ns_ops(kobj->parent);
- }
- bool kobj_ns_current_may_mount(enum kobj_ns_type type)
- {
- bool may_mount = true;
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) &&
- kobj_ns_ops_tbl[type])
- may_mount = kobj_ns_ops_tbl[type]->current_may_mount();
- spin_unlock(&kobj_ns_type_lock);
- return may_mount;
- }
- void *kobj_ns_grab_current(enum kobj_ns_type type)
- {
- void *ns = NULL;
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) &&
- kobj_ns_ops_tbl[type])
- ns = kobj_ns_ops_tbl[type]->grab_current_ns();
- spin_unlock(&kobj_ns_type_lock);
- return ns;
- }
- const void *kobj_ns_netlink(enum kobj_ns_type type, struct sock *sk)
- {
- const void *ns = NULL;
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) &&
- kobj_ns_ops_tbl[type])
- ns = kobj_ns_ops_tbl[type]->netlink_ns(sk);
- spin_unlock(&kobj_ns_type_lock);
- return ns;
- }
- const void *kobj_ns_initial(enum kobj_ns_type type)
- {
- const void *ns = NULL;
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) &&
- kobj_ns_ops_tbl[type])
- ns = kobj_ns_ops_tbl[type]->initial_ns();
- spin_unlock(&kobj_ns_type_lock);
- return ns;
- }
- void kobj_ns_drop(enum kobj_ns_type type, void *ns)
- {
- spin_lock(&kobj_ns_type_lock);
- if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) &&
- kobj_ns_ops_tbl[type] && kobj_ns_ops_tbl[type]->drop_ns)
- kobj_ns_ops_tbl[type]->drop_ns(ns);
- spin_unlock(&kobj_ns_type_lock);
- }
|