diff options
Diffstat (limited to 'lib/kobject.c')
-rw-r--r-- | lib/kobject.c | 121 |
1 files changed, 118 insertions, 3 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index b512b746d2a..f07c57252e8 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, | |||
700 | return ret; | 700 | return ret; |
701 | } | 701 | } |
702 | 702 | ||
703 | struct sysfs_ops kobj_sysfs_ops = { | 703 | const struct sysfs_ops kobj_sysfs_ops = { |
704 | .show = kobj_attr_show, | 704 | .show = kobj_attr_show, |
705 | .store = kobj_attr_store, | 705 | .store = kobj_attr_store, |
706 | }; | 706 | }; |
@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = { | |||
789 | * If the kset was not able to be created, NULL will be returned. | 789 | * If the kset was not able to be created, NULL will be returned. |
790 | */ | 790 | */ |
791 | static struct kset *kset_create(const char *name, | 791 | static struct kset *kset_create(const char *name, |
792 | struct kset_uevent_ops *uevent_ops, | 792 | const struct kset_uevent_ops *uevent_ops, |
793 | struct kobject *parent_kobj) | 793 | struct kobject *parent_kobj) |
794 | { | 794 | { |
795 | struct kset *kset; | 795 | struct kset *kset; |
@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name, | |||
832 | * If the kset was not able to be created, NULL will be returned. | 832 | * If the kset was not able to be created, NULL will be returned. |
833 | */ | 833 | */ |
834 | struct kset *kset_create_and_add(const char *name, | 834 | struct kset *kset_create_and_add(const char *name, |
835 | struct kset_uevent_ops *uevent_ops, | 835 | const struct kset_uevent_ops *uevent_ops, |
836 | struct kobject *parent_kobj) | 836 | struct kobject *parent_kobj) |
837 | { | 837 | { |
838 | struct kset *kset; | 838 | struct kset *kset; |
@@ -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); |