diff options
Diffstat (limited to 'lib/kobject.c')
| -rw-r--r-- | lib/kobject.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 8115eb1bbf4d..f07c57252e82 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
| @@ -850,6 +850,121 @@ struct kset *kset_create_and_add(const char *name, | |||
| 850 | } | 850 | } |
| 851 | EXPORT_SYMBOL_GPL(kset_create_and_add); | 851 | EXPORT_SYMBOL_GPL(kset_create_and_add); |
| 852 | 852 | ||
| 853 | |||
| 854 | static DEFINE_SPINLOCK(kobj_ns_type_lock); | ||
| 855 | static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES]; | ||
| 856 | |||
| 857 | int kobj_ns_type_register(const struct kobj_ns_type_operations *ops) | ||
| 858 | { | ||
| 859 | enum kobj_ns_type type = ops->type; | ||
| 860 | int error; | ||
| 861 | |||
| 862 | spin_lock(&kobj_ns_type_lock); | ||
| 863 | |||
| 864 | error = -EINVAL; | ||
| 865 | if (type >= KOBJ_NS_TYPES) | ||
| 866 | goto out; | ||
| 867 | |||
| 868 | error = -EINVAL; | ||
| 869 | if (type <= KOBJ_NS_TYPE_NONE) | ||
| 870 | goto out; | ||
| 871 | |||
| 872 | error = -EBUSY; | ||
| 873 | if (kobj_ns_ops_tbl[type]) | ||
| 874 | goto out; | ||
| 875 | |||
| 876 | error = 0; | ||
| 877 | kobj_ns_ops_tbl[type] = ops; | ||
| 878 | |||
| 879 | out: | ||
| 880 | spin_unlock(&kobj_ns_type_lock); | ||
| 881 | return error; | ||
| 882 | } | ||
| 883 | |||
| 884 | int kobj_ns_type_registered(enum kobj_ns_type type) | ||
| 885 | { | ||
| 886 | int registered = 0; | ||
| 887 | |||
| 888 | spin_lock(&kobj_ns_type_lock); | ||
| 889 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES)) | ||
| 890 | registered = kobj_ns_ops_tbl[type] != NULL; | ||
| 891 | spin_unlock(&kobj_ns_type_lock); | ||
| 892 | |||
| 893 | return registered; | ||
| 894 | } | ||
| 895 | |||
| 896 | const struct kobj_ns_type_operations *kobj_child_ns_ops(struct kobject *parent) | ||
| 897 | { | ||
| 898 | const struct kobj_ns_type_operations *ops = NULL; | ||
| 899 | |||
| 900 | if (parent && parent->ktype->child_ns_type) | ||
| 901 | ops = parent->ktype->child_ns_type(parent); | ||
| 902 | |||
| 903 | return ops; | ||
| 904 | } | ||
| 905 | |||
| 906 | const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) | ||
| 907 | { | ||
| 908 | return kobj_child_ns_ops(kobj->parent); | ||
| 909 | } | ||
| 910 | |||
| 911 | |||
| 912 | const void *kobj_ns_current(enum kobj_ns_type type) | ||
| 913 | { | ||
| 914 | const void *ns = NULL; | ||
| 915 | |||
| 916 | spin_lock(&kobj_ns_type_lock); | ||
| 917 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
| 918 | kobj_ns_ops_tbl[type]) | ||
| 919 | ns = kobj_ns_ops_tbl[type]->current_ns(); | ||
| 920 | spin_unlock(&kobj_ns_type_lock); | ||
| 921 | |||
| 922 | return ns; | ||
| 923 | } | ||
| 924 | |||
| 925 | const void *kobj_ns_netlink(enum kobj_ns_type type, struct sock *sk) | ||
| 926 | { | ||
| 927 | const void *ns = NULL; | ||
| 928 | |||
| 929 | spin_lock(&kobj_ns_type_lock); | ||
| 930 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
| 931 | kobj_ns_ops_tbl[type]) | ||
| 932 | ns = kobj_ns_ops_tbl[type]->netlink_ns(sk); | ||
| 933 | spin_unlock(&kobj_ns_type_lock); | ||
| 934 | |||
| 935 | return ns; | ||
| 936 | } | ||
| 937 | |||
| 938 | const void *kobj_ns_initial(enum kobj_ns_type type) | ||
| 939 | { | ||
| 940 | const void *ns = NULL; | ||
| 941 | |||
| 942 | spin_lock(&kobj_ns_type_lock); | ||
| 943 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
| 944 | kobj_ns_ops_tbl[type]) | ||
| 945 | ns = kobj_ns_ops_tbl[type]->initial_ns(); | ||
| 946 | spin_unlock(&kobj_ns_type_lock); | ||
| 947 | |||
| 948 | return ns; | ||
| 949 | } | ||
| 950 | |||
| 951 | /* | ||
| 952 | * kobj_ns_exit - invalidate a namespace tag | ||
| 953 | * | ||
| 954 | * @type: the namespace type (i.e. KOBJ_NS_TYPE_NET) | ||
| 955 | * @ns: the actual namespace being invalidated | ||
| 956 | * | ||
| 957 | * This is called when a tag is no longer valid. For instance, | ||
| 958 | * when a network namespace exits, it uses this helper to | ||
| 959 | * make sure no sb's sysfs_info points to the now-invalidated | ||
| 960 | * netns. | ||
| 961 | */ | ||
| 962 | void kobj_ns_exit(enum kobj_ns_type type, const void *ns) | ||
| 963 | { | ||
| 964 | sysfs_exit_ns(type, ns); | ||
| 965 | } | ||
| 966 | |||
| 967 | |||
| 853 | EXPORT_SYMBOL(kobject_get); | 968 | EXPORT_SYMBOL(kobject_get); |
| 854 | EXPORT_SYMBOL(kobject_put); | 969 | EXPORT_SYMBOL(kobject_put); |
| 855 | EXPORT_SYMBOL(kobject_del); | 970 | EXPORT_SYMBOL(kobject_del); |
