diff options
| -rw-r--r-- | fs/sysfs/dir.c | 8 | ||||
| -rw-r--r-- | fs/sysfs/sysfs.h | 13 | ||||
| -rw-r--r-- | include/linux/kobject.h | 11 | ||||
| -rw-r--r-- | include/linux/sysfs.h | 1 | ||||
| -rw-r--r-- | lib/kobject.c | 11 |
5 files changed, 43 insertions, 1 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index a63eb4ba7867..7e54bac8c4b0 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
| @@ -614,6 +614,14 @@ int sysfs_create_subdir(struct kobject *kobj, const char *name, | |||
| 614 | KOBJ_NS_TYPE_NONE, NULL, name, p_sd); | 614 | KOBJ_NS_TYPE_NONE, NULL, name, p_sd); |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | /** | ||
| 618 | * sysfs_read_ns_type: return associated ns_type | ||
| 619 | * @kobj: the kobject being queried | ||
| 620 | * | ||
| 621 | * Each kobject can be tagged with exactly one namespace type | ||
| 622 | * (i.e. network or user). Return the ns_type associated with | ||
| 623 | * this object if any | ||
| 624 | */ | ||
| 617 | static enum kobj_ns_type sysfs_read_ns_type(struct kobject *kobj) | 625 | static enum kobj_ns_type sysfs_read_ns_type(struct kobject *kobj) |
| 618 | { | 626 | { |
| 619 | const struct kobj_ns_type_operations *ops; | 627 | const struct kobj_ns_type_operations *ops; |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 93847d54c2e3..6a13105b5594 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
| @@ -58,7 +58,7 @@ struct sysfs_dirent { | |||
| 58 | struct sysfs_dirent *s_sibling; | 58 | struct sysfs_dirent *s_sibling; |
| 59 | const char *s_name; | 59 | const char *s_name; |
| 60 | 60 | ||
| 61 | const void *s_ns; | 61 | const void *s_ns; /* namespace tag */ |
| 62 | union { | 62 | union { |
| 63 | struct sysfs_elem_dir s_dir; | 63 | struct sysfs_elem_dir s_dir; |
| 64 | struct sysfs_elem_symlink s_symlink; | 64 | struct sysfs_elem_symlink s_symlink; |
| @@ -82,6 +82,7 @@ struct sysfs_dirent { | |||
| 82 | #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) | 82 | #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) |
| 83 | #define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR) | 83 | #define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR) |
| 84 | 84 | ||
| 85 | /* identify any namespace tag on sysfs_dirents */ | ||
| 85 | #define SYSFS_NS_TYPE_MASK 0xff00 | 86 | #define SYSFS_NS_TYPE_MASK 0xff00 |
| 86 | #define SYSFS_NS_TYPE_SHIFT 8 | 87 | #define SYSFS_NS_TYPE_SHIFT 8 |
| 87 | 88 | ||
| @@ -93,6 +94,10 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd) | |||
| 93 | return sd->s_flags & SYSFS_TYPE_MASK; | 94 | return sd->s_flags & SYSFS_TYPE_MASK; |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 97 | /* | ||
| 98 | * Return any namespace tags on this dirent. | ||
| 99 | * enum kobj_ns_type is defined in linux/kobject.h | ||
| 100 | */ | ||
| 96 | static inline enum kobj_ns_type sysfs_ns_type(struct sysfs_dirent *sd) | 101 | static inline enum kobj_ns_type sysfs_ns_type(struct sysfs_dirent *sd) |
| 97 | { | 102 | { |
| 98 | return (sd->s_flags & SYSFS_NS_TYPE_MASK) >> SYSFS_NS_TYPE_SHIFT; | 103 | return (sd->s_flags & SYSFS_NS_TYPE_MASK) >> SYSFS_NS_TYPE_SHIFT; |
| @@ -123,6 +128,12 @@ struct sysfs_addrm_cxt { | |||
| 123 | /* | 128 | /* |
| 124 | * mount.c | 129 | * mount.c |
| 125 | */ | 130 | */ |
| 131 | |||
| 132 | /* | ||
| 133 | * Each sb is associated with a set of namespace tags (i.e. | ||
| 134 | * the network namespace of the task which mounted this sysfs | ||
| 135 | * instance). | ||
| 136 | */ | ||
| 126 | struct sysfs_super_info { | 137 | struct sysfs_super_info { |
| 127 | const void *ns[KOBJ_NS_TYPES]; | 138 | const void *ns[KOBJ_NS_TYPES]; |
| 128 | }; | 139 | }; |
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index d9456f69904f..b60d2dfe4e69 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
| @@ -136,12 +136,23 @@ struct kobj_attribute { | |||
| 136 | 136 | ||
| 137 | extern const struct sysfs_ops kobj_sysfs_ops; | 137 | extern const struct sysfs_ops kobj_sysfs_ops; |
| 138 | 138 | ||
| 139 | /* | ||
| 140 | * Namespace types which are used to tag kobjects and sysfs entries. | ||
| 141 | * Network namespace will likely be the first. | ||
| 142 | */ | ||
| 139 | enum kobj_ns_type { | 143 | enum kobj_ns_type { |
| 140 | KOBJ_NS_TYPE_NONE = 0, | 144 | KOBJ_NS_TYPE_NONE = 0, |
| 141 | KOBJ_NS_TYPES | 145 | KOBJ_NS_TYPES |
| 142 | }; | 146 | }; |
| 143 | 147 | ||
| 144 | struct sock; | 148 | struct sock; |
| 149 | |||
| 150 | /* | ||
| 151 | * Callbacks so sysfs can determine namespaces | ||
| 152 | * @current_ns: return calling task's namespace | ||
| 153 | * @netlink_ns: return namespace to which a sock belongs (right?) | ||
| 154 | * @initial_ns: return the initial namespace (i.e. init_net_ns) | ||
| 155 | */ | ||
| 145 | struct kobj_ns_type_operations { | 156 | struct kobj_ns_type_operations { |
| 146 | enum kobj_ns_type type; | 157 | enum kobj_ns_type type; |
| 147 | const void *(*current_ns)(void); | 158 | const void *(*current_ns)(void); |
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 976c4664b216..47f1c95b5298 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
| @@ -178,6 +178,7 @@ struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd); | |||
| 178 | void sysfs_put(struct sysfs_dirent *sd); | 178 | void sysfs_put(struct sysfs_dirent *sd); |
| 179 | void sysfs_printk_last_file(void); | 179 | void sysfs_printk_last_file(void); |
| 180 | 180 | ||
| 181 | /* Called to clear a ns tag when it is no longer valid */ | ||
| 181 | void sysfs_exit_ns(enum kobj_ns_type type, const void *tag); | 182 | void sysfs_exit_ns(enum kobj_ns_type type, const void *tag); |
| 182 | 183 | ||
| 183 | int __must_check sysfs_init(void); | 184 | int __must_check sysfs_init(void); |
diff --git a/lib/kobject.c b/lib/kobject.c index b2c6d1f56e65..f07c57252e82 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
| @@ -948,6 +948,17 @@ const void *kobj_ns_initial(enum kobj_ns_type type) | |||
| 948 | return ns; | 948 | return ns; |
| 949 | } | 949 | } |
| 950 | 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 | */ | ||
| 951 | void kobj_ns_exit(enum kobj_ns_type type, const void *ns) | 962 | void kobj_ns_exit(enum kobj_ns_type type, const void *ns) |
| 952 | { | 963 | { |
| 953 | sysfs_exit_ns(type, ns); | 964 | sysfs_exit_ns(type, ns); |
