blob: 7150730e2ff11b9896039bd46a05ef83c8d26931 [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{
180 struct dentry *dentry;
181 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:
Arnd Bergmann3f51dd92006-01-04 20:31:27 +0100196 spufs_prune_dir(dir);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500197 return ret;
198}
199
Arnd Bergmann67207b92005-11-15 15:53:48 -0500200static int spufs_dir_close(struct inode *inode, struct file *file)
201{
Michael Ellerman0309f022006-06-19 20:33:22 +0200202 struct spu_context *ctx;
Arnd Bergmann62632032006-10-04 17:26:15 +0200203 struct inode *parent;
204 struct dentry *dir;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500205 int ret;
206
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800207 dir = file->f_path.dentry;
Arnd Bergmann62632032006-10-04 17:26:15 +0200208 parent = dir->d_parent->d_inode;
209 ctx = SPUFS_I(dir->d_inode)->i_ctx;
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100210
Arnd Bergmann62632032006-10-04 17:26:15 +0200211 mutex_lock(&parent->i_mutex);
212 ret = spufs_rmdir(parent, dir);
213 mutex_unlock(&parent->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500214 WARN_ON(ret);
Arnd Bergmannc8ca0632006-01-04 20:31:22 +0100215
Michael Ellerman0309f022006-06-19 20:33:22 +0200216 /* We have to give up the mm_struct */
217 spu_forget(ctx);
218
Arnd Bergmann67207b92005-11-15 15:53:48 -0500219 return dcache_dir_close(inode, file);
220}
221
Arjan van de Ven754661f2007-02-12 00:55:38 -0800222const struct inode_operations spufs_dir_inode_operations = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500223 .lookup = simple_lookup,
224};
225
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800226const struct file_operations spufs_context_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500227 .open = dcache_dir_open,
228 .release = spufs_dir_close,
229 .llseek = dcache_dir_lseek,
230 .read = generic_read_dir,
231 .readdir = dcache_readdir,
232 .fsync = simple_sync_file,
233};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100234EXPORT_SYMBOL_GPL(spufs_context_fops);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500235
236static int
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200237spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
238 int mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500239{
240 int ret;
241 struct inode *inode;
242 struct spu_context *ctx;
243
244 ret = -ENOSPC;
245 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
246 if (!inode)
247 goto out;
248
249 if (dir->i_mode & S_ISGID) {
250 inode->i_gid = dir->i_gid;
251 inode->i_mode &= S_ISGID;
252 }
Arnd Bergmann62632032006-10-04 17:26:15 +0200253 ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500254 SPUFS_I(inode)->i_ctx = ctx;
255 if (!ctx)
256 goto out_iput;
257
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200258 ctx->flags = flags;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500259 inode->i_op = &spufs_dir_inode_operations;
260 inode->i_fop = &simple_dir_operations;
Mark Nutter5737edd2006-10-24 18:31:16 +0200261 if (flags & SPU_CREATE_NOSCHED)
262 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
263 mode, ctx);
264 else
265 ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
266
Arnd Bergmann67207b92005-11-15 15:53:48 -0500267 if (ret)
268 goto out_free_ctx;
269
270 d_instantiate(dentry, inode);
271 dget(dentry);
272 dir->i_nlink++;
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100273 dentry->d_inode->i_nlink++;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500274 goto out;
275
276out_free_ctx:
277 put_spu_context(ctx);
278out_iput:
279 iput(inode);
280out:
281 return ret;
282}
283
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100284static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
285{
286 int ret;
287 struct file *filp;
288
289 ret = get_unused_fd();
290 if (ret < 0) {
291 dput(dentry);
292 mntput(mnt);
293 goto out;
294 }
295
296 filp = dentry_open(dentry, mnt, O_RDONLY);
297 if (IS_ERR(filp)) {
298 put_unused_fd(ret);
299 ret = PTR_ERR(filp);
300 goto out;
301 }
302
303 filp->f_op = &spufs_context_fops;
304 fd_install(ret, filp);
305out:
306 return ret;
307}
308
Arnd Bergmann62632032006-10-04 17:26:15 +0200309static int spufs_create_context(struct inode *inode,
310 struct dentry *dentry,
311 struct vfsmount *mnt, int flags, int mode)
312{
313 int ret;
314
Mark Nutter5737edd2006-10-24 18:31:16 +0200315 ret = -EPERM;
316 if ((flags & SPU_CREATE_NOSCHED) &&
317 !capable(CAP_SYS_NICE))
318 goto out_unlock;
319
320 ret = -EINVAL;
321 if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
322 == SPU_CREATE_ISOLATE)
323 goto out_unlock;
324
Jeremy Kerrbd2e5f82006-11-27 19:18:52 +0100325 ret = -ENODEV;
326 if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
327 goto out_unlock;
328
Arnd Bergmann62632032006-10-04 17:26:15 +0200329 ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
330 if (ret)
331 goto out_unlock;
332
333 /*
334 * get references for dget and mntget, will be released
335 * in error path of *_open().
336 */
337 ret = spufs_context_open(dget(dentry), mntget(mnt));
338 if (ret < 0) {
339 WARN_ON(spufs_rmdir(inode, dentry));
340 mutex_unlock(&inode->i_mutex);
341 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
342 goto out;
343 }
344
345out_unlock:
346 mutex_unlock(&inode->i_mutex);
347out:
348 dput(dentry);
349 return ret;
350}
351
352static int spufs_rmgang(struct inode *root, struct dentry *dir)
353{
354 /* FIXME: this fails if the dir is not empty,
355 which causes a leak of gangs. */
356 return simple_rmdir(root, dir);
357}
358
359static int spufs_gang_close(struct inode *inode, struct file *file)
360{
361 struct inode *parent;
362 struct dentry *dir;
363 int ret;
364
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800365 dir = file->f_path.dentry;
Arnd Bergmann62632032006-10-04 17:26:15 +0200366 parent = dir->d_parent->d_inode;
367
368 ret = spufs_rmgang(parent, dir);
369 WARN_ON(ret);
370
371 return dcache_dir_close(inode, file);
372}
373
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800374const struct file_operations spufs_gang_fops = {
Arnd Bergmann62632032006-10-04 17:26:15 +0200375 .open = dcache_dir_open,
376 .release = spufs_gang_close,
377 .llseek = dcache_dir_lseek,
378 .read = generic_read_dir,
379 .readdir = dcache_readdir,
380 .fsync = simple_sync_file,
381};
382
383static int
384spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
385{
386 int ret;
387 struct inode *inode;
388 struct spu_gang *gang;
389
390 ret = -ENOSPC;
391 inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
392 if (!inode)
393 goto out;
394
395 ret = 0;
396 if (dir->i_mode & S_ISGID) {
397 inode->i_gid = dir->i_gid;
398 inode->i_mode &= S_ISGID;
399 }
400 gang = alloc_spu_gang();
401 SPUFS_I(inode)->i_ctx = NULL;
402 SPUFS_I(inode)->i_gang = gang;
403 if (!gang)
404 goto out_iput;
405
406 inode->i_op = &spufs_dir_inode_operations;
407 inode->i_fop = &simple_dir_operations;
408
409 d_instantiate(dentry, inode);
410 dget(dentry);
411 dir->i_nlink++;
412 dentry->d_inode->i_nlink++;
413 return ret;
414
415out_iput:
416 iput(inode);
417out:
418 return ret;
419}
420
421static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
422{
423 int ret;
424 struct file *filp;
425
426 ret = get_unused_fd();
427 if (ret < 0) {
428 dput(dentry);
429 mntput(mnt);
430 goto out;
431 }
432
433 filp = dentry_open(dentry, mnt, O_RDONLY);
434 if (IS_ERR(filp)) {
435 put_unused_fd(ret);
436 ret = PTR_ERR(filp);
437 goto out;
438 }
439
440 filp->f_op = &spufs_gang_fops;
441 fd_install(ret, filp);
442out:
443 return ret;
444}
445
446static int spufs_create_gang(struct inode *inode,
447 struct dentry *dentry,
448 struct vfsmount *mnt, int mode)
449{
450 int ret;
451
452 ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
453 if (ret)
454 goto out;
455
456 /*
457 * get references for dget and mntget, will be released
458 * in error path of *_open().
459 */
460 ret = spufs_gang_open(dget(dentry), mntget(mnt));
461 if (ret < 0)
462 WARN_ON(spufs_rmgang(inode, dentry));
463
464out:
465 mutex_unlock(&inode->i_mutex);
466 dput(dentry);
467 return ret;
468}
469
470
Arnd Bergmann346f4d32006-01-04 20:31:26 +0100471static struct file_system_type spufs_type;
472
Arnd Bergmann62632032006-10-04 17:26:15 +0200473long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500474{
475 struct dentry *dentry;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500476 int ret;
477
Arnd Bergmann67207b92005-11-15 15:53:48 -0500478 ret = -EINVAL;
Arnd Bergmann62632032006-10-04 17:26:15 +0200479 /* check if we are on spufs */
480 if (nd->dentry->d_sb->s_type != &spufs_type)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500481 goto out;
482
Arnd Bergmann62632032006-10-04 17:26:15 +0200483 /* don't accept undefined flags */
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200484 if (flags & (~SPU_CREATE_FLAG_ALL))
arnd@arndb.dec9832942006-06-19 20:33:34 +0200485 goto out;
486
Arnd Bergmann62632032006-10-04 17:26:15 +0200487 /* only threads can be underneath a gang */
488 if (nd->dentry != nd->dentry->d_sb->s_root) {
489 if ((flags & SPU_CREATE_GANG) ||
490 !SPUFS_I(nd->dentry->d_inode)->i_gang)
491 goto out;
492 }
493
Arnd Bergmann67207b92005-11-15 15:53:48 -0500494 dentry = lookup_create(nd, 1);
495 ret = PTR_ERR(dentry);
496 if (IS_ERR(dentry))
497 goto out_dir;
498
499 ret = -EEXIST;
500 if (dentry->d_inode)
501 goto out_dput;
502
503 mode &= ~current->fs->umask;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500504
Arnd Bergmann62632032006-10-04 17:26:15 +0200505 if (flags & SPU_CREATE_GANG)
506 return spufs_create_gang(nd->dentry->d_inode,
507 dentry, nd->mnt, mode);
508 else
509 return spufs_create_context(nd->dentry->d_inode,
510 dentry, nd->mnt, flags, mode);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500511
512out_dput:
513 dput(dentry);
514out_dir:
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800515 mutex_unlock(&nd->dentry->d_inode->i_mutex);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500516out:
517 return ret;
518}
519
520/* File system initialization */
521enum {
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200522 Opt_uid, Opt_gid, Opt_mode, Opt_err,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500523};
524
525static match_table_t spufs_tokens = {
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200526 { Opt_uid, "uid=%d" },
527 { Opt_gid, "gid=%d" },
528 { Opt_mode, "mode=%o" },
529 { Opt_err, NULL },
Arnd Bergmann67207b92005-11-15 15:53:48 -0500530};
531
532static int
533spufs_parse_options(char *options, struct inode *root)
534{
535 char *p;
536 substring_t args[MAX_OPT_ARGS];
537
538 while ((p = strsep(&options, ",")) != NULL) {
539 int token, option;
540
541 if (!*p)
542 continue;
543
544 token = match_token(p, spufs_tokens, args);
545 switch (token) {
546 case Opt_uid:
547 if (match_int(&args[0], &option))
548 return 0;
549 root->i_uid = option;
550 break;
551 case Opt_gid:
552 if (match_int(&args[0], &option))
553 return 0;
554 root->i_gid = option;
555 break;
Jeremy Kerrf11f5ee2007-04-23 21:08:23 +0200556 case Opt_mode:
557 if (match_octal(&args[0], &option))
558 return 0;
559 root->i_mode = option | S_IFDIR;
560 break;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500561 default:
562 return 0;
563 }
564 }
565 return 1;
566}
567
Akinobu Mitadb1384b402007-04-23 21:08:20 +0200568static void spufs_exit_isolated_loader(void)
569{
570 kfree(isolated_loader);
571}
572
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200573static void
574spufs_init_isolated_loader(void)
575{
576 struct device_node *dn;
577 const char *loader;
578 int size;
579
580 dn = of_find_node_by_path("/spu-isolation");
581 if (!dn)
582 return;
583
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000584 loader = of_get_property(dn, "loader", &size);
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200585 if (!loader)
586 return;
587
588 /* kmalloc should align on a 16 byte boundary..* */
589 isolated_loader = kmalloc(size, GFP_KERNEL);
590 if (!isolated_loader)
591 return;
592
593 memcpy(isolated_loader, loader, size);
594 printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
595}
596
Arnd Bergmann67207b92005-11-15 15:53:48 -0500597static int
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500598spufs_create_root(struct super_block *sb, void *data)
599{
Arnd Bergmann67207b92005-11-15 15:53:48 -0500600 struct inode *inode;
601 int ret;
602
603 ret = -ENOMEM;
604 inode = spufs_new_inode(sb, S_IFDIR | 0775);
605 if (!inode)
606 goto out;
607
608 inode->i_op = &spufs_dir_inode_operations;
609 inode->i_fop = &simple_dir_operations;
610 SPUFS_I(inode)->i_ctx = NULL;
611
612 ret = -EINVAL;
613 if (!spufs_parse_options(data, inode))
614 goto out_iput;
615
616 ret = -ENOMEM;
617 sb->s_root = d_alloc_root(inode);
618 if (!sb->s_root)
619 goto out_iput;
620
621 return 0;
622out_iput:
623 iput(inode);
624out:
625 return ret;
626}
627
628static int
629spufs_fill_super(struct super_block *sb, void *data, int silent)
630{
631 static struct super_operations s_ops = {
632 .alloc_inode = spufs_alloc_inode,
633 .destroy_inode = spufs_destroy_inode,
634 .statfs = simple_statfs,
635 .delete_inode = spufs_delete_inode,
636 .drop_inode = generic_delete_inode,
637 };
638
639 sb->s_maxbytes = MAX_LFS_FILESIZE;
640 sb->s_blocksize = PAGE_CACHE_SIZE;
641 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
642 sb->s_magic = SPUFS_MAGIC;
643 sb->s_op = &s_ops;
644
645 return spufs_create_root(sb, data);
646}
647
David Howells454e2392006-06-23 02:02:57 -0700648static int
Arnd Bergmann67207b92005-11-15 15:53:48 -0500649spufs_get_sb(struct file_system_type *fstype, int flags,
David Howells454e2392006-06-23 02:02:57 -0700650 const char *name, void *data, struct vfsmount *mnt)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500651{
David Howells454e2392006-06-23 02:02:57 -0700652 return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500653}
654
655static struct file_system_type spufs_type = {
656 .owner = THIS_MODULE,
657 .name = "spufs",
658 .get_sb = spufs_get_sb,
659 .kill_sb = kill_litter_super,
660};
661
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200662static int __init spufs_init(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500663{
664 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100665
Jeremy Kerrccf17e92007-04-23 21:08:29 +0200666 ret = -ENODEV;
667 if (!spu_management_ops)
668 goto out;
669
Arnd Bergmann67207b92005-11-15 15:53:48 -0500670 ret = -ENOMEM;
671 spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
672 sizeof(struct spufs_inode_info), 0,
673 SLAB_HWCACHE_ALIGN, spufs_init_once, NULL);
674
675 if (!spufs_inode_cache)
676 goto out;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200677 ret = spu_sched_init();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500678 if (ret)
679 goto out_cache;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200680 ret = register_filesystem(&spufs_type);
681 if (ret)
682 goto out_sched;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500683 ret = register_spu_syscalls(&spufs_calls);
684 if (ret)
685 goto out_fs;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100686 ret = register_arch_coredump_calls(&spufs_coredump_calls);
687 if (ret)
Akinobu Mitac99c1992007-04-23 21:08:19 +0200688 goto out_syscalls;
arnd@arndb.de0afacde2006-10-24 18:31:18 +0200689
690 spufs_init_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100691
Arnd Bergmann67207b92005-11-15 15:53:48 -0500692 return 0;
Akinobu Mitac99c1992007-04-23 21:08:19 +0200693
694out_syscalls:
695 unregister_spu_syscalls(&spufs_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500696out_fs:
697 unregister_filesystem(&spufs_type);
Akinobu Mitac99c1992007-04-23 21:08:19 +0200698out_sched:
699 spu_sched_exit();
Arnd Bergmann67207b92005-11-15 15:53:48 -0500700out_cache:
701 kmem_cache_destroy(spufs_inode_cache);
702out:
703 return ret;
704}
705module_init(spufs_init);
706
Arnd Bergmanne78b47a2006-03-27 21:27:40 +0200707static void __exit spufs_exit(void)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500708{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500709 spu_sched_exit();
Akinobu Mitadb1384b402007-04-23 21:08:20 +0200710 spufs_exit_isolated_loader();
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100711 unregister_arch_coredump_calls(&spufs_coredump_calls);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500712 unregister_spu_syscalls(&spufs_calls);
713 unregister_filesystem(&spufs_type);
714 kmem_cache_destroy(spufs_inode_cache);
715}
716module_exit(spufs_exit);
717
718MODULE_LICENSE("GPL");
719MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
720