diff options
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/bin.c | 68 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 32 |
2 files changed, 47 insertions, 53 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c index 4e321f7353fa..a4759833d62d 100644 --- a/fs/sysfs/bin.c +++ b/fs/sysfs/bin.c | |||
@@ -179,30 +179,14 @@ static void bin_vma_open(struct vm_area_struct *vma) | |||
179 | struct bin_buffer *bb = file->private_data; | 179 | struct bin_buffer *bb = file->private_data; |
180 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 180 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
181 | 181 | ||
182 | if (!bb->vm_ops || !bb->vm_ops->open) | 182 | if (!bb->vm_ops) |
183 | return; | ||
184 | |||
185 | if (!sysfs_get_active(attr_sd)) | ||
186 | return; | ||
187 | |||
188 | bb->vm_ops->open(vma); | ||
189 | |||
190 | sysfs_put_active(attr_sd); | ||
191 | } | ||
192 | |||
193 | static void bin_vma_close(struct vm_area_struct *vma) | ||
194 | { | ||
195 | struct file *file = vma->vm_file; | ||
196 | struct bin_buffer *bb = file->private_data; | ||
197 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | ||
198 | |||
199 | if (!bb->vm_ops || !bb->vm_ops->close) | ||
200 | return; | 183 | return; |
201 | 184 | ||
202 | if (!sysfs_get_active(attr_sd)) | 185 | if (!sysfs_get_active(attr_sd)) |
203 | return; | 186 | return; |
204 | 187 | ||
205 | bb->vm_ops->close(vma); | 188 | if (bb->vm_ops->open) |
189 | bb->vm_ops->open(vma); | ||
206 | 190 | ||
207 | sysfs_put_active(attr_sd); | 191 | sysfs_put_active(attr_sd); |
208 | } | 192 | } |
@@ -214,13 +198,15 @@ static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
214 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 198 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
215 | int ret; | 199 | int ret; |
216 | 200 | ||
217 | if (!bb->vm_ops || !bb->vm_ops->fault) | 201 | if (!bb->vm_ops) |
218 | return VM_FAULT_SIGBUS; | 202 | return VM_FAULT_SIGBUS; |
219 | 203 | ||
220 | if (!sysfs_get_active(attr_sd)) | 204 | if (!sysfs_get_active(attr_sd)) |
221 | return VM_FAULT_SIGBUS; | 205 | return VM_FAULT_SIGBUS; |
222 | 206 | ||
223 | ret = bb->vm_ops->fault(vma, vmf); | 207 | ret = VM_FAULT_SIGBUS; |
208 | if (bb->vm_ops->fault) | ||
209 | ret = bb->vm_ops->fault(vma, vmf); | ||
224 | 210 | ||
225 | sysfs_put_active(attr_sd); | 211 | sysfs_put_active(attr_sd); |
226 | return ret; | 212 | return ret; |
@@ -236,13 +222,12 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
236 | if (!bb->vm_ops) | 222 | if (!bb->vm_ops) |
237 | return VM_FAULT_SIGBUS; | 223 | return VM_FAULT_SIGBUS; |
238 | 224 | ||
239 | if (!bb->vm_ops->page_mkwrite) | ||
240 | return 0; | ||
241 | |||
242 | if (!sysfs_get_active(attr_sd)) | 225 | if (!sysfs_get_active(attr_sd)) |
243 | return VM_FAULT_SIGBUS; | 226 | return VM_FAULT_SIGBUS; |
244 | 227 | ||
245 | ret = bb->vm_ops->page_mkwrite(vma, vmf); | 228 | ret = 0; |
229 | if (bb->vm_ops->page_mkwrite) | ||
230 | ret = bb->vm_ops->page_mkwrite(vma, vmf); | ||
246 | 231 | ||
247 | sysfs_put_active(attr_sd); | 232 | sysfs_put_active(attr_sd); |
248 | return ret; | 233 | return ret; |
@@ -256,13 +241,15 @@ static int bin_access(struct vm_area_struct *vma, unsigned long addr, | |||
256 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 241 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
257 | int ret; | 242 | int ret; |
258 | 243 | ||
259 | if (!bb->vm_ops || !bb->vm_ops->access) | 244 | if (!bb->vm_ops) |
260 | return -EINVAL; | 245 | return -EINVAL; |
261 | 246 | ||
262 | if (!sysfs_get_active(attr_sd)) | 247 | if (!sysfs_get_active(attr_sd)) |
263 | return -EINVAL; | 248 | return -EINVAL; |
264 | 249 | ||
265 | ret = bb->vm_ops->access(vma, addr, buf, len, write); | 250 | ret = -EINVAL; |
251 | if (bb->vm_ops->access) | ||
252 | ret = bb->vm_ops->access(vma, addr, buf, len, write); | ||
266 | 253 | ||
267 | sysfs_put_active(attr_sd); | 254 | sysfs_put_active(attr_sd); |
268 | return ret; | 255 | return ret; |
@@ -276,13 +263,15 @@ static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new) | |||
276 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 263 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
277 | int ret; | 264 | int ret; |
278 | 265 | ||
279 | if (!bb->vm_ops || !bb->vm_ops->set_policy) | 266 | if (!bb->vm_ops) |
280 | return 0; | 267 | return 0; |
281 | 268 | ||
282 | if (!sysfs_get_active(attr_sd)) | 269 | if (!sysfs_get_active(attr_sd)) |
283 | return -EINVAL; | 270 | return -EINVAL; |
284 | 271 | ||
285 | ret = bb->vm_ops->set_policy(vma, new); | 272 | ret = 0; |
273 | if (bb->vm_ops->set_policy) | ||
274 | ret = bb->vm_ops->set_policy(vma, new); | ||
286 | 275 | ||
287 | sysfs_put_active(attr_sd); | 276 | sysfs_put_active(attr_sd); |
288 | return ret; | 277 | return ret; |
@@ -296,13 +285,15 @@ static struct mempolicy *bin_get_policy(struct vm_area_struct *vma, | |||
296 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 285 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
297 | struct mempolicy *pol; | 286 | struct mempolicy *pol; |
298 | 287 | ||
299 | if (!bb->vm_ops || !bb->vm_ops->get_policy) | 288 | if (!bb->vm_ops) |
300 | return vma->vm_policy; | 289 | return vma->vm_policy; |
301 | 290 | ||
302 | if (!sysfs_get_active(attr_sd)) | 291 | if (!sysfs_get_active(attr_sd)) |
303 | return vma->vm_policy; | 292 | return vma->vm_policy; |
304 | 293 | ||
305 | pol = bb->vm_ops->get_policy(vma, addr); | 294 | pol = vma->vm_policy; |
295 | if (bb->vm_ops->get_policy) | ||
296 | pol = bb->vm_ops->get_policy(vma, addr); | ||
306 | 297 | ||
307 | sysfs_put_active(attr_sd); | 298 | sysfs_put_active(attr_sd); |
308 | return pol; | 299 | return pol; |
@@ -316,13 +307,15 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from, | |||
316 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 307 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
317 | int ret; | 308 | int ret; |
318 | 309 | ||
319 | if (!bb->vm_ops || !bb->vm_ops->migrate) | 310 | if (!bb->vm_ops) |
320 | return 0; | 311 | return 0; |
321 | 312 | ||
322 | if (!sysfs_get_active(attr_sd)) | 313 | if (!sysfs_get_active(attr_sd)) |
323 | return 0; | 314 | return 0; |
324 | 315 | ||
325 | ret = bb->vm_ops->migrate(vma, from, to, flags); | 316 | ret = 0; |
317 | if (bb->vm_ops->migrate) | ||
318 | ret = bb->vm_ops->migrate(vma, from, to, flags); | ||
326 | 319 | ||
327 | sysfs_put_active(attr_sd); | 320 | sysfs_put_active(attr_sd); |
328 | return ret; | 321 | return ret; |
@@ -331,7 +324,6 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from, | |||
331 | 324 | ||
332 | static const struct vm_operations_struct bin_vm_ops = { | 325 | static const struct vm_operations_struct bin_vm_ops = { |
333 | .open = bin_vma_open, | 326 | .open = bin_vma_open, |
334 | .close = bin_vma_close, | ||
335 | .fault = bin_fault, | 327 | .fault = bin_fault, |
336 | .page_mkwrite = bin_page_mkwrite, | 328 | .page_mkwrite = bin_page_mkwrite, |
337 | .access = bin_access, | 329 | .access = bin_access, |
@@ -377,6 +369,14 @@ static int mmap(struct file *file, struct vm_area_struct *vma) | |||
377 | if (bb->mmapped && bb->vm_ops != vma->vm_ops) | 369 | if (bb->mmapped && bb->vm_ops != vma->vm_ops) |
378 | goto out_put; | 370 | goto out_put; |
379 | 371 | ||
372 | /* | ||
373 | * It is not possible to successfully wrap close. | ||
374 | * So error if someone is trying to use close. | ||
375 | */ | ||
376 | rc = -EINVAL; | ||
377 | if (vma->vm_ops && vma->vm_ops->close) | ||
378 | goto out_put; | ||
379 | |||
380 | rc = 0; | 380 | rc = 0; |
381 | bb->mmapped = 1; | 381 | bb->mmapped = 1; |
382 | bb->vm_ops = vma->vm_ops; | 382 | bb->vm_ops = vma->vm_ops; |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index f2af22574c50..266895783b47 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "sysfs.h" | 23 | #include "sysfs.h" |
24 | 24 | ||
25 | 25 | ||
26 | static struct vfsmount *sysfs_mount; | 26 | static struct vfsmount *sysfs_mnt; |
27 | struct kmem_cache *sysfs_dir_cachep; | 27 | struct kmem_cache *sysfs_dir_cachep; |
28 | 28 | ||
29 | static const struct super_operations sysfs_ops = { | 29 | static const struct super_operations sysfs_ops = { |
@@ -95,18 +95,17 @@ static int sysfs_set_super(struct super_block *sb, void *data) | |||
95 | return error; | 95 | return error; |
96 | } | 96 | } |
97 | 97 | ||
98 | static int sysfs_get_sb(struct file_system_type *fs_type, | 98 | static struct dentry *sysfs_mount(struct file_system_type *fs_type, |
99 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | 99 | int flags, const char *dev_name, void *data) |
100 | { | 100 | { |
101 | struct sysfs_super_info *info; | 101 | struct sysfs_super_info *info; |
102 | enum kobj_ns_type type; | 102 | enum kobj_ns_type type; |
103 | struct super_block *sb; | 103 | struct super_block *sb; |
104 | int error; | 104 | int error; |
105 | 105 | ||
106 | error = -ENOMEM; | ||
107 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 106 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
108 | if (!info) | 107 | if (!info) |
109 | goto out; | 108 | return ERR_PTR(-ENOMEM); |
110 | 109 | ||
111 | for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) | 110 | for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) |
112 | info->ns[type] = kobj_ns_current(type); | 111 | info->ns[type] = kobj_ns_current(type); |
@@ -114,24 +113,19 @@ static int sysfs_get_sb(struct file_system_type *fs_type, | |||
114 | sb = sget(fs_type, sysfs_test_super, sysfs_set_super, info); | 113 | sb = sget(fs_type, sysfs_test_super, sysfs_set_super, info); |
115 | if (IS_ERR(sb) || sb->s_fs_info != info) | 114 | if (IS_ERR(sb) || sb->s_fs_info != info) |
116 | kfree(info); | 115 | kfree(info); |
117 | if (IS_ERR(sb)) { | 116 | if (IS_ERR(sb)) |
118 | error = PTR_ERR(sb); | 117 | return ERR_CAST(sb); |
119 | goto out; | ||
120 | } | ||
121 | if (!sb->s_root) { | 118 | if (!sb->s_root) { |
122 | sb->s_flags = flags; | 119 | sb->s_flags = flags; |
123 | error = sysfs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); | 120 | error = sysfs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); |
124 | if (error) { | 121 | if (error) { |
125 | deactivate_locked_super(sb); | 122 | deactivate_locked_super(sb); |
126 | goto out; | 123 | return ERR_PTR(error); |
127 | } | 124 | } |
128 | sb->s_flags |= MS_ACTIVE; | 125 | sb->s_flags |= MS_ACTIVE; |
129 | } | 126 | } |
130 | 127 | ||
131 | simple_set_mnt(mnt, sb); | 128 | return dget(sb->s_root); |
132 | error = 0; | ||
133 | out: | ||
134 | return error; | ||
135 | } | 129 | } |
136 | 130 | ||
137 | static void sysfs_kill_sb(struct super_block *sb) | 131 | static void sysfs_kill_sb(struct super_block *sb) |
@@ -147,7 +141,7 @@ static void sysfs_kill_sb(struct super_block *sb) | |||
147 | 141 | ||
148 | static struct file_system_type sysfs_fs_type = { | 142 | static struct file_system_type sysfs_fs_type = { |
149 | .name = "sysfs", | 143 | .name = "sysfs", |
150 | .get_sb = sysfs_get_sb, | 144 | .mount = sysfs_mount, |
151 | .kill_sb = sysfs_kill_sb, | 145 | .kill_sb = sysfs_kill_sb, |
152 | }; | 146 | }; |
153 | 147 | ||
@@ -189,11 +183,11 @@ int __init sysfs_init(void) | |||
189 | 183 | ||
190 | err = register_filesystem(&sysfs_fs_type); | 184 | err = register_filesystem(&sysfs_fs_type); |
191 | if (!err) { | 185 | if (!err) { |
192 | sysfs_mount = kern_mount(&sysfs_fs_type); | 186 | sysfs_mnt = kern_mount(&sysfs_fs_type); |
193 | if (IS_ERR(sysfs_mount)) { | 187 | if (IS_ERR(sysfs_mnt)) { |
194 | printk(KERN_ERR "sysfs: could not mount!\n"); | 188 | printk(KERN_ERR "sysfs: could not mount!\n"); |
195 | err = PTR_ERR(sysfs_mount); | 189 | err = PTR_ERR(sysfs_mnt); |
196 | sysfs_mount = NULL; | 190 | sysfs_mnt = NULL; |
197 | unregister_filesystem(&sysfs_fs_type); | 191 | unregister_filesystem(&sysfs_fs_type); |
198 | goto out_err; | 192 | goto out_err; |
199 | } | 193 | } |