xref: /linux/arch/powerpc/platforms/cell/spufs/inode.c (revision 6747e83235caecd30b186d1282e4eba7679f81b7)
14ac91378SJan Blunck 
267207b96SArnd Bergmann /*
367207b96SArnd Bergmann  * SPU file system
467207b96SArnd Bergmann  *
567207b96SArnd Bergmann  * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
667207b96SArnd Bergmann  *
767207b96SArnd Bergmann  * Author: Arnd Bergmann <arndb@de.ibm.com>
867207b96SArnd Bergmann  *
967207b96SArnd Bergmann  * This program is free software; you can redistribute it and/or modify
1067207b96SArnd Bergmann  * it under the terms of the GNU General Public License as published by
1167207b96SArnd Bergmann  * the Free Software Foundation; either version 2, or (at your option)
1267207b96SArnd Bergmann  * any later version.
1367207b96SArnd Bergmann  *
1467207b96SArnd Bergmann  * This program is distributed in the hope that it will be useful,
1567207b96SArnd Bergmann  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1667207b96SArnd Bergmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1767207b96SArnd Bergmann  * GNU General Public License for more details.
1867207b96SArnd Bergmann  *
1967207b96SArnd Bergmann  * You should have received a copy of the GNU General Public License
2067207b96SArnd Bergmann  * along with this program; if not, write to the Free Software
2167207b96SArnd Bergmann  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2267207b96SArnd Bergmann  */
2367207b96SArnd Bergmann 
2467207b96SArnd Bergmann #include <linux/file.h>
2567207b96SArnd Bergmann #include <linux/fs.h>
26826be063SChristoph Hellwig #include <linux/fsnotify.h>
2767207b96SArnd Bergmann #include <linux/backing-dev.h>
2867207b96SArnd Bergmann #include <linux/init.h>
2967207b96SArnd Bergmann #include <linux/ioctl.h>
3067207b96SArnd Bergmann #include <linux/module.h>
31346f4d3cSArnd Bergmann #include <linux/mount.h>
3267207b96SArnd Bergmann #include <linux/namei.h>
3367207b96SArnd Bergmann #include <linux/pagemap.h>
3467207b96SArnd Bergmann #include <linux/poll.h>
3567207b96SArnd Bergmann #include <linux/slab.h>
3667207b96SArnd Bergmann #include <linux/parser.h>
3767207b96SArnd Bergmann 
380afacde3Sarnd@arndb.de #include <asm/prom.h>
3967207b96SArnd Bergmann #include <asm/spu.h>
40ccf17e9dSJeremy Kerr #include <asm/spu_priv1.h>
4167207b96SArnd Bergmann #include <asm/uaccess.h>
4267207b96SArnd Bergmann 
4367207b96SArnd Bergmann #include "spufs.h"
4467207b96SArnd Bergmann 
452c3e4787SJeremy Kerr struct spufs_sb_info {
462c3e4787SJeremy Kerr 	int debug;
472c3e4787SJeremy Kerr };
482c3e4787SJeremy Kerr 
49e18b890bSChristoph Lameter static struct kmem_cache *spufs_inode_cache;
50c6730ed4SJeremy Kerr char *isolated_loader;
518b0d3121SSebastian Siewior static int isolated_loader_size;
5267207b96SArnd Bergmann 
532c3e4787SJeremy Kerr static struct spufs_sb_info *spufs_get_sb_info(struct super_block *sb)
542c3e4787SJeremy Kerr {
552c3e4787SJeremy Kerr 	return sb->s_fs_info;
562c3e4787SJeremy Kerr }
572c3e4787SJeremy Kerr 
5867207b96SArnd Bergmann static struct inode *
5967207b96SArnd Bergmann spufs_alloc_inode(struct super_block *sb)
6067207b96SArnd Bergmann {
6167207b96SArnd Bergmann 	struct spufs_inode_info *ei;
6267207b96SArnd Bergmann 
63e94b1766SChristoph Lameter 	ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
6467207b96SArnd Bergmann 	if (!ei)
6567207b96SArnd Bergmann 		return NULL;
666263203eSArnd Bergmann 
676263203eSArnd Bergmann 	ei->i_gang = NULL;
686263203eSArnd Bergmann 	ei->i_ctx = NULL;
6943c2bbd9SChristoph Hellwig 	ei->i_openers = 0;
706263203eSArnd Bergmann 
7167207b96SArnd Bergmann 	return &ei->vfs_inode;
7267207b96SArnd Bergmann }
7367207b96SArnd Bergmann 
74fa0d7e3dSNick Piggin static void spufs_i_callback(struct rcu_head *head)
7567207b96SArnd Bergmann {
76fa0d7e3dSNick Piggin 	struct inode *inode = container_of(head, struct inode, i_rcu);
7767207b96SArnd Bergmann 	kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
7867207b96SArnd Bergmann }
7967207b96SArnd Bergmann 
80fa0d7e3dSNick Piggin static void spufs_destroy_inode(struct inode *inode)
81fa0d7e3dSNick Piggin {
82fa0d7e3dSNick Piggin 	call_rcu(&inode->i_rcu, spufs_i_callback);
83fa0d7e3dSNick Piggin }
84fa0d7e3dSNick Piggin 
8567207b96SArnd Bergmann static void
8651cc5068SAlexey Dobriyan spufs_init_once(void *p)
8767207b96SArnd Bergmann {
8867207b96SArnd Bergmann 	struct spufs_inode_info *ei = p;
8967207b96SArnd Bergmann 
9067207b96SArnd Bergmann 	inode_init_once(&ei->vfs_inode);
9167207b96SArnd Bergmann }
9267207b96SArnd Bergmann 
9367207b96SArnd Bergmann static struct inode *
94c6684b26SAl Viro spufs_new_inode(struct super_block *sb, umode_t mode)
9567207b96SArnd Bergmann {
9667207b96SArnd Bergmann 	struct inode *inode;
9767207b96SArnd Bergmann 
9867207b96SArnd Bergmann 	inode = new_inode(sb);
9967207b96SArnd Bergmann 	if (!inode)
10067207b96SArnd Bergmann 		goto out;
10167207b96SArnd Bergmann 
102*6747e832SMichael Ellerman 	inode->i_ino = get_next_ino();
10367207b96SArnd Bergmann 	inode->i_mode = mode;
1041330deb0SDavid Howells 	inode->i_uid = current_fsuid();
1051330deb0SDavid Howells 	inode->i_gid = current_fsgid();
10667207b96SArnd Bergmann 	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
10767207b96SArnd Bergmann out:
10867207b96SArnd Bergmann 	return inode;
10967207b96SArnd Bergmann }
11067207b96SArnd Bergmann 
11167207b96SArnd Bergmann static int
11267207b96SArnd Bergmann spufs_setattr(struct dentry *dentry, struct iattr *attr)
11367207b96SArnd Bergmann {
11467207b96SArnd Bergmann 	struct inode *inode = dentry->d_inode;
11567207b96SArnd Bergmann 
11667207b96SArnd Bergmann 	if ((attr->ia_valid & ATTR_SIZE) &&
11767207b96SArnd Bergmann 	    (attr->ia_size != inode->i_size))
11867207b96SArnd Bergmann 		return -EINVAL;
1191025774cSChristoph Hellwig 	setattr_copy(inode, attr);
1201025774cSChristoph Hellwig 	mark_inode_dirty(inode);
1211025774cSChristoph Hellwig 	return 0;
12267207b96SArnd Bergmann }
12367207b96SArnd Bergmann 
12467207b96SArnd Bergmann 
12567207b96SArnd Bergmann static int
12667207b96SArnd Bergmann spufs_new_file(struct super_block *sb, struct dentry *dentry,
127c6684b26SAl Viro 		const struct file_operations *fops, umode_t mode,
12823d893f5SJeremy Kerr 		size_t size, struct spu_context *ctx)
12967207b96SArnd Bergmann {
1306e1d5dccSAlexey Dobriyan 	static const struct inode_operations spufs_file_iops = {
13167207b96SArnd Bergmann 		.setattr = spufs_setattr,
13267207b96SArnd Bergmann 	};
13367207b96SArnd Bergmann 	struct inode *inode;
13467207b96SArnd Bergmann 	int ret;
13567207b96SArnd Bergmann 
13667207b96SArnd Bergmann 	ret = -ENOSPC;
13767207b96SArnd Bergmann 	inode = spufs_new_inode(sb, S_IFREG | mode);
13867207b96SArnd Bergmann 	if (!inode)
13967207b96SArnd Bergmann 		goto out;
14067207b96SArnd Bergmann 
14167207b96SArnd Bergmann 	ret = 0;
14267207b96SArnd Bergmann 	inode->i_op = &spufs_file_iops;
14367207b96SArnd Bergmann 	inode->i_fop = fops;
14423d893f5SJeremy Kerr 	inode->i_size = size;
1458e18e294STheodore Ts'o 	inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
14667207b96SArnd Bergmann 	d_add(dentry, inode);
14767207b96SArnd Bergmann out:
14867207b96SArnd Bergmann 	return ret;
14967207b96SArnd Bergmann }
15067207b96SArnd Bergmann 
15167207b96SArnd Bergmann static void
1520f3f63a4SAl Viro spufs_evict_inode(struct inode *inode)
15367207b96SArnd Bergmann {
1546263203eSArnd Bergmann 	struct spufs_inode_info *ei = SPUFS_I(inode);
155dbd5768fSJan Kara 	clear_inode(inode);
1566263203eSArnd Bergmann 	if (ei->i_ctx)
1576263203eSArnd Bergmann 		put_spu_context(ei->i_ctx);
1586263203eSArnd Bergmann 	if (ei->i_gang)
1596263203eSArnd Bergmann 		put_spu_gang(ei->i_gang);
16067207b96SArnd Bergmann }
16167207b96SArnd Bergmann 
1623f51dd91SArnd Bergmann static void spufs_prune_dir(struct dentry *dir)
1633f51dd91SArnd Bergmann {
1643f51dd91SArnd Bergmann 	struct dentry *dentry, *tmp;
1656263203eSArnd Bergmann 
1661b1dcc1bSJes Sorensen 	mutex_lock(&dir->d_inode->i_mutex);
167c3a9aea7SAndrew Morton 	list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
1683f51dd91SArnd Bergmann 		spin_lock(&dentry->d_lock);
1693f51dd91SArnd Bergmann 		if (!(d_unhashed(dentry)) && dentry->d_inode) {
170dc0474beSNick Piggin 			dget_dlock(dentry);
1713f51dd91SArnd Bergmann 			__d_drop(dentry);
1723f51dd91SArnd Bergmann 			spin_unlock(&dentry->d_lock);
1733f51dd91SArnd Bergmann 			simple_unlink(dir->d_inode, dentry);
174b5c84bf6SNick Piggin 			/* XXX: what was dcache_lock protecting here? Other
175da502956SNick Piggin 			 * filesystems (IB, configfs) release dcache_lock
176da502956SNick Piggin 			 * before unlink */
1773f51dd91SArnd Bergmann 			dput(dentry);
1783f51dd91SArnd Bergmann 		} else {
1793f51dd91SArnd Bergmann 			spin_unlock(&dentry->d_lock);
1803f51dd91SArnd Bergmann 		}
1813f51dd91SArnd Bergmann 	}
1823f51dd91SArnd Bergmann 	shrink_dcache_parent(dir);
1831b1dcc1bSJes Sorensen 	mutex_unlock(&dir->d_inode->i_mutex);
1843f51dd91SArnd Bergmann }
1853f51dd91SArnd Bergmann 
1866263203eSArnd Bergmann /* Caller must hold parent->i_mutex */
1876263203eSArnd Bergmann static int spufs_rmdir(struct inode *parent, struct dentry *dir)
1883f51dd91SArnd Bergmann {
1893f51dd91SArnd Bergmann 	/* remove all entries */
19067cba9fdSAl Viro 	int res;
1916263203eSArnd Bergmann 	spufs_prune_dir(dir);
192c443acabSJeremy Kerr 	d_drop(dir);
19367cba9fdSAl Viro 	res = simple_rmdir(parent, dir);
19467cba9fdSAl Viro 	/* We have to give up the mm_struct */
19567cba9fdSAl Viro 	spu_forget(SPUFS_I(dir->d_inode)->i_ctx);
19667cba9fdSAl Viro 	return res;
1973f51dd91SArnd Bergmann }
1983f51dd91SArnd Bergmann 
19974254647SJeremy Kerr static int spufs_fill_dir(struct dentry *dir,
200c6684b26SAl Viro 		const struct spufs_tree_descr *files, umode_t mode,
20174254647SJeremy Kerr 		struct spu_context *ctx)
20267207b96SArnd Bergmann {
20367207b96SArnd Bergmann 	while (files->name && files->name[0]) {
2042248b87eSAl Viro 		int ret;
2052248b87eSAl Viro 		struct dentry *dentry = d_alloc_name(dir, files->name);
20667207b96SArnd Bergmann 		if (!dentry)
2072248b87eSAl Viro 			return -ENOMEM;
20867207b96SArnd Bergmann 		ret = spufs_new_file(dir->d_sb, dentry, files->ops,
20923d893f5SJeremy Kerr 					files->mode & mode, files->size, ctx);
21067207b96SArnd Bergmann 		if (ret)
2112248b87eSAl Viro 			return ret;
21267207b96SArnd Bergmann 		files++;
21367207b96SArnd Bergmann 	}
21467207b96SArnd Bergmann 	return 0;
21567207b96SArnd Bergmann }
21667207b96SArnd Bergmann 
21767207b96SArnd Bergmann static int spufs_dir_close(struct inode *inode, struct file *file)
21867207b96SArnd Bergmann {
2190309f02dSMichael Ellerman 	struct spu_context *ctx;
2206263203eSArnd Bergmann 	struct inode *parent;
2216263203eSArnd Bergmann 	struct dentry *dir;
22267207b96SArnd Bergmann 	int ret;
22367207b96SArnd Bergmann 
224b4d1ab58SJosef Sipek 	dir = file->f_path.dentry;
2256263203eSArnd Bergmann 	parent = dir->d_parent->d_inode;
2266263203eSArnd Bergmann 	ctx = SPUFS_I(dir->d_inode)->i_ctx;
227c8ca0633SArnd Bergmann 
22802539d71SChristoph Hellwig 	mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT);
2296263203eSArnd Bergmann 	ret = spufs_rmdir(parent, dir);
2306263203eSArnd Bergmann 	mutex_unlock(&parent->i_mutex);
23167207b96SArnd Bergmann 	WARN_ON(ret);
232c8ca0633SArnd Bergmann 
23367207b96SArnd Bergmann 	return dcache_dir_close(inode, file);
23467207b96SArnd Bergmann }
23567207b96SArnd Bergmann 
2365dfe4c96SArjan van de Ven const struct file_operations spufs_context_fops = {
23767207b96SArnd Bergmann 	.open		= dcache_dir_open,
23867207b96SArnd Bergmann 	.release	= spufs_dir_close,
23967207b96SArnd Bergmann 	.llseek		= dcache_dir_lseek,
24067207b96SArnd Bergmann 	.read		= generic_read_dir,
24167207b96SArnd Bergmann 	.readdir	= dcache_readdir,
2421b061d92SChristoph Hellwig 	.fsync		= noop_fsync,
24367207b96SArnd Bergmann };
244bf1ab978SDwayne Grant McConnell EXPORT_SYMBOL_GPL(spufs_context_fops);
24567207b96SArnd Bergmann 
24667207b96SArnd Bergmann static int
2479add11daSArnd Bergmann spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
248c6684b26SAl Viro 		umode_t mode)
24967207b96SArnd Bergmann {
25067207b96SArnd Bergmann 	int ret;
25167207b96SArnd Bergmann 	struct inode *inode;
25267207b96SArnd Bergmann 	struct spu_context *ctx;
25367207b96SArnd Bergmann 
25467207b96SArnd Bergmann 	inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
25567207b96SArnd Bergmann 	if (!inode)
2562248b87eSAl Viro 		return -ENOSPC;
25767207b96SArnd Bergmann 
25867207b96SArnd Bergmann 	if (dir->i_mode & S_ISGID) {
25967207b96SArnd Bergmann 		inode->i_gid = dir->i_gid;
26067207b96SArnd Bergmann 		inode->i_mode &= S_ISGID;
26167207b96SArnd Bergmann 	}
2626263203eSArnd Bergmann 	ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
26367207b96SArnd Bergmann 	SPUFS_I(inode)->i_ctx = ctx;
2642248b87eSAl Viro 	if (!ctx) {
2652248b87eSAl Viro 		iput(inode);
2662248b87eSAl Viro 		return -ENOSPC;
2672248b87eSAl Viro 	}
26867207b96SArnd Bergmann 
2699add11daSArnd Bergmann 	ctx->flags = flags;
270b8c295f9SJeremy Kerr 	inode->i_op = &simple_dir_inode_operations;
27167207b96SArnd Bergmann 	inode->i_fop = &simple_dir_operations;
2722248b87eSAl Viro 
2732248b87eSAl Viro 	mutex_lock(&inode->i_mutex);
2742248b87eSAl Viro 
2752248b87eSAl Viro 	dget(dentry);
2762248b87eSAl Viro 	inc_nlink(dir);
2772248b87eSAl Viro 	inc_nlink(inode);
2782248b87eSAl Viro 
2792248b87eSAl Viro 	d_instantiate(dentry, inode);
2802248b87eSAl Viro 
2815737edd1SMark Nutter 	if (flags & SPU_CREATE_NOSCHED)
2825737edd1SMark Nutter 		ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
2835737edd1SMark Nutter 					 mode, ctx);
2845737edd1SMark Nutter 	else
28567207b96SArnd Bergmann 		ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
2865737edd1SMark Nutter 
2872248b87eSAl Viro 	if (!ret && spufs_get_sb_info(dir->i_sb)->debug)
2882c3e4787SJeremy Kerr 		ret = spufs_fill_dir(dentry, spufs_dir_debug_contents,
2892c3e4787SJeremy Kerr 				mode, ctx);
2902c3e4787SJeremy Kerr 
2912c3e4787SJeremy Kerr 	if (ret)
2922248b87eSAl Viro 		spufs_rmdir(dir, dentry);
2932c3e4787SJeremy Kerr 
2942248b87eSAl Viro 	mutex_unlock(&inode->i_mutex);
29567207b96SArnd Bergmann 
29667207b96SArnd Bergmann 	return ret;
29767207b96SArnd Bergmann }
29867207b96SArnd Bergmann 
299765927b2SAl Viro static int spufs_context_open(struct path *path)
300346f4d3cSArnd Bergmann {
301346f4d3cSArnd Bergmann 	int ret;
302346f4d3cSArnd Bergmann 	struct file *filp;
303346f4d3cSArnd Bergmann 
304346f4d3cSArnd Bergmann 	ret = get_unused_fd();
305bf349a44SAl Viro 	if (ret < 0)
306bf349a44SAl Viro 		return ret;
307346f4d3cSArnd Bergmann 
308765927b2SAl Viro 	filp = dentry_open(path, O_RDONLY, current_cred());
309346f4d3cSArnd Bergmann 	if (IS_ERR(filp)) {
310346f4d3cSArnd Bergmann 		put_unused_fd(ret);
311bf349a44SAl Viro 		return PTR_ERR(filp);
312346f4d3cSArnd Bergmann 	}
313346f4d3cSArnd Bergmann 
314346f4d3cSArnd Bergmann 	filp->f_op = &spufs_context_fops;
315346f4d3cSArnd Bergmann 	fd_install(ret, filp);
316346f4d3cSArnd Bergmann 	return ret;
317346f4d3cSArnd Bergmann }
318346f4d3cSArnd Bergmann 
3198e68e2f2SArnd Bergmann static struct spu_context *
3208e68e2f2SArnd Bergmann spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
3218e68e2f2SArnd Bergmann 						struct file *filp)
3228e68e2f2SArnd Bergmann {
32358119068SAndre Detsch 	struct spu_context *tmp, *neighbor, *err;
3248e68e2f2SArnd Bergmann 	int count, node;
3258e68e2f2SArnd Bergmann 	int aff_supp;
3268e68e2f2SArnd Bergmann 
3278e68e2f2SArnd Bergmann 	aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
3288e68e2f2SArnd Bergmann 					struct spu, cbe_list))->aff_list);
3298e68e2f2SArnd Bergmann 
3308e68e2f2SArnd Bergmann 	if (!aff_supp)
3318e68e2f2SArnd Bergmann 		return ERR_PTR(-EINVAL);
3328e68e2f2SArnd Bergmann 
3338e68e2f2SArnd Bergmann 	if (flags & SPU_CREATE_GANG)
3348e68e2f2SArnd Bergmann 		return ERR_PTR(-EINVAL);
3358e68e2f2SArnd Bergmann 
3368e68e2f2SArnd Bergmann 	if (flags & SPU_CREATE_AFFINITY_MEM &&
3378e68e2f2SArnd Bergmann 	    gang->aff_ref_ctx &&
3388e68e2f2SArnd Bergmann 	    gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
3398e68e2f2SArnd Bergmann 		return ERR_PTR(-EEXIST);
3408e68e2f2SArnd Bergmann 
3418e68e2f2SArnd Bergmann 	if (gang->aff_flags & AFF_MERGED)
3428e68e2f2SArnd Bergmann 		return ERR_PTR(-EBUSY);
3438e68e2f2SArnd Bergmann 
3448e68e2f2SArnd Bergmann 	neighbor = NULL;
3458e68e2f2SArnd Bergmann 	if (flags & SPU_CREATE_AFFINITY_SPU) {
3468e68e2f2SArnd Bergmann 		if (!filp || filp->f_op != &spufs_context_fops)
3478e68e2f2SArnd Bergmann 			return ERR_PTR(-EINVAL);
3488e68e2f2SArnd Bergmann 
3498e68e2f2SArnd Bergmann 		neighbor = get_spu_context(
350496ad9aaSAl Viro 				SPUFS_I(file_inode(filp))->i_ctx);
3518e68e2f2SArnd Bergmann 
3528e68e2f2SArnd Bergmann 		if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
3538e68e2f2SArnd Bergmann 		    !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
3548e68e2f2SArnd Bergmann 		    !list_entry(neighbor->aff_list.next, struct spu_context,
35558119068SAndre Detsch 		    aff_list)->aff_head) {
35658119068SAndre Detsch 			err = ERR_PTR(-EEXIST);
35758119068SAndre Detsch 			goto out_put_neighbor;
35858119068SAndre Detsch 		}
3598e68e2f2SArnd Bergmann 
36058119068SAndre Detsch 		if (gang != neighbor->gang) {
36158119068SAndre Detsch 			err = ERR_PTR(-EINVAL);
36258119068SAndre Detsch 			goto out_put_neighbor;
36358119068SAndre Detsch 		}
3648e68e2f2SArnd Bergmann 
3658e68e2f2SArnd Bergmann 		count = 1;
3668e68e2f2SArnd Bergmann 		list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
3678e68e2f2SArnd Bergmann 			count++;
3688e68e2f2SArnd Bergmann 		if (list_empty(&neighbor->aff_list))
3698e68e2f2SArnd Bergmann 			count++;
3708e68e2f2SArnd Bergmann 
3718e68e2f2SArnd Bergmann 		for (node = 0; node < MAX_NUMNODES; node++) {
3728e68e2f2SArnd Bergmann 			if ((cbe_spu_info[node].n_spus - atomic_read(
3738e68e2f2SArnd Bergmann 				&cbe_spu_info[node].reserved_spus)) >= count)
3748e68e2f2SArnd Bergmann 				break;
3758e68e2f2SArnd Bergmann 		}
3768e68e2f2SArnd Bergmann 
37758119068SAndre Detsch 		if (node == MAX_NUMNODES) {
37858119068SAndre Detsch 			err = ERR_PTR(-EEXIST);
37958119068SAndre Detsch 			goto out_put_neighbor;
38058119068SAndre Detsch 		}
3818e68e2f2SArnd Bergmann 	}
3828e68e2f2SArnd Bergmann 
3838e68e2f2SArnd Bergmann 	return neighbor;
38458119068SAndre Detsch 
38558119068SAndre Detsch out_put_neighbor:
38658119068SAndre Detsch 	put_spu_context(neighbor);
38758119068SAndre Detsch 	return err;
3888e68e2f2SArnd Bergmann }
3898e68e2f2SArnd Bergmann 
3908e68e2f2SArnd Bergmann static void
3918e68e2f2SArnd Bergmann spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
3928e68e2f2SArnd Bergmann 					struct spu_context *neighbor)
3938e68e2f2SArnd Bergmann {
3948e68e2f2SArnd Bergmann 	if (flags & SPU_CREATE_AFFINITY_MEM)
3958e68e2f2SArnd Bergmann 		ctx->gang->aff_ref_ctx = ctx;
3968e68e2f2SArnd Bergmann 
3978e68e2f2SArnd Bergmann 	if (flags & SPU_CREATE_AFFINITY_SPU) {
3988e68e2f2SArnd Bergmann 		if (list_empty(&neighbor->aff_list)) {
3998e68e2f2SArnd Bergmann 			list_add_tail(&neighbor->aff_list,
4008e68e2f2SArnd Bergmann 				&ctx->gang->aff_list_head);
4018e68e2f2SArnd Bergmann 			neighbor->aff_head = 1;
4028e68e2f2SArnd Bergmann 		}
4038e68e2f2SArnd Bergmann 
4048e68e2f2SArnd Bergmann 		if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
4058e68e2f2SArnd Bergmann 		    || list_entry(neighbor->aff_list.next, struct spu_context,
4068e68e2f2SArnd Bergmann 							aff_list)->aff_head) {
4078e68e2f2SArnd Bergmann 			list_add(&ctx->aff_list, &neighbor->aff_list);
4088e68e2f2SArnd Bergmann 		} else  {
4098e68e2f2SArnd Bergmann 			list_add_tail(&ctx->aff_list, &neighbor->aff_list);
4108e68e2f2SArnd Bergmann 			if (neighbor->aff_head) {
4118e68e2f2SArnd Bergmann 				neighbor->aff_head = 0;
4128e68e2f2SArnd Bergmann 				ctx->aff_head = 1;
4138e68e2f2SArnd Bergmann 			}
4148e68e2f2SArnd Bergmann 		}
4158e68e2f2SArnd Bergmann 
4168e68e2f2SArnd Bergmann 		if (!ctx->gang->aff_ref_ctx)
4178e68e2f2SArnd Bergmann 			ctx->gang->aff_ref_ctx = ctx;
4188e68e2f2SArnd Bergmann 	}
4198e68e2f2SArnd Bergmann }
4208e68e2f2SArnd Bergmann 
4218e68e2f2SArnd Bergmann static int
4228e68e2f2SArnd Bergmann spufs_create_context(struct inode *inode, struct dentry *dentry,
423c6684b26SAl Viro 			struct vfsmount *mnt, int flags, umode_t mode,
4248e68e2f2SArnd Bergmann 			struct file *aff_filp)
4256263203eSArnd Bergmann {
4266263203eSArnd Bergmann 	int ret;
4278e68e2f2SArnd Bergmann 	int affinity;
4288e68e2f2SArnd Bergmann 	struct spu_gang *gang;
4298e68e2f2SArnd Bergmann 	struct spu_context *neighbor;
430765927b2SAl Viro 	struct path path = {.mnt = mnt, .dentry = dentry};
4316263203eSArnd Bergmann 
4325737edd1SMark Nutter 	if ((flags & SPU_CREATE_NOSCHED) &&
4335737edd1SMark Nutter 	    !capable(CAP_SYS_NICE))
4341ba44cc9SAl Viro 		return -EPERM;
4355737edd1SMark Nutter 
4365737edd1SMark Nutter 	if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
4375737edd1SMark Nutter 	    == SPU_CREATE_ISOLATE)
4381ba44cc9SAl Viro 		return -EINVAL;
4395737edd1SMark Nutter 
440bd2e5f82SJeremy Kerr 	if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
4411ba44cc9SAl Viro 		return -ENODEV;
442bd2e5f82SJeremy Kerr 
4438e68e2f2SArnd Bergmann 	gang = NULL;
4448e68e2f2SArnd Bergmann 	neighbor = NULL;
4458e68e2f2SArnd Bergmann 	affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
4468e68e2f2SArnd Bergmann 	if (affinity) {
4478e68e2f2SArnd Bergmann 		gang = SPUFS_I(inode)->i_gang;
4488e68e2f2SArnd Bergmann 		if (!gang)
4491ba44cc9SAl Viro 			return -EINVAL;
4508e68e2f2SArnd Bergmann 		mutex_lock(&gang->aff_mutex);
4518e68e2f2SArnd Bergmann 		neighbor = spufs_assert_affinity(flags, gang, aff_filp);
4528e68e2f2SArnd Bergmann 		if (IS_ERR(neighbor)) {
4538e68e2f2SArnd Bergmann 			ret = PTR_ERR(neighbor);
4548e68e2f2SArnd Bergmann 			goto out_aff_unlock;
4558e68e2f2SArnd Bergmann 		}
4568e68e2f2SArnd Bergmann 	}
4578e68e2f2SArnd Bergmann 
4586263203eSArnd Bergmann 	ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
4596263203eSArnd Bergmann 	if (ret)
4608e68e2f2SArnd Bergmann 		goto out_aff_unlock;
4618e68e2f2SArnd Bergmann 
46258119068SAndre Detsch 	if (affinity) {
4638e68e2f2SArnd Bergmann 		spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
4648e68e2f2SArnd Bergmann 								neighbor);
46558119068SAndre Detsch 		if (neighbor)
46658119068SAndre Detsch 			put_spu_context(neighbor);
46758119068SAndre Detsch 	}
4686263203eSArnd Bergmann 
469765927b2SAl Viro 	ret = spufs_context_open(&path);
47066ec7b2cSAl Viro 	if (ret < 0)
4716263203eSArnd Bergmann 		WARN_ON(spufs_rmdir(inode, dentry));
4726263203eSArnd Bergmann 
4738e68e2f2SArnd Bergmann out_aff_unlock:
4748e68e2f2SArnd Bergmann 	if (affinity)
4758e68e2f2SArnd Bergmann 		mutex_unlock(&gang->aff_mutex);
4766263203eSArnd Bergmann 	return ret;
4776263203eSArnd Bergmann }
4786263203eSArnd Bergmann 
4796263203eSArnd Bergmann static int
480c6684b26SAl Viro spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
4816263203eSArnd Bergmann {
4826263203eSArnd Bergmann 	int ret;
4836263203eSArnd Bergmann 	struct inode *inode;
4846263203eSArnd Bergmann 	struct spu_gang *gang;
4856263203eSArnd Bergmann 
4866263203eSArnd Bergmann 	ret = -ENOSPC;
4876263203eSArnd Bergmann 	inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
4886263203eSArnd Bergmann 	if (!inode)
4896263203eSArnd Bergmann 		goto out;
4906263203eSArnd Bergmann 
4916263203eSArnd Bergmann 	ret = 0;
4926263203eSArnd Bergmann 	if (dir->i_mode & S_ISGID) {
4936263203eSArnd Bergmann 		inode->i_gid = dir->i_gid;
4946263203eSArnd Bergmann 		inode->i_mode &= S_ISGID;
4956263203eSArnd Bergmann 	}
4966263203eSArnd Bergmann 	gang = alloc_spu_gang();
4976263203eSArnd Bergmann 	SPUFS_I(inode)->i_ctx = NULL;
4986263203eSArnd Bergmann 	SPUFS_I(inode)->i_gang = gang;
4996263203eSArnd Bergmann 	if (!gang)
5006263203eSArnd Bergmann 		goto out_iput;
5016263203eSArnd Bergmann 
502b8c295f9SJeremy Kerr 	inode->i_op = &simple_dir_inode_operations;
5036263203eSArnd Bergmann 	inode->i_fop = &simple_dir_operations;
5046263203eSArnd Bergmann 
5056263203eSArnd Bergmann 	d_instantiate(dentry, inode);
506ba0b996dSJeremy Kerr 	inc_nlink(dir);
507ba0b996dSJeremy Kerr 	inc_nlink(dentry->d_inode);
5086263203eSArnd Bergmann 	return ret;
5096263203eSArnd Bergmann 
5106263203eSArnd Bergmann out_iput:
5116263203eSArnd Bergmann 	iput(inode);
5126263203eSArnd Bergmann out:
5136263203eSArnd Bergmann 	return ret;
5146263203eSArnd Bergmann }
5156263203eSArnd Bergmann 
516765927b2SAl Viro static int spufs_gang_open(struct path *path)
5176263203eSArnd Bergmann {
5186263203eSArnd Bergmann 	int ret;
5196263203eSArnd Bergmann 	struct file *filp;
5206263203eSArnd Bergmann 
5216263203eSArnd Bergmann 	ret = get_unused_fd();
522bf349a44SAl Viro 	if (ret < 0)
523bf349a44SAl Viro 		return ret;
5246263203eSArnd Bergmann 
525bf349a44SAl Viro 	/*
526bf349a44SAl Viro 	 * get references for dget and mntget, will be released
527bf349a44SAl Viro 	 * in error path of *_open().
528bf349a44SAl Viro 	 */
529765927b2SAl Viro 	filp = dentry_open(path, O_RDONLY, current_cred());
5306263203eSArnd Bergmann 	if (IS_ERR(filp)) {
5316263203eSArnd Bergmann 		put_unused_fd(ret);
532bf349a44SAl Viro 		return PTR_ERR(filp);
5336263203eSArnd Bergmann 	}
5346263203eSArnd Bergmann 
535877907d3SJeremy Kerr 	filp->f_op = &simple_dir_operations;
5366263203eSArnd Bergmann 	fd_install(ret, filp);
5376263203eSArnd Bergmann 	return ret;
5386263203eSArnd Bergmann }
5396263203eSArnd Bergmann 
5406263203eSArnd Bergmann static int spufs_create_gang(struct inode *inode,
5416263203eSArnd Bergmann 			struct dentry *dentry,
542c6684b26SAl Viro 			struct vfsmount *mnt, umode_t mode)
5436263203eSArnd Bergmann {
544765927b2SAl Viro 	struct path path = {.mnt = mnt, .dentry = dentry};
5456263203eSArnd Bergmann 	int ret;
5466263203eSArnd Bergmann 
5476263203eSArnd Bergmann 	ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
5481ba44cc9SAl Viro 	if (!ret) {
549765927b2SAl Viro 		ret = spufs_gang_open(&path);
550877907d3SJeremy Kerr 		if (ret < 0) {
551877907d3SJeremy Kerr 			int err = simple_rmdir(inode, dentry);
552877907d3SJeremy Kerr 			WARN_ON(err);
553877907d3SJeremy Kerr 		}
5541ba44cc9SAl Viro 	}
5556263203eSArnd Bergmann 	return ret;
5566263203eSArnd Bergmann }
5576263203eSArnd Bergmann 
5586263203eSArnd Bergmann 
559346f4d3cSArnd Bergmann static struct file_system_type spufs_type;
560346f4d3cSArnd Bergmann 
5611ba10681SAl Viro long spufs_create(struct path *path, struct dentry *dentry,
562c6684b26SAl Viro 		unsigned int flags, umode_t mode, struct file *filp)
56367207b96SArnd Bergmann {
56425b2692aSAl Viro 	struct inode *dir = path->dentry->d_inode;
56567207b96SArnd Bergmann 	int ret;
56667207b96SArnd Bergmann 
5676263203eSArnd Bergmann 	/* check if we are on spufs */
5681ba10681SAl Viro 	if (path->dentry->d_sb->s_type != &spufs_type)
56925b2692aSAl Viro 		return -EINVAL;
57067207b96SArnd Bergmann 
5716263203eSArnd Bergmann 	/* don't accept undefined flags */
5729add11daSArnd Bergmann 	if (flags & (~SPU_CREATE_FLAG_ALL))
57325b2692aSAl Viro 		return -EINVAL;
574c9832948Sarnd@arndb.de 
5756263203eSArnd Bergmann 	/* only threads can be underneath a gang */
57625b2692aSAl Viro 	if (path->dentry != path->dentry->d_sb->s_root)
57725b2692aSAl Viro 		if ((flags & SPU_CREATE_GANG) || !SPUFS_I(dir)->i_gang)
57825b2692aSAl Viro 			return -EINVAL;
5796263203eSArnd Bergmann 
580ce3b0f8dSAl Viro 	mode &= ~current_umask();
58167207b96SArnd Bergmann 
5826263203eSArnd Bergmann 	if (flags & SPU_CREATE_GANG)
58325b2692aSAl Viro 		ret = spufs_create_gang(dir, dentry, path->mnt, mode);
5846263203eSArnd Bergmann 	else
58525b2692aSAl Viro 		ret = spufs_create_context(dir, dentry, path->mnt, flags, mode,
5864ac91378SJan Blunck 					    filp);
587826be063SChristoph Hellwig 	if (ret >= 0)
58825b2692aSAl Viro 		fsnotify_mkdir(dir, dentry);
58967207b96SArnd Bergmann 
59067207b96SArnd Bergmann 	return ret;
59167207b96SArnd Bergmann }
59267207b96SArnd Bergmann 
59367207b96SArnd Bergmann /* File system initialization */
59467207b96SArnd Bergmann enum {
5952c3e4787SJeremy Kerr 	Opt_uid, Opt_gid, Opt_mode, Opt_debug, Opt_err,
59667207b96SArnd Bergmann };
59767207b96SArnd Bergmann 
598a447c093SSteven Whitehouse static const match_table_t spufs_tokens = {
59967207b96SArnd Bergmann 	{ Opt_uid,   "uid=%d" },
60067207b96SArnd Bergmann 	{ Opt_gid,   "gid=%d" },
601f11f5ee7SJeremy Kerr 	{ Opt_mode,  "mode=%o" },
6022c3e4787SJeremy Kerr 	{ Opt_debug, "debug" },
60367207b96SArnd Bergmann 	{ Opt_err,    NULL  },
60467207b96SArnd Bergmann };
60567207b96SArnd Bergmann 
60667207b96SArnd Bergmann static int
6072c3e4787SJeremy Kerr spufs_parse_options(struct super_block *sb, char *options, struct inode *root)
60867207b96SArnd Bergmann {
60967207b96SArnd Bergmann 	char *p;
61067207b96SArnd Bergmann 	substring_t args[MAX_OPT_ARGS];
61167207b96SArnd Bergmann 
61267207b96SArnd Bergmann 	while ((p = strsep(&options, ",")) != NULL) {
61367207b96SArnd Bergmann 		int token, option;
61467207b96SArnd Bergmann 
61567207b96SArnd Bergmann 		if (!*p)
61667207b96SArnd Bergmann 			continue;
61767207b96SArnd Bergmann 
61867207b96SArnd Bergmann 		token = match_token(p, spufs_tokens, args);
61967207b96SArnd Bergmann 		switch (token) {
62067207b96SArnd Bergmann 		case Opt_uid:
62167207b96SArnd Bergmann 			if (match_int(&args[0], &option))
62267207b96SArnd Bergmann 				return 0;
62367207b96SArnd Bergmann 			root->i_uid = option;
62467207b96SArnd Bergmann 			break;
62567207b96SArnd Bergmann 		case Opt_gid:
62667207b96SArnd Bergmann 			if (match_int(&args[0], &option))
62767207b96SArnd Bergmann 				return 0;
62867207b96SArnd Bergmann 			root->i_gid = option;
62967207b96SArnd Bergmann 			break;
630f11f5ee7SJeremy Kerr 		case Opt_mode:
631f11f5ee7SJeremy Kerr 			if (match_octal(&args[0], &option))
632f11f5ee7SJeremy Kerr 				return 0;
633f11f5ee7SJeremy Kerr 			root->i_mode = option | S_IFDIR;
634f11f5ee7SJeremy Kerr 			break;
6352c3e4787SJeremy Kerr 		case Opt_debug:
6362c3e4787SJeremy Kerr 			spufs_get_sb_info(sb)->debug = 1;
6372c3e4787SJeremy Kerr 			break;
63867207b96SArnd Bergmann 		default:
63967207b96SArnd Bergmann 			return 0;
64067207b96SArnd Bergmann 		}
64167207b96SArnd Bergmann 	}
64267207b96SArnd Bergmann 	return 1;
64367207b96SArnd Bergmann }
64467207b96SArnd Bergmann 
645db1384b4SAkinobu Mita static void spufs_exit_isolated_loader(void)
646db1384b4SAkinobu Mita {
6478b0d3121SSebastian Siewior 	free_pages((unsigned long) isolated_loader,
6488b0d3121SSebastian Siewior 			get_order(isolated_loader_size));
649db1384b4SAkinobu Mita }
650db1384b4SAkinobu Mita 
6510afacde3Sarnd@arndb.de static void
6520afacde3Sarnd@arndb.de spufs_init_isolated_loader(void)
6530afacde3Sarnd@arndb.de {
6540afacde3Sarnd@arndb.de 	struct device_node *dn;
6550afacde3Sarnd@arndb.de 	const char *loader;
6560afacde3Sarnd@arndb.de 	int size;
6570afacde3Sarnd@arndb.de 
6580afacde3Sarnd@arndb.de 	dn = of_find_node_by_path("/spu-isolation");
6590afacde3Sarnd@arndb.de 	if (!dn)
6600afacde3Sarnd@arndb.de 		return;
6610afacde3Sarnd@arndb.de 
662e2eb6392SStephen Rothwell 	loader = of_get_property(dn, "loader", &size);
6630afacde3Sarnd@arndb.de 	if (!loader)
6640afacde3Sarnd@arndb.de 		return;
6650afacde3Sarnd@arndb.de 
6668b0d3121SSebastian Siewior 	/* the loader must be align on a 16 byte boundary */
6678b0d3121SSebastian Siewior 	isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size));
6680afacde3Sarnd@arndb.de 	if (!isolated_loader)
6690afacde3Sarnd@arndb.de 		return;
6700afacde3Sarnd@arndb.de 
6718b0d3121SSebastian Siewior 	isolated_loader_size = size;
6720afacde3Sarnd@arndb.de 	memcpy(isolated_loader, loader, size);
6730afacde3Sarnd@arndb.de 	printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
6740afacde3Sarnd@arndb.de }
6750afacde3Sarnd@arndb.de 
67667207b96SArnd Bergmann static int
6778b3d6663SArnd Bergmann spufs_create_root(struct super_block *sb, void *data)
6788b3d6663SArnd Bergmann {
67967207b96SArnd Bergmann 	struct inode *inode;
68067207b96SArnd Bergmann 	int ret;
68167207b96SArnd Bergmann 
6828f18a158SArnd Bergmann 	ret = -ENODEV;
6838f18a158SArnd Bergmann 	if (!spu_management_ops)
6848f18a158SArnd Bergmann 		goto out;
6858f18a158SArnd Bergmann 
68667207b96SArnd Bergmann 	ret = -ENOMEM;
68767207b96SArnd Bergmann 	inode = spufs_new_inode(sb, S_IFDIR | 0775);
68867207b96SArnd Bergmann 	if (!inode)
68967207b96SArnd Bergmann 		goto out;
69067207b96SArnd Bergmann 
691b8c295f9SJeremy Kerr 	inode->i_op = &simple_dir_inode_operations;
69267207b96SArnd Bergmann 	inode->i_fop = &simple_dir_operations;
69367207b96SArnd Bergmann 	SPUFS_I(inode)->i_ctx = NULL;
694e2ed6e4dSJeremy Kerr 	inc_nlink(inode);
69567207b96SArnd Bergmann 
69667207b96SArnd Bergmann 	ret = -EINVAL;
6972c3e4787SJeremy Kerr 	if (!spufs_parse_options(sb, data, inode))
69867207b96SArnd Bergmann 		goto out_iput;
69967207b96SArnd Bergmann 
70067207b96SArnd Bergmann 	ret = -ENOMEM;
70148fde701SAl Viro 	sb->s_root = d_make_root(inode);
70267207b96SArnd Bergmann 	if (!sb->s_root)
70348fde701SAl Viro 		goto out;
70467207b96SArnd Bergmann 
70567207b96SArnd Bergmann 	return 0;
70667207b96SArnd Bergmann out_iput:
70767207b96SArnd Bergmann 	iput(inode);
70867207b96SArnd Bergmann out:
70967207b96SArnd Bergmann 	return ret;
71067207b96SArnd Bergmann }
71167207b96SArnd Bergmann 
71267207b96SArnd Bergmann static int
71367207b96SArnd Bergmann spufs_fill_super(struct super_block *sb, void *data, int silent)
71467207b96SArnd Bergmann {
7152c3e4787SJeremy Kerr 	struct spufs_sb_info *info;
716b87221deSAlexey Dobriyan 	static const struct super_operations s_ops = {
71767207b96SArnd Bergmann 		.alloc_inode = spufs_alloc_inode,
71867207b96SArnd Bergmann 		.destroy_inode = spufs_destroy_inode,
71967207b96SArnd Bergmann 		.statfs = simple_statfs,
7200f3f63a4SAl Viro 		.evict_inode = spufs_evict_inode,
72190d09e14SMiklos Szeredi 		.show_options = generic_show_options,
72267207b96SArnd Bergmann 	};
72367207b96SArnd Bergmann 
72490d09e14SMiklos Szeredi 	save_mount_options(sb, data);
72590d09e14SMiklos Szeredi 
7262c3e4787SJeremy Kerr 	info = kzalloc(sizeof(*info), GFP_KERNEL);
7272c3e4787SJeremy Kerr 	if (!info)
7282c3e4787SJeremy Kerr 		return -ENOMEM;
7292c3e4787SJeremy Kerr 
73067207b96SArnd Bergmann 	sb->s_maxbytes = MAX_LFS_FILESIZE;
73167207b96SArnd Bergmann 	sb->s_blocksize = PAGE_CACHE_SIZE;
73267207b96SArnd Bergmann 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
73367207b96SArnd Bergmann 	sb->s_magic = SPUFS_MAGIC;
73467207b96SArnd Bergmann 	sb->s_op = &s_ops;
7352c3e4787SJeremy Kerr 	sb->s_fs_info = info;
73667207b96SArnd Bergmann 
73767207b96SArnd Bergmann 	return spufs_create_root(sb, data);
73867207b96SArnd Bergmann }
73967207b96SArnd Bergmann 
740fc14f2feSAl Viro static struct dentry *
741fc14f2feSAl Viro spufs_mount(struct file_system_type *fstype, int flags,
742fc14f2feSAl Viro 		const char *name, void *data)
74367207b96SArnd Bergmann {
744fc14f2feSAl Viro 	return mount_single(fstype, flags, data, spufs_fill_super);
74567207b96SArnd Bergmann }
74667207b96SArnd Bergmann 
74767207b96SArnd Bergmann static struct file_system_type spufs_type = {
74867207b96SArnd Bergmann 	.owner = THIS_MODULE,
74967207b96SArnd Bergmann 	.name = "spufs",
750fc14f2feSAl Viro 	.mount = spufs_mount,
75167207b96SArnd Bergmann 	.kill_sb = kill_litter_super,
75267207b96SArnd Bergmann };
7537f78e035SEric W. Biederman MODULE_ALIAS_FS("spufs");
75467207b96SArnd Bergmann 
755e78b47a5SArnd Bergmann static int __init spufs_init(void)
75667207b96SArnd Bergmann {
75767207b96SArnd Bergmann 	int ret;
758bf1ab978SDwayne Grant McConnell 
759ccf17e9dSJeremy Kerr 	ret = -ENODEV;
760ccf17e9dSJeremy Kerr 	if (!spu_management_ops)
761ccf17e9dSJeremy Kerr 		goto out;
762ccf17e9dSJeremy Kerr 
76367207b96SArnd Bergmann 	ret = -ENOMEM;
76467207b96SArnd Bergmann 	spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
76567207b96SArnd Bergmann 			sizeof(struct spufs_inode_info), 0,
76620c2df83SPaul Mundt 			SLAB_HWCACHE_ALIGN, spufs_init_once);
76767207b96SArnd Bergmann 
76867207b96SArnd Bergmann 	if (!spufs_inode_cache)
76967207b96SArnd Bergmann 		goto out;
770c99c1994SAkinobu Mita 	ret = spu_sched_init();
77167207b96SArnd Bergmann 	if (ret)
77267207b96SArnd Bergmann 		goto out_cache;
77367207b96SArnd Bergmann 	ret = register_spu_syscalls(&spufs_calls);
77467207b96SArnd Bergmann 	if (ret)
775640045a1SAl Viro 		goto out_sched;
776640045a1SAl Viro 	ret = register_filesystem(&spufs_type);
777640045a1SAl Viro 	if (ret)
778640045a1SAl Viro 		goto out_syscalls;
7790afacde3Sarnd@arndb.de 
7800afacde3Sarnd@arndb.de 	spufs_init_isolated_loader();
781bf1ab978SDwayne Grant McConnell 
78267207b96SArnd Bergmann 	return 0;
783c99c1994SAkinobu Mita 
784640045a1SAl Viro out_syscalls:
785640045a1SAl Viro 	unregister_spu_syscalls(&spufs_calls);
786c99c1994SAkinobu Mita out_sched:
787c99c1994SAkinobu Mita 	spu_sched_exit();
78867207b96SArnd Bergmann out_cache:
78967207b96SArnd Bergmann 	kmem_cache_destroy(spufs_inode_cache);
79067207b96SArnd Bergmann out:
79167207b96SArnd Bergmann 	return ret;
79267207b96SArnd Bergmann }
79367207b96SArnd Bergmann module_init(spufs_init);
79467207b96SArnd Bergmann 
795e78b47a5SArnd Bergmann static void __exit spufs_exit(void)
79667207b96SArnd Bergmann {
7978b3d6663SArnd Bergmann 	spu_sched_exit();
798db1384b4SAkinobu Mita 	spufs_exit_isolated_loader();
79967207b96SArnd Bergmann 	unregister_spu_syscalls(&spufs_calls);
80067207b96SArnd Bergmann 	unregister_filesystem(&spufs_type);
80167207b96SArnd Bergmann 	kmem_cache_destroy(spufs_inode_cache);
80267207b96SArnd Bergmann }
80367207b96SArnd Bergmann module_exit(spufs_exit);
80467207b96SArnd Bergmann 
80567207b96SArnd Bergmann MODULE_LICENSE("GPL");
80667207b96SArnd Bergmann MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
80767207b96SArnd Bergmann 
808