diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-28 14:54:23 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-29 20:41:35 -0500 |
commit | a7dc66dfb4c6d6c1d7c14d5106ce467f1dbd4eba (patch) | |
tree | 013752fe5b620dd8bda9318bd1156941c5995de3 /fs | |
parent | 471bd7b78bd56c580e91e00a0f656ca922ab3b3c (diff) |
sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR
After kernfs_ops and sysfs_dirent->s_attr.size addition, the
distinction between SYSFS_KOBJ_BIN_ATTR and SYSFS_KOBJ_ATTR is only
necessary while creating files to decide which kernfs_ops to use.
Afterwards, they behave exactly the same.
This patch removes SYSFS_KOBJ_BIN_ATTR along with sysfs_is_bin().
sysfs_add_file[_mode_ns]() are updated to take bool @is_bin instead of
@type.
This patch doesn't introduce any behavior changes. This completely
isolates the distinction between the two sysfs file types in the sysfs
layer proper.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/sysfs/file.c | 23 | ||||
-rw-r--r-- | fs/sysfs/group.c | 5 | ||||
-rw-r--r-- | fs/sysfs/inode.c | 1 | ||||
-rw-r--r-- | fs/sysfs/sysfs.h | 11 |
4 files changed, 14 insertions, 26 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 0b0cec8e9d8f..e2ce6743113a 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -47,11 +47,6 @@ struct sysfs_open_dirent { | |||
47 | struct list_head files; /* goes through sysfs_open_file.list */ | 47 | struct list_head files; /* goes through sysfs_open_file.list */ |
48 | }; | 48 | }; |
49 | 49 | ||
50 | static bool sysfs_is_bin(struct sysfs_dirent *sd) | ||
51 | { | ||
52 | return sysfs_type(sd) == SYSFS_KOBJ_BIN_ATTR; | ||
53 | } | ||
54 | |||
55 | static struct sysfs_open_file *sysfs_of(struct file *file) | 50 | static struct sysfs_open_file *sysfs_of(struct file *file) |
56 | { | 51 | { |
57 | return ((struct seq_file *)file->private_data)->private; | 52 | return ((struct seq_file *)file->private_data)->private; |
@@ -916,7 +911,7 @@ static const struct kernfs_ops sysfs_bin_kfops_rw = { | |||
916 | }; | 911 | }; |
917 | 912 | ||
918 | int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | 913 | int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, |
919 | const struct attribute *attr, int type, | 914 | const struct attribute *attr, bool is_bin, |
920 | umode_t amode, const void *ns) | 915 | umode_t amode, const void *ns) |
921 | { | 916 | { |
922 | umode_t mode = (amode & S_IALLUGO) | S_IFREG; | 917 | umode_t mode = (amode & S_IALLUGO) | S_IFREG; |
@@ -926,7 +921,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
926 | loff_t size; | 921 | loff_t size; |
927 | int rc; | 922 | int rc; |
928 | 923 | ||
929 | if (type == SYSFS_KOBJ_ATTR) { | 924 | if (!is_bin) { |
930 | struct kobject *kobj = dir_sd->priv; | 925 | struct kobject *kobj = dir_sd->priv; |
931 | const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; | 926 | const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; |
932 | 927 | ||
@@ -961,7 +956,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
961 | size = battr->size; | 956 | size = battr->size; |
962 | } | 957 | } |
963 | 958 | ||
964 | sd = sysfs_new_dirent(attr->name, mode, type); | 959 | sd = sysfs_new_dirent(attr->name, mode, SYSFS_KOBJ_ATTR); |
965 | if (!sd) | 960 | if (!sd) |
966 | return -ENOMEM; | 961 | return -ENOMEM; |
967 | 962 | ||
@@ -991,11 +986,10 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
991 | return rc; | 986 | return rc; |
992 | } | 987 | } |
993 | 988 | ||
994 | |||
995 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | 989 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, |
996 | int type) | 990 | bool is_bin) |
997 | { | 991 | { |
998 | return sysfs_add_file_mode_ns(dir_sd, attr, type, attr->mode, NULL); | 992 | return sysfs_add_file_mode_ns(dir_sd, attr, is_bin, attr->mode, NULL); |
999 | } | 993 | } |
1000 | 994 | ||
1001 | /** | 995 | /** |
@@ -1009,8 +1003,7 @@ int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, | |||
1009 | { | 1003 | { |
1010 | BUG_ON(!kobj || !kobj->sd || !attr); | 1004 | BUG_ON(!kobj || !kobj->sd || !attr); |
1011 | 1005 | ||
1012 | return sysfs_add_file_mode_ns(kobj->sd, attr, SYSFS_KOBJ_ATTR, | 1006 | return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode, ns); |
1013 | attr->mode, ns); | ||
1014 | 1007 | ||
1015 | } | 1008 | } |
1016 | EXPORT_SYMBOL_GPL(sysfs_create_file_ns); | 1009 | EXPORT_SYMBOL_GPL(sysfs_create_file_ns); |
@@ -1049,7 +1042,7 @@ int sysfs_add_file_to_group(struct kobject *kobj, | |||
1049 | if (!dir_sd) | 1042 | if (!dir_sd) |
1050 | return -ENOENT; | 1043 | return -ENOENT; |
1051 | 1044 | ||
1052 | error = sysfs_add_file(dir_sd, attr, SYSFS_KOBJ_ATTR); | 1045 | error = sysfs_add_file(dir_sd, attr, false); |
1053 | sysfs_put(dir_sd); | 1046 | sysfs_put(dir_sd); |
1054 | 1047 | ||
1055 | return error; | 1048 | return error; |
@@ -1141,7 +1134,7 @@ int sysfs_create_bin_file(struct kobject *kobj, | |||
1141 | { | 1134 | { |
1142 | BUG_ON(!kobj || !kobj->sd || !attr); | 1135 | BUG_ON(!kobj || !kobj->sd || !attr); |
1143 | 1136 | ||
1144 | return sysfs_add_file(kobj->sd, &attr->attr, SYSFS_KOBJ_BIN_ATTR); | 1137 | return sysfs_add_file(kobj->sd, &attr->attr, true); |
1145 | } | 1138 | } |
1146 | EXPORT_SYMBOL_GPL(sysfs_create_bin_file); | 1139 | EXPORT_SYMBOL_GPL(sysfs_create_bin_file); |
1147 | 1140 | ||
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 065689ddb4cb..9f65cd97a2d7 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c | |||
@@ -55,8 +55,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, | |||
55 | if (!mode) | 55 | if (!mode) |
56 | continue; | 56 | continue; |
57 | } | 57 | } |
58 | error = sysfs_add_file_mode_ns(dir_sd, *attr, | 58 | error = sysfs_add_file_mode_ns(dir_sd, *attr, false, |
59 | SYSFS_KOBJ_ATTR, | ||
60 | (*attr)->mode | mode, | 59 | (*attr)->mode | mode, |
61 | NULL); | 60 | NULL); |
62 | if (unlikely(error)) | 61 | if (unlikely(error)) |
@@ -269,7 +268,7 @@ int sysfs_merge_group(struct kobject *kobj, | |||
269 | return -ENOENT; | 268 | return -ENOENT; |
270 | 269 | ||
271 | for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) | 270 | for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) |
272 | error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR); | 271 | error = sysfs_add_file(dir_sd, *attr, false); |
273 | if (error) { | 272 | if (error) { |
274 | while (--i >= 0) | 273 | while (--i >= 0) |
275 | kernfs_remove_by_name(dir_sd, (*--attr)->name); | 274 | kernfs_remove_by_name(dir_sd, (*--attr)->name); |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index 037a8925f56e..b3c717ab3496 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -269,7 +269,6 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) | |||
269 | inode->i_fop = &sysfs_dir_operations; | 269 | inode->i_fop = &sysfs_dir_operations; |
270 | break; | 270 | break; |
271 | case SYSFS_KOBJ_ATTR: | 271 | case SYSFS_KOBJ_ATTR: |
272 | case SYSFS_KOBJ_BIN_ATTR: | ||
273 | inode->i_size = sd->s_attr.size; | 272 | inode->i_size = sd->s_attr.size; |
274 | inode->i_fop = &kernfs_file_operations; | 273 | inode->i_fop = &kernfs_file_operations; |
275 | break; | 274 | break; |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index d40e85e8c2ee..28898fa551c6 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -83,10 +83,9 @@ struct sysfs_dirent { | |||
83 | #define SYSFS_TYPE_MASK 0x00ff | 83 | #define SYSFS_TYPE_MASK 0x00ff |
84 | #define SYSFS_DIR 0x0001 | 84 | #define SYSFS_DIR 0x0001 |
85 | #define SYSFS_KOBJ_ATTR 0x0002 | 85 | #define SYSFS_KOBJ_ATTR 0x0002 |
86 | #define SYSFS_KOBJ_BIN_ATTR 0x0004 | ||
87 | #define SYSFS_KOBJ_LINK 0x0008 | 86 | #define SYSFS_KOBJ_LINK 0x0008 |
88 | #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) | 87 | #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) |
89 | #define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR) | 88 | #define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR |
90 | 89 | ||
91 | #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK | 90 | #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK |
92 | #define SYSFS_FLAG_NS 0x01000 | 91 | #define SYSFS_FLAG_NS 0x01000 |
@@ -115,10 +114,8 @@ do { \ | |||
115 | static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd) | 114 | static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd) |
116 | { | 115 | { |
117 | struct attribute *attr = sd->priv; | 116 | struct attribute *attr = sd->priv; |
118 | int type = sysfs_type(sd); | ||
119 | 117 | ||
120 | return (type == SYSFS_KOBJ_ATTR || type == SYSFS_KOBJ_BIN_ATTR) && | 118 | return sysfs_type(sd) == SYSFS_KOBJ_ATTR && attr->ignore_lockdep; |
121 | attr->ignore_lockdep; | ||
122 | } | 119 | } |
123 | 120 | ||
124 | #else | 121 | #else |
@@ -219,10 +216,10 @@ int sysfs_inode_init(void); | |||
219 | extern const struct file_operations kernfs_file_operations; | 216 | extern const struct file_operations kernfs_file_operations; |
220 | 217 | ||
221 | int sysfs_add_file(struct sysfs_dirent *dir_sd, | 218 | int sysfs_add_file(struct sysfs_dirent *dir_sd, |
222 | const struct attribute *attr, int type); | 219 | const struct attribute *attr, bool is_bin); |
223 | 220 | ||
224 | int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | 221 | int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, |
225 | const struct attribute *attr, int type, | 222 | const struct attribute *attr, bool is_bin, |
226 | umode_t amode, const void *ns); | 223 | umode_t amode, const void *ns); |
227 | void sysfs_unmap_bin_file(struct sysfs_dirent *sd); | 224 | void sysfs_unmap_bin_file(struct sysfs_dirent *sd); |
228 | 225 | ||