]>
Commit | Line | Data |
---|---|---|
67207b96 AB |
1 | /* |
2 | * SPU file system | |
3 | * | |
4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 | |
5 | * | |
6 | * Author: Arnd Bergmann <arndb@de.ibm.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | */ | |
22 | ||
23 | #include <linux/file.h> | |
24 | #include <linux/fs.h> | |
25 | #include <linux/backing-dev.h> | |
26 | #include <linux/init.h> | |
27 | #include <linux/ioctl.h> | |
28 | #include <linux/module.h> | |
346f4d3c | 29 | #include <linux/mount.h> |
67207b96 AB |
30 | #include <linux/namei.h> |
31 | #include <linux/pagemap.h> | |
32 | #include <linux/poll.h> | |
33 | #include <linux/slab.h> | |
34 | #include <linux/parser.h> | |
35 | ||
0afacde3 | 36 | #include <asm/prom.h> |
67207b96 AB |
37 | #include <asm/semaphore.h> |
38 | #include <asm/spu.h> | |
ccf17e9d | 39 | #include <asm/spu_priv1.h> |
67207b96 AB |
40 | #include <asm/uaccess.h> |
41 | ||
42 | #include "spufs.h" | |
43 | ||
e18b890b | 44 | static struct kmem_cache *spufs_inode_cache; |
c6730ed4 | 45 | char *isolated_loader; |
67207b96 | 46 | |
67207b96 AB |
47 | static struct inode * |
48 | spufs_alloc_inode(struct super_block *sb) | |
49 | { | |
50 | struct spufs_inode_info *ei; | |
51 | ||
e94b1766 | 52 | ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL); |
67207b96 AB |
53 | if (!ei) |
54 | return NULL; | |
6263203e AB |
55 | |
56 | ei->i_gang = NULL; | |
57 | ei->i_ctx = NULL; | |
43c2bbd9 | 58 | ei->i_openers = 0; |
6263203e | 59 | |
67207b96 AB |
60 | return &ei->vfs_inode; |
61 | } | |
62 | ||
63 | static void | |
64 | spufs_destroy_inode(struct inode *inode) | |
65 | { | |
66 | kmem_cache_free(spufs_inode_cache, SPUFS_I(inode)); | |
67 | } | |
68 | ||
69 | static void | |
e18b890b | 70 | spufs_init_once(void *p, struct kmem_cache * cachep, unsigned long flags) |
67207b96 AB |
71 | { |
72 | struct spufs_inode_info *ei = p; | |
73 | ||
50953fe9 | 74 | if (flags & SLAB_CTOR_CONSTRUCTOR) { |
67207b96 AB |
75 | inode_init_once(&ei->vfs_inode); |
76 | } | |
77 | } | |
78 | ||
79 | static struct inode * | |
80 | spufs_new_inode(struct super_block *sb, int mode) | |
81 | { | |
82 | struct inode *inode; | |
83 | ||
84 | inode = new_inode(sb); | |
85 | if (!inode) | |
86 | goto out; | |
87 | ||
88 | inode->i_mode = mode; | |
89 | inode->i_uid = current->fsuid; | |
90 | inode->i_gid = current->fsgid; | |
67207b96 AB |
91 | inode->i_blocks = 0; |
92 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | |
93 | out: | |
94 | return inode; | |
95 | } | |
96 | ||
97 | static int | |
98 | spufs_setattr(struct dentry *dentry, struct iattr *attr) | |
99 | { | |
100 | struct inode *inode = dentry->d_inode; | |
101 | ||
67207b96 AB |
102 | if ((attr->ia_valid & ATTR_SIZE) && |
103 | (attr->ia_size != inode->i_size)) | |
104 | return -EINVAL; | |
105 | return inode_setattr(inode, attr); | |
106 | } | |
107 | ||
108 | ||
109 | static int | |
110 | spufs_new_file(struct super_block *sb, struct dentry *dentry, | |
99ac48f5 | 111 | const struct file_operations *fops, int mode, |
67207b96 AB |
112 | struct spu_context *ctx) |
113 | { | |
114 | static struct inode_operations spufs_file_iops = { | |
67207b96 | 115 | .setattr = spufs_setattr, |
67207b96 AB |
116 | }; |
117 | struct inode *inode; | |
118 | int ret; | |
119 | ||
120 | ret = -ENOSPC; | |
121 | inode = spufs_new_inode(sb, S_IFREG | mode); | |
122 | if (!inode) | |
123 | goto out; | |
124 | ||
125 | ret = 0; | |
126 | inode->i_op = &spufs_file_iops; | |
127 | inode->i_fop = fops; | |
8e18e294 | 128 | inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx); |
67207b96 AB |
129 | d_add(dentry, inode); |
130 | out: | |
131 | return ret; | |
132 | } | |
133 | ||
134 | static void | |
135 | spufs_delete_inode(struct inode *inode) | |
136 | { | |
6263203e AB |
137 | struct spufs_inode_info *ei = SPUFS_I(inode); |
138 | ||
139 | if (ei->i_ctx) | |
140 | put_spu_context(ei->i_ctx); | |
141 | if (ei->i_gang) | |
142 | put_spu_gang(ei->i_gang); | |
67207b96 AB |
143 | clear_inode(inode); |
144 | } | |
145 | ||
3f51dd91 | 146 | static void spufs_prune_dir(struct dentry *dir) |
67207b96 | 147 | { |
8b3d6663 | 148 | struct dentry *dentry, *tmp; |
6263203e | 149 | |
1b1dcc1b | 150 | mutex_lock(&dir->d_inode->i_mutex); |
c3a9aea7 | 151 | list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) { |
8b3d6663 | 152 | spin_lock(&dcache_lock); |
67207b96 | 153 | spin_lock(&dentry->d_lock); |
8b3d6663 AB |
154 | if (!(d_unhashed(dentry)) && dentry->d_inode) { |
155 | dget_locked(dentry); | |
156 | __d_drop(dentry); | |
157 | spin_unlock(&dentry->d_lock); | |
3f51dd91 | 158 | simple_unlink(dir->d_inode, dentry); |
8b3d6663 AB |
159 | spin_unlock(&dcache_lock); |
160 | dput(dentry); | |
161 | } else { | |
162 | spin_unlock(&dentry->d_lock); | |
163 | spin_unlock(&dcache_lock); | |
164 | } | |
67207b96 | 165 | } |
3f51dd91 | 166 | shrink_dcache_parent(dir); |
1b1dcc1b | 167 | mutex_unlock(&dir->d_inode->i_mutex); |
3f51dd91 AB |
168 | } |
169 | ||
6263203e AB |
170 | /* Caller must hold parent->i_mutex */ |
171 | static int spufs_rmdir(struct inode *parent, struct dentry *dir) | |
3f51dd91 | 172 | { |
3f51dd91 | 173 | /* remove all entries */ |
6263203e | 174 | spufs_prune_dir(dir); |
8b3d6663 | 175 | |
6263203e | 176 | return simple_rmdir(parent, dir); |
67207b96 AB |
177 | } |
178 | ||
3f51dd91 AB |
179 | static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files, |
180 | int mode, struct spu_context *ctx) | |
181 | { | |
182 | struct dentry *dentry; | |
183 | int ret; | |
184 | ||
185 | while (files->name && files->name[0]) { | |
186 | ret = -ENOMEM; | |
187 | dentry = d_alloc_name(dir, files->name); | |
188 | if (!dentry) | |
189 | goto out; | |
190 | ret = spufs_new_file(dir->d_sb, dentry, files->ops, | |
191 | files->mode & mode, ctx); | |
192 | if (ret) | |
193 | goto out; | |
194 | files++; | |
195 | } | |
196 | return 0; | |
197 | out: | |
198 | spufs_prune_dir(dir); | |
199 | return ret; | |
200 | } | |
201 | ||
67207b96 AB |
202 | static int spufs_dir_close(struct inode *inode, struct file *file) |
203 | { | |
0309f02d | 204 | struct spu_context *ctx; |
6263203e AB |
205 | struct inode *parent; |
206 | struct dentry *dir; | |
67207b96 AB |
207 | int ret; |
208 | ||
b4d1ab58 | 209 | dir = file->f_path.dentry; |
6263203e AB |
210 | parent = dir->d_parent->d_inode; |
211 | ctx = SPUFS_I(dir->d_inode)->i_ctx; | |
c8ca0633 | 212 | |
6263203e AB |
213 | mutex_lock(&parent->i_mutex); |
214 | ret = spufs_rmdir(parent, dir); | |
215 | mutex_unlock(&parent->i_mutex); | |
67207b96 | 216 | WARN_ON(ret); |
c8ca0633 | 217 | |
0309f02d ME |
218 | /* We have to give up the mm_struct */ |
219 | spu_forget(ctx); | |
220 | ||
67207b96 AB |
221 | return dcache_dir_close(inode, file); |
222 | } | |
223 | ||
754661f1 | 224 | const struct inode_operations spufs_dir_inode_operations = { |
67207b96 AB |
225 | .lookup = simple_lookup, |
226 | }; | |
227 | ||
5dfe4c96 | 228 | const struct file_operations spufs_context_fops = { |
67207b96 AB |
229 | .open = dcache_dir_open, |
230 | .release = spufs_dir_close, | |
231 | .llseek = dcache_dir_lseek, | |
232 | .read = generic_read_dir, | |
233 | .readdir = dcache_readdir, | |
234 | .fsync = simple_sync_file, | |
235 | }; | |
bf1ab978 | 236 | EXPORT_SYMBOL_GPL(spufs_context_fops); |
67207b96 AB |
237 | |
238 | static int | |
9add11da AB |
239 | spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags, |
240 | int mode) | |
67207b96 AB |
241 | { |
242 | int ret; | |
243 | struct inode *inode; | |
244 | struct spu_context *ctx; | |
245 | ||
246 | ret = -ENOSPC; | |
247 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); | |
248 | if (!inode) | |
249 | goto out; | |
250 | ||
251 | if (dir->i_mode & S_ISGID) { | |
252 | inode->i_gid = dir->i_gid; | |
253 | inode->i_mode &= S_ISGID; | |
254 | } | |
6263203e | 255 | ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */ |
67207b96 AB |
256 | SPUFS_I(inode)->i_ctx = ctx; |
257 | if (!ctx) | |
258 | goto out_iput; | |
259 | ||
9add11da | 260 | ctx->flags = flags; |
67207b96 AB |
261 | inode->i_op = &spufs_dir_inode_operations; |
262 | inode->i_fop = &simple_dir_operations; | |
5737edd1 MN |
263 | if (flags & SPU_CREATE_NOSCHED) |
264 | ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents, | |
265 | mode, ctx); | |
266 | else | |
267 | ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx); | |
268 | ||
67207b96 AB |
269 | if (ret) |
270 | goto out_free_ctx; | |
271 | ||
272 | d_instantiate(dentry, inode); | |
273 | dget(dentry); | |
274 | dir->i_nlink++; | |
346f4d3c | 275 | dentry->d_inode->i_nlink++; |
67207b96 AB |
276 | goto out; |
277 | ||
278 | out_free_ctx: | |
279 | put_spu_context(ctx); | |
280 | out_iput: | |
281 | iput(inode); | |
282 | out: | |
283 | return ret; | |
284 | } | |
285 | ||
346f4d3c AB |
286 | static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt) |
287 | { | |
288 | int ret; | |
289 | struct file *filp; | |
290 | ||
291 | ret = get_unused_fd(); | |
292 | if (ret < 0) { | |
293 | dput(dentry); | |
294 | mntput(mnt); | |
295 | goto out; | |
296 | } | |
297 | ||
298 | filp = dentry_open(dentry, mnt, O_RDONLY); | |
299 | if (IS_ERR(filp)) { | |
300 | put_unused_fd(ret); | |
301 | ret = PTR_ERR(filp); | |
302 | goto out; | |
303 | } | |
304 | ||
305 | filp->f_op = &spufs_context_fops; | |
306 | fd_install(ret, filp); | |
307 | out: | |
308 | return ret; | |
309 | } | |
310 | ||
6263203e AB |
311 | static int spufs_create_context(struct inode *inode, |
312 | struct dentry *dentry, | |
313 | struct vfsmount *mnt, int flags, int mode) | |
314 | { | |
315 | int ret; | |
316 | ||
5737edd1 MN |
317 | ret = -EPERM; |
318 | if ((flags & SPU_CREATE_NOSCHED) && | |
319 | !capable(CAP_SYS_NICE)) | |
320 | goto out_unlock; | |
321 | ||
322 | ret = -EINVAL; | |
323 | if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE)) | |
324 | == SPU_CREATE_ISOLATE) | |
325 | goto out_unlock; | |
326 | ||
bd2e5f82 JK |
327 | ret = -ENODEV; |
328 | if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader) | |
329 | goto out_unlock; | |
330 | ||
6263203e AB |
331 | ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO); |
332 | if (ret) | |
333 | goto out_unlock; | |
334 | ||
335 | /* | |
336 | * get references for dget and mntget, will be released | |
337 | * in error path of *_open(). | |
338 | */ | |
339 | ret = spufs_context_open(dget(dentry), mntget(mnt)); | |
340 | if (ret < 0) { | |
341 | WARN_ON(spufs_rmdir(inode, dentry)); | |
342 | mutex_unlock(&inode->i_mutex); | |
343 | spu_forget(SPUFS_I(dentry->d_inode)->i_ctx); | |
344 | goto out; | |
345 | } | |
346 | ||
347 | out_unlock: | |
348 | mutex_unlock(&inode->i_mutex); | |
349 | out: | |
350 | dput(dentry); | |
351 | return ret; | |
352 | } | |
353 | ||
354 | static int spufs_rmgang(struct inode *root, struct dentry *dir) | |
355 | { | |
356 | /* FIXME: this fails if the dir is not empty, | |
357 | which causes a leak of gangs. */ | |
358 | return simple_rmdir(root, dir); | |
359 | } | |
360 | ||
361 | static int spufs_gang_close(struct inode *inode, struct file *file) | |
362 | { | |
363 | struct inode *parent; | |
364 | struct dentry *dir; | |
365 | int ret; | |
366 | ||
b4d1ab58 | 367 | dir = file->f_path.dentry; |
6263203e AB |
368 | parent = dir->d_parent->d_inode; |
369 | ||
370 | ret = spufs_rmgang(parent, dir); | |
371 | WARN_ON(ret); | |
372 | ||
373 | return dcache_dir_close(inode, file); | |
374 | } | |
375 | ||
5dfe4c96 | 376 | const struct file_operations spufs_gang_fops = { |
6263203e AB |
377 | .open = dcache_dir_open, |
378 | .release = spufs_gang_close, | |
379 | .llseek = dcache_dir_lseek, | |
380 | .read = generic_read_dir, | |
381 | .readdir = dcache_readdir, | |
382 | .fsync = simple_sync_file, | |
383 | }; | |
384 | ||
385 | static int | |
386 | spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode) | |
387 | { | |
388 | int ret; | |
389 | struct inode *inode; | |
390 | struct spu_gang *gang; | |
391 | ||
392 | ret = -ENOSPC; | |
393 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); | |
394 | if (!inode) | |
395 | goto out; | |
396 | ||
397 | ret = 0; | |
398 | if (dir->i_mode & S_ISGID) { | |
399 | inode->i_gid = dir->i_gid; | |
400 | inode->i_mode &= S_ISGID; | |
401 | } | |
402 | gang = alloc_spu_gang(); | |
403 | SPUFS_I(inode)->i_ctx = NULL; | |
404 | SPUFS_I(inode)->i_gang = gang; | |
405 | if (!gang) | |
406 | goto out_iput; | |
407 | ||
408 | inode->i_op = &spufs_dir_inode_operations; | |
409 | inode->i_fop = &simple_dir_operations; | |
410 | ||
411 | d_instantiate(dentry, inode); | |
412 | dget(dentry); | |
413 | dir->i_nlink++; | |
414 | dentry->d_inode->i_nlink++; | |
415 | return ret; | |
416 | ||
417 | out_iput: | |
418 | iput(inode); | |
419 | out: | |
420 | return ret; | |
421 | } | |
422 | ||
423 | static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt) | |
424 | { | |
425 | int ret; | |
426 | struct file *filp; | |
427 | ||
428 | ret = get_unused_fd(); | |
429 | if (ret < 0) { | |
430 | dput(dentry); | |
431 | mntput(mnt); | |
432 | goto out; | |
433 | } | |
434 | ||
435 | filp = dentry_open(dentry, mnt, O_RDONLY); | |
436 | if (IS_ERR(filp)) { | |
437 | put_unused_fd(ret); | |
438 | ret = PTR_ERR(filp); | |
439 | goto out; | |
440 | } | |
441 | ||
442 | filp->f_op = &spufs_gang_fops; | |
443 | fd_install(ret, filp); | |
444 | out: | |
445 | return ret; | |
446 | } | |
447 | ||
448 | static int spufs_create_gang(struct inode *inode, | |
449 | struct dentry *dentry, | |
450 | struct vfsmount *mnt, int mode) | |
451 | { | |
452 | int ret; | |
453 | ||
454 | ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO); | |
455 | if (ret) | |
456 | goto out; | |
457 | ||
458 | /* | |
459 | * get references for dget and mntget, will be released | |
460 | * in error path of *_open(). | |
461 | */ | |
462 | ret = spufs_gang_open(dget(dentry), mntget(mnt)); | |
463 | if (ret < 0) | |
464 | WARN_ON(spufs_rmgang(inode, dentry)); | |
465 | ||
466 | out: | |
467 | mutex_unlock(&inode->i_mutex); | |
468 | dput(dentry); | |
469 | return ret; | |
470 | } | |
471 | ||
472 | ||
346f4d3c AB |
473 | static struct file_system_type spufs_type; |
474 | ||
6263203e | 475 | long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode) |
67207b96 AB |
476 | { |
477 | struct dentry *dentry; | |
67207b96 AB |
478 | int ret; |
479 | ||
67207b96 | 480 | ret = -EINVAL; |
6263203e AB |
481 | /* check if we are on spufs */ |
482 | if (nd->dentry->d_sb->s_type != &spufs_type) | |
67207b96 AB |
483 | goto out; |
484 | ||
6263203e | 485 | /* don't accept undefined flags */ |
9add11da | 486 | if (flags & (~SPU_CREATE_FLAG_ALL)) |
c9832948 AB |
487 | goto out; |
488 | ||
6263203e AB |
489 | /* only threads can be underneath a gang */ |
490 | if (nd->dentry != nd->dentry->d_sb->s_root) { | |
491 | if ((flags & SPU_CREATE_GANG) || | |
492 | !SPUFS_I(nd->dentry->d_inode)->i_gang) | |
493 | goto out; | |
494 | } | |
495 | ||
67207b96 AB |
496 | dentry = lookup_create(nd, 1); |
497 | ret = PTR_ERR(dentry); | |
498 | if (IS_ERR(dentry)) | |
499 | goto out_dir; | |
500 | ||
501 | ret = -EEXIST; | |
502 | if (dentry->d_inode) | |
503 | goto out_dput; | |
504 | ||
505 | mode &= ~current->fs->umask; | |
67207b96 | 506 | |
6263203e AB |
507 | if (flags & SPU_CREATE_GANG) |
508 | return spufs_create_gang(nd->dentry->d_inode, | |
509 | dentry, nd->mnt, mode); | |
510 | else | |
511 | return spufs_create_context(nd->dentry->d_inode, | |
512 | dentry, nd->mnt, flags, mode); | |
67207b96 AB |
513 | |
514 | out_dput: | |
515 | dput(dentry); | |
516 | out_dir: | |
1b1dcc1b | 517 | mutex_unlock(&nd->dentry->d_inode->i_mutex); |
67207b96 AB |
518 | out: |
519 | return ret; | |
520 | } | |
521 | ||
522 | /* File system initialization */ | |
523 | enum { | |
f11f5ee7 | 524 | Opt_uid, Opt_gid, Opt_mode, Opt_err, |
67207b96 AB |
525 | }; |
526 | ||
527 | static match_table_t spufs_tokens = { | |
f11f5ee7 JK |
528 | { Opt_uid, "uid=%d" }, |
529 | { Opt_gid, "gid=%d" }, | |
530 | { Opt_mode, "mode=%o" }, | |
531 | { Opt_err, NULL }, | |
67207b96 AB |
532 | }; |
533 | ||
534 | static int | |
535 | spufs_parse_options(char *options, struct inode *root) | |
536 | { | |
537 | char *p; | |
538 | substring_t args[MAX_OPT_ARGS]; | |
539 | ||
540 | while ((p = strsep(&options, ",")) != NULL) { | |
541 | int token, option; | |
542 | ||
543 | if (!*p) | |
544 | continue; | |
545 | ||
546 | token = match_token(p, spufs_tokens, args); | |
547 | switch (token) { | |
548 | case Opt_uid: | |
549 | if (match_int(&args[0], &option)) | |
550 | return 0; | |
551 | root->i_uid = option; | |
552 | break; | |
553 | case Opt_gid: | |
554 | if (match_int(&args[0], &option)) | |
555 | return 0; | |
556 | root->i_gid = option; | |
557 | break; | |
f11f5ee7 JK |
558 | case Opt_mode: |
559 | if (match_octal(&args[0], &option)) | |
560 | return 0; | |
561 | root->i_mode = option | S_IFDIR; | |
562 | break; | |
67207b96 AB |
563 | default: |
564 | return 0; | |
565 | } | |
566 | } | |
567 | return 1; | |
568 | } | |
569 | ||
db1384b4 AM |
570 | static void spufs_exit_isolated_loader(void) |
571 | { | |
572 | kfree(isolated_loader); | |
573 | } | |
574 | ||
0afacde3 AB |
575 | static void |
576 | spufs_init_isolated_loader(void) | |
577 | { | |
578 | struct device_node *dn; | |
579 | const char *loader; | |
580 | int size; | |
581 | ||
582 | dn = of_find_node_by_path("/spu-isolation"); | |
583 | if (!dn) | |
584 | return; | |
585 | ||
e2eb6392 | 586 | loader = of_get_property(dn, "loader", &size); |
0afacde3 AB |
587 | if (!loader) |
588 | return; | |
589 | ||
590 | /* kmalloc should align on a 16 byte boundary..* */ | |
591 | isolated_loader = kmalloc(size, GFP_KERNEL); | |
592 | if (!isolated_loader) | |
593 | return; | |
594 | ||
595 | memcpy(isolated_loader, loader, size); | |
596 | printk(KERN_INFO "spufs: SPU isolation mode enabled\n"); | |
597 | } | |
598 | ||
67207b96 | 599 | static int |
8b3d6663 AB |
600 | spufs_create_root(struct super_block *sb, void *data) |
601 | { | |
67207b96 AB |
602 | struct inode *inode; |
603 | int ret; | |
604 | ||
605 | ret = -ENOMEM; | |
606 | inode = spufs_new_inode(sb, S_IFDIR | 0775); | |
607 | if (!inode) | |
608 | goto out; | |
609 | ||
610 | inode->i_op = &spufs_dir_inode_operations; | |
611 | inode->i_fop = &simple_dir_operations; | |
612 | SPUFS_I(inode)->i_ctx = NULL; | |
613 | ||
614 | ret = -EINVAL; | |
615 | if (!spufs_parse_options(data, inode)) | |
616 | goto out_iput; | |
617 | ||
618 | ret = -ENOMEM; | |
619 | sb->s_root = d_alloc_root(inode); | |
620 | if (!sb->s_root) | |
621 | goto out_iput; | |
622 | ||
623 | return 0; | |
624 | out_iput: | |
625 | iput(inode); | |
626 | out: | |
627 | return ret; | |
628 | } | |
629 | ||
630 | static int | |
631 | spufs_fill_super(struct super_block *sb, void *data, int silent) | |
632 | { | |
633 | static struct super_operations s_ops = { | |
634 | .alloc_inode = spufs_alloc_inode, | |
635 | .destroy_inode = spufs_destroy_inode, | |
636 | .statfs = simple_statfs, | |
637 | .delete_inode = spufs_delete_inode, | |
638 | .drop_inode = generic_delete_inode, | |
639 | }; | |
640 | ||
641 | sb->s_maxbytes = MAX_LFS_FILESIZE; | |
642 | sb->s_blocksize = PAGE_CACHE_SIZE; | |
643 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; | |
644 | sb->s_magic = SPUFS_MAGIC; | |
645 | sb->s_op = &s_ops; | |
646 | ||
647 | return spufs_create_root(sb, data); | |
648 | } | |
649 | ||
454e2398 | 650 | static int |
67207b96 | 651 | spufs_get_sb(struct file_system_type *fstype, int flags, |
454e2398 | 652 | const char *name, void *data, struct vfsmount *mnt) |
67207b96 | 653 | { |
454e2398 | 654 | return get_sb_single(fstype, flags, data, spufs_fill_super, mnt); |
67207b96 AB |
655 | } |
656 | ||
657 | static struct file_system_type spufs_type = { | |
658 | .owner = THIS_MODULE, | |
659 | .name = "spufs", | |
660 | .get_sb = spufs_get_sb, | |
661 | .kill_sb = kill_litter_super, | |
662 | }; | |
663 | ||
e78b47a5 | 664 | static int __init spufs_init(void) |
67207b96 AB |
665 | { |
666 | int ret; | |
bf1ab978 | 667 | |
ccf17e9d JK |
668 | ret = -ENODEV; |
669 | if (!spu_management_ops) | |
670 | goto out; | |
671 | ||
67207b96 AB |
672 | ret = -ENOMEM; |
673 | spufs_inode_cache = kmem_cache_create("spufs_inode_cache", | |
674 | sizeof(struct spufs_inode_info), 0, | |
675 | SLAB_HWCACHE_ALIGN, spufs_init_once, NULL); | |
676 | ||
677 | if (!spufs_inode_cache) | |
678 | goto out; | |
c99c1994 | 679 | ret = spu_sched_init(); |
67207b96 AB |
680 | if (ret) |
681 | goto out_cache; | |
c99c1994 AM |
682 | ret = register_filesystem(&spufs_type); |
683 | if (ret) | |
684 | goto out_sched; | |
67207b96 | 685 | ret = register_spu_syscalls(&spufs_calls); |
bf1ab978 DGM |
686 | if (ret) |
687 | goto out_fs; | |
688 | ret = register_arch_coredump_calls(&spufs_coredump_calls); | |
67207b96 | 689 | if (ret) |
c99c1994 | 690 | goto out_syscalls; |
0afacde3 AB |
691 | |
692 | spufs_init_isolated_loader(); | |
bf1ab978 | 693 | |
67207b96 | 694 | return 0; |
c99c1994 AM |
695 | |
696 | out_syscalls: | |
697 | unregister_spu_syscalls(&spufs_calls); | |
67207b96 AB |
698 | out_fs: |
699 | unregister_filesystem(&spufs_type); | |
c99c1994 AM |
700 | out_sched: |
701 | spu_sched_exit(); | |
67207b96 AB |
702 | out_cache: |
703 | kmem_cache_destroy(spufs_inode_cache); | |
704 | out: | |
705 | return ret; | |
706 | } | |
707 | module_init(spufs_init); | |
708 | ||
e78b47a5 | 709 | static void __exit spufs_exit(void) |
67207b96 | 710 | { |
8b3d6663 | 711 | spu_sched_exit(); |
db1384b4 | 712 | spufs_exit_isolated_loader(); |
bf1ab978 | 713 | unregister_arch_coredump_calls(&spufs_coredump_calls); |
67207b96 AB |
714 | unregister_spu_syscalls(&spufs_calls); |
715 | unregister_filesystem(&spufs_type); | |
716 | kmem_cache_destroy(spufs_inode_cache); | |
717 | } | |
718 | module_exit(spufs_exit); | |
719 | ||
720 | MODULE_LICENSE("GPL"); | |
721 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); | |
722 |