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