xref: /linux/arch/powerpc/platforms/cell/spufs/inode.c (revision 4413e16d9d21673bb5048a2e542f1aaa00015c2e)
1 
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>
26 #include <linux/fsnotify.h>
27 #include <linux/backing-dev.h>
28 #include <linux/init.h>
29 #include <linux/ioctl.h>
30 #include <linux/module.h>
31 #include <linux/mount.h>
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 
38 #include <asm/prom.h>
39 #include <asm/spu.h>
40 #include <asm/spu_priv1.h>
41 #include <asm/uaccess.h>
42 
43 #include "spufs.h"
44 
45 struct spufs_sb_info {
46 	int debug;
47 };
48 
49 static struct kmem_cache *spufs_inode_cache;
50 char *isolated_loader;
51 static int isolated_loader_size;
52 
53 static struct spufs_sb_info *spufs_get_sb_info(struct super_block *sb)
54 {
55 	return sb->s_fs_info;
56 }
57 
58 static struct inode *
59 spufs_alloc_inode(struct super_block *sb)
60 {
61 	struct spufs_inode_info *ei;
62 
63 	ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
64 	if (!ei)
65 		return NULL;
66 
67 	ei->i_gang = NULL;
68 	ei->i_ctx = NULL;
69 	ei->i_openers = 0;
70 
71 	return &ei->vfs_inode;
72 }
73 
74 static void spufs_i_callback(struct rcu_head *head)
75 {
76 	struct inode *inode = container_of(head, struct inode, i_rcu);
77 	kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
78 }
79 
80 static void spufs_destroy_inode(struct inode *inode)
81 {
82 	call_rcu(&inode->i_rcu, spufs_i_callback);
83 }
84 
85 static void
86 spufs_init_once(void *p)
87 {
88 	struct spufs_inode_info *ei = p;
89 
90 	inode_init_once(&ei->vfs_inode);
91 }
92 
93 static struct inode *
94 spufs_new_inode(struct super_block *sb, umode_t mode)
95 {
96 	struct inode *inode;
97 
98 	inode = new_inode(sb);
99 	if (!inode)
100 		goto out;
101 
102 	inode->i_mode = mode;
103 	inode->i_uid = current_fsuid();
104 	inode->i_gid = current_fsgid();
105 	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
106 out:
107 	return inode;
108 }
109 
110 static int
111 spufs_setattr(struct dentry *dentry, struct iattr *attr)
112 {
113 	struct inode *inode = dentry->d_inode;
114 
115 	if ((attr->ia_valid & ATTR_SIZE) &&
116 	    (attr->ia_size != inode->i_size))
117 		return -EINVAL;
118 	setattr_copy(inode, attr);
119 	mark_inode_dirty(inode);
120 	return 0;
121 }
122 
123 
124 static int
125 spufs_new_file(struct super_block *sb, struct dentry *dentry,
126 		const struct file_operations *fops, umode_t mode,
127 		size_t size, struct spu_context *ctx)
128 {
129 	static const struct inode_operations spufs_file_iops = {
130 		.setattr = spufs_setattr,
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;
143 	inode->i_size = size;
144 	inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
145 	d_add(dentry, inode);
146 out:
147 	return ret;
148 }
149 
150 static void
151 spufs_evict_inode(struct inode *inode)
152 {
153 	struct spufs_inode_info *ei = SPUFS_I(inode);
154 	clear_inode(inode);
155 	if (ei->i_ctx)
156 		put_spu_context(ei->i_ctx);
157 	if (ei->i_gang)
158 		put_spu_gang(ei->i_gang);
159 }
160 
161 static void spufs_prune_dir(struct dentry *dir)
162 {
163 	struct dentry *dentry, *tmp;
164 
165 	mutex_lock(&dir->d_inode->i_mutex);
166 	list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
167 		spin_lock(&dentry->d_lock);
168 		if (!(d_unhashed(dentry)) && dentry->d_inode) {
169 			dget_dlock(dentry);
170 			__d_drop(dentry);
171 			spin_unlock(&dentry->d_lock);
172 			simple_unlink(dir->d_inode, dentry);
173 			/* XXX: what was dcache_lock protecting here? Other
174 			 * filesystems (IB, configfs) release dcache_lock
175 			 * before unlink */
176 			dput(dentry);
177 		} else {
178 			spin_unlock(&dentry->d_lock);
179 		}
180 	}
181 	shrink_dcache_parent(dir);
182 	mutex_unlock(&dir->d_inode->i_mutex);
183 }
184 
185 /* Caller must hold parent->i_mutex */
186 static int spufs_rmdir(struct inode *parent, struct dentry *dir)
187 {
188 	/* remove all entries */
189 	int res;
190 	spufs_prune_dir(dir);
191 	d_drop(dir);
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;
196 }
197 
198 static int spufs_fill_dir(struct dentry *dir,
199 		const struct spufs_tree_descr *files, umode_t mode,
200 		struct spu_context *ctx)
201 {
202 	struct dentry *dentry, *tmp;
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,
211 					files->mode & mode, files->size, ctx);
212 		if (ret)
213 			goto out;
214 		files++;
215 	}
216 	return 0;
217 out:
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);
232 	return ret;
233 }
234 
235 static int spufs_dir_close(struct inode *inode, struct file *file)
236 {
237 	struct spu_context *ctx;
238 	struct inode *parent;
239 	struct dentry *dir;
240 	int ret;
241 
242 	dir = file->f_path.dentry;
243 	parent = dir->d_parent->d_inode;
244 	ctx = SPUFS_I(dir->d_inode)->i_ctx;
245 
246 	mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT);
247 	ret = spufs_rmdir(parent, dir);
248 	mutex_unlock(&parent->i_mutex);
249 	WARN_ON(ret);
250 
251 	return dcache_dir_close(inode, file);
252 }
253 
254 const struct file_operations spufs_context_fops = {
255 	.open		= dcache_dir_open,
256 	.release	= spufs_dir_close,
257 	.llseek		= dcache_dir_lseek,
258 	.read		= generic_read_dir,
259 	.readdir	= dcache_readdir,
260 	.fsync		= noop_fsync,
261 };
262 EXPORT_SYMBOL_GPL(spufs_context_fops);
263 
264 static int
265 spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
266 		umode_t mode)
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 	}
281 	ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
282 	SPUFS_I(inode)->i_ctx = ctx;
283 	if (!ctx)
284 		goto out_iput;
285 
286 	ctx->flags = flags;
287 	inode->i_op = &simple_dir_inode_operations;
288 	inode->i_fop = &simple_dir_operations;
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 
295 	if (ret)
296 		goto out_free_ctx;
297 
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 
305 	d_instantiate(dentry, inode);
306 	dget(dentry);
307 	inc_nlink(dir);
308 	inc_nlink(dentry->d_inode);
309 	goto out;
310 
311 out_free_ctx:
312 	spu_forget(ctx);
313 	put_spu_context(ctx);
314 out_iput:
315 	iput(inode);
316 out:
317 	return ret;
318 }
319 
320 static int spufs_context_open(struct path *path)
321 {
322 	int ret;
323 	struct file *filp;
324 
325 	ret = get_unused_fd();
326 	if (ret < 0)
327 		return ret;
328 
329 	filp = dentry_open(path, O_RDONLY, current_cred());
330 	if (IS_ERR(filp)) {
331 		put_unused_fd(ret);
332 		return PTR_ERR(filp);
333 	}
334 
335 	filp->f_op = &spufs_context_fops;
336 	fd_install(ret, filp);
337 	return ret;
338 }
339 
340 static struct spu_context *
341 spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
342 						struct file *filp)
343 {
344 	struct spu_context *tmp, *neighbor, *err;
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,
376 		    aff_list)->aff_head) {
377 			err = ERR_PTR(-EEXIST);
378 			goto out_put_neighbor;
379 		}
380 
381 		if (gang != neighbor->gang) {
382 			err = ERR_PTR(-EINVAL);
383 			goto out_put_neighbor;
384 		}
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 
398 		if (node == MAX_NUMNODES) {
399 			err = ERR_PTR(-EEXIST);
400 			goto out_put_neighbor;
401 		}
402 	}
403 
404 	return neighbor;
405 
406 out_put_neighbor:
407 	put_spu_context(neighbor);
408 	return err;
409 }
410 
411 static void
412 spufs_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 
442 static int
443 spufs_create_context(struct inode *inode, struct dentry *dentry,
444 			struct vfsmount *mnt, int flags, umode_t mode,
445 			struct file *aff_filp)
446 {
447 	int ret;
448 	int affinity;
449 	struct spu_gang *gang;
450 	struct spu_context *neighbor;
451 	struct path path = {.mnt = mnt, .dentry = dentry};
452 
453 	if ((flags & SPU_CREATE_NOSCHED) &&
454 	    !capable(CAP_SYS_NICE))
455 		return -EPERM;
456 
457 	if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
458 	    == SPU_CREATE_ISOLATE)
459 		return -EINVAL;
460 
461 	if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
462 		return -ENODEV;
463 
464 	gang = NULL;
465 	neighbor = NULL;
466 	affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
467 	if (affinity) {
468 		gang = SPUFS_I(inode)->i_gang;
469 		if (!gang)
470 			return -EINVAL;
471 		mutex_lock(&gang->aff_mutex);
472 		neighbor = spufs_assert_affinity(flags, gang, aff_filp);
473 		if (IS_ERR(neighbor)) {
474 			ret = PTR_ERR(neighbor);
475 			goto out_aff_unlock;
476 		}
477 	}
478 
479 	ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
480 	if (ret)
481 		goto out_aff_unlock;
482 
483 	if (affinity) {
484 		spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
485 								neighbor);
486 		if (neighbor)
487 			put_spu_context(neighbor);
488 	}
489 
490 	ret = spufs_context_open(&path);
491 	if (ret < 0)
492 		WARN_ON(spufs_rmdir(inode, dentry));
493 
494 out_aff_unlock:
495 	if (affinity)
496 		mutex_unlock(&gang->aff_mutex);
497 	return ret;
498 }
499 
500 static int
501 spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
502 {
503 	int ret;
504 	struct inode *inode;
505 	struct spu_gang *gang;
506 
507 	ret = -ENOSPC;
508 	inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
509 	if (!inode)
510 		goto out;
511 
512 	ret = 0;
513 	if (dir->i_mode & S_ISGID) {
514 		inode->i_gid = dir->i_gid;
515 		inode->i_mode &= S_ISGID;
516 	}
517 	gang = alloc_spu_gang();
518 	SPUFS_I(inode)->i_ctx = NULL;
519 	SPUFS_I(inode)->i_gang = gang;
520 	if (!gang)
521 		goto out_iput;
522 
523 	inode->i_op = &simple_dir_inode_operations;
524 	inode->i_fop = &simple_dir_operations;
525 
526 	d_instantiate(dentry, inode);
527 	inc_nlink(dir);
528 	inc_nlink(dentry->d_inode);
529 	return ret;
530 
531 out_iput:
532 	iput(inode);
533 out:
534 	return ret;
535 }
536 
537 static int spufs_gang_open(struct path *path)
538 {
539 	int ret;
540 	struct file *filp;
541 
542 	ret = get_unused_fd();
543 	if (ret < 0)
544 		return ret;
545 
546 	/*
547 	 * get references for dget and mntget, will be released
548 	 * in error path of *_open().
549 	 */
550 	filp = dentry_open(path, O_RDONLY, current_cred());
551 	if (IS_ERR(filp)) {
552 		put_unused_fd(ret);
553 		return PTR_ERR(filp);
554 	}
555 
556 	filp->f_op = &simple_dir_operations;
557 	fd_install(ret, filp);
558 	return ret;
559 }
560 
561 static int spufs_create_gang(struct inode *inode,
562 			struct dentry *dentry,
563 			struct vfsmount *mnt, umode_t mode)
564 {
565 	struct path path = {.mnt = mnt, .dentry = dentry};
566 	int ret;
567 
568 	ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
569 	if (!ret) {
570 		ret = spufs_gang_open(&path);
571 		if (ret < 0) {
572 			int err = simple_rmdir(inode, dentry);
573 			WARN_ON(err);
574 		}
575 	}
576 	return ret;
577 }
578 
579 
580 static struct file_system_type spufs_type;
581 
582 long spufs_create(struct path *path, struct dentry *dentry,
583 		unsigned int flags, umode_t mode, struct file *filp)
584 {
585 	struct inode *dir = path->dentry->d_inode;
586 	int ret;
587 
588 	/* check if we are on spufs */
589 	if (path->dentry->d_sb->s_type != &spufs_type)
590 		return -EINVAL;
591 
592 	/* don't accept undefined flags */
593 	if (flags & (~SPU_CREATE_FLAG_ALL))
594 		return -EINVAL;
595 
596 	/* only threads can be underneath a gang */
597 	if (path->dentry != path->dentry->d_sb->s_root)
598 		if ((flags & SPU_CREATE_GANG) || !SPUFS_I(dir)->i_gang)
599 			return -EINVAL;
600 
601 	mode &= ~current_umask();
602 
603 	if (flags & SPU_CREATE_GANG)
604 		ret = spufs_create_gang(dir, dentry, path->mnt, mode);
605 	else
606 		ret = spufs_create_context(dir, dentry, path->mnt, flags, mode,
607 					    filp);
608 	if (ret >= 0)
609 		fsnotify_mkdir(dir, dentry);
610 
611 	return ret;
612 }
613 
614 /* File system initialization */
615 enum {
616 	Opt_uid, Opt_gid, Opt_mode, Opt_debug, Opt_err,
617 };
618 
619 static const match_table_t spufs_tokens = {
620 	{ Opt_uid,   "uid=%d" },
621 	{ Opt_gid,   "gid=%d" },
622 	{ Opt_mode,  "mode=%o" },
623 	{ Opt_debug, "debug" },
624 	{ Opt_err,    NULL  },
625 };
626 
627 static int
628 spufs_parse_options(struct super_block *sb, char *options, struct inode *root)
629 {
630 	char *p;
631 	substring_t args[MAX_OPT_ARGS];
632 
633 	while ((p = strsep(&options, ",")) != NULL) {
634 		int token, option;
635 
636 		if (!*p)
637 			continue;
638 
639 		token = match_token(p, spufs_tokens, args);
640 		switch (token) {
641 		case Opt_uid:
642 			if (match_int(&args[0], &option))
643 				return 0;
644 			root->i_uid = option;
645 			break;
646 		case Opt_gid:
647 			if (match_int(&args[0], &option))
648 				return 0;
649 			root->i_gid = option;
650 			break;
651 		case Opt_mode:
652 			if (match_octal(&args[0], &option))
653 				return 0;
654 			root->i_mode = option | S_IFDIR;
655 			break;
656 		case Opt_debug:
657 			spufs_get_sb_info(sb)->debug = 1;
658 			break;
659 		default:
660 			return 0;
661 		}
662 	}
663 	return 1;
664 }
665 
666 static void spufs_exit_isolated_loader(void)
667 {
668 	free_pages((unsigned long) isolated_loader,
669 			get_order(isolated_loader_size));
670 }
671 
672 static void
673 spufs_init_isolated_loader(void)
674 {
675 	struct device_node *dn;
676 	const char *loader;
677 	int size;
678 
679 	dn = of_find_node_by_path("/spu-isolation");
680 	if (!dn)
681 		return;
682 
683 	loader = of_get_property(dn, "loader", &size);
684 	if (!loader)
685 		return;
686 
687 	/* the loader must be align on a 16 byte boundary */
688 	isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size));
689 	if (!isolated_loader)
690 		return;
691 
692 	isolated_loader_size = size;
693 	memcpy(isolated_loader, loader, size);
694 	printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
695 }
696 
697 static int
698 spufs_create_root(struct super_block *sb, void *data)
699 {
700 	struct inode *inode;
701 	int ret;
702 
703 	ret = -ENODEV;
704 	if (!spu_management_ops)
705 		goto out;
706 
707 	ret = -ENOMEM;
708 	inode = spufs_new_inode(sb, S_IFDIR | 0775);
709 	if (!inode)
710 		goto out;
711 
712 	inode->i_op = &simple_dir_inode_operations;
713 	inode->i_fop = &simple_dir_operations;
714 	SPUFS_I(inode)->i_ctx = NULL;
715 	inc_nlink(inode);
716 
717 	ret = -EINVAL;
718 	if (!spufs_parse_options(sb, data, inode))
719 		goto out_iput;
720 
721 	ret = -ENOMEM;
722 	sb->s_root = d_make_root(inode);
723 	if (!sb->s_root)
724 		goto out;
725 
726 	return 0;
727 out_iput:
728 	iput(inode);
729 out:
730 	return ret;
731 }
732 
733 static int
734 spufs_fill_super(struct super_block *sb, void *data, int silent)
735 {
736 	struct spufs_sb_info *info;
737 	static const struct super_operations s_ops = {
738 		.alloc_inode = spufs_alloc_inode,
739 		.destroy_inode = spufs_destroy_inode,
740 		.statfs = simple_statfs,
741 		.evict_inode = spufs_evict_inode,
742 		.show_options = generic_show_options,
743 	};
744 
745 	save_mount_options(sb, data);
746 
747 	info = kzalloc(sizeof(*info), GFP_KERNEL);
748 	if (!info)
749 		return -ENOMEM;
750 
751 	sb->s_maxbytes = MAX_LFS_FILESIZE;
752 	sb->s_blocksize = PAGE_CACHE_SIZE;
753 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
754 	sb->s_magic = SPUFS_MAGIC;
755 	sb->s_op = &s_ops;
756 	sb->s_fs_info = info;
757 
758 	return spufs_create_root(sb, data);
759 }
760 
761 static struct dentry *
762 spufs_mount(struct file_system_type *fstype, int flags,
763 		const char *name, void *data)
764 {
765 	return mount_single(fstype, flags, data, spufs_fill_super);
766 }
767 
768 static struct file_system_type spufs_type = {
769 	.owner = THIS_MODULE,
770 	.name = "spufs",
771 	.mount = spufs_mount,
772 	.kill_sb = kill_litter_super,
773 };
774 
775 static int __init spufs_init(void)
776 {
777 	int ret;
778 
779 	ret = -ENODEV;
780 	if (!spu_management_ops)
781 		goto out;
782 
783 	ret = -ENOMEM;
784 	spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
785 			sizeof(struct spufs_inode_info), 0,
786 			SLAB_HWCACHE_ALIGN, spufs_init_once);
787 
788 	if (!spufs_inode_cache)
789 		goto out;
790 	ret = spu_sched_init();
791 	if (ret)
792 		goto out_cache;
793 	ret = register_spu_syscalls(&spufs_calls);
794 	if (ret)
795 		goto out_sched;
796 	ret = register_filesystem(&spufs_type);
797 	if (ret)
798 		goto out_syscalls;
799 
800 	spufs_init_isolated_loader();
801 
802 	return 0;
803 
804 out_syscalls:
805 	unregister_spu_syscalls(&spufs_calls);
806 out_sched:
807 	spu_sched_exit();
808 out_cache:
809 	kmem_cache_destroy(spufs_inode_cache);
810 out:
811 	return ret;
812 }
813 module_init(spufs_init);
814 
815 static void __exit spufs_exit(void)
816 {
817 	spu_sched_exit();
818 	spufs_exit_isolated_loader();
819 	unregister_spu_syscalls(&spufs_calls);
820 	unregister_filesystem(&spufs_type);
821 	kmem_cache_destroy(spufs_inode_cache);
822 }
823 module_exit(spufs_exit);
824 
825 MODULE_LICENSE("GPL");
826 MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
827 
828