blob: a3ca06bd0ca17f27b6be7324e77042b6e1b6605f [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001/*
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>
Arnd Bergmann346f4d32006-01-04 20:31:26 +010029#include <linux/mount.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050030#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
arnd@arndb.de0afacde2006-10-24 18:31:18 +020036#include <asm/prom.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050037#include <asm/semaphore.h>
38#include <asm/spu.h>
39#include <asm/uaccess.h>
40
41#include "spufs.h"
42
43static kmem_cache_t *spufs_inode_cache;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +010044char *isolated_loader;
Arnd Bergmann67207b92005-11-15 15:53:48 -050045
Arnd Bergmann67207b92005-11-15 15:53:48 -050046static struct inode *
47spufs_alloc_inode(struct super_block *sb)
48{
49 struct spufs_inode_info *ei;
50
51 ei = kmem_cache_alloc(spufs_inode_cache, SLAB_KERNEL);
52 if (!ei)
53 return NULL;
Arnd Bergmann62632032006-10-04 17:26:15 +020054
55 ei->i_gang = NULL;
56 ei->i_ctx = NULL;
57
Arnd Bergmann67207b92005-11-15 15:53:48 -050058 return &ei->vfs_inode;
59}
60
61static void
62spufs_destroy_inode(struct inode *inode)
63{
64 kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
65}
66
67static void
68spufs_init_once(void *p, kmem_cache_t * cachep, unsigned long flags)
69{
70 struct spufs_inode_info *ei = p;
71
72 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
73 SLAB_CTOR_CONSTRUCTOR) {
74 inode_init_once(&ei->vfs_inode);
75 }
76}
77
78static struct inode *
79spufs_new_inode(struct super_block *sb, int mode)
80{
81 struct inode *inode;
82
83 inode = new_inode(sb);
84 if (!inode)
85 goto out;
86
87 inode->i_mode = mode;
88 inode->i_uid = current->fsuid;
89 inode->i_gid = current->fsgid;
Arnd Bergmann67207b92005-11-15 15:53:48 -050090 inode->i_blocks = 0;
91 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
92out:
93 return inode;
94}
95
96static int
97spufs_setattr(struct dentry *dentry, struct iattr *attr)
98{
99 struct inode *inode = dentry->d_inode;
100
Arnd Bergmann67207b92005-11-15 15:53:48 -0500101 if ((attr->ia_valid & ATTR_SIZE) &&
102 (attr->ia_size != inode->i_size))
103 return -EINVAL;
104 return inode_setattr(inode, attr);
105}
106
107
108static int
109spufs_new_file(struct super_block *sb, struct dentry *dentry,
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800110 const struct file_operations *fops, int mode,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500111 struct spu_context *ctx)
112{
113 static struct inode_operations spufs_file_iops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500114 .setattr = spufs_setattr,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500115 };
116 struct inode *inode;
117 int ret;
118
119 ret = -ENOSPC;
120 inode = spufs_new_inode(sb, S_IFREG | mode);
121 if (!inode)
122 goto out;
123
124 ret = 0;
125 inode->i_op = &spufs_file_iops;
126 inode->i_fop = fops;
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700127 inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500128 d_add(dentry, inode);
129out:
130 return ret;
131}
132
133static void
134spufs_delete_inode(struct inode *inode)
135{
Arnd Bergmann62632032006-10-04 17:26:15 +0200136 struct spufs_inode_info *ei = SPUFS_I(inode);
137
138 if (ei->i_ctx)
139 put_spu_context(ei->i_ctx);
140 if (ei->i_gang)
141 put_spu_gang(ei->i_gang);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500142 clear_inode(inode);
143}
144
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100145static void spufs_prune_dir(struct dentry *dir)
146{
147 struct dentry *dentry, *tmp;
Arnd Bergmann62632032006-10-04 17:26:15 +0200148
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800149 mutex_lock(&dir->d_inode->i_mutex);
Andrew Mortonc3a9aea2006-01-09 20:51:24 -0800150 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100151 spin_lock(&dcache_lock);
152 spin_lock(&dentry->d_lock);
153 if (!(d_unhashed(dentry)) && dentry->d_inode) {
154 dget_locked(dentry);
155 __d_drop(dentry);
156 spin_unlock(&dentry->d_lock);
157 simple_unlink(dir->d_inode, dentry);
158 spin_unlock(&dcache_lock);
159 dput(dentry);
160 } else {
161 spin_unlock(&dentry->d_lock);
162 spin_unlock(&dcache_lock);
163 }
164 }
165 shrink_dcache_parent(dir);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800166 mutex_unlock(&dir->d_inode->i_mutex);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100167}
168
Arnd Bergmann62632032006-10-04 17:26:15 +0200169/* Caller must hold parent->i_mutex */
170static int spufs_rmdir(struct inode *parent, struct dentry *dir)
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100171{
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100172 /* remove all entries */
Arnd Bergmann62632032006-10-04 17:26:15 +0200173 spufs_prune_dir(dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100174
Arnd Bergmann62632032006-10-04 17:26:15 +0200175 return simple_rmdir(parent, dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100176}
177
178static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files,
179 int mode, struct spu_context *ctx)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500180{
181 struct dentry *dentry;
182 int ret;
183
184 while (files->name && files->name[0]) {
185 ret = -ENOMEM;
186 dentry = d_alloc_name(dir, files->name);
187 if (!dentry)
188 goto out;
189 ret = spufs_new_file(dir->d_sb, dentry, files->ops,
190 files->mode & mode, ctx);
191 if (ret)
192 goto out;
193 files++;
194 }
195 return 0;
196out:
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100197 spufs_prune_dir(dir);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500198 return ret;
199}
200
Arnd Bergmann67207b92005-11-15 15:53:48 -0500201static int spufs_dir_close(struct inode *inode, struct file *file)
202{
Michael Ellerman0309f022006-06-19 20:33:22 +0200203 struct spu_context *ctx;
Arnd Bergmann62632032006-10-04 17:26:15 +0200204 struct inode *parent;
205 struct dentry *dir;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500206 int ret;
207
Arnd Bergmann62632032006-10-04 17:26:15 +0200208 dir = file->f_dentry;
209 parent = dir->d_parent->d_inode;
210 ctx = SPUFS_I(dir->d_inode)->i_ctx;
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100211
Arnd Bergmann62632032006-10-04 17:26:15 +0200212 mutex_lock(&parent->i_mutex);
213 ret = spufs_rmdir(parent, dir);
214 mutex_unlock(&parent->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500215 WARN_ON(ret);
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100216
Michael Ellerman0309f022006-06-19 20:33:22 +0200217 /* We have to give up the mm_struct */
218 spu_forget(ctx);
219
Arnd Bergmann67207b92005-11-15 15:53:48 -0500220 return dcache_dir_close(inode, file);
221}
222
223struct inode_operations spufs_dir_inode_operations = {
224 .lookup = simple_lookup,
225};
226
Arnd Bergmanne80358a2006-01-04 20:31:23 +0100227struct file_operations spufs_context_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500228 .open = dcache_dir_open,
229 .release = spufs_dir_close,
230 .llseek = dcache_dir_lseek,
231 .read = generic_read_dir,
232 .readdir = dcache_readdir,
233 .fsync = simple_sync_file,
234};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100235EXPORT_SYMBOL_GPL(spufs_context_fops);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500236
237static int
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200238spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
239 int mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500240{
241 int ret;
242 struct inode *inode;
243 struct spu_context *ctx;
244
245 ret = -ENOSPC;
246 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
247 if (!inode)
248 goto out;
249
250 if (dir->i_mode & S_ISGID) {
251 inode->i_gid = dir->i_gid;
252 inode->i_mode &= S_ISGID;
253 }
Arnd Bergmann62632032006-10-04 17:26:15 +0200254 ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500255 SPUFS_I(inode)->i_ctx = ctx;
256 if (!ctx)
257 goto out_iput;
258
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200259 ctx->flags = flags;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500260 inode->i_op = &spufs_dir_inode_operations;
261 inode->i_fop = &simple_dir_operations;
Mark Nutter5737edd2006-10-24 18:31:16 +0200262 if (flags & SPU_CREATE_NOSCHED)
263 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
264 mode, ctx);
265 else
266 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
267
Arnd Bergmann67207b92005-11-15 15:53:48 -0500268 if (ret)
269 goto out_free_ctx;
270
271 d_instantiate(dentry, inode);
272 dget(dentry);
273 dir->i_nlink++;
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100274 dentry->d_inode->i_nlink++;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500275 goto out;
276
277out_free_ctx:
278 put_spu_context(ctx);
279out_iput:
280 iput(inode);
281out:
282 return ret;
283}
284
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100285static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
286{
287 int ret;
288 struct file *filp;
289
290 ret = get_unused_fd();
291 if (ret < 0) {
292 dput(dentry);
293 mntput(mnt);
294 goto out;
295 }
296
297 filp = dentry_open(dentry, mnt, O_RDONLY);
298 if (IS_ERR(filp)) {
299 put_unused_fd(ret);
300 ret = PTR_ERR(filp);
301 goto out;
302 }
303
304 filp->f_op = &spufs_context_fops;
305 fd_install(ret, filp);
306out:
307 return ret;
308}
309
Arnd Bergmann62632032006-10-04 17:26:15 +0200310static int spufs_create_context(struct inode *inode,
311 struct dentry *dentry,
312 struct vfsmount *mnt, int flags, int mode)
313{
314 int ret;
315
Mark Nutter5737edd2006-10-24 18:31:16 +0200316 ret = -EPERM;
317 if ((flags & SPU_CREATE_NOSCHED) &&
318 !capable(CAP_SYS_NICE))
319 goto out_unlock;
320
321 ret = -EINVAL;
322 if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
323 == SPU_CREATE_ISOLATE)
324 goto out_unlock;
325
Arnd Bergmann62632032006-10-04 17:26:15 +0200326 ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
327 if (ret)
328 goto out_unlock;
329
330 /*
331 * get references for dget and mntget, will be released
332 * in error path of *_open().
333 */
334 ret = spufs_context_open(dget(dentry), mntget(mnt));
335 if (ret < 0) {
336 WARN_ON(spufs_rmdir(inode, dentry));
337 mutex_unlock(&inode->i_mutex);
338 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
339 goto out;
340 }
341
342out_unlock:
343 mutex_unlock(&inode->i_mutex);
344out:
345 dput(dentry);
346 return ret;
347}
348
349static int spufs_rmgang(struct inode *root, struct dentry *dir)
350{
351 /* FIXME: this fails if the dir is not empty,
352 which causes a leak of gangs. */
353 return simple_rmdir(root, dir);
354}
355
356static int spufs_gang_close(struct inode *inode, struct file *file)
357{
358 struct inode *parent;
359 struct dentry *dir;
360 int ret;
361
362 dir = file->f_dentry;
363 parent = dir->d_parent->d_inode;
364
365 ret = spufs_rmgang(parent, dir);
366 WARN_ON(ret);
367
368 return dcache_dir_close(inode, file);
369}
370
371struct file_operations spufs_gang_fops = {
372 .open = dcache_dir_open,
373 .release = spufs_gang_close,
374 .llseek = dcache_dir_lseek,
375 .read = generic_read_dir,
376 .readdir = dcache_readdir,
377 .fsync = simple_sync_file,
378};
379
380static int
381spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
382{
383 int ret;
384 struct inode *inode;
385 struct spu_gang *gang;
386
387 ret = -ENOSPC;
388 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
389 if (!inode)
390 goto out;
391
392 ret = 0;
393 if (dir->i_mode & S_ISGID) {
394 inode->i_gid = dir->i_gid;
395 inode->i_mode &= S_ISGID;
396 }
397 gang = alloc_spu_gang();
398 SPUFS_I(inode)->i_ctx = NULL;
399 SPUFS_I(inode)->i_gang = gang;
400 if (!gang)
401 goto out_iput;
402
403 inode->i_op = &spufs_dir_inode_operations;
404 inode->i_fop = &simple_dir_operations;
405
406 d_instantiate(dentry, inode);
407 dget(dentry);
408 dir->i_nlink++;
409 dentry->d_inode->i_nlink++;
410 return ret;
411
412out_iput:
413 iput(inode);
414out:
415 return ret;
416}
417
418static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
419{
420 int ret;
421 struct file *filp;
422
423 ret = get_unused_fd();
424 if (ret < 0) {
425 dput(dentry);
426 mntput(mnt);
427 goto out;
428 }
429
430 filp = dentry_open(dentry, mnt, O_RDONLY);
431 if (IS_ERR(filp)) {
432 put_unused_fd(ret);
433 ret = PTR_ERR(filp);
434 goto out;
435 }
436
437 filp->f_op = &spufs_gang_fops;
438 fd_install(ret, filp);
439out:
440 return ret;
441}
442
443static int spufs_create_gang(struct inode *inode,
444 struct dentry *dentry,
445 struct vfsmount *mnt, int mode)
446{
447 int ret;
448
449 ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
450 if (ret)
451 goto out;
452
453 /*
454 * get references for dget and mntget, will be released
455 * in error path of *_open().
456 */
457 ret = spufs_gang_open(dget(dentry), mntget(mnt));
458 if (ret < 0)
459 WARN_ON(spufs_rmgang(inode, dentry));
460
461out:
462 mutex_unlock(&inode->i_mutex);
463 dput(dentry);
464 return ret;
465}
466
467
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100468static struct file_system_type spufs_type;
469
Arnd Bergmann62632032006-10-04 17:26:15 +0200470long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500471{
472 struct dentry *dentry;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500473 int ret;
474
Arnd Bergmann67207b92005-11-15 15:53:48 -0500475 ret = -EINVAL;
Arnd Bergmann62632032006-10-04 17:26:15 +0200476 /* check if we are on spufs */
477 if (nd->dentry->d_sb->s_type != &spufs_type)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500478 goto out;
479
Arnd Bergmann62632032006-10-04 17:26:15 +0200480 /* don't accept undefined flags */
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200481 if (flags & (~SPU_CREATE_FLAG_ALL))
arnd@arndb.dec9832942006-06-19 20:33:34 +0200482 goto out;
483
Arnd Bergmann62632032006-10-04 17:26:15 +0200484 /* only threads can be underneath a gang */
485 if (nd->dentry != nd->dentry->d_sb->s_root) {
486 if ((flags & SPU_CREATE_GANG) ||
487 !SPUFS_I(nd->dentry->d_inode)->i_gang)
488 goto out;
489 }
490
Arnd Bergmann67207b92005-11-15 15:53:48 -0500491 dentry = lookup_create(nd, 1);
492 ret = PTR_ERR(dentry);
493 if (IS_ERR(dentry))
494 goto out_dir;
495
496 ret = -EEXIST;
497 if (dentry->d_inode)
498 goto out_dput;
499
500 mode &= ~current->fs->umask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500501
Arnd Bergmann62632032006-10-04 17:26:15 +0200502 if (flags & SPU_CREATE_GANG)
503 return spufs_create_gang(nd->dentry->d_inode,
504 dentry, nd->mnt, mode);
505 else
506 return spufs_create_context(nd->dentry->d_inode,
507 dentry, nd->mnt, flags, mode);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500508
509out_dput:
510 dput(dentry);
511out_dir:
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800512 mutex_unlock(&nd->dentry->d_inode->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500513out:
514 return ret;
515}
516
517/* File system initialization */
518enum {
519 Opt_uid, Opt_gid, Opt_err,
520};
521
522static match_table_t spufs_tokens = {
523 { Opt_uid, "uid=%d" },
524 { Opt_gid, "gid=%d" },
525 { Opt_err, NULL },
526};
527
528static int
529spufs_parse_options(char *options, struct inode *root)
530{
531 char *p;
532 substring_t args[MAX_OPT_ARGS];
533
534 while ((p = strsep(&options, ",")) != NULL) {
535 int token, option;
536
537 if (!*p)
538 continue;
539
540 token = match_token(p, spufs_tokens, args);
541 switch (token) {
542 case Opt_uid:
543 if (match_int(&args[0], &option))
544 return 0;
545 root->i_uid = option;
546 break;
547 case Opt_gid:
548 if (match_int(&args[0], &option))
549 return 0;
550 root->i_gid = option;
551 break;
552 default:
553 return 0;
554 }
555 }
556 return 1;
557}
558
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200559static void
560spufs_init_isolated_loader(void)
561{
562 struct device_node *dn;
563 const char *loader;
564 int size;
565
566 dn = of_find_node_by_path("/spu-isolation");
567 if (!dn)
568 return;
569
570 loader = get_property(dn, "loader", &size);
571 if (!loader)
572 return;
573
574 /* kmalloc should align on a 16 byte boundary..* */
575 isolated_loader = kmalloc(size, GFP_KERNEL);
576 if (!isolated_loader)
577 return;
578
579 memcpy(isolated_loader, loader, size);
580 printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
581}
582
Arnd Bergmann67207b92005-11-15 15:53:48 -0500583static int
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500584spufs_create_root(struct super_block *sb, void *data)
585{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500586 struct inode *inode;
587 int ret;
588
589 ret = -ENOMEM;
590 inode = spufs_new_inode(sb, S_IFDIR | 0775);
591 if (!inode)
592 goto out;
593
594 inode->i_op = &spufs_dir_inode_operations;
595 inode->i_fop = &simple_dir_operations;
596 SPUFS_I(inode)->i_ctx = NULL;
597
598 ret = -EINVAL;
599 if (!spufs_parse_options(data, inode))
600 goto out_iput;
601
602 ret = -ENOMEM;
603 sb->s_root = d_alloc_root(inode);
604 if (!sb->s_root)
605 goto out_iput;
606
607 return 0;
608out_iput:
609 iput(inode);
610out:
611 return ret;
612}
613
614static int
615spufs_fill_super(struct super_block *sb, void *data, int silent)
616{
617 static struct super_operations s_ops = {
618 .alloc_inode = spufs_alloc_inode,
619 .destroy_inode = spufs_destroy_inode,
620 .statfs = simple_statfs,
621 .delete_inode = spufs_delete_inode,
622 .drop_inode = generic_delete_inode,
623 };
624
625 sb->s_maxbytes = MAX_LFS_FILESIZE;
626 sb->s_blocksize = PAGE_CACHE_SIZE;
627 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
628 sb->s_magic = SPUFS_MAGIC;
629 sb->s_op = &s_ops;
630
631 return spufs_create_root(sb, data);
632}
633
David Howells454e2392006-06-23 02:02:57 -0700634static int
Arnd Bergmann67207b92005-11-15 15:53:48 -0500635spufs_get_sb(struct file_system_type *fstype, int flags,
David Howells454e2392006-06-23 02:02:57 -0700636 const char *name, void *data, struct vfsmount *mnt)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500637{
David Howells454e2392006-06-23 02:02:57 -0700638 return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500639}
640
641static struct file_system_type spufs_type = {
642 .owner = THIS_MODULE,
643 .name = "spufs",
644 .get_sb = spufs_get_sb,
645 .kill_sb = kill_litter_super,
646};
647
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200648static int __init spufs_init(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500649{
650 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100651
Arnd Bergmann67207b92005-11-15 15:53:48 -0500652 ret = -ENOMEM;
653 spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
654 sizeof(struct spufs_inode_info), 0,
655 SLAB_HWCACHE_ALIGN, spufs_init_once, NULL);
656
657 if (!spufs_inode_cache)
658 goto out;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500659 if (spu_sched_init() != 0) {
660 kmem_cache_destroy(spufs_inode_cache);
661 goto out;
662 }
Arnd Bergmann67207b92005-11-15 15:53:48 -0500663 ret = register_filesystem(&spufs_type);
664 if (ret)
665 goto out_cache;
666 ret = register_spu_syscalls(&spufs_calls);
667 if (ret)
668 goto out_fs;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100669 ret = register_arch_coredump_calls(&spufs_coredump_calls);
670 if (ret)
671 goto out_fs;
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200672
673 spufs_init_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100674
Arnd Bergmann67207b92005-11-15 15:53:48 -0500675 return 0;
676out_fs:
677 unregister_filesystem(&spufs_type);
678out_cache:
679 kmem_cache_destroy(spufs_inode_cache);
680out:
681 return ret;
682}
683module_init(spufs_init);
684
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200685static void __exit spufs_exit(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500686{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500687 spu_sched_exit();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100688 unregister_arch_coredump_calls(&spufs_coredump_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500689 unregister_spu_syscalls(&spufs_calls);
690 unregister_filesystem(&spufs_type);
691 kmem_cache_destroy(spufs_inode_cache);
692}
693module_exit(spufs_exit);
694
695MODULE_LICENSE("GPL");
696MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
697