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