Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 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/backing-dev.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/ioctl.h> |
| 29 | #include <linux/module.h> |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 30 | #include <linux/mount.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 31 | #include <linux/namei.h> |
| 32 | #include <linux/pagemap.h> |
| 33 | #include <linux/poll.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/parser.h> |
| 36 | |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 37 | #include <asm/prom.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 38 | #include <asm/spu.h> |
Jeremy Kerr | ccf17e9 | 2007-04-23 21:08:29 +0200 | [diff] [blame] | 39 | #include <asm/spu_priv1.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 40 | #include <asm/uaccess.h> |
| 41 | |
| 42 | #include "spufs.h" |
| 43 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 44 | static struct kmem_cache *spufs_inode_cache; |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 45 | char *isolated_loader; |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 46 | static int isolated_loader_size; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 47 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 48 | static struct inode * |
| 49 | spufs_alloc_inode(struct super_block *sb) |
| 50 | { |
| 51 | struct spufs_inode_info *ei; |
| 52 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 53 | ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 54 | if (!ei) |
| 55 | return NULL; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 56 | |
| 57 | ei->i_gang = NULL; |
| 58 | ei->i_ctx = NULL; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 59 | ei->i_openers = 0; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 60 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 61 | return &ei->vfs_inode; |
| 62 | } |
| 63 | |
| 64 | static void |
| 65 | spufs_destroy_inode(struct inode *inode) |
| 66 | { |
| 67 | kmem_cache_free(spufs_inode_cache, SPUFS_I(inode)); |
| 68 | } |
| 69 | |
| 70 | static void |
Christoph Lameter | 4ba9b9d | 2007-10-16 23:25:51 -0700 | [diff] [blame] | 71 | spufs_init_once(struct kmem_cache *cachep, void *p) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 72 | { |
| 73 | struct spufs_inode_info *ei = p; |
| 74 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 75 | inode_init_once(&ei->vfs_inode); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static struct inode * |
| 79 | spufs_new_inode(struct super_block *sb, int mode) |
| 80 | { |
| 81 | struct inode *inode; |
| 82 | |
| 83 | inode = new_inode(sb); |
| 84 | if (!inode) |
| 85 | goto out; |
| 86 | |
| 87 | inode->i_mode = mode; |
| 88 | inode->i_uid = current->fsuid; |
| 89 | inode->i_gid = current->fsgid; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 90 | inode->i_blocks = 0; |
| 91 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 92 | out: |
| 93 | return inode; |
| 94 | } |
| 95 | |
| 96 | static int |
| 97 | spufs_setattr(struct dentry *dentry, struct iattr *attr) |
| 98 | { |
| 99 | struct inode *inode = dentry->d_inode; |
| 100 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 101 | if ((attr->ia_valid & ATTR_SIZE) && |
| 102 | (attr->ia_size != inode->i_size)) |
| 103 | return -EINVAL; |
| 104 | return inode_setattr(inode, attr); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | static int |
| 109 | spufs_new_file(struct super_block *sb, struct dentry *dentry, |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 110 | const struct file_operations *fops, int mode, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 111 | struct spu_context *ctx) |
| 112 | { |
| 113 | static struct inode_operations spufs_file_iops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 114 | .setattr = spufs_setattr, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 115 | }; |
| 116 | struct inode *inode; |
| 117 | int ret; |
| 118 | |
| 119 | ret = -ENOSPC; |
| 120 | inode = spufs_new_inode(sb, S_IFREG | mode); |
| 121 | if (!inode) |
| 122 | goto out; |
| 123 | |
| 124 | ret = 0; |
| 125 | inode->i_op = &spufs_file_iops; |
| 126 | inode->i_fop = fops; |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 127 | inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 128 | d_add(dentry, inode); |
| 129 | out: |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | static void |
| 134 | spufs_delete_inode(struct inode *inode) |
| 135 | { |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 136 | struct spufs_inode_info *ei = SPUFS_I(inode); |
| 137 | |
| 138 | if (ei->i_ctx) |
| 139 | put_spu_context(ei->i_ctx); |
| 140 | if (ei->i_gang) |
| 141 | put_spu_gang(ei->i_gang); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 142 | clear_inode(inode); |
| 143 | } |
| 144 | |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 145 | static void spufs_prune_dir(struct dentry *dir) |
| 146 | { |
| 147 | struct dentry *dentry, *tmp; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 148 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 149 | mutex_lock(&dir->d_inode->i_mutex); |
Andrew Morton | c3a9aea | 2006-01-09 20:51:24 -0800 | [diff] [blame] | 150 | list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) { |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 151 | spin_lock(&dcache_lock); |
| 152 | spin_lock(&dentry->d_lock); |
| 153 | if (!(d_unhashed(dentry)) && dentry->d_inode) { |
| 154 | dget_locked(dentry); |
| 155 | __d_drop(dentry); |
| 156 | spin_unlock(&dentry->d_lock); |
| 157 | simple_unlink(dir->d_inode, dentry); |
| 158 | spin_unlock(&dcache_lock); |
| 159 | dput(dentry); |
| 160 | } else { |
| 161 | spin_unlock(&dentry->d_lock); |
| 162 | spin_unlock(&dcache_lock); |
| 163 | } |
| 164 | } |
| 165 | shrink_dcache_parent(dir); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 166 | mutex_unlock(&dir->d_inode->i_mutex); |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 169 | /* Caller must hold parent->i_mutex */ |
| 170 | static int spufs_rmdir(struct inode *parent, struct dentry *dir) |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 171 | { |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 172 | /* remove all entries */ |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 173 | spufs_prune_dir(dir); |
Jeremy Kerr | c443aca | 2007-11-16 13:32:23 +1100 | [diff] [blame] | 174 | d_drop(dir); |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 175 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 176 | return simple_rmdir(parent, dir); |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files, |
| 180 | int mode, struct spu_context *ctx) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 181 | { |
Sebastian Siewior | 87873c8 | 2007-06-06 14:03:58 +1000 | [diff] [blame] | 182 | struct dentry *dentry, *tmp; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 183 | int ret; |
| 184 | |
| 185 | while (files->name && files->name[0]) { |
| 186 | ret = -ENOMEM; |
| 187 | dentry = d_alloc_name(dir, files->name); |
| 188 | if (!dentry) |
| 189 | goto out; |
| 190 | ret = spufs_new_file(dir->d_sb, dentry, files->ops, |
| 191 | files->mode & mode, ctx); |
| 192 | if (ret) |
| 193 | goto out; |
| 194 | files++; |
| 195 | } |
| 196 | return 0; |
| 197 | out: |
Sebastian Siewior | 87873c8 | 2007-06-06 14:03:58 +1000 | [diff] [blame] | 198 | /* |
| 199 | * remove all children from dir. dir->inode is not set so don't |
| 200 | * just simply use spufs_prune_dir() and panic afterwards :) |
| 201 | * dput() looks like it will do the right thing: |
| 202 | * - dec parent's ref counter |
| 203 | * - remove child from parent's child list |
| 204 | * - free child's inode if possible |
| 205 | * - free child |
| 206 | */ |
| 207 | list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) { |
| 208 | dput(dentry); |
| 209 | } |
| 210 | |
| 211 | shrink_dcache_parent(dir); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 212 | return ret; |
| 213 | } |
| 214 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 215 | static int spufs_dir_close(struct inode *inode, struct file *file) |
| 216 | { |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 217 | struct spu_context *ctx; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 218 | struct inode *parent; |
| 219 | struct dentry *dir; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 220 | int ret; |
| 221 | |
Josef Sipek | b4d1ab5 | 2006-12-08 02:37:30 -0800 | [diff] [blame] | 222 | dir = file->f_path.dentry; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 223 | parent = dir->d_parent->d_inode; |
| 224 | ctx = SPUFS_I(dir->d_inode)->i_ctx; |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 225 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 226 | mutex_lock(&parent->i_mutex); |
| 227 | ret = spufs_rmdir(parent, dir); |
| 228 | mutex_unlock(&parent->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 229 | WARN_ON(ret); |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 230 | |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 231 | /* We have to give up the mm_struct */ |
| 232 | spu_forget(ctx); |
| 233 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 234 | return dcache_dir_close(inode, file); |
| 235 | } |
| 236 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 237 | const struct file_operations spufs_context_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 238 | .open = dcache_dir_open, |
| 239 | .release = spufs_dir_close, |
| 240 | .llseek = dcache_dir_lseek, |
| 241 | .read = generic_read_dir, |
| 242 | .readdir = dcache_readdir, |
| 243 | .fsync = simple_sync_file, |
| 244 | }; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 245 | EXPORT_SYMBOL_GPL(spufs_context_fops); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 246 | |
| 247 | static int |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 248 | spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags, |
| 249 | int mode) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 250 | { |
| 251 | int ret; |
| 252 | struct inode *inode; |
| 253 | struct spu_context *ctx; |
| 254 | |
| 255 | ret = -ENOSPC; |
| 256 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); |
| 257 | if (!inode) |
| 258 | goto out; |
| 259 | |
| 260 | if (dir->i_mode & S_ISGID) { |
| 261 | inode->i_gid = dir->i_gid; |
| 262 | inode->i_mode &= S_ISGID; |
| 263 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 264 | ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 265 | SPUFS_I(inode)->i_ctx = ctx; |
| 266 | if (!ctx) |
| 267 | goto out_iput; |
| 268 | |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 269 | ctx->flags = flags; |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 270 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 271 | inode->i_fop = &simple_dir_operations; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 272 | if (flags & SPU_CREATE_NOSCHED) |
| 273 | ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents, |
| 274 | mode, ctx); |
| 275 | else |
| 276 | ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx); |
| 277 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 278 | if (ret) |
| 279 | goto out_free_ctx; |
| 280 | |
| 281 | d_instantiate(dentry, inode); |
| 282 | dget(dentry); |
| 283 | dir->i_nlink++; |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 284 | dentry->d_inode->i_nlink++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 285 | goto out; |
| 286 | |
| 287 | out_free_ctx: |
Sebastian Siewior | 89df008 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 288 | spu_forget(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 289 | put_spu_context(ctx); |
| 290 | out_iput: |
| 291 | iput(inode); |
| 292 | out: |
| 293 | return ret; |
| 294 | } |
| 295 | |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 296 | static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt) |
| 297 | { |
| 298 | int ret; |
| 299 | struct file *filp; |
| 300 | |
| 301 | ret = get_unused_fd(); |
| 302 | if (ret < 0) { |
| 303 | dput(dentry); |
| 304 | mntput(mnt); |
| 305 | goto out; |
| 306 | } |
| 307 | |
| 308 | filp = dentry_open(dentry, mnt, O_RDONLY); |
| 309 | if (IS_ERR(filp)) { |
| 310 | put_unused_fd(ret); |
| 311 | ret = PTR_ERR(filp); |
| 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | filp->f_op = &spufs_context_fops; |
| 316 | fd_install(ret, filp); |
| 317 | out: |
| 318 | return ret; |
| 319 | } |
| 320 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 321 | static struct spu_context * |
| 322 | spufs_assert_affinity(unsigned int flags, struct spu_gang *gang, |
| 323 | struct file *filp) |
| 324 | { |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 325 | struct spu_context *tmp, *neighbor, *err; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 326 | int count, node; |
| 327 | int aff_supp; |
| 328 | |
| 329 | aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next, |
| 330 | struct spu, cbe_list))->aff_list); |
| 331 | |
| 332 | if (!aff_supp) |
| 333 | return ERR_PTR(-EINVAL); |
| 334 | |
| 335 | if (flags & SPU_CREATE_GANG) |
| 336 | return ERR_PTR(-EINVAL); |
| 337 | |
| 338 | if (flags & SPU_CREATE_AFFINITY_MEM && |
| 339 | gang->aff_ref_ctx && |
| 340 | gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM) |
| 341 | return ERR_PTR(-EEXIST); |
| 342 | |
| 343 | if (gang->aff_flags & AFF_MERGED) |
| 344 | return ERR_PTR(-EBUSY); |
| 345 | |
| 346 | neighbor = NULL; |
| 347 | if (flags & SPU_CREATE_AFFINITY_SPU) { |
| 348 | if (!filp || filp->f_op != &spufs_context_fops) |
| 349 | return ERR_PTR(-EINVAL); |
| 350 | |
| 351 | neighbor = get_spu_context( |
| 352 | SPUFS_I(filp->f_dentry->d_inode)->i_ctx); |
| 353 | |
| 354 | if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) && |
| 355 | !list_is_last(&neighbor->aff_list, &gang->aff_list_head) && |
| 356 | !list_entry(neighbor->aff_list.next, struct spu_context, |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 357 | aff_list)->aff_head) { |
| 358 | err = ERR_PTR(-EEXIST); |
| 359 | goto out_put_neighbor; |
| 360 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 361 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 362 | if (gang != neighbor->gang) { |
| 363 | err = ERR_PTR(-EINVAL); |
| 364 | goto out_put_neighbor; |
| 365 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 366 | |
| 367 | count = 1; |
| 368 | list_for_each_entry(tmp, &gang->aff_list_head, aff_list) |
| 369 | count++; |
| 370 | if (list_empty(&neighbor->aff_list)) |
| 371 | count++; |
| 372 | |
| 373 | for (node = 0; node < MAX_NUMNODES; node++) { |
| 374 | if ((cbe_spu_info[node].n_spus - atomic_read( |
| 375 | &cbe_spu_info[node].reserved_spus)) >= count) |
| 376 | break; |
| 377 | } |
| 378 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 379 | if (node == MAX_NUMNODES) { |
| 380 | err = ERR_PTR(-EEXIST); |
| 381 | goto out_put_neighbor; |
| 382 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | return neighbor; |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 386 | |
| 387 | out_put_neighbor: |
| 388 | put_spu_context(neighbor); |
| 389 | return err; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void |
| 393 | spufs_set_affinity(unsigned int flags, struct spu_context *ctx, |
| 394 | struct spu_context *neighbor) |
| 395 | { |
| 396 | if (flags & SPU_CREATE_AFFINITY_MEM) |
| 397 | ctx->gang->aff_ref_ctx = ctx; |
| 398 | |
| 399 | if (flags & SPU_CREATE_AFFINITY_SPU) { |
| 400 | if (list_empty(&neighbor->aff_list)) { |
| 401 | list_add_tail(&neighbor->aff_list, |
| 402 | &ctx->gang->aff_list_head); |
| 403 | neighbor->aff_head = 1; |
| 404 | } |
| 405 | |
| 406 | if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head) |
| 407 | || list_entry(neighbor->aff_list.next, struct spu_context, |
| 408 | aff_list)->aff_head) { |
| 409 | list_add(&ctx->aff_list, &neighbor->aff_list); |
| 410 | } else { |
| 411 | list_add_tail(&ctx->aff_list, &neighbor->aff_list); |
| 412 | if (neighbor->aff_head) { |
| 413 | neighbor->aff_head = 0; |
| 414 | ctx->aff_head = 1; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | if (!ctx->gang->aff_ref_ctx) |
| 419 | ctx->gang->aff_ref_ctx = ctx; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | static int |
| 424 | spufs_create_context(struct inode *inode, struct dentry *dentry, |
| 425 | struct vfsmount *mnt, int flags, int mode, |
| 426 | struct file *aff_filp) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 427 | { |
| 428 | int ret; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 429 | int affinity; |
| 430 | struct spu_gang *gang; |
| 431 | struct spu_context *neighbor; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 432 | |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 433 | ret = -EPERM; |
| 434 | if ((flags & SPU_CREATE_NOSCHED) && |
| 435 | !capable(CAP_SYS_NICE)) |
| 436 | goto out_unlock; |
| 437 | |
| 438 | ret = -EINVAL; |
| 439 | if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE)) |
| 440 | == SPU_CREATE_ISOLATE) |
| 441 | goto out_unlock; |
| 442 | |
Jeremy Kerr | bd2e5f8 | 2006-11-27 19:18:52 +0100 | [diff] [blame] | 443 | ret = -ENODEV; |
| 444 | if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader) |
| 445 | goto out_unlock; |
| 446 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 447 | gang = NULL; |
| 448 | neighbor = NULL; |
| 449 | affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU); |
| 450 | if (affinity) { |
| 451 | gang = SPUFS_I(inode)->i_gang; |
| 452 | ret = -EINVAL; |
| 453 | if (!gang) |
| 454 | goto out_unlock; |
| 455 | mutex_lock(&gang->aff_mutex); |
| 456 | neighbor = spufs_assert_affinity(flags, gang, aff_filp); |
| 457 | if (IS_ERR(neighbor)) { |
| 458 | ret = PTR_ERR(neighbor); |
| 459 | goto out_aff_unlock; |
| 460 | } |
| 461 | } |
| 462 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 463 | ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO); |
| 464 | if (ret) |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 465 | goto out_aff_unlock; |
| 466 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 467 | if (affinity) { |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 468 | spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx, |
| 469 | neighbor); |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 470 | if (neighbor) |
| 471 | put_spu_context(neighbor); |
| 472 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 473 | |
| 474 | /* |
| 475 | * get references for dget and mntget, will be released |
| 476 | * in error path of *_open(). |
| 477 | */ |
| 478 | ret = spufs_context_open(dget(dentry), mntget(mnt)); |
| 479 | if (ret < 0) { |
| 480 | WARN_ON(spufs_rmdir(inode, dentry)); |
| 481 | mutex_unlock(&inode->i_mutex); |
| 482 | spu_forget(SPUFS_I(dentry->d_inode)->i_ctx); |
| 483 | goto out; |
| 484 | } |
| 485 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 486 | out_aff_unlock: |
| 487 | if (affinity) |
| 488 | mutex_unlock(&gang->aff_mutex); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 489 | out_unlock: |
| 490 | mutex_unlock(&inode->i_mutex); |
| 491 | out: |
| 492 | dput(dentry); |
| 493 | return ret; |
| 494 | } |
| 495 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 496 | static int |
| 497 | spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode) |
| 498 | { |
| 499 | int ret; |
| 500 | struct inode *inode; |
| 501 | struct spu_gang *gang; |
| 502 | |
| 503 | ret = -ENOSPC; |
| 504 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); |
| 505 | if (!inode) |
| 506 | goto out; |
| 507 | |
| 508 | ret = 0; |
| 509 | if (dir->i_mode & S_ISGID) { |
| 510 | inode->i_gid = dir->i_gid; |
| 511 | inode->i_mode &= S_ISGID; |
| 512 | } |
| 513 | gang = alloc_spu_gang(); |
| 514 | SPUFS_I(inode)->i_ctx = NULL; |
| 515 | SPUFS_I(inode)->i_gang = gang; |
| 516 | if (!gang) |
| 517 | goto out_iput; |
| 518 | |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 519 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 520 | inode->i_fop = &simple_dir_operations; |
| 521 | |
| 522 | d_instantiate(dentry, inode); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 523 | dir->i_nlink++; |
| 524 | dentry->d_inode->i_nlink++; |
| 525 | return ret; |
| 526 | |
| 527 | out_iput: |
| 528 | iput(inode); |
| 529 | out: |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt) |
| 534 | { |
| 535 | int ret; |
| 536 | struct file *filp; |
| 537 | |
| 538 | ret = get_unused_fd(); |
| 539 | if (ret < 0) { |
| 540 | dput(dentry); |
| 541 | mntput(mnt); |
| 542 | goto out; |
| 543 | } |
| 544 | |
| 545 | filp = dentry_open(dentry, mnt, O_RDONLY); |
| 546 | if (IS_ERR(filp)) { |
| 547 | put_unused_fd(ret); |
| 548 | ret = PTR_ERR(filp); |
| 549 | goto out; |
| 550 | } |
| 551 | |
Jeremy Kerr | 877907d | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 552 | filp->f_op = &simple_dir_operations; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 553 | fd_install(ret, filp); |
| 554 | out: |
| 555 | return ret; |
| 556 | } |
| 557 | |
| 558 | static int spufs_create_gang(struct inode *inode, |
| 559 | struct dentry *dentry, |
| 560 | struct vfsmount *mnt, int mode) |
| 561 | { |
| 562 | int ret; |
| 563 | |
| 564 | ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO); |
| 565 | if (ret) |
| 566 | goto out; |
| 567 | |
| 568 | /* |
| 569 | * get references for dget and mntget, will be released |
| 570 | * in error path of *_open(). |
| 571 | */ |
| 572 | ret = spufs_gang_open(dget(dentry), mntget(mnt)); |
Jeremy Kerr | 877907d | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 573 | if (ret < 0) { |
| 574 | int err = simple_rmdir(inode, dentry); |
| 575 | WARN_ON(err); |
| 576 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 577 | |
| 578 | out: |
| 579 | mutex_unlock(&inode->i_mutex); |
| 580 | dput(dentry); |
| 581 | return ret; |
| 582 | } |
| 583 | |
| 584 | |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 585 | static struct file_system_type spufs_type; |
| 586 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 587 | long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode, |
| 588 | struct file *filp) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 589 | { |
| 590 | struct dentry *dentry; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 591 | int ret; |
| 592 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 593 | ret = -EINVAL; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 594 | /* check if we are on spufs */ |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 595 | if (nd->path.dentry->d_sb->s_type != &spufs_type) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 596 | goto out; |
| 597 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 598 | /* don't accept undefined flags */ |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 599 | if (flags & (~SPU_CREATE_FLAG_ALL)) |
arnd@arndb.de | c983294 | 2006-06-19 20:33:34 +0200 | [diff] [blame] | 600 | goto out; |
| 601 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 602 | /* only threads can be underneath a gang */ |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 603 | if (nd->path.dentry != nd->path.dentry->d_sb->s_root) { |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 604 | if ((flags & SPU_CREATE_GANG) || |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 605 | !SPUFS_I(nd->path.dentry->d_inode)->i_gang) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 606 | goto out; |
| 607 | } |
| 608 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 609 | dentry = lookup_create(nd, 1); |
| 610 | ret = PTR_ERR(dentry); |
| 611 | if (IS_ERR(dentry)) |
| 612 | goto out_dir; |
| 613 | |
| 614 | ret = -EEXIST; |
| 615 | if (dentry->d_inode) |
| 616 | goto out_dput; |
| 617 | |
| 618 | mode &= ~current->fs->umask; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 619 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 620 | if (flags & SPU_CREATE_GANG) |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 621 | return spufs_create_gang(nd->path.dentry->d_inode, |
| 622 | dentry, nd->path.mnt, mode); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 623 | else |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 624 | return spufs_create_context(nd->path.dentry->d_inode, |
| 625 | dentry, nd->path.mnt, flags, mode, |
| 626 | filp); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 627 | |
| 628 | out_dput: |
| 629 | dput(dentry); |
| 630 | out_dir: |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 631 | mutex_unlock(&nd->path.dentry->d_inode->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 632 | out: |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | /* File system initialization */ |
| 637 | enum { |
Jeremy Kerr | f11f5ee | 2007-04-23 21:08:23 +0200 | [diff] [blame] | 638 | Opt_uid, Opt_gid, Opt_mode, Opt_err, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | static match_table_t spufs_tokens = { |
Jeremy Kerr | f11f5ee | 2007-04-23 21:08:23 +0200 | [diff] [blame] | 642 | { Opt_uid, "uid=%d" }, |
| 643 | { Opt_gid, "gid=%d" }, |
| 644 | { Opt_mode, "mode=%o" }, |
| 645 | { Opt_err, NULL }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 646 | }; |
| 647 | |
| 648 | static int |
| 649 | spufs_parse_options(char *options, struct inode *root) |
| 650 | { |
| 651 | char *p; |
| 652 | substring_t args[MAX_OPT_ARGS]; |
| 653 | |
| 654 | while ((p = strsep(&options, ",")) != NULL) { |
| 655 | int token, option; |
| 656 | |
| 657 | if (!*p) |
| 658 | continue; |
| 659 | |
| 660 | token = match_token(p, spufs_tokens, args); |
| 661 | switch (token) { |
| 662 | case Opt_uid: |
| 663 | if (match_int(&args[0], &option)) |
| 664 | return 0; |
| 665 | root->i_uid = option; |
| 666 | break; |
| 667 | case Opt_gid: |
| 668 | if (match_int(&args[0], &option)) |
| 669 | return 0; |
| 670 | root->i_gid = option; |
| 671 | break; |
Jeremy Kerr | f11f5ee | 2007-04-23 21:08:23 +0200 | [diff] [blame] | 672 | case Opt_mode: |
| 673 | if (match_octal(&args[0], &option)) |
| 674 | return 0; |
| 675 | root->i_mode = option | S_IFDIR; |
| 676 | break; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 677 | default: |
| 678 | return 0; |
| 679 | } |
| 680 | } |
| 681 | return 1; |
| 682 | } |
| 683 | |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 684 | static void spufs_exit_isolated_loader(void) |
| 685 | { |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 686 | free_pages((unsigned long) isolated_loader, |
| 687 | get_order(isolated_loader_size)); |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 688 | } |
| 689 | |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 690 | static void |
| 691 | spufs_init_isolated_loader(void) |
| 692 | { |
| 693 | struct device_node *dn; |
| 694 | const char *loader; |
| 695 | int size; |
| 696 | |
| 697 | dn = of_find_node_by_path("/spu-isolation"); |
| 698 | if (!dn) |
| 699 | return; |
| 700 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 701 | loader = of_get_property(dn, "loader", &size); |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 702 | if (!loader) |
| 703 | return; |
| 704 | |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 705 | /* the loader must be align on a 16 byte boundary */ |
| 706 | isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size)); |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 707 | if (!isolated_loader) |
| 708 | return; |
| 709 | |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 710 | isolated_loader_size = size; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 711 | memcpy(isolated_loader, loader, size); |
| 712 | printk(KERN_INFO "spufs: SPU isolation mode enabled\n"); |
| 713 | } |
| 714 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 715 | static int |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 716 | spufs_create_root(struct super_block *sb, void *data) |
| 717 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 718 | struct inode *inode; |
| 719 | int ret; |
| 720 | |
Arnd Bergmann | 8f18a15 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 721 | ret = -ENODEV; |
| 722 | if (!spu_management_ops) |
| 723 | goto out; |
| 724 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 725 | ret = -ENOMEM; |
| 726 | inode = spufs_new_inode(sb, S_IFDIR | 0775); |
| 727 | if (!inode) |
| 728 | goto out; |
| 729 | |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 730 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 731 | inode->i_fop = &simple_dir_operations; |
| 732 | SPUFS_I(inode)->i_ctx = NULL; |
| 733 | |
| 734 | ret = -EINVAL; |
| 735 | if (!spufs_parse_options(data, inode)) |
| 736 | goto out_iput; |
| 737 | |
| 738 | ret = -ENOMEM; |
| 739 | sb->s_root = d_alloc_root(inode); |
| 740 | if (!sb->s_root) |
| 741 | goto out_iput; |
| 742 | |
| 743 | return 0; |
| 744 | out_iput: |
| 745 | iput(inode); |
| 746 | out: |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | static int |
| 751 | spufs_fill_super(struct super_block *sb, void *data, int silent) |
| 752 | { |
| 753 | static struct super_operations s_ops = { |
| 754 | .alloc_inode = spufs_alloc_inode, |
| 755 | .destroy_inode = spufs_destroy_inode, |
| 756 | .statfs = simple_statfs, |
| 757 | .delete_inode = spufs_delete_inode, |
| 758 | .drop_inode = generic_delete_inode, |
Miklos Szeredi | 90d09e1 | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 759 | .show_options = generic_show_options, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 760 | }; |
| 761 | |
Miklos Szeredi | 90d09e1 | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 762 | save_mount_options(sb, data); |
| 763 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 764 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 765 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 766 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 767 | sb->s_magic = SPUFS_MAGIC; |
| 768 | sb->s_op = &s_ops; |
| 769 | |
| 770 | return spufs_create_root(sb, data); |
| 771 | } |
| 772 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 773 | static int |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 774 | spufs_get_sb(struct file_system_type *fstype, int flags, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 775 | const char *name, void *data, struct vfsmount *mnt) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 776 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 777 | return get_sb_single(fstype, flags, data, spufs_fill_super, mnt); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static struct file_system_type spufs_type = { |
| 781 | .owner = THIS_MODULE, |
| 782 | .name = "spufs", |
| 783 | .get_sb = spufs_get_sb, |
| 784 | .kill_sb = kill_litter_super, |
| 785 | }; |
| 786 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 787 | static int __init spufs_init(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 788 | { |
| 789 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 790 | |
Jeremy Kerr | ccf17e9 | 2007-04-23 21:08:29 +0200 | [diff] [blame] | 791 | ret = -ENODEV; |
| 792 | if (!spu_management_ops) |
| 793 | goto out; |
| 794 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 795 | ret = -ENOMEM; |
| 796 | spufs_inode_cache = kmem_cache_create("spufs_inode_cache", |
| 797 | sizeof(struct spufs_inode_info), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 798 | SLAB_HWCACHE_ALIGN, spufs_init_once); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 799 | |
| 800 | if (!spufs_inode_cache) |
| 801 | goto out; |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 802 | ret = spu_sched_init(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 803 | if (ret) |
| 804 | goto out_cache; |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 805 | ret = register_filesystem(&spufs_type); |
| 806 | if (ret) |
| 807 | goto out_sched; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 808 | ret = register_spu_syscalls(&spufs_calls); |
| 809 | if (ret) |
| 810 | goto out_fs; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 811 | |
| 812 | spufs_init_isolated_loader(); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 813 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 814 | return 0; |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 815 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 816 | out_fs: |
| 817 | unregister_filesystem(&spufs_type); |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 818 | out_sched: |
| 819 | spu_sched_exit(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 820 | out_cache: |
| 821 | kmem_cache_destroy(spufs_inode_cache); |
| 822 | out: |
| 823 | return ret; |
| 824 | } |
| 825 | module_init(spufs_init); |
| 826 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 827 | static void __exit spufs_exit(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 828 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 829 | spu_sched_exit(); |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 830 | spufs_exit_isolated_loader(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 831 | unregister_spu_syscalls(&spufs_calls); |
| 832 | unregister_filesystem(&spufs_type); |
| 833 | kmem_cache_destroy(spufs_inode_cache); |
| 834 | } |
| 835 | module_exit(spufs_exit); |
| 836 | |
| 837 | MODULE_LICENSE("GPL"); |
| 838 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |
| 839 | |