blob: f37460e5bfd29b218775e7a8e9f1eb8da7274749 [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>
Jeremy Kerrccf17e92007-04-23 21:08:29 +020039#include <asm/spu_priv1.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050040#include <asm/uaccess.h>
41
42#include "spufs.h"
43
Christoph Lametere18b8902006-12-06 20:33:20 -080044static struct kmem_cache *spufs_inode_cache;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +010045char *isolated_loader;
Arnd Bergmann67207b92005-11-15 15:53:48 -050046
Arnd Bergmann67207b92005-11-15 15:53:48 -050047static struct inode *
48spufs_alloc_inode(struct super_block *sb)
49{
50 struct spufs_inode_info *ei;
51
Christoph Lametere94b1762006-12-06 20:33:17 -080052 ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
Arnd Bergmann67207b92005-11-15 15:53:48 -050053 if (!ei)
54 return NULL;
Arnd Bergmann62632032006-10-04 17:26:15 +020055
56 ei->i_gang = NULL;
57 ei->i_ctx = NULL;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020058 ei->i_openers = 0;
Arnd Bergmann62632032006-10-04 17:26:15 +020059
Arnd Bergmann67207b92005-11-15 15:53:48 -050060 return &ei->vfs_inode;
61}
62
63static void
64spufs_destroy_inode(struct inode *inode)
65{
66 kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
67}
68
69static void
Christoph Lametere18b8902006-12-06 20:33:20 -080070spufs_init_once(void *p, struct kmem_cache * cachep, unsigned long flags)
Arnd Bergmann67207b92005-11-15 15:53:48 -050071{
72 struct spufs_inode_info *ei = p;
73
Christoph Lametera35afb82007-05-16 22:10:57 -070074 inode_init_once(&ei->vfs_inode);
Arnd Bergmann67207b92005-11-15 15:53:48 -050075}
76
77static struct inode *
78spufs_new_inode(struct super_block *sb, int mode)
79{
80 struct inode *inode;
81
82 inode = new_inode(sb);
83 if (!inode)
84 goto out;
85
86 inode->i_mode = mode;
87 inode->i_uid = current->fsuid;
88 inode->i_gid = current->fsgid;
Arnd Bergmann67207b92005-11-15 15:53:48 -050089 inode->i_blocks = 0;
90 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
91out:
92 return inode;
93}
94
95static int
96spufs_setattr(struct dentry *dentry, struct iattr *attr)
97{
98 struct inode *inode = dentry->d_inode;
99
Arnd Bergmann67207b92005-11-15 15:53:48 -0500100 if ((attr->ia_valid & ATTR_SIZE) &&
101 (attr->ia_size != inode->i_size))
102 return -EINVAL;
103 return inode_setattr(inode, attr);
104}
105
106
107static int
108spufs_new_file(struct super_block *sb, struct dentry *dentry,
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800109 const struct file_operations *fops, int mode,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500110 struct spu_context *ctx)
111{
112 static struct inode_operations spufs_file_iops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500113 .setattr = spufs_setattr,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500114 };
115 struct inode *inode;
116 int ret;
117
118 ret = -ENOSPC;
119 inode = spufs_new_inode(sb, S_IFREG | mode);
120 if (!inode)
121 goto out;
122
123 ret = 0;
124 inode->i_op = &spufs_file_iops;
125 inode->i_fop = fops;
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700126 inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500127 d_add(dentry, inode);
128out:
129 return ret;
130}
131
132static void
133spufs_delete_inode(struct inode *inode)
134{
Arnd Bergmann62632032006-10-04 17:26:15 +0200135 struct spufs_inode_info *ei = SPUFS_I(inode);
136
137 if (ei->i_ctx)
138 put_spu_context(ei->i_ctx);
139 if (ei->i_gang)
140 put_spu_gang(ei->i_gang);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500141 clear_inode(inode);
142}
143
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100144static void spufs_prune_dir(struct dentry *dir)
145{
146 struct dentry *dentry, *tmp;
Arnd Bergmann62632032006-10-04 17:26:15 +0200147
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800148 mutex_lock(&dir->d_inode->i_mutex);
Andrew Mortonc3a9aea2006-01-09 20:51:24 -0800149 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100150 spin_lock(&dcache_lock);
151 spin_lock(&dentry->d_lock);
152 if (!(d_unhashed(dentry)) && dentry->d_inode) {
153 dget_locked(dentry);
154 __d_drop(dentry);
155 spin_unlock(&dentry->d_lock);
156 simple_unlink(dir->d_inode, dentry);
157 spin_unlock(&dcache_lock);
158 dput(dentry);
159 } else {
160 spin_unlock(&dentry->d_lock);
161 spin_unlock(&dcache_lock);
162 }
163 }
164 shrink_dcache_parent(dir);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800165 mutex_unlock(&dir->d_inode->i_mutex);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100166}
167
Arnd Bergmann62632032006-10-04 17:26:15 +0200168/* Caller must hold parent->i_mutex */
169static int spufs_rmdir(struct inode *parent, struct dentry *dir)
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100170{
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100171 /* remove all entries */
Arnd Bergmann62632032006-10-04 17:26:15 +0200172 spufs_prune_dir(dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100173
Arnd Bergmann62632032006-10-04 17:26:15 +0200174 return simple_rmdir(parent, dir);
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100175}
176
177static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files,
178 int mode, struct spu_context *ctx)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500179{
Sebastian Siewior87873c82007-06-06 14:03:58 +1000180 struct dentry *dentry, *tmp;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500181 int ret;
182
183 while (files->name && files->name[0]) {
184 ret = -ENOMEM;
185 dentry = d_alloc_name(dir, files->name);
186 if (!dentry)
187 goto out;
188 ret = spufs_new_file(dir->d_sb, dentry, files->ops,
189 files->mode & mode, ctx);
190 if (ret)
191 goto out;
192 files++;
193 }
194 return 0;
195out:
Sebastian Siewior87873c82007-06-06 14:03:58 +1000196 /*
197 * remove all children from dir. dir->inode is not set so don't
198 * just simply use spufs_prune_dir() and panic afterwards :)
199 * dput() looks like it will do the right thing:
200 * - dec parent's ref counter
201 * - remove child from parent's child list
202 * - free child's inode if possible
203 * - free child
204 */
205 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
206 dput(dentry);
207 }
208
209 shrink_dcache_parent(dir);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500210 return ret;
211}
212
Arnd Bergmann67207b92005-11-15 15:53:48 -0500213static int spufs_dir_close(struct inode *inode, struct file *file)
214{
Michael Ellerman0309f022006-06-19 20:33:22 +0200215 struct spu_context *ctx;
Arnd Bergmann62632032006-10-04 17:26:15 +0200216 struct inode *parent;
217 struct dentry *dir;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500218 int ret;
219
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800220 dir = file->f_path.dentry;
Arnd Bergmann62632032006-10-04 17:26:15 +0200221 parent = dir->d_parent->d_inode;
222 ctx = SPUFS_I(dir->d_inode)->i_ctx;
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100223
Arnd Bergmann62632032006-10-04 17:26:15 +0200224 mutex_lock(&parent->i_mutex);
225 ret = spufs_rmdir(parent, dir);
226 mutex_unlock(&parent->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500227 WARN_ON(ret);
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100228
Michael Ellerman0309f022006-06-19 20:33:22 +0200229 /* We have to give up the mm_struct */
230 spu_forget(ctx);
231
Arnd Bergmann67207b92005-11-15 15:53:48 -0500232 return dcache_dir_close(inode, file);
233}
234
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800235const struct file_operations spufs_context_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500236 .open = dcache_dir_open,
237 .release = spufs_dir_close,
238 .llseek = dcache_dir_lseek,
239 .read = generic_read_dir,
240 .readdir = dcache_readdir,
241 .fsync = simple_sync_file,
242};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100243EXPORT_SYMBOL_GPL(spufs_context_fops);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500244
245static int
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200246spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
247 int mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500248{
249 int ret;
250 struct inode *inode;
251 struct spu_context *ctx;
252
253 ret = -ENOSPC;
254 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
255 if (!inode)
256 goto out;
257
258 if (dir->i_mode & S_ISGID) {
259 inode->i_gid = dir->i_gid;
260 inode->i_mode &= S_ISGID;
261 }
Arnd Bergmann62632032006-10-04 17:26:15 +0200262 ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500263 SPUFS_I(inode)->i_ctx = ctx;
264 if (!ctx)
265 goto out_iput;
266
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200267 ctx->flags = flags;
Jeremy Kerrb8c295f2007-06-29 10:57:59 +1000268 inode->i_op = &simple_dir_inode_operations;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500269 inode->i_fop = &simple_dir_operations;
Mark Nutter5737edd2006-10-24 18:31:16 +0200270 if (flags & SPU_CREATE_NOSCHED)
271 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
272 mode, ctx);
273 else
274 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
275
Arnd Bergmann67207b92005-11-15 15:53:48 -0500276 if (ret)
277 goto out_free_ctx;
278
279 d_instantiate(dentry, inode);
280 dget(dentry);
281 dir->i_nlink++;
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100282 dentry->d_inode->i_nlink++;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500283 goto out;
284
285out_free_ctx:
Sebastian Siewior89df0082007-06-04 23:26:51 +1000286 spu_forget(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500287 put_spu_context(ctx);
288out_iput:
289 iput(inode);
290out:
291 return ret;
292}
293
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100294static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
295{
296 int ret;
297 struct file *filp;
298
299 ret = get_unused_fd();
300 if (ret < 0) {
301 dput(dentry);
302 mntput(mnt);
303 goto out;
304 }
305
306 filp = dentry_open(dentry, mnt, O_RDONLY);
307 if (IS_ERR(filp)) {
308 put_unused_fd(ret);
309 ret = PTR_ERR(filp);
310 goto out;
311 }
312
313 filp->f_op = &spufs_context_fops;
314 fd_install(ret, filp);
315out:
316 return ret;
317}
318
Arnd Bergmann62632032006-10-04 17:26:15 +0200319static int spufs_create_context(struct inode *inode,
320 struct dentry *dentry,
321 struct vfsmount *mnt, int flags, int mode)
322{
323 int ret;
324
Mark Nutter5737edd2006-10-24 18:31:16 +0200325 ret = -EPERM;
326 if ((flags & SPU_CREATE_NOSCHED) &&
327 !capable(CAP_SYS_NICE))
328 goto out_unlock;
329
330 ret = -EINVAL;
331 if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
332 == SPU_CREATE_ISOLATE)
333 goto out_unlock;
334
Jeremy Kerrbd2e5f82006-11-27 19:18:52 +0100335 ret = -ENODEV;
336 if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
337 goto out_unlock;
338
Arnd Bergmann62632032006-10-04 17:26:15 +0200339 ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
340 if (ret)
341 goto out_unlock;
342
343 /*
344 * get references for dget and mntget, will be released
345 * in error path of *_open().
346 */
347 ret = spufs_context_open(dget(dentry), mntget(mnt));
348 if (ret < 0) {
349 WARN_ON(spufs_rmdir(inode, dentry));
350 mutex_unlock(&inode->i_mutex);
351 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
352 goto out;
353 }
354
355out_unlock:
356 mutex_unlock(&inode->i_mutex);
357out:
358 dput(dentry);
359 return ret;
360}
361
Arnd Bergmann62632032006-10-04 17:26:15 +0200362static int
363spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
364{
365 int ret;
366 struct inode *inode;
367 struct spu_gang *gang;
368
369 ret = -ENOSPC;
370 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
371 if (!inode)
372 goto out;
373
374 ret = 0;
375 if (dir->i_mode & S_ISGID) {
376 inode->i_gid = dir->i_gid;
377 inode->i_mode &= S_ISGID;
378 }
379 gang = alloc_spu_gang();
380 SPUFS_I(inode)->i_ctx = NULL;
381 SPUFS_I(inode)->i_gang = gang;
382 if (!gang)
383 goto out_iput;
384
Jeremy Kerrb8c295f2007-06-29 10:57:59 +1000385 inode->i_op = &simple_dir_inode_operations;
Arnd Bergmann62632032006-10-04 17:26:15 +0200386 inode->i_fop = &simple_dir_operations;
387
388 d_instantiate(dentry, inode);
Arnd Bergmann62632032006-10-04 17:26:15 +0200389 dir->i_nlink++;
390 dentry->d_inode->i_nlink++;
391 return ret;
392
393out_iput:
394 iput(inode);
395out:
396 return ret;
397}
398
399static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
400{
401 int ret;
402 struct file *filp;
403
404 ret = get_unused_fd();
405 if (ret < 0) {
406 dput(dentry);
407 mntput(mnt);
408 goto out;
409 }
410
411 filp = dentry_open(dentry, mnt, O_RDONLY);
412 if (IS_ERR(filp)) {
413 put_unused_fd(ret);
414 ret = PTR_ERR(filp);
415 goto out;
416 }
417
Jeremy Kerr877907d2007-06-04 23:26:51 +1000418 filp->f_op = &simple_dir_operations;
Arnd Bergmann62632032006-10-04 17:26:15 +0200419 fd_install(ret, filp);
420out:
421 return ret;
422}
423
424static int spufs_create_gang(struct inode *inode,
425 struct dentry *dentry,
426 struct vfsmount *mnt, int mode)
427{
428 int ret;
429
430 ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
431 if (ret)
432 goto out;
433
434 /*
435 * get references for dget and mntget, will be released
436 * in error path of *_open().
437 */
438 ret = spufs_gang_open(dget(dentry), mntget(mnt));
Jeremy Kerr877907d2007-06-04 23:26:51 +1000439 if (ret < 0) {
440 int err = simple_rmdir(inode, dentry);
441 WARN_ON(err);
442 }
Arnd Bergmann62632032006-10-04 17:26:15 +0200443
444out:
445 mutex_unlock(&inode->i_mutex);
446 dput(dentry);
447 return ret;
448}
449
450
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100451static struct file_system_type spufs_type;
452
Arnd Bergmann62632032006-10-04 17:26:15 +0200453long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500454{
455 struct dentry *dentry;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500456 int ret;
457
Arnd Bergmann67207b92005-11-15 15:53:48 -0500458 ret = -EINVAL;
Arnd Bergmann62632032006-10-04 17:26:15 +0200459 /* check if we are on spufs */
460 if (nd->dentry->d_sb->s_type != &spufs_type)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500461 goto out;
462
Arnd Bergmann62632032006-10-04 17:26:15 +0200463 /* don't accept undefined flags */
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200464 if (flags & (~SPU_CREATE_FLAG_ALL))
arnd@arndb.dec9832942006-06-19 20:33:34 +0200465 goto out;
466
Arnd Bergmann62632032006-10-04 17:26:15 +0200467 /* only threads can be underneath a gang */
468 if (nd->dentry != nd->dentry->d_sb->s_root) {
469 if ((flags & SPU_CREATE_GANG) ||
470 !SPUFS_I(nd->dentry->d_inode)->i_gang)
471 goto out;
472 }
473
Arnd Bergmann67207b92005-11-15 15:53:48 -0500474 dentry = lookup_create(nd, 1);
475 ret = PTR_ERR(dentry);
476 if (IS_ERR(dentry))
477 goto out_dir;
478
479 ret = -EEXIST;
480 if (dentry->d_inode)
481 goto out_dput;
482
483 mode &= ~current->fs->umask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500484
Arnd Bergmann62632032006-10-04 17:26:15 +0200485 if (flags & SPU_CREATE_GANG)
486 return spufs_create_gang(nd->dentry->d_inode,
487 dentry, nd->mnt, mode);
488 else
489 return spufs_create_context(nd->dentry->d_inode,
490 dentry, nd->mnt, flags, mode);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500491
492out_dput:
493 dput(dentry);
494out_dir:
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800495 mutex_unlock(&nd->dentry->d_inode->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500496out:
497 return ret;
498}
499
500/* File system initialization */
501enum {
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200502 Opt_uid, Opt_gid, Opt_mode, Opt_err,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500503};
504
505static match_table_t spufs_tokens = {
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200506 { Opt_uid, "uid=%d" },
507 { Opt_gid, "gid=%d" },
508 { Opt_mode, "mode=%o" },
509 { Opt_err, NULL },
Arnd Bergmann67207b92005-11-15 15:53:48 -0500510};
511
512static int
513spufs_parse_options(char *options, struct inode *root)
514{
515 char *p;
516 substring_t args[MAX_OPT_ARGS];
517
518 while ((p = strsep(&options, ",")) != NULL) {
519 int token, option;
520
521 if (!*p)
522 continue;
523
524 token = match_token(p, spufs_tokens, args);
525 switch (token) {
526 case Opt_uid:
527 if (match_int(&args[0], &option))
528 return 0;
529 root->i_uid = option;
530 break;
531 case Opt_gid:
532 if (match_int(&args[0], &option))
533 return 0;
534 root->i_gid = option;
535 break;
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200536 case Opt_mode:
537 if (match_octal(&args[0], &option))
538 return 0;
539 root->i_mode = option | S_IFDIR;
540 break;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500541 default:
542 return 0;
543 }
544 }
545 return 1;
546}
547
Akinobu Mitadb1384b2007-04-23 21:08:20 +0200548static void spufs_exit_isolated_loader(void)
549{
550 kfree(isolated_loader);
551}
552
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200553static void
554spufs_init_isolated_loader(void)
555{
556 struct device_node *dn;
557 const char *loader;
558 int size;
559
560 dn = of_find_node_by_path("/spu-isolation");
561 if (!dn)
562 return;
563
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000564 loader = of_get_property(dn, "loader", &size);
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200565 if (!loader)
566 return;
567
568 /* kmalloc should align on a 16 byte boundary..* */
569 isolated_loader = kmalloc(size, GFP_KERNEL);
570 if (!isolated_loader)
571 return;
572
573 memcpy(isolated_loader, loader, size);
574 printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
575}
576
Arnd Bergmann67207b92005-11-15 15:53:48 -0500577static int
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500578spufs_create_root(struct super_block *sb, void *data)
579{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500580 struct inode *inode;
581 int ret;
582
Arnd Bergmann8f18a152007-06-04 23:26:51 +1000583 ret = -ENODEV;
584 if (!spu_management_ops)
585 goto out;
586
Arnd Bergmann67207b92005-11-15 15:53:48 -0500587 ret = -ENOMEM;
588 inode = spufs_new_inode(sb, S_IFDIR | 0775);
589 if (!inode)
590 goto out;
591
Jeremy Kerrb8c295f2007-06-29 10:57:59 +1000592 inode->i_op = &simple_dir_inode_operations;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500593 inode->i_fop = &simple_dir_operations;
594 SPUFS_I(inode)->i_ctx = NULL;
595
596 ret = -EINVAL;
597 if (!spufs_parse_options(data, inode))
598 goto out_iput;
599
600 ret = -ENOMEM;
601 sb->s_root = d_alloc_root(inode);
602 if (!sb->s_root)
603 goto out_iput;
604
605 return 0;
606out_iput:
607 iput(inode);
608out:
609 return ret;
610}
611
612static int
613spufs_fill_super(struct super_block *sb, void *data, int silent)
614{
615 static struct super_operations s_ops = {
616 .alloc_inode = spufs_alloc_inode,
617 .destroy_inode = spufs_destroy_inode,
618 .statfs = simple_statfs,
619 .delete_inode = spufs_delete_inode,
620 .drop_inode = generic_delete_inode,
621 };
622
623 sb->s_maxbytes = MAX_LFS_FILESIZE;
624 sb->s_blocksize = PAGE_CACHE_SIZE;
625 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
626 sb->s_magic = SPUFS_MAGIC;
627 sb->s_op = &s_ops;
628
629 return spufs_create_root(sb, data);
630}
631
David Howells454e2392006-06-23 02:02:57 -0700632static int
Arnd Bergmann67207b92005-11-15 15:53:48 -0500633spufs_get_sb(struct file_system_type *fstype, int flags,
David Howells454e2392006-06-23 02:02:57 -0700634 const char *name, void *data, struct vfsmount *mnt)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500635{
David Howells454e2392006-06-23 02:02:57 -0700636 return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500637}
638
639static struct file_system_type spufs_type = {
640 .owner = THIS_MODULE,
641 .name = "spufs",
642 .get_sb = spufs_get_sb,
643 .kill_sb = kill_litter_super,
644};
645
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200646static int __init spufs_init(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500647{
648 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100649
Jeremy Kerrccf17e92007-04-23 21:08:29 +0200650 ret = -ENODEV;
651 if (!spu_management_ops)
652 goto out;
653
Arnd Bergmann67207b92005-11-15 15:53:48 -0500654 ret = -ENOMEM;
655 spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
656 sizeof(struct spufs_inode_info), 0,
657 SLAB_HWCACHE_ALIGN, spufs_init_once, NULL);
658
659 if (!spufs_inode_cache)
660 goto out;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200661 ret = spu_sched_init();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500662 if (ret)
663 goto out_cache;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200664 ret = register_filesystem(&spufs_type);
665 if (ret)
666 goto out_sched;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500667 ret = register_spu_syscalls(&spufs_calls);
668 if (ret)
669 goto out_fs;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100670 ret = register_arch_coredump_calls(&spufs_coredump_calls);
671 if (ret)
Akinobu Mitac99c1992007-04-23 21:08:19 +0200672 goto out_syscalls;
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200673
674 spufs_init_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100675
Arnd Bergmann67207b92005-11-15 15:53:48 -0500676 return 0;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200677
678out_syscalls:
679 unregister_spu_syscalls(&spufs_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500680out_fs:
681 unregister_filesystem(&spufs_type);
Akinobu Mitac99c1992007-04-23 21:08:19 +0200682out_sched:
683 spu_sched_exit();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500684out_cache:
685 kmem_cache_destroy(spufs_inode_cache);
686out:
687 return ret;
688}
689module_init(spufs_init);
690
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200691static void __exit spufs_exit(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500692{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500693 spu_sched_exit();
Akinobu Mitadb1384b2007-04-23 21:08:20 +0200694 spufs_exit_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100695 unregister_arch_coredump_calls(&spufs_coredump_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500696 unregister_spu_syscalls(&spufs_calls);
697 unregister_filesystem(&spufs_type);
698 kmem_cache_destroy(spufs_inode_cache);
699}
700module_exit(spufs_exit);
701
702MODULE_LICENSE("GPL");
703MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
704