Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SPU file system |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Arnd Bergmann <arndb@de.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/file.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/backing-dev.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/ioctl.h> |
| 28 | #include <linux/module.h> |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 29 | #include <linux/mount.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 30 | #include <linux/namei.h> |
| 31 | #include <linux/pagemap.h> |
| 32 | #include <linux/poll.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/parser.h> |
| 35 | |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/semaphore.h> |
| 38 | #include <asm/spu.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | |
| 41 | #include "spufs.h" |
| 42 | |
| 43 | static kmem_cache_t *spufs_inode_cache; |
| 44 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 45 | static struct inode * |
| 46 | spufs_alloc_inode(struct super_block *sb) |
| 47 | { |
| 48 | struct spufs_inode_info *ei; |
| 49 | |
| 50 | ei = kmem_cache_alloc(spufs_inode_cache, SLAB_KERNEL); |
| 51 | if (!ei) |
| 52 | return NULL; |
| 53 | return &ei->vfs_inode; |
| 54 | } |
| 55 | |
| 56 | static void |
| 57 | spufs_destroy_inode(struct inode *inode) |
| 58 | { |
| 59 | kmem_cache_free(spufs_inode_cache, SPUFS_I(inode)); |
| 60 | } |
| 61 | |
| 62 | static void |
| 63 | spufs_init_once(void *p, kmem_cache_t * cachep, unsigned long flags) |
| 64 | { |
| 65 | struct spufs_inode_info *ei = p; |
| 66 | |
| 67 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 68 | SLAB_CTOR_CONSTRUCTOR) { |
| 69 | inode_init_once(&ei->vfs_inode); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static struct inode * |
| 74 | spufs_new_inode(struct super_block *sb, int mode) |
| 75 | { |
| 76 | struct inode *inode; |
| 77 | |
| 78 | inode = new_inode(sb); |
| 79 | if (!inode) |
| 80 | goto out; |
| 81 | |
| 82 | inode->i_mode = mode; |
| 83 | inode->i_uid = current->fsuid; |
| 84 | inode->i_gid = current->fsgid; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 85 | inode->i_blocks = 0; |
| 86 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 87 | out: |
| 88 | return inode; |
| 89 | } |
| 90 | |
| 91 | static int |
| 92 | spufs_setattr(struct dentry *dentry, struct iattr *attr) |
| 93 | { |
| 94 | struct inode *inode = dentry->d_inode; |
| 95 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 96 | if ((attr->ia_valid & ATTR_SIZE) && |
| 97 | (attr->ia_size != inode->i_size)) |
| 98 | return -EINVAL; |
| 99 | return inode_setattr(inode, attr); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | static int |
| 104 | spufs_new_file(struct super_block *sb, struct dentry *dentry, |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 105 | const struct file_operations *fops, int mode, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 106 | struct spu_context *ctx) |
| 107 | { |
| 108 | static struct inode_operations spufs_file_iops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 109 | .setattr = spufs_setattr, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 110 | }; |
| 111 | struct inode *inode; |
| 112 | int ret; |
| 113 | |
| 114 | ret = -ENOSPC; |
| 115 | inode = spufs_new_inode(sb, S_IFREG | mode); |
| 116 | if (!inode) |
| 117 | goto out; |
| 118 | |
| 119 | ret = 0; |
| 120 | inode->i_op = &spufs_file_iops; |
| 121 | inode->i_fop = fops; |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 122 | inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 123 | d_add(dentry, inode); |
| 124 | out: |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | static void |
| 129 | spufs_delete_inode(struct inode *inode) |
| 130 | { |
| 131 | if (SPUFS_I(inode)->i_ctx) |
| 132 | put_spu_context(SPUFS_I(inode)->i_ctx); |
| 133 | clear_inode(inode); |
| 134 | } |
| 135 | |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 136 | static void spufs_prune_dir(struct dentry *dir) |
| 137 | { |
| 138 | struct dentry *dentry, *tmp; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 139 | mutex_lock(&dir->d_inode->i_mutex); |
Andrew Morton | c3a9aea | 2006-01-09 20:51:24 -0800 | [diff] [blame] | 140 | 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] | 141 | spin_lock(&dcache_lock); |
| 142 | spin_lock(&dentry->d_lock); |
| 143 | if (!(d_unhashed(dentry)) && dentry->d_inode) { |
| 144 | dget_locked(dentry); |
| 145 | __d_drop(dentry); |
| 146 | spin_unlock(&dentry->d_lock); |
| 147 | simple_unlink(dir->d_inode, dentry); |
| 148 | spin_unlock(&dcache_lock); |
| 149 | dput(dentry); |
| 150 | } else { |
| 151 | spin_unlock(&dentry->d_lock); |
| 152 | spin_unlock(&dcache_lock); |
| 153 | } |
| 154 | } |
| 155 | shrink_dcache_parent(dir); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 156 | mutex_unlock(&dir->d_inode->i_mutex); |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 159 | /* Caller must hold root->i_mutex */ |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 160 | static int spufs_rmdir(struct inode *root, struct dentry *dir_dentry) |
| 161 | { |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 162 | /* remove all entries */ |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 163 | spufs_prune_dir(dir_dentry); |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 164 | |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 165 | return simple_rmdir(root, dir_dentry); |
| 166 | } |
| 167 | |
| 168 | static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files, |
| 169 | int mode, struct spu_context *ctx) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 170 | { |
| 171 | struct dentry *dentry; |
| 172 | int ret; |
| 173 | |
| 174 | while (files->name && files->name[0]) { |
| 175 | ret = -ENOMEM; |
| 176 | dentry = d_alloc_name(dir, files->name); |
| 177 | if (!dentry) |
| 178 | goto out; |
| 179 | ret = spufs_new_file(dir->d_sb, dentry, files->ops, |
| 180 | files->mode & mode, ctx); |
| 181 | if (ret) |
| 182 | goto out; |
| 183 | files++; |
| 184 | } |
| 185 | return 0; |
| 186 | out: |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 187 | spufs_prune_dir(dir); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 188 | return ret; |
| 189 | } |
| 190 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 191 | static int spufs_dir_close(struct inode *inode, struct file *file) |
| 192 | { |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 193 | struct spu_context *ctx; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 194 | struct inode *dir; |
| 195 | struct dentry *dentry; |
| 196 | int ret; |
| 197 | |
| 198 | dentry = file->f_dentry; |
| 199 | dir = dentry->d_parent->d_inode; |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 200 | ctx = SPUFS_I(dentry->d_inode)->i_ctx; |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 201 | |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 202 | mutex_lock(&dir->i_mutex); |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 203 | ret = spufs_rmdir(dir, dentry); |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 204 | mutex_unlock(&dir->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 205 | WARN_ON(ret); |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 206 | |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 207 | /* We have to give up the mm_struct */ |
| 208 | spu_forget(ctx); |
| 209 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 210 | return dcache_dir_close(inode, file); |
| 211 | } |
| 212 | |
| 213 | struct inode_operations spufs_dir_inode_operations = { |
| 214 | .lookup = simple_lookup, |
| 215 | }; |
| 216 | |
Arnd Bergmann | e80358a | 2006-01-04 20:31:23 +0100 | [diff] [blame] | 217 | struct file_operations spufs_context_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 218 | .open = dcache_dir_open, |
| 219 | .release = spufs_dir_close, |
| 220 | .llseek = dcache_dir_lseek, |
| 221 | .read = generic_read_dir, |
| 222 | .readdir = dcache_readdir, |
| 223 | .fsync = simple_sync_file, |
| 224 | }; |
| 225 | |
| 226 | static int |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame^] | 227 | spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags, |
| 228 | int mode) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 229 | { |
| 230 | int ret; |
| 231 | struct inode *inode; |
| 232 | struct spu_context *ctx; |
| 233 | |
| 234 | ret = -ENOSPC; |
| 235 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); |
| 236 | if (!inode) |
| 237 | goto out; |
| 238 | |
| 239 | if (dir->i_mode & S_ISGID) { |
| 240 | inode->i_gid = dir->i_gid; |
| 241 | inode->i_mode &= S_ISGID; |
| 242 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 243 | ctx = alloc_spu_context(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 244 | SPUFS_I(inode)->i_ctx = ctx; |
| 245 | if (!ctx) |
| 246 | goto out_iput; |
| 247 | |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame^] | 248 | ctx->flags = flags; |
| 249 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 250 | inode->i_op = &spufs_dir_inode_operations; |
| 251 | inode->i_fop = &simple_dir_operations; |
| 252 | ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx); |
| 253 | if (ret) |
| 254 | goto out_free_ctx; |
| 255 | |
| 256 | d_instantiate(dentry, inode); |
| 257 | dget(dentry); |
| 258 | dir->i_nlink++; |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 259 | dentry->d_inode->i_nlink++; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 260 | goto out; |
| 261 | |
| 262 | out_free_ctx: |
| 263 | put_spu_context(ctx); |
| 264 | out_iput: |
| 265 | iput(inode); |
| 266 | out: |
| 267 | return ret; |
| 268 | } |
| 269 | |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 270 | static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt) |
| 271 | { |
| 272 | int ret; |
| 273 | struct file *filp; |
| 274 | |
| 275 | ret = get_unused_fd(); |
| 276 | if (ret < 0) { |
| 277 | dput(dentry); |
| 278 | mntput(mnt); |
| 279 | goto out; |
| 280 | } |
| 281 | |
| 282 | filp = dentry_open(dentry, mnt, O_RDONLY); |
| 283 | if (IS_ERR(filp)) { |
| 284 | put_unused_fd(ret); |
| 285 | ret = PTR_ERR(filp); |
| 286 | goto out; |
| 287 | } |
| 288 | |
| 289 | filp->f_op = &spufs_context_fops; |
| 290 | fd_install(ret, filp); |
| 291 | out: |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | static struct file_system_type spufs_type; |
| 296 | |
Arnd Bergmann | 6ff730c | 2006-01-04 20:31:31 +0100 | [diff] [blame] | 297 | long spufs_create_thread(struct nameidata *nd, |
| 298 | unsigned int flags, mode_t mode) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 299 | { |
| 300 | struct dentry *dentry; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 301 | int ret; |
| 302 | |
| 303 | /* need to be at the root of spufs */ |
| 304 | ret = -EINVAL; |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 305 | if (nd->dentry->d_sb->s_type != &spufs_type || |
| 306 | nd->dentry != nd->dentry->d_sb->s_root) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 307 | goto out; |
| 308 | |
arnd@arndb.de | c983294 | 2006-06-19 20:33:34 +0200 | [diff] [blame] | 309 | /* all flags are reserved */ |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame^] | 310 | if (flags & (~SPU_CREATE_FLAG_ALL)) |
arnd@arndb.de | c983294 | 2006-06-19 20:33:34 +0200 | [diff] [blame] | 311 | goto out; |
| 312 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 313 | dentry = lookup_create(nd, 1); |
| 314 | ret = PTR_ERR(dentry); |
| 315 | if (IS_ERR(dentry)) |
| 316 | goto out_dir; |
| 317 | |
| 318 | ret = -EEXIST; |
| 319 | if (dentry->d_inode) |
| 320 | goto out_dput; |
| 321 | |
| 322 | mode &= ~current->fs->umask; |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame^] | 323 | ret = spufs_mkdir(nd->dentry->d_inode, dentry, flags, mode & S_IRWXUGO); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 324 | if (ret) |
| 325 | goto out_dput; |
| 326 | |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 327 | /* |
| 328 | * get references for dget and mntget, will be released |
| 329 | * in error path of *_open(). |
| 330 | */ |
| 331 | ret = spufs_context_open(dget(dentry), mntget(nd->mnt)); |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 332 | if (ret < 0) { |
| 333 | WARN_ON(spufs_rmdir(nd->dentry->d_inode, dentry)); |
| 334 | mutex_unlock(&nd->dentry->d_inode->i_mutex); |
| 335 | spu_forget(SPUFS_I(dentry->d_inode)->i_ctx); |
| 336 | dput(dentry); |
| 337 | goto out; |
| 338 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 339 | |
| 340 | out_dput: |
| 341 | dput(dentry); |
| 342 | out_dir: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 343 | mutex_unlock(&nd->dentry->d_inode->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 344 | out: |
| 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | /* File system initialization */ |
| 349 | enum { |
| 350 | Opt_uid, Opt_gid, Opt_err, |
| 351 | }; |
| 352 | |
| 353 | static match_table_t spufs_tokens = { |
| 354 | { Opt_uid, "uid=%d" }, |
| 355 | { Opt_gid, "gid=%d" }, |
| 356 | { Opt_err, NULL }, |
| 357 | }; |
| 358 | |
| 359 | static int |
| 360 | spufs_parse_options(char *options, struct inode *root) |
| 361 | { |
| 362 | char *p; |
| 363 | substring_t args[MAX_OPT_ARGS]; |
| 364 | |
| 365 | while ((p = strsep(&options, ",")) != NULL) { |
| 366 | int token, option; |
| 367 | |
| 368 | if (!*p) |
| 369 | continue; |
| 370 | |
| 371 | token = match_token(p, spufs_tokens, args); |
| 372 | switch (token) { |
| 373 | case Opt_uid: |
| 374 | if (match_int(&args[0], &option)) |
| 375 | return 0; |
| 376 | root->i_uid = option; |
| 377 | break; |
| 378 | case Opt_gid: |
| 379 | if (match_int(&args[0], &option)) |
| 380 | return 0; |
| 381 | root->i_gid = option; |
| 382 | break; |
| 383 | default: |
| 384 | return 0; |
| 385 | } |
| 386 | } |
| 387 | return 1; |
| 388 | } |
| 389 | |
| 390 | static int |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 391 | spufs_create_root(struct super_block *sb, void *data) |
| 392 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 393 | struct inode *inode; |
| 394 | int ret; |
| 395 | |
| 396 | ret = -ENOMEM; |
| 397 | inode = spufs_new_inode(sb, S_IFDIR | 0775); |
| 398 | if (!inode) |
| 399 | goto out; |
| 400 | |
| 401 | inode->i_op = &spufs_dir_inode_operations; |
| 402 | inode->i_fop = &simple_dir_operations; |
| 403 | SPUFS_I(inode)->i_ctx = NULL; |
| 404 | |
| 405 | ret = -EINVAL; |
| 406 | if (!spufs_parse_options(data, inode)) |
| 407 | goto out_iput; |
| 408 | |
| 409 | ret = -ENOMEM; |
| 410 | sb->s_root = d_alloc_root(inode); |
| 411 | if (!sb->s_root) |
| 412 | goto out_iput; |
| 413 | |
| 414 | return 0; |
| 415 | out_iput: |
| 416 | iput(inode); |
| 417 | out: |
| 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | static int |
| 422 | spufs_fill_super(struct super_block *sb, void *data, int silent) |
| 423 | { |
| 424 | static struct super_operations s_ops = { |
| 425 | .alloc_inode = spufs_alloc_inode, |
| 426 | .destroy_inode = spufs_destroy_inode, |
| 427 | .statfs = simple_statfs, |
| 428 | .delete_inode = spufs_delete_inode, |
| 429 | .drop_inode = generic_delete_inode, |
| 430 | }; |
| 431 | |
| 432 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 433 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 434 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 435 | sb->s_magic = SPUFS_MAGIC; |
| 436 | sb->s_op = &s_ops; |
| 437 | |
| 438 | return spufs_create_root(sb, data); |
| 439 | } |
| 440 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 441 | static int |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 442 | spufs_get_sb(struct file_system_type *fstype, int flags, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 443 | const char *name, void *data, struct vfsmount *mnt) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 444 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 445 | return get_sb_single(fstype, flags, data, spufs_fill_super, mnt); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static struct file_system_type spufs_type = { |
| 449 | .owner = THIS_MODULE, |
| 450 | .name = "spufs", |
| 451 | .get_sb = spufs_get_sb, |
| 452 | .kill_sb = kill_litter_super, |
| 453 | }; |
| 454 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 455 | static int __init spufs_init(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 456 | { |
| 457 | int ret; |
| 458 | ret = -ENOMEM; |
| 459 | spufs_inode_cache = kmem_cache_create("spufs_inode_cache", |
| 460 | sizeof(struct spufs_inode_info), 0, |
| 461 | SLAB_HWCACHE_ALIGN, spufs_init_once, NULL); |
| 462 | |
| 463 | if (!spufs_inode_cache) |
| 464 | goto out; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 465 | if (spu_sched_init() != 0) { |
| 466 | kmem_cache_destroy(spufs_inode_cache); |
| 467 | goto out; |
| 468 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 469 | ret = register_filesystem(&spufs_type); |
| 470 | if (ret) |
| 471 | goto out_cache; |
| 472 | ret = register_spu_syscalls(&spufs_calls); |
| 473 | if (ret) |
| 474 | goto out_fs; |
| 475 | return 0; |
| 476 | out_fs: |
| 477 | unregister_filesystem(&spufs_type); |
| 478 | out_cache: |
| 479 | kmem_cache_destroy(spufs_inode_cache); |
| 480 | out: |
| 481 | return ret; |
| 482 | } |
| 483 | module_init(spufs_init); |
| 484 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 485 | static void __exit spufs_exit(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 486 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 487 | spu_sched_exit(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 488 | unregister_spu_syscalls(&spufs_calls); |
| 489 | unregister_filesystem(&spufs_type); |
| 490 | kmem_cache_destroy(spufs_inode_cache); |
| 491 | } |
| 492 | module_exit(spufs_exit); |
| 493 | |
| 494 | MODULE_LICENSE("GPL"); |
| 495 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |
| 496 | |