spufs: switch to ->free_inode()
[muen/linux.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 <linux/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 spufs_free_inode(struct inode *inode)
75 {
76         kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
77 }
78
79 static void
80 spufs_init_once(void *p)
81 {
82         struct spufs_inode_info *ei = p;
83
84         inode_init_once(&ei->vfs_inode);
85 }
86
87 static struct inode *
88 spufs_new_inode(struct super_block *sb, umode_t mode)
89 {
90         struct inode *inode;
91
92         inode = new_inode(sb);
93         if (!inode)
94                 goto out;
95
96         inode->i_ino = get_next_ino();
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(inode);
101 out:
102         return inode;
103 }
104
105 static int
106 spufs_setattr(struct dentry *dentry, struct iattr *attr)
107 {
108         struct inode *inode = d_inode(dentry);
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, umode_t 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         clear_inode(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         inode_lock(d_inode(dir));
161         list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) {
162                 spin_lock(&dentry->d_lock);
163                 if (simple_positive(dentry)) {
164                         dget_dlock(dentry);
165                         __d_drop(dentry);
166                         spin_unlock(&dentry->d_lock);
167                         simple_unlink(d_inode(dir), dentry);
168                         /* XXX: what was dcache_lock protecting here? Other
169                          * filesystems (IB, configfs) release dcache_lock
170                          * before unlink */
171                         dput(dentry);
172                 } else {
173                         spin_unlock(&dentry->d_lock);
174                 }
175         }
176         shrink_dcache_parent(dir);
177         inode_unlock(d_inode(dir));
178 }
179
180 /* Caller must hold parent->i_mutex */
181 static int spufs_rmdir(struct inode *parent, struct dentry *dir)
182 {
183         /* remove all entries */
184         int res;
185         spufs_prune_dir(dir);
186         d_drop(dir);
187         res = simple_rmdir(parent, dir);
188         /* We have to give up the mm_struct */
189         spu_forget(SPUFS_I(d_inode(dir))->i_ctx);
190         return res;
191 }
192
193 static int spufs_fill_dir(struct dentry *dir,
194                 const struct spufs_tree_descr *files, umode_t mode,
195                 struct spu_context *ctx)
196 {
197         while (files->name && files->name[0]) {
198                 int ret;
199                 struct dentry *dentry = d_alloc_name(dir, files->name);
200                 if (!dentry)
201                         return -ENOMEM;
202                 ret = spufs_new_file(dir->d_sb, dentry, files->ops,
203                                         files->mode & mode, files->size, ctx);
204                 if (ret)
205                         return ret;
206                 files++;
207         }
208         return 0;
209 }
210
211 static int spufs_dir_close(struct inode *inode, struct file *file)
212 {
213         struct spu_context *ctx;
214         struct inode *parent;
215         struct dentry *dir;
216         int ret;
217
218         dir = file->f_path.dentry;
219         parent = d_inode(dir->d_parent);
220         ctx = SPUFS_I(d_inode(dir))->i_ctx;
221
222         inode_lock_nested(parent, I_MUTEX_PARENT);
223         ret = spufs_rmdir(parent, dir);
224         inode_unlock(parent);
225         WARN_ON(ret);
226
227         return dcache_dir_close(inode, file);
228 }
229
230 const struct file_operations spufs_context_fops = {
231         .open           = dcache_dir_open,
232         .release        = spufs_dir_close,
233         .llseek         = dcache_dir_lseek,
234         .read           = generic_read_dir,
235         .iterate_shared = dcache_readdir,
236         .fsync          = noop_fsync,
237 };
238 EXPORT_SYMBOL_GPL(spufs_context_fops);
239
240 static int
241 spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
242                 umode_t mode)
243 {
244         int ret;
245         struct inode *inode;
246         struct spu_context *ctx;
247
248         inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
249         if (!inode)
250                 return -ENOSPC;
251
252         if (dir->i_mode & S_ISGID) {
253                 inode->i_gid = dir->i_gid;
254                 inode->i_mode &= S_ISGID;
255         }
256         ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
257         SPUFS_I(inode)->i_ctx = ctx;
258         if (!ctx) {
259                 iput(inode);
260                 return -ENOSPC;
261         }
262
263         ctx->flags = flags;
264         inode->i_op = &simple_dir_inode_operations;
265         inode->i_fop = &simple_dir_operations;
266
267         inode_lock(inode);
268
269         dget(dentry);
270         inc_nlink(dir);
271         inc_nlink(inode);
272
273         d_instantiate(dentry, inode);
274
275         if (flags & SPU_CREATE_NOSCHED)
276                 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
277                                          mode, ctx);
278         else
279                 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
280
281         if (!ret && spufs_get_sb_info(dir->i_sb)->debug)
282                 ret = spufs_fill_dir(dentry, spufs_dir_debug_contents,
283                                 mode, ctx);
284
285         if (ret)
286                 spufs_rmdir(dir, dentry);
287
288         inode_unlock(inode);
289
290         return ret;
291 }
292
293 static int spufs_context_open(struct path *path)
294 {
295         int ret;
296         struct file *filp;
297
298         ret = get_unused_fd_flags(0);
299         if (ret < 0)
300                 return ret;
301
302         filp = dentry_open(path, O_RDONLY, current_cred());
303         if (IS_ERR(filp)) {
304                 put_unused_fd(ret);
305                 return PTR_ERR(filp);
306         }
307
308         filp->f_op = &spufs_context_fops;
309         fd_install(ret, filp);
310         return ret;
311 }
312
313 static struct spu_context *
314 spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
315                                                 struct file *filp)
316 {
317         struct spu_context *tmp, *neighbor, *err;
318         int count, node;
319         int aff_supp;
320
321         aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
322                                         struct spu, cbe_list))->aff_list);
323
324         if (!aff_supp)
325                 return ERR_PTR(-EINVAL);
326
327         if (flags & SPU_CREATE_GANG)
328                 return ERR_PTR(-EINVAL);
329
330         if (flags & SPU_CREATE_AFFINITY_MEM &&
331             gang->aff_ref_ctx &&
332             gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
333                 return ERR_PTR(-EEXIST);
334
335         if (gang->aff_flags & AFF_MERGED)
336                 return ERR_PTR(-EBUSY);
337
338         neighbor = NULL;
339         if (flags & SPU_CREATE_AFFINITY_SPU) {
340                 if (!filp || filp->f_op != &spufs_context_fops)
341                         return ERR_PTR(-EINVAL);
342
343                 neighbor = get_spu_context(
344                                 SPUFS_I(file_inode(filp))->i_ctx);
345
346                 if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
347                     !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
348                     !list_entry(neighbor->aff_list.next, struct spu_context,
349                     aff_list)->aff_head) {
350                         err = ERR_PTR(-EEXIST);
351                         goto out_put_neighbor;
352                 }
353
354                 if (gang != neighbor->gang) {
355                         err = ERR_PTR(-EINVAL);
356                         goto out_put_neighbor;
357                 }
358
359                 count = 1;
360                 list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
361                         count++;
362                 if (list_empty(&neighbor->aff_list))
363                         count++;
364
365                 for (node = 0; node < MAX_NUMNODES; node++) {
366                         if ((cbe_spu_info[node].n_spus - atomic_read(
367                                 &cbe_spu_info[node].reserved_spus)) >= count)
368                                 break;
369                 }
370
371                 if (node == MAX_NUMNODES) {
372                         err = ERR_PTR(-EEXIST);
373                         goto out_put_neighbor;
374                 }
375         }
376
377         return neighbor;
378
379 out_put_neighbor:
380         put_spu_context(neighbor);
381         return err;
382 }
383
384 static void
385 spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
386                                         struct spu_context *neighbor)
387 {
388         if (flags & SPU_CREATE_AFFINITY_MEM)
389                 ctx->gang->aff_ref_ctx = ctx;
390
391         if (flags & SPU_CREATE_AFFINITY_SPU) {
392                 if (list_empty(&neighbor->aff_list)) {
393                         list_add_tail(&neighbor->aff_list,
394                                 &ctx->gang->aff_list_head);
395                         neighbor->aff_head = 1;
396                 }
397
398                 if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
399                     || list_entry(neighbor->aff_list.next, struct spu_context,
400                                                         aff_list)->aff_head) {
401                         list_add(&ctx->aff_list, &neighbor->aff_list);
402                 } else  {
403                         list_add_tail(&ctx->aff_list, &neighbor->aff_list);
404                         if (neighbor->aff_head) {
405                                 neighbor->aff_head = 0;
406                                 ctx->aff_head = 1;
407                         }
408                 }
409
410                 if (!ctx->gang->aff_ref_ctx)
411                         ctx->gang->aff_ref_ctx = ctx;
412         }
413 }
414
415 static int
416 spufs_create_context(struct inode *inode, struct dentry *dentry,
417                         struct vfsmount *mnt, int flags, umode_t mode,
418                         struct file *aff_filp)
419 {
420         int ret;
421         int affinity;
422         struct spu_gang *gang;
423         struct spu_context *neighbor;
424         struct path path = {.mnt = mnt, .dentry = dentry};
425
426         if ((flags & SPU_CREATE_NOSCHED) &&
427             !capable(CAP_SYS_NICE))
428                 return -EPERM;
429
430         if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
431             == SPU_CREATE_ISOLATE)
432                 return -EINVAL;
433
434         if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
435                 return -ENODEV;
436
437         gang = NULL;
438         neighbor = NULL;
439         affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
440         if (affinity) {
441                 gang = SPUFS_I(inode)->i_gang;
442                 if (!gang)
443                         return -EINVAL;
444                 mutex_lock(&gang->aff_mutex);
445                 neighbor = spufs_assert_affinity(flags, gang, aff_filp);
446                 if (IS_ERR(neighbor)) {
447                         ret = PTR_ERR(neighbor);
448                         goto out_aff_unlock;
449                 }
450         }
451
452         ret = spufs_mkdir(inode, dentry, flags, mode & 0777);
453         if (ret)
454                 goto out_aff_unlock;
455
456         if (affinity) {
457                 spufs_set_affinity(flags, SPUFS_I(d_inode(dentry))->i_ctx,
458                                                                 neighbor);
459                 if (neighbor)
460                         put_spu_context(neighbor);
461         }
462
463         ret = spufs_context_open(&path);
464         if (ret < 0)
465                 WARN_ON(spufs_rmdir(inode, dentry));
466
467 out_aff_unlock:
468         if (affinity)
469                 mutex_unlock(&gang->aff_mutex);
470         return ret;
471 }
472
473 static int
474 spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
475 {
476         int ret;
477         struct inode *inode;
478         struct spu_gang *gang;
479
480         ret = -ENOSPC;
481         inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
482         if (!inode)
483                 goto out;
484
485         ret = 0;
486         if (dir->i_mode & S_ISGID) {
487                 inode->i_gid = dir->i_gid;
488                 inode->i_mode &= S_ISGID;
489         }
490         gang = alloc_spu_gang();
491         SPUFS_I(inode)->i_ctx = NULL;
492         SPUFS_I(inode)->i_gang = gang;
493         if (!gang) {
494                 ret = -ENOMEM;
495                 goto out_iput;
496         }
497
498         inode->i_op = &simple_dir_inode_operations;
499         inode->i_fop = &simple_dir_operations;
500
501         d_instantiate(dentry, inode);
502         inc_nlink(dir);
503         inc_nlink(d_inode(dentry));
504         return ret;
505
506 out_iput:
507         iput(inode);
508 out:
509         return ret;
510 }
511
512 static int spufs_gang_open(struct path *path)
513 {
514         int ret;
515         struct file *filp;
516
517         ret = get_unused_fd_flags(0);
518         if (ret < 0)
519                 return ret;
520
521         /*
522          * get references for dget and mntget, will be released
523          * in error path of *_open().
524          */
525         filp = dentry_open(path, O_RDONLY, current_cred());
526         if (IS_ERR(filp)) {
527                 put_unused_fd(ret);
528                 return PTR_ERR(filp);
529         }
530
531         filp->f_op = &simple_dir_operations;
532         fd_install(ret, filp);
533         return ret;
534 }
535
536 static int spufs_create_gang(struct inode *inode,
537                         struct dentry *dentry,
538                         struct vfsmount *mnt, umode_t mode)
539 {
540         struct path path = {.mnt = mnt, .dentry = dentry};
541         int ret;
542
543         ret = spufs_mkgang(inode, dentry, mode & 0777);
544         if (!ret) {
545                 ret = spufs_gang_open(&path);
546                 if (ret < 0) {
547                         int err = simple_rmdir(inode, dentry);
548                         WARN_ON(err);
549                 }
550         }
551         return ret;
552 }
553
554
555 static struct file_system_type spufs_type;
556
557 long spufs_create(struct path *path, struct dentry *dentry,
558                 unsigned int flags, umode_t mode, struct file *filp)
559 {
560         struct inode *dir = d_inode(path->dentry);
561         int ret;
562
563         /* check if we are on spufs */
564         if (path->dentry->d_sb->s_type != &spufs_type)
565                 return -EINVAL;
566
567         /* don't accept undefined flags */
568         if (flags & (~SPU_CREATE_FLAG_ALL))
569                 return -EINVAL;
570
571         /* only threads can be underneath a gang */
572         if (path->dentry != path->dentry->d_sb->s_root)
573                 if ((flags & SPU_CREATE_GANG) || !SPUFS_I(dir)->i_gang)
574                         return -EINVAL;
575
576         mode &= ~current_umask();
577
578         if (flags & SPU_CREATE_GANG)
579                 ret = spufs_create_gang(dir, dentry, path->mnt, mode);
580         else
581                 ret = spufs_create_context(dir, dentry, path->mnt, flags, mode,
582                                             filp);
583         if (ret >= 0)
584                 fsnotify_mkdir(dir, dentry);
585
586         return ret;
587 }
588
589 /* File system initialization */
590 enum {
591         Opt_uid, Opt_gid, Opt_mode, Opt_debug, Opt_err,
592 };
593
594 static const match_table_t spufs_tokens = {
595         { Opt_uid,   "uid=%d" },
596         { Opt_gid,   "gid=%d" },
597         { Opt_mode,  "mode=%o" },
598         { Opt_debug, "debug" },
599         { Opt_err,    NULL  },
600 };
601
602 static int spufs_show_options(struct seq_file *m, struct dentry *root)
603 {
604         struct spufs_sb_info *sbi = spufs_get_sb_info(root->d_sb);
605         struct inode *inode = root->d_inode;
606
607         if (!uid_eq(inode->i_uid, GLOBAL_ROOT_UID))
608                 seq_printf(m, ",uid=%u",
609                            from_kuid_munged(&init_user_ns, inode->i_uid));
610         if (!gid_eq(inode->i_gid, GLOBAL_ROOT_GID))
611                 seq_printf(m, ",gid=%u",
612                            from_kgid_munged(&init_user_ns, inode->i_gid));
613         if ((inode->i_mode & S_IALLUGO) != 0775)
614                 seq_printf(m, ",mode=%o", inode->i_mode);
615         if (sbi->debug)
616                 seq_puts(m, ",debug");
617         return 0;
618 }
619
620 static int
621 spufs_parse_options(struct super_block *sb, char *options, struct inode *root)
622 {
623         char *p;
624         substring_t args[MAX_OPT_ARGS];
625
626         while ((p = strsep(&options, ",")) != NULL) {
627                 int token, option;
628
629                 if (!*p)
630                         continue;
631
632                 token = match_token(p, spufs_tokens, args);
633                 switch (token) {
634                 case Opt_uid:
635                         if (match_int(&args[0], &option))
636                                 return 0;
637                         root->i_uid = make_kuid(current_user_ns(), option);
638                         if (!uid_valid(root->i_uid))
639                                 return 0;
640                         break;
641                 case Opt_gid:
642                         if (match_int(&args[0], &option))
643                                 return 0;
644                         root->i_gid = make_kgid(current_user_ns(), option);
645                         if (!gid_valid(root->i_gid))
646                                 return 0;
647                         break;
648                 case Opt_mode:
649                         if (match_octal(&args[0], &option))
650                                 return 0;
651                         root->i_mode = option | S_IFDIR;
652                         break;
653                 case Opt_debug:
654                         spufs_get_sb_info(sb)->debug = 1;
655                         break;
656                 default:
657                         return 0;
658                 }
659         }
660         return 1;
661 }
662
663 static void spufs_exit_isolated_loader(void)
664 {
665         free_pages((unsigned long) isolated_loader,
666                         get_order(isolated_loader_size));
667 }
668
669 static void
670 spufs_init_isolated_loader(void)
671 {
672         struct device_node *dn;
673         const char *loader;
674         int size;
675
676         dn = of_find_node_by_path("/spu-isolation");
677         if (!dn)
678                 return;
679
680         loader = of_get_property(dn, "loader", &size);
681         if (!loader)
682                 return;
683
684         /* the loader must be align on a 16 byte boundary */
685         isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size));
686         if (!isolated_loader)
687                 return;
688
689         isolated_loader_size = size;
690         memcpy(isolated_loader, loader, size);
691         printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
692 }
693
694 static int
695 spufs_create_root(struct super_block *sb, void *data)
696 {
697         struct inode *inode;
698         int ret;
699
700         ret = -ENODEV;
701         if (!spu_management_ops)
702                 goto out;
703
704         ret = -ENOMEM;
705         inode = spufs_new_inode(sb, S_IFDIR | 0775);
706         if (!inode)
707                 goto out;
708
709         inode->i_op = &simple_dir_inode_operations;
710         inode->i_fop = &simple_dir_operations;
711         SPUFS_I(inode)->i_ctx = NULL;
712         inc_nlink(inode);
713
714         ret = -EINVAL;
715         if (!spufs_parse_options(sb, data, inode))
716                 goto out_iput;
717
718         ret = -ENOMEM;
719         sb->s_root = d_make_root(inode);
720         if (!sb->s_root)
721                 goto out;
722
723         return 0;
724 out_iput:
725         iput(inode);
726 out:
727         return ret;
728 }
729
730 static int
731 spufs_fill_super(struct super_block *sb, void *data, int silent)
732 {
733         struct spufs_sb_info *info;
734         static const struct super_operations s_ops = {
735                 .alloc_inode = spufs_alloc_inode,
736                 .free_inode = spufs_free_inode,
737                 .statfs = simple_statfs,
738                 .evict_inode = spufs_evict_inode,
739                 .show_options = spufs_show_options,
740         };
741
742         info = kzalloc(sizeof(*info), GFP_KERNEL);
743         if (!info)
744                 return -ENOMEM;
745
746         sb->s_maxbytes = MAX_LFS_FILESIZE;
747         sb->s_blocksize = PAGE_SIZE;
748         sb->s_blocksize_bits = PAGE_SHIFT;
749         sb->s_magic = SPUFS_MAGIC;
750         sb->s_op = &s_ops;
751         sb->s_fs_info = info;
752
753         return spufs_create_root(sb, data);
754 }
755
756 static struct dentry *
757 spufs_mount(struct file_system_type *fstype, int flags,
758                 const char *name, void *data)
759 {
760         return mount_single(fstype, flags, data, spufs_fill_super);
761 }
762
763 static struct file_system_type spufs_type = {
764         .owner = THIS_MODULE,
765         .name = "spufs",
766         .mount = spufs_mount,
767         .kill_sb = kill_litter_super,
768 };
769 MODULE_ALIAS_FS("spufs");
770
771 static int __init spufs_init(void)
772 {
773         int ret;
774
775         ret = -ENODEV;
776         if (!spu_management_ops)
777                 goto out;
778
779         ret = -ENOMEM;
780         spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
781                         sizeof(struct spufs_inode_info), 0,
782                         SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, spufs_init_once);
783
784         if (!spufs_inode_cache)
785                 goto out;
786         ret = spu_sched_init();
787         if (ret)
788                 goto out_cache;
789         ret = register_spu_syscalls(&spufs_calls);
790         if (ret)
791                 goto out_sched;
792         ret = register_filesystem(&spufs_type);
793         if (ret)
794                 goto out_syscalls;
795
796         spufs_init_isolated_loader();
797
798         return 0;
799
800 out_syscalls:
801         unregister_spu_syscalls(&spufs_calls);
802 out_sched:
803         spu_sched_exit();
804 out_cache:
805         kmem_cache_destroy(spufs_inode_cache);
806 out:
807         return ret;
808 }
809 module_init(spufs_init);
810
811 static void __exit spufs_exit(void)
812 {
813         spu_sched_exit();
814         spufs_exit_isolated_loader();
815         unregister_spu_syscalls(&spufs_calls);
816         unregister_filesystem(&spufs_type);
817         kmem_cache_destroy(spufs_inode_cache);
818 }
819 module_exit(spufs_exit);
820
821 MODULE_LICENSE("GPL");
822 MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
823