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