]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/powerpc/platforms/cell/spufs/inode.c
fs: dcache scale d_unhashed
[mirror_ubuntu-hirsute-kernel.git] / arch / powerpc / platforms / cell / spufs / inode.c
1
2 /*
3 * SPU file system
4 *
5 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 *
7 * Author: Arnd Bergmann <arndb@de.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include <linux/file.h>
25 #include <linux/fs.h>
26 #include <linux/fsnotify.h>
27 #include <linux/backing-dev.h>
28 #include <linux/init.h>
29 #include <linux/ioctl.h>
30 #include <linux/module.h>
31 #include <linux/mount.h>
32 #include <linux/namei.h>
33 #include <linux/pagemap.h>
34 #include <linux/poll.h>
35 #include <linux/slab.h>
36 #include <linux/parser.h>
37
38 #include <asm/prom.h>
39 #include <asm/spu.h>
40 #include <asm/spu_priv1.h>
41 #include <asm/uaccess.h>
42
43 #include "spufs.h"
44
45 struct spufs_sb_info {
46 int debug;
47 };
48
49 static struct kmem_cache *spufs_inode_cache;
50 char *isolated_loader;
51 static int isolated_loader_size;
52
53 static struct spufs_sb_info *spufs_get_sb_info(struct super_block *sb)
54 {
55 return sb->s_fs_info;
56 }
57
58 static struct inode *
59 spufs_alloc_inode(struct super_block *sb)
60 {
61 struct spufs_inode_info *ei;
62
63 ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
64 if (!ei)
65 return NULL;
66
67 ei->i_gang = NULL;
68 ei->i_ctx = NULL;
69 ei->i_openers = 0;
70
71 return &ei->vfs_inode;
72 }
73
74 static void
75 spufs_destroy_inode(struct inode *inode)
76 {
77 kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
78 }
79
80 static void
81 spufs_init_once(void *p)
82 {
83 struct spufs_inode_info *ei = p;
84
85 inode_init_once(&ei->vfs_inode);
86 }
87
88 static struct inode *
89 spufs_new_inode(struct super_block *sb, int mode)
90 {
91 struct inode *inode;
92
93 inode = new_inode(sb);
94 if (!inode)
95 goto out;
96
97 inode->i_mode = mode;
98 inode->i_uid = current_fsuid();
99 inode->i_gid = current_fsgid();
100 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
101 out:
102 return inode;
103 }
104
105 static int
106 spufs_setattr(struct dentry *dentry, struct iattr *attr)
107 {
108 struct inode *inode = dentry->d_inode;
109
110 if ((attr->ia_valid & ATTR_SIZE) &&
111 (attr->ia_size != inode->i_size))
112 return -EINVAL;
113 setattr_copy(inode, attr);
114 mark_inode_dirty(inode);
115 return 0;
116 }
117
118
119 static int
120 spufs_new_file(struct super_block *sb, struct dentry *dentry,
121 const struct file_operations *fops, int mode,
122 size_t size, struct spu_context *ctx)
123 {
124 static const struct inode_operations spufs_file_iops = {
125 .setattr = spufs_setattr,
126 };
127 struct inode *inode;
128 int ret;
129
130 ret = -ENOSPC;
131 inode = spufs_new_inode(sb, S_IFREG | mode);
132 if (!inode)
133 goto out;
134
135 ret = 0;
136 inode->i_op = &spufs_file_iops;
137 inode->i_fop = fops;
138 inode->i_size = size;
139 inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
140 d_add(dentry, inode);
141 out:
142 return ret;
143 }
144
145 static void
146 spufs_evict_inode(struct inode *inode)
147 {
148 struct spufs_inode_info *ei = SPUFS_I(inode);
149 end_writeback(inode);
150 if (ei->i_ctx)
151 put_spu_context(ei->i_ctx);
152 if (ei->i_gang)
153 put_spu_gang(ei->i_gang);
154 }
155
156 static void spufs_prune_dir(struct dentry *dir)
157 {
158 struct dentry *dentry, *tmp;
159
160 mutex_lock(&dir->d_inode->i_mutex);
161 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
162 spin_lock(&dcache_lock);
163 spin_lock(&dentry->d_lock);
164 if (!(d_unhashed(dentry)) && dentry->d_inode) {
165 dget_locked_dlock(dentry);
166 __d_drop(dentry);
167 spin_unlock(&dentry->d_lock);
168 simple_unlink(dir->d_inode, dentry);
169 /* XXX: what is dcache_lock protecting here? Other
170 * filesystems (IB, configfs) release dcache_lock
171 * before unlink */
172 spin_unlock(&dcache_lock);
173 dput(dentry);
174 } else {
175 spin_unlock(&dentry->d_lock);
176 spin_unlock(&dcache_lock);
177 }
178 }
179 shrink_dcache_parent(dir);
180 mutex_unlock(&dir->d_inode->i_mutex);
181 }
182
183 /* Caller must hold parent->i_mutex */
184 static int spufs_rmdir(struct inode *parent, struct dentry *dir)
185 {
186 /* remove all entries */
187 spufs_prune_dir(dir);
188 d_drop(dir);
189
190 return simple_rmdir(parent, dir);
191 }
192
193 static int spufs_fill_dir(struct dentry *dir,
194 const struct spufs_tree_descr *files, int mode,
195 struct spu_context *ctx)
196 {
197 struct dentry *dentry, *tmp;
198 int ret;
199
200 while (files->name && files->name[0]) {
201 ret = -ENOMEM;
202 dentry = d_alloc_name(dir, files->name);
203 if (!dentry)
204 goto out;
205 ret = spufs_new_file(dir->d_sb, dentry, files->ops,
206 files->mode & mode, files->size, ctx);
207 if (ret)
208 goto out;
209 files++;
210 }
211 return 0;
212 out:
213 /*
214 * remove all children from dir. dir->inode is not set so don't
215 * just simply use spufs_prune_dir() and panic afterwards :)
216 * dput() looks like it will do the right thing:
217 * - dec parent's ref counter
218 * - remove child from parent's child list
219 * - free child's inode if possible
220 * - free child
221 */
222 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
223 dput(dentry);
224 }
225
226 shrink_dcache_parent(dir);
227 return ret;
228 }
229
230 static int spufs_dir_close(struct inode *inode, struct file *file)
231 {
232 struct spu_context *ctx;
233 struct inode *parent;
234 struct dentry *dir;
235 int ret;
236
237 dir = file->f_path.dentry;
238 parent = dir->d_parent->d_inode;
239 ctx = SPUFS_I(dir->d_inode)->i_ctx;
240
241 mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT);
242 ret = spufs_rmdir(parent, dir);
243 mutex_unlock(&parent->i_mutex);
244 WARN_ON(ret);
245
246 /* We have to give up the mm_struct */
247 spu_forget(ctx);
248
249 return dcache_dir_close(inode, file);
250 }
251
252 const struct file_operations spufs_context_fops = {
253 .open = dcache_dir_open,
254 .release = spufs_dir_close,
255 .llseek = dcache_dir_lseek,
256 .read = generic_read_dir,
257 .readdir = dcache_readdir,
258 .fsync = noop_fsync,
259 };
260 EXPORT_SYMBOL_GPL(spufs_context_fops);
261
262 static int
263 spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
264 int mode)
265 {
266 int ret;
267 struct inode *inode;
268 struct spu_context *ctx;
269
270 ret = -ENOSPC;
271 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
272 if (!inode)
273 goto out;
274
275 if (dir->i_mode & S_ISGID) {
276 inode->i_gid = dir->i_gid;
277 inode->i_mode &= S_ISGID;
278 }
279 ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
280 SPUFS_I(inode)->i_ctx = ctx;
281 if (!ctx)
282 goto out_iput;
283
284 ctx->flags = flags;
285 inode->i_op = &simple_dir_inode_operations;
286 inode->i_fop = &simple_dir_operations;
287 if (flags & SPU_CREATE_NOSCHED)
288 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
289 mode, ctx);
290 else
291 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
292
293 if (ret)
294 goto out_free_ctx;
295
296 if (spufs_get_sb_info(dir->i_sb)->debug)
297 ret = spufs_fill_dir(dentry, spufs_dir_debug_contents,
298 mode, ctx);
299
300 if (ret)
301 goto out_free_ctx;
302
303 d_instantiate(dentry, inode);
304 dget(dentry);
305 inc_nlink(dir);
306 inc_nlink(dentry->d_inode);
307 goto out;
308
309 out_free_ctx:
310 spu_forget(ctx);
311 put_spu_context(ctx);
312 out_iput:
313 iput(inode);
314 out:
315 return ret;
316 }
317
318 static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
319 {
320 int ret;
321 struct file *filp;
322
323 ret = get_unused_fd();
324 if (ret < 0) {
325 dput(dentry);
326 mntput(mnt);
327 goto out;
328 }
329
330 filp = dentry_open(dentry, mnt, O_RDONLY, current_cred());
331 if (IS_ERR(filp)) {
332 put_unused_fd(ret);
333 ret = PTR_ERR(filp);
334 goto out;
335 }
336
337 filp->f_op = &spufs_context_fops;
338 fd_install(ret, filp);
339 out:
340 return ret;
341 }
342
343 static struct spu_context *
344 spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
345 struct file *filp)
346 {
347 struct spu_context *tmp, *neighbor, *err;
348 int count, node;
349 int aff_supp;
350
351 aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
352 struct spu, cbe_list))->aff_list);
353
354 if (!aff_supp)
355 return ERR_PTR(-EINVAL);
356
357 if (flags & SPU_CREATE_GANG)
358 return ERR_PTR(-EINVAL);
359
360 if (flags & SPU_CREATE_AFFINITY_MEM &&
361 gang->aff_ref_ctx &&
362 gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
363 return ERR_PTR(-EEXIST);
364
365 if (gang->aff_flags & AFF_MERGED)
366 return ERR_PTR(-EBUSY);
367
368 neighbor = NULL;
369 if (flags & SPU_CREATE_AFFINITY_SPU) {
370 if (!filp || filp->f_op != &spufs_context_fops)
371 return ERR_PTR(-EINVAL);
372
373 neighbor = get_spu_context(
374 SPUFS_I(filp->f_dentry->d_inode)->i_ctx);
375
376 if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
377 !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
378 !list_entry(neighbor->aff_list.next, struct spu_context,
379 aff_list)->aff_head) {
380 err = ERR_PTR(-EEXIST);
381 goto out_put_neighbor;
382 }
383
384 if (gang != neighbor->gang) {
385 err = ERR_PTR(-EINVAL);
386 goto out_put_neighbor;
387 }
388
389 count = 1;
390 list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
391 count++;
392 if (list_empty(&neighbor->aff_list))
393 count++;
394
395 for (node = 0; node < MAX_NUMNODES; node++) {
396 if ((cbe_spu_info[node].n_spus - atomic_read(
397 &cbe_spu_info[node].reserved_spus)) >= count)
398 break;
399 }
400
401 if (node == MAX_NUMNODES) {
402 err = ERR_PTR(-EEXIST);
403 goto out_put_neighbor;
404 }
405 }
406
407 return neighbor;
408
409 out_put_neighbor:
410 put_spu_context(neighbor);
411 return err;
412 }
413
414 static void
415 spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
416 struct spu_context *neighbor)
417 {
418 if (flags & SPU_CREATE_AFFINITY_MEM)
419 ctx->gang->aff_ref_ctx = ctx;
420
421 if (flags & SPU_CREATE_AFFINITY_SPU) {
422 if (list_empty(&neighbor->aff_list)) {
423 list_add_tail(&neighbor->aff_list,
424 &ctx->gang->aff_list_head);
425 neighbor->aff_head = 1;
426 }
427
428 if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
429 || list_entry(neighbor->aff_list.next, struct spu_context,
430 aff_list)->aff_head) {
431 list_add(&ctx->aff_list, &neighbor->aff_list);
432 } else {
433 list_add_tail(&ctx->aff_list, &neighbor->aff_list);
434 if (neighbor->aff_head) {
435 neighbor->aff_head = 0;
436 ctx->aff_head = 1;
437 }
438 }
439
440 if (!ctx->gang->aff_ref_ctx)
441 ctx->gang->aff_ref_ctx = ctx;
442 }
443 }
444
445 static int
446 spufs_create_context(struct inode *inode, struct dentry *dentry,
447 struct vfsmount *mnt, int flags, int mode,
448 struct file *aff_filp)
449 {
450 int ret;
451 int affinity;
452 struct spu_gang *gang;
453 struct spu_context *neighbor;
454
455 ret = -EPERM;
456 if ((flags & SPU_CREATE_NOSCHED) &&
457 !capable(CAP_SYS_NICE))
458 goto out_unlock;
459
460 ret = -EINVAL;
461 if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
462 == SPU_CREATE_ISOLATE)
463 goto out_unlock;
464
465 ret = -ENODEV;
466 if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
467 goto out_unlock;
468
469 gang = NULL;
470 neighbor = NULL;
471 affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
472 if (affinity) {
473 gang = SPUFS_I(inode)->i_gang;
474 ret = -EINVAL;
475 if (!gang)
476 goto out_unlock;
477 mutex_lock(&gang->aff_mutex);
478 neighbor = spufs_assert_affinity(flags, gang, aff_filp);
479 if (IS_ERR(neighbor)) {
480 ret = PTR_ERR(neighbor);
481 goto out_aff_unlock;
482 }
483 }
484
485 ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
486 if (ret)
487 goto out_aff_unlock;
488
489 if (affinity) {
490 spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
491 neighbor);
492 if (neighbor)
493 put_spu_context(neighbor);
494 }
495
496 /*
497 * get references for dget and mntget, will be released
498 * in error path of *_open().
499 */
500 ret = spufs_context_open(dget(dentry), mntget(mnt));
501 if (ret < 0) {
502 WARN_ON(spufs_rmdir(inode, dentry));
503 if (affinity)
504 mutex_unlock(&gang->aff_mutex);
505 mutex_unlock(&inode->i_mutex);
506 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
507 goto out;
508 }
509
510 out_aff_unlock:
511 if (affinity)
512 mutex_unlock(&gang->aff_mutex);
513 out_unlock:
514 mutex_unlock(&inode->i_mutex);
515 out:
516 dput(dentry);
517 return ret;
518 }
519
520 static int
521 spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
522 {
523 int ret;
524 struct inode *inode;
525 struct spu_gang *gang;
526
527 ret = -ENOSPC;
528 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
529 if (!inode)
530 goto out;
531
532 ret = 0;
533 if (dir->i_mode & S_ISGID) {
534 inode->i_gid = dir->i_gid;
535 inode->i_mode &= S_ISGID;
536 }
537 gang = alloc_spu_gang();
538 SPUFS_I(inode)->i_ctx = NULL;
539 SPUFS_I(inode)->i_gang = gang;
540 if (!gang)
541 goto out_iput;
542
543 inode->i_op = &simple_dir_inode_operations;
544 inode->i_fop = &simple_dir_operations;
545
546 d_instantiate(dentry, inode);
547 inc_nlink(dir);
548 inc_nlink(dentry->d_inode);
549 return ret;
550
551 out_iput:
552 iput(inode);
553 out:
554 return ret;
555 }
556
557 static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
558 {
559 int ret;
560 struct file *filp;
561
562 ret = get_unused_fd();
563 if (ret < 0) {
564 dput(dentry);
565 mntput(mnt);
566 goto out;
567 }
568
569 filp = dentry_open(dentry, mnt, O_RDONLY, current_cred());
570 if (IS_ERR(filp)) {
571 put_unused_fd(ret);
572 ret = PTR_ERR(filp);
573 goto out;
574 }
575
576 filp->f_op = &simple_dir_operations;
577 fd_install(ret, filp);
578 out:
579 return ret;
580 }
581
582 static int spufs_create_gang(struct inode *inode,
583 struct dentry *dentry,
584 struct vfsmount *mnt, int mode)
585 {
586 int ret;
587
588 ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
589 if (ret)
590 goto out;
591
592 /*
593 * get references for dget and mntget, will be released
594 * in error path of *_open().
595 */
596 ret = spufs_gang_open(dget(dentry), mntget(mnt));
597 if (ret < 0) {
598 int err = simple_rmdir(inode, dentry);
599 WARN_ON(err);
600 }
601
602 out:
603 mutex_unlock(&inode->i_mutex);
604 dput(dentry);
605 return ret;
606 }
607
608
609 static struct file_system_type spufs_type;
610
611 long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
612 struct file *filp)
613 {
614 struct dentry *dentry;
615 int ret;
616
617 ret = -EINVAL;
618 /* check if we are on spufs */
619 if (nd->path.dentry->d_sb->s_type != &spufs_type)
620 goto out;
621
622 /* don't accept undefined flags */
623 if (flags & (~SPU_CREATE_FLAG_ALL))
624 goto out;
625
626 /* only threads can be underneath a gang */
627 if (nd->path.dentry != nd->path.dentry->d_sb->s_root) {
628 if ((flags & SPU_CREATE_GANG) ||
629 !SPUFS_I(nd->path.dentry->d_inode)->i_gang)
630 goto out;
631 }
632
633 dentry = lookup_create(nd, 1);
634 ret = PTR_ERR(dentry);
635 if (IS_ERR(dentry))
636 goto out_dir;
637
638 mode &= ~current_umask();
639
640 if (flags & SPU_CREATE_GANG)
641 ret = spufs_create_gang(nd->path.dentry->d_inode,
642 dentry, nd->path.mnt, mode);
643 else
644 ret = spufs_create_context(nd->path.dentry->d_inode,
645 dentry, nd->path.mnt, flags, mode,
646 filp);
647 if (ret >= 0)
648 fsnotify_mkdir(nd->path.dentry->d_inode, dentry);
649 return ret;
650
651 out_dir:
652 mutex_unlock(&nd->path.dentry->d_inode->i_mutex);
653 out:
654 return ret;
655 }
656
657 /* File system initialization */
658 enum {
659 Opt_uid, Opt_gid, Opt_mode, Opt_debug, Opt_err,
660 };
661
662 static const match_table_t spufs_tokens = {
663 { Opt_uid, "uid=%d" },
664 { Opt_gid, "gid=%d" },
665 { Opt_mode, "mode=%o" },
666 { Opt_debug, "debug" },
667 { Opt_err, NULL },
668 };
669
670 static int
671 spufs_parse_options(struct super_block *sb, char *options, struct inode *root)
672 {
673 char *p;
674 substring_t args[MAX_OPT_ARGS];
675
676 while ((p = strsep(&options, ",")) != NULL) {
677 int token, option;
678
679 if (!*p)
680 continue;
681
682 token = match_token(p, spufs_tokens, args);
683 switch (token) {
684 case Opt_uid:
685 if (match_int(&args[0], &option))
686 return 0;
687 root->i_uid = option;
688 break;
689 case Opt_gid:
690 if (match_int(&args[0], &option))
691 return 0;
692 root->i_gid = option;
693 break;
694 case Opt_mode:
695 if (match_octal(&args[0], &option))
696 return 0;
697 root->i_mode = option | S_IFDIR;
698 break;
699 case Opt_debug:
700 spufs_get_sb_info(sb)->debug = 1;
701 break;
702 default:
703 return 0;
704 }
705 }
706 return 1;
707 }
708
709 static void spufs_exit_isolated_loader(void)
710 {
711 free_pages((unsigned long) isolated_loader,
712 get_order(isolated_loader_size));
713 }
714
715 static void
716 spufs_init_isolated_loader(void)
717 {
718 struct device_node *dn;
719 const char *loader;
720 int size;
721
722 dn = of_find_node_by_path("/spu-isolation");
723 if (!dn)
724 return;
725
726 loader = of_get_property(dn, "loader", &size);
727 if (!loader)
728 return;
729
730 /* the loader must be align on a 16 byte boundary */
731 isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size));
732 if (!isolated_loader)
733 return;
734
735 isolated_loader_size = size;
736 memcpy(isolated_loader, loader, size);
737 printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
738 }
739
740 static int
741 spufs_create_root(struct super_block *sb, void *data)
742 {
743 struct inode *inode;
744 int ret;
745
746 ret = -ENODEV;
747 if (!spu_management_ops)
748 goto out;
749
750 ret = -ENOMEM;
751 inode = spufs_new_inode(sb, S_IFDIR | 0775);
752 if (!inode)
753 goto out;
754
755 inode->i_op = &simple_dir_inode_operations;
756 inode->i_fop = &simple_dir_operations;
757 SPUFS_I(inode)->i_ctx = NULL;
758 inc_nlink(inode);
759
760 ret = -EINVAL;
761 if (!spufs_parse_options(sb, data, inode))
762 goto out_iput;
763
764 ret = -ENOMEM;
765 sb->s_root = d_alloc_root(inode);
766 if (!sb->s_root)
767 goto out_iput;
768
769 return 0;
770 out_iput:
771 iput(inode);
772 out:
773 return ret;
774 }
775
776 static int
777 spufs_fill_super(struct super_block *sb, void *data, int silent)
778 {
779 struct spufs_sb_info *info;
780 static const struct super_operations s_ops = {
781 .alloc_inode = spufs_alloc_inode,
782 .destroy_inode = spufs_destroy_inode,
783 .statfs = simple_statfs,
784 .evict_inode = spufs_evict_inode,
785 .show_options = generic_show_options,
786 };
787
788 save_mount_options(sb, data);
789
790 info = kzalloc(sizeof(*info), GFP_KERNEL);
791 if (!info)
792 return -ENOMEM;
793
794 sb->s_maxbytes = MAX_LFS_FILESIZE;
795 sb->s_blocksize = PAGE_CACHE_SIZE;
796 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
797 sb->s_magic = SPUFS_MAGIC;
798 sb->s_op = &s_ops;
799 sb->s_fs_info = info;
800
801 return spufs_create_root(sb, data);
802 }
803
804 static struct dentry *
805 spufs_mount(struct file_system_type *fstype, int flags,
806 const char *name, void *data)
807 {
808 return mount_single(fstype, flags, data, spufs_fill_super);
809 }
810
811 static struct file_system_type spufs_type = {
812 .owner = THIS_MODULE,
813 .name = "spufs",
814 .mount = spufs_mount,
815 .kill_sb = kill_litter_super,
816 };
817
818 static int __init spufs_init(void)
819 {
820 int ret;
821
822 ret = -ENODEV;
823 if (!spu_management_ops)
824 goto out;
825
826 ret = -ENOMEM;
827 spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
828 sizeof(struct spufs_inode_info), 0,
829 SLAB_HWCACHE_ALIGN, spufs_init_once);
830
831 if (!spufs_inode_cache)
832 goto out;
833 ret = spu_sched_init();
834 if (ret)
835 goto out_cache;
836 ret = register_filesystem(&spufs_type);
837 if (ret)
838 goto out_sched;
839 ret = register_spu_syscalls(&spufs_calls);
840 if (ret)
841 goto out_fs;
842
843 spufs_init_isolated_loader();
844
845 return 0;
846
847 out_fs:
848 unregister_filesystem(&spufs_type);
849 out_sched:
850 spu_sched_exit();
851 out_cache:
852 kmem_cache_destroy(spufs_inode_cache);
853 out:
854 return ret;
855 }
856 module_init(spufs_init);
857
858 static void __exit spufs_exit(void)
859 {
860 spu_sched_exit();
861 spufs_exit_isolated_loader();
862 unregister_spu_syscalls(&spufs_calls);
863 unregister_filesystem(&spufs_type);
864 kmem_cache_destroy(spufs_inode_cache);
865 }
866 module_exit(spufs_exit);
867
868 MODULE_LICENSE("GPL");
869 MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
870