blob: 6b52dfabaeefee97a417cd843b18c92db07d444f [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
Christoph Lametere18b8902006-12-06 20:33:20 -080043static struct kmem_cache *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
Christoph Lametere94b1762006-12-06 20:33:17 -080051 ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
Arnd Bergmann67207b92005-11-15 15:53:48 -050052 if (!ei)
53 return NULL;
Arnd Bergmann62632032006-10-04 17:26:15 +020054
55 ei->i_gang = NULL;
56 ei->i_ctx = NULL;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020057 ei->i_openers = 0;
Arnd Bergmann62632032006-10-04 17:26:15 +020058
Arnd Bergmann67207b92005-11-15 15:53:48 -050059 return &ei->vfs_inode;
60}
61
62static void
63spufs_destroy_inode(struct inode *inode)
64{
65 kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
66}
67
68static void
Christoph Lametere18b8902006-12-06 20:33:20 -080069spufs_init_once(void *p, struct kmem_cache * cachep, unsigned long flags)
Arnd Bergmann67207b92005-11-15 15:53:48 -050070{
71 struct spufs_inode_info *ei = p;
72
73 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
74 SLAB_CTOR_CONSTRUCTOR) {
75 inode_init_once(&ei->vfs_inode);
76 }
77}
78
79static struct inode *
80spufs_new_inode(struct super_block *sb, int mode)
81{
82 struct inode *inode;
83
84 inode = new_inode(sb);
85 if (!inode)
86 goto out;
87
88 inode->i_mode = mode;
89 inode->i_uid = current->fsuid;
90 inode->i_gid = current->fsgid;
Arnd Bergmann67207b92005-11-15 15:53:48 -050091 inode->i_blocks = 0;
92 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
93out:
94 return inode;
95}
96
97static int
98spufs_setattr(struct dentry *dentry, struct iattr *attr)
99{
100 struct inode *inode = dentry->d_inode;
101
Arnd Bergmann67207b92005-11-15 15:53:48 -0500102 if ((attr->ia_valid & ATTR_SIZE) &&
103 (attr->ia_size != inode->i_size))
104 return -EINVAL;
105 return inode_setattr(inode, attr);
106}
107
108
109static int
110spufs_new_file(struct super_block *sb, struct dentry *dentry,
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800111 const struct file_operations *fops, int mode,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500112 struct spu_context *ctx)
113{
114 static struct inode_operations spufs_file_iops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500115 .setattr = spufs_setattr,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500116 };
117 struct inode *inode;
118 int ret;
119
120 ret = -ENOSPC;
121 inode = spufs_new_inode(sb, S_IFREG | mode);
122 if (!inode)
123 goto out;
124
125 ret = 0;
126 inode->i_op = &spufs_file_iops;
127 inode->i_fop = fops;
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700128 inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500129 d_add(dentry, inode);
130out:
131 return ret;
132}
133
134static void
135spufs_delete_inode(struct inode *inode)
136{
Arnd Bergmann62632032006-10-04 17:26:15 +0200137 struct spufs_inode_info *ei = SPUFS_I(inode);
138
139 if (ei->i_ctx)
140 put_spu_context(ei->i_ctx);
141 if (ei->i_gang)
142 put_spu_gang(ei->i_gang);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500143 clear_inode(inode);
144}
145
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100146static void spufs_prune_dir(struct dentry *dir)
147{
148 struct dentry *dentry, *tmp;
Arnd Bergmann62632032006-10-04 17:26:15 +0200149
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800150 mutex_lock(&dir->d_inode->i_mutex);
Andrew Mortonc3a9aea2006-01-09 20:51:24 -0800151 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100152 spin_lock(&dcache_lock);
153 spin_lock(&dentry->d_lock);
154 if (!(d_unhashed(dentry)) && dentry->d_inode) {
155 dget_locked(dentry);
156 __d_drop(dentry);
157 spin_unlock(&dentry->d_lock);
158 simple_unlink(dir->d_inode, dentry);
159 spin_unlock(&dcache_lock);
160 dput(dentry);
161 } else {
162 spin_unlock(&dentry->d_lock);
163 spin_unlock(&dcache_lock);
164 }
165 }
166 shrink_dcache_parent(dir);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800167 mutex_unlock(&dir->d_inode->i_mutex);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100168}
169
Arnd Bergmann62632032006-10-04 17:26:15 +0200170/* Caller must hold parent->i_mutex */
171static int spufs_rmdir(struct inode *parent, struct dentry *dir)
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100172{
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100173 /* remove all entries */
Arnd Bergmann62632032006-10-04 17:26:15 +0200174 spufs_prune_dir(dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100175
Arnd Bergmann62632032006-10-04 17:26:15 +0200176 return simple_rmdir(parent, dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100177}
178
179static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files,
180 int mode, struct spu_context *ctx)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500181{
182 struct dentry *dentry;
183 int ret;
184
185 while (files->name && files->name[0]) {
186 ret = -ENOMEM;
187 dentry = d_alloc_name(dir, files->name);
188 if (!dentry)
189 goto out;
190 ret = spufs_new_file(dir->d_sb, dentry, files->ops,
191 files->mode & mode, ctx);
192 if (ret)
193 goto out;
194 files++;
195 }
196 return 0;
197out:
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100198 spufs_prune_dir(dir);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500199 return ret;
200}
201
Arnd Bergmann67207b92005-11-15 15:53:48 -0500202static int spufs_dir_close(struct inode *inode, struct file *file)
203{
Michael Ellerman0309f022006-06-19 20:33:22 +0200204 struct spu_context *ctx;
Arnd Bergmann62632032006-10-04 17:26:15 +0200205 struct inode *parent;
206 struct dentry *dir;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500207 int ret;
208
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800209 dir = file->f_path.dentry;
Arnd Bergmann62632032006-10-04 17:26:15 +0200210 parent = dir->d_parent->d_inode;
211 ctx = SPUFS_I(dir->d_inode)->i_ctx;
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100212
Arnd Bergmann62632032006-10-04 17:26:15 +0200213 mutex_lock(&parent->i_mutex);
214 ret = spufs_rmdir(parent, dir);
215 mutex_unlock(&parent->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500216 WARN_ON(ret);
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100217
Michael Ellerman0309f022006-06-19 20:33:22 +0200218 /* We have to give up the mm_struct */
219 spu_forget(ctx);
220
Arnd Bergmann67207b92005-11-15 15:53:48 -0500221 return dcache_dir_close(inode, file);
222}
223
Arjan van de Ven754661f2007-02-12 00:55:38 -0800224const struct inode_operations spufs_dir_inode_operations = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500225 .lookup = simple_lookup,
226};
227
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800228const struct file_operations spufs_context_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500229 .open = dcache_dir_open,
230 .release = spufs_dir_close,
231 .llseek = dcache_dir_lseek,
232 .read = generic_read_dir,
233 .readdir = dcache_readdir,
234 .fsync = simple_sync_file,
235};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100236EXPORT_SYMBOL_GPL(spufs_context_fops);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500237
238static int
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200239spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
240 int mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500241{
242 int ret;
243 struct inode *inode;
244 struct spu_context *ctx;
245
246 ret = -ENOSPC;
247 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
248 if (!inode)
249 goto out;
250
251 if (dir->i_mode & S_ISGID) {
252 inode->i_gid = dir->i_gid;
253 inode->i_mode &= S_ISGID;
254 }
Arnd Bergmann62632032006-10-04 17:26:15 +0200255 ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500256 SPUFS_I(inode)->i_ctx = ctx;
257 if (!ctx)
258 goto out_iput;
259
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200260 ctx->flags = flags;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500261 inode->i_op = &spufs_dir_inode_operations;
262 inode->i_fop = &simple_dir_operations;
Mark Nutter5737edd2006-10-24 18:31:16 +0200263 if (flags & SPU_CREATE_NOSCHED)
264 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
265 mode, ctx);
266 else
267 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
268
Arnd Bergmann67207b92005-11-15 15:53:48 -0500269 if (ret)
270 goto out_free_ctx;
271
272 d_instantiate(dentry, inode);
273 dget(dentry);
274 dir->i_nlink++;
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100275 dentry->d_inode->i_nlink++;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500276 goto out;
277
278out_free_ctx:
279 put_spu_context(ctx);
280out_iput:
281 iput(inode);
282out:
283 return ret;
284}
285
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100286static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
287{
288 int ret;
289 struct file *filp;
290
291 ret = get_unused_fd();
292 if (ret < 0) {
293 dput(dentry);
294 mntput(mnt);
295 goto out;
296 }
297
298 filp = dentry_open(dentry, mnt, O_RDONLY);
299 if (IS_ERR(filp)) {
300 put_unused_fd(ret);
301 ret = PTR_ERR(filp);
302 goto out;
303 }
304
305 filp->f_op = &spufs_context_fops;
306 fd_install(ret, filp);
307out:
308 return ret;
309}
310
Arnd Bergmann62632032006-10-04 17:26:15 +0200311static int spufs_create_context(struct inode *inode,
312 struct dentry *dentry,
313 struct vfsmount *mnt, int flags, int mode)
314{
315 int ret;
316
Mark Nutter5737edd2006-10-24 18:31:16 +0200317 ret = -EPERM;
318 if ((flags & SPU_CREATE_NOSCHED) &&
319 !capable(CAP_SYS_NICE))
320 goto out_unlock;
321
322 ret = -EINVAL;
323 if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
324 == SPU_CREATE_ISOLATE)
325 goto out_unlock;
326
Jeremy Kerrbd2e5f82006-11-27 19:18:52 +0100327 ret = -ENODEV;
328 if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
329 goto out_unlock;
330
Arnd Bergmann62632032006-10-04 17:26:15 +0200331 ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
332 if (ret)
333 goto out_unlock;
334
335 /*
336 * get references for dget and mntget, will be released
337 * in error path of *_open().
338 */
339 ret = spufs_context_open(dget(dentry), mntget(mnt));
340 if (ret < 0) {
341 WARN_ON(spufs_rmdir(inode, dentry));
342 mutex_unlock(&inode->i_mutex);
343 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
344 goto out;
345 }
346
347out_unlock:
348 mutex_unlock(&inode->i_mutex);
349out:
350 dput(dentry);
351 return ret;
352}
353
354static int spufs_rmgang(struct inode *root, struct dentry *dir)
355{
356 /* FIXME: this fails if the dir is not empty,
357 which causes a leak of gangs. */
358 return simple_rmdir(root, dir);
359}
360
361static int spufs_gang_close(struct inode *inode, struct file *file)
362{
363 struct inode *parent;
364 struct dentry *dir;
365 int ret;
366
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800367 dir = file->f_path.dentry;
Arnd Bergmann62632032006-10-04 17:26:15 +0200368 parent = dir->d_parent->d_inode;
369
370 ret = spufs_rmgang(parent, dir);
371 WARN_ON(ret);
372
373 return dcache_dir_close(inode, file);
374}
375
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800376const struct file_operations spufs_gang_fops = {
Arnd Bergmann62632032006-10-04 17:26:15 +0200377 .open = dcache_dir_open,
378 .release = spufs_gang_close,
379 .llseek = dcache_dir_lseek,
380 .read = generic_read_dir,
381 .readdir = dcache_readdir,
382 .fsync = simple_sync_file,
383};
384
385static int
386spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
387{
388 int ret;
389 struct inode *inode;
390 struct spu_gang *gang;
391
392 ret = -ENOSPC;
393 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
394 if (!inode)
395 goto out;
396
397 ret = 0;
398 if (dir->i_mode & S_ISGID) {
399 inode->i_gid = dir->i_gid;
400 inode->i_mode &= S_ISGID;
401 }
402 gang = alloc_spu_gang();
403 SPUFS_I(inode)->i_ctx = NULL;
404 SPUFS_I(inode)->i_gang = gang;
405 if (!gang)
406 goto out_iput;
407
408 inode->i_op = &spufs_dir_inode_operations;
409 inode->i_fop = &simple_dir_operations;
410
411 d_instantiate(dentry, inode);
412 dget(dentry);
413 dir->i_nlink++;
414 dentry->d_inode->i_nlink++;
415 return ret;
416
417out_iput:
418 iput(inode);
419out:
420 return ret;
421}
422
423static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
424{
425 int ret;
426 struct file *filp;
427
428 ret = get_unused_fd();
429 if (ret < 0) {
430 dput(dentry);
431 mntput(mnt);
432 goto out;
433 }
434
435 filp = dentry_open(dentry, mnt, O_RDONLY);
436 if (IS_ERR(filp)) {
437 put_unused_fd(ret);
438 ret = PTR_ERR(filp);
439 goto out;
440 }
441
442 filp->f_op = &spufs_gang_fops;
443 fd_install(ret, filp);
444out:
445 return ret;
446}
447
448static int spufs_create_gang(struct inode *inode,
449 struct dentry *dentry,
450 struct vfsmount *mnt, int mode)
451{
452 int ret;
453
454 ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
455 if (ret)
456 goto out;
457
458 /*
459 * get references for dget and mntget, will be released
460 * in error path of *_open().
461 */
462 ret = spufs_gang_open(dget(dentry), mntget(mnt));
463 if (ret < 0)
464 WARN_ON(spufs_rmgang(inode, dentry));
465
466out:
467 mutex_unlock(&inode->i_mutex);
468 dput(dentry);
469 return ret;
470}
471
472
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100473static struct file_system_type spufs_type;
474
Arnd Bergmann62632032006-10-04 17:26:15 +0200475long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500476{
477 struct dentry *dentry;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500478 int ret;
479
Arnd Bergmann67207b92005-11-15 15:53:48 -0500480 ret = -EINVAL;
Arnd Bergmann62632032006-10-04 17:26:15 +0200481 /* check if we are on spufs */
482 if (nd->dentry->d_sb->s_type != &spufs_type)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500483 goto out;
484
Arnd Bergmann62632032006-10-04 17:26:15 +0200485 /* don't accept undefined flags */
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200486 if (flags & (~SPU_CREATE_FLAG_ALL))
arnd@arndb.dec9832942006-06-19 20:33:34 +0200487 goto out;
488
Arnd Bergmann62632032006-10-04 17:26:15 +0200489 /* only threads can be underneath a gang */
490 if (nd->dentry != nd->dentry->d_sb->s_root) {
491 if ((flags & SPU_CREATE_GANG) ||
492 !SPUFS_I(nd->dentry->d_inode)->i_gang)
493 goto out;
494 }
495
Arnd Bergmann67207b92005-11-15 15:53:48 -0500496 dentry = lookup_create(nd, 1);
497 ret = PTR_ERR(dentry);
498 if (IS_ERR(dentry))
499 goto out_dir;
500
501 ret = -EEXIST;
502 if (dentry->d_inode)
503 goto out_dput;
504
505 mode &= ~current->fs->umask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500506
Arnd Bergmann62632032006-10-04 17:26:15 +0200507 if (flags & SPU_CREATE_GANG)
508 return spufs_create_gang(nd->dentry->d_inode,
509 dentry, nd->mnt, mode);
510 else
511 return spufs_create_context(nd->dentry->d_inode,
512 dentry, nd->mnt, flags, mode);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500513
514out_dput:
515 dput(dentry);
516out_dir:
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800517 mutex_unlock(&nd->dentry->d_inode->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500518out:
519 return ret;
520}
521
522/* File system initialization */
523enum {
524 Opt_uid, Opt_gid, Opt_err,
525};
526
527static match_table_t spufs_tokens = {
528 { Opt_uid, "uid=%d" },
529 { Opt_gid, "gid=%d" },
530 { Opt_err, NULL },
531};
532
533static int
534spufs_parse_options(char *options, struct inode *root)
535{
536 char *p;
537 substring_t args[MAX_OPT_ARGS];
538
539 while ((p = strsep(&options, ",")) != NULL) {
540 int token, option;
541
542 if (!*p)
543 continue;
544
545 token = match_token(p, spufs_tokens, args);
546 switch (token) {
547 case Opt_uid:
548 if (match_int(&args[0], &option))
549 return 0;
550 root->i_uid = option;
551 break;
552 case Opt_gid:
553 if (match_int(&args[0], &option))
554 return 0;
555 root->i_gid = option;
556 break;
557 default:
558 return 0;
559 }
560 }
561 return 1;
562}
563
Akinobu Mitadb1384b2007-04-23 21:08:20 +0200564static void spufs_exit_isolated_loader(void)
565{
566 kfree(isolated_loader);
567}
568
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200569static void
570spufs_init_isolated_loader(void)
571{
572 struct device_node *dn;
573 const char *loader;
574 int size;
575
576 dn = of_find_node_by_path("/spu-isolation");
577 if (!dn)
578 return;
579
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000580 loader = of_get_property(dn, "loader", &size);
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200581 if (!loader)
582 return;
583
584 /* kmalloc should align on a 16 byte boundary..* */
585 isolated_loader = kmalloc(size, GFP_KERNEL);
586 if (!isolated_loader)
587 return;
588
589 memcpy(isolated_loader, loader, size);
590 printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
591}
592
Arnd Bergmann67207b92005-11-15 15:53:48 -0500593static int
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500594spufs_create_root(struct super_block *sb, void *data)
595{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500596 struct inode *inode;
597 int ret;
598
599 ret = -ENOMEM;
600 inode = spufs_new_inode(sb, S_IFDIR | 0775);
601 if (!inode)
602 goto out;
603
604 inode->i_op = &spufs_dir_inode_operations;
605 inode->i_fop = &simple_dir_operations;
606 SPUFS_I(inode)->i_ctx = NULL;
607
608 ret = -EINVAL;
609 if (!spufs_parse_options(data, inode))
610 goto out_iput;
611
612 ret = -ENOMEM;
613 sb->s_root = d_alloc_root(inode);
614 if (!sb->s_root)
615 goto out_iput;
616
617 return 0;
618out_iput:
619 iput(inode);
620out:
621 return ret;
622}
623
624static int
625spufs_fill_super(struct super_block *sb, void *data, int silent)
626{
627 static struct super_operations s_ops = {
628 .alloc_inode = spufs_alloc_inode,
629 .destroy_inode = spufs_destroy_inode,
630 .statfs = simple_statfs,
631 .delete_inode = spufs_delete_inode,
632 .drop_inode = generic_delete_inode,
633 };
634
635 sb->s_maxbytes = MAX_LFS_FILESIZE;
636 sb->s_blocksize = PAGE_CACHE_SIZE;
637 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
638 sb->s_magic = SPUFS_MAGIC;
639 sb->s_op = &s_ops;
640
641 return spufs_create_root(sb, data);
642}
643
David Howells454e2392006-06-23 02:02:57 -0700644static int
Arnd Bergmann67207b92005-11-15 15:53:48 -0500645spufs_get_sb(struct file_system_type *fstype, int flags,
David Howells454e2392006-06-23 02:02:57 -0700646 const char *name, void *data, struct vfsmount *mnt)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500647{
David Howells454e2392006-06-23 02:02:57 -0700648 return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500649}
650
651static struct file_system_type spufs_type = {
652 .owner = THIS_MODULE,
653 .name = "spufs",
654 .get_sb = spufs_get_sb,
655 .kill_sb = kill_litter_super,
656};
657
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200658static int __init spufs_init(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500659{
660 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100661
Arnd Bergmann67207b92005-11-15 15:53:48 -0500662 ret = -ENOMEM;
663 spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
664 sizeof(struct spufs_inode_info), 0,
665 SLAB_HWCACHE_ALIGN, spufs_init_once, NULL);
666
667 if (!spufs_inode_cache)
668 goto out;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200669 ret = spu_sched_init();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500670 if (ret)
671 goto out_cache;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200672 ret = register_filesystem(&spufs_type);
673 if (ret)
674 goto out_sched;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500675 ret = register_spu_syscalls(&spufs_calls);
676 if (ret)
677 goto out_fs;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100678 ret = register_arch_coredump_calls(&spufs_coredump_calls);
679 if (ret)
Akinobu Mitac99c1992007-04-23 21:08:19 +0200680 goto out_syscalls;
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200681
682 spufs_init_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100683
Arnd Bergmann67207b92005-11-15 15:53:48 -0500684 return 0;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200685
686out_syscalls:
687 unregister_spu_syscalls(&spufs_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500688out_fs:
689 unregister_filesystem(&spufs_type);
Akinobu Mitac99c1992007-04-23 21:08:19 +0200690out_sched:
691 spu_sched_exit();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500692out_cache:
693 kmem_cache_destroy(spufs_inode_cache);
694out:
695 return ret;
696}
697module_init(spufs_init);
698
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200699static void __exit spufs_exit(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500700{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500701 spu_sched_exit();
Akinobu Mitadb1384b2007-04-23 21:08:20 +0200702 spufs_exit_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100703 unregister_arch_coredump_calls(&spufs_coredump_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500704 unregister_spu_syscalls(&spufs_calls);
705 unregister_filesystem(&spufs_type);
706 kmem_cache_destroy(spufs_inode_cache);
707}
708module_exit(spufs_exit);
709
710MODULE_LICENSE("GPL");
711MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
712