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 */ |
Al Viro | 67cba9f | 2012-07-19 16:03:21 +0400 | [diff] [blame] | 189 | int res; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 190 | spufs_prune_dir(dir); |
Jeremy Kerr | c443aca | 2007-11-16 13:32:23 +1100 | [diff] [blame] | 191 | d_drop(dir); |
Al Viro | 67cba9f | 2012-07-19 16:03:21 +0400 | [diff] [blame] | 192 | res = simple_rmdir(parent, dir); |
| 193 | /* We have to give up the mm_struct */ |
| 194 | spu_forget(SPUFS_I(dir->d_inode)->i_ctx); |
| 195 | return res; |
Arnd Bergmann | 3f51dd9 | 2006-01-04 20:31:27 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 198 | static int spufs_fill_dir(struct dentry *dir, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 199 | const struct spufs_tree_descr *files, umode_t mode, |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 200 | struct spu_context *ctx) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 201 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 202 | while (files->name && files->name[0]) { |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 203 | int ret; |
| 204 | struct dentry *dentry = d_alloc_name(dir, files->name); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 205 | if (!dentry) |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 206 | return -ENOMEM; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 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) |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 210 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 211 | files++; |
| 212 | } |
| 213 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 216 | static int spufs_dir_close(struct inode *inode, struct file *file) |
| 217 | { |
Michael Ellerman | 0309f02 | 2006-06-19 20:33:22 +0200 | [diff] [blame] | 218 | struct spu_context *ctx; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 219 | struct inode *parent; |
| 220 | struct dentry *dir; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 221 | int ret; |
| 222 | |
Josef Sipek | b4d1ab5 | 2006-12-08 02:37:30 -0800 | [diff] [blame] | 223 | dir = file->f_path.dentry; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 224 | parent = dir->d_parent->d_inode; |
| 225 | ctx = SPUFS_I(dir->d_inode)->i_ctx; |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 226 | |
Christoph Hellwig | 02539d7 | 2008-05-08 15:29:12 +1000 | [diff] [blame] | 227 | mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 228 | ret = spufs_rmdir(parent, dir); |
| 229 | mutex_unlock(&parent->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 230 | WARN_ON(ret); |
Arnd Bergmann | c8ca063 | 2006-01-04 20:31:22 +0100 | [diff] [blame] | 231 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 232 | return dcache_dir_close(inode, file); |
| 233 | } |
| 234 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 235 | const struct file_operations spufs_context_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 236 | .open = dcache_dir_open, |
| 237 | .release = spufs_dir_close, |
| 238 | .llseek = dcache_dir_lseek, |
| 239 | .read = generic_read_dir, |
| 240 | .readdir = dcache_readdir, |
Christoph Hellwig | 1b061d9 | 2010-05-26 17:53:41 +0200 | [diff] [blame] | 241 | .fsync = noop_fsync, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 242 | }; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 243 | EXPORT_SYMBOL_GPL(spufs_context_fops); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 244 | |
| 245 | static int |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 246 | spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 247 | umode_t mode) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 248 | { |
| 249 | int ret; |
| 250 | struct inode *inode; |
| 251 | struct spu_context *ctx; |
| 252 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 253 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); |
| 254 | if (!inode) |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 255 | return -ENOSPC; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 256 | |
| 257 | if (dir->i_mode & S_ISGID) { |
| 258 | inode->i_gid = dir->i_gid; |
| 259 | inode->i_mode &= S_ISGID; |
| 260 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 261 | ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 262 | SPUFS_I(inode)->i_ctx = ctx; |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 263 | if (!ctx) { |
| 264 | iput(inode); |
| 265 | return -ENOSPC; |
| 266 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 267 | |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 268 | ctx->flags = flags; |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 269 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 270 | inode->i_fop = &simple_dir_operations; |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 271 | |
| 272 | mutex_lock(&inode->i_mutex); |
| 273 | |
| 274 | dget(dentry); |
| 275 | inc_nlink(dir); |
| 276 | inc_nlink(inode); |
| 277 | |
| 278 | d_instantiate(dentry, inode); |
| 279 | |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 280 | if (flags & SPU_CREATE_NOSCHED) |
| 281 | ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents, |
| 282 | mode, ctx); |
| 283 | else |
| 284 | ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx); |
| 285 | |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 286 | if (!ret && spufs_get_sb_info(dir->i_sb)->debug) |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 287 | ret = spufs_fill_dir(dentry, spufs_dir_debug_contents, |
| 288 | mode, ctx); |
| 289 | |
| 290 | if (ret) |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 291 | spufs_rmdir(dir, dentry); |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 292 | |
Al Viro | 2248b87 | 2013-01-28 20:37:21 -0500 | [diff] [blame^] | 293 | mutex_unlock(&inode->i_mutex); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 294 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 295 | return ret; |
| 296 | } |
| 297 | |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 298 | static int spufs_context_open(struct path *path) |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 299 | { |
| 300 | int ret; |
| 301 | struct file *filp; |
| 302 | |
| 303 | ret = get_unused_fd(); |
Al Viro | bf349a4 | 2012-06-25 11:46:13 +0400 | [diff] [blame] | 304 | if (ret < 0) |
| 305 | return ret; |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 306 | |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 307 | filp = dentry_open(path, O_RDONLY, current_cred()); |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 308 | if (IS_ERR(filp)) { |
| 309 | put_unused_fd(ret); |
Al Viro | bf349a4 | 2012-06-25 11:46:13 +0400 | [diff] [blame] | 310 | return PTR_ERR(filp); |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | filp->f_op = &spufs_context_fops; |
| 314 | fd_install(ret, filp); |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 318 | static struct spu_context * |
| 319 | spufs_assert_affinity(unsigned int flags, struct spu_gang *gang, |
| 320 | struct file *filp) |
| 321 | { |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 322 | struct spu_context *tmp, *neighbor, *err; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 323 | int count, node; |
| 324 | int aff_supp; |
| 325 | |
| 326 | aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next, |
| 327 | struct spu, cbe_list))->aff_list); |
| 328 | |
| 329 | if (!aff_supp) |
| 330 | return ERR_PTR(-EINVAL); |
| 331 | |
| 332 | if (flags & SPU_CREATE_GANG) |
| 333 | return ERR_PTR(-EINVAL); |
| 334 | |
| 335 | if (flags & SPU_CREATE_AFFINITY_MEM && |
| 336 | gang->aff_ref_ctx && |
| 337 | gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM) |
| 338 | return ERR_PTR(-EEXIST); |
| 339 | |
| 340 | if (gang->aff_flags & AFF_MERGED) |
| 341 | return ERR_PTR(-EBUSY); |
| 342 | |
| 343 | neighbor = NULL; |
| 344 | if (flags & SPU_CREATE_AFFINITY_SPU) { |
| 345 | if (!filp || filp->f_op != &spufs_context_fops) |
| 346 | return ERR_PTR(-EINVAL); |
| 347 | |
| 348 | neighbor = get_spu_context( |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 349 | SPUFS_I(file_inode(filp))->i_ctx); |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 350 | |
| 351 | if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) && |
| 352 | !list_is_last(&neighbor->aff_list, &gang->aff_list_head) && |
| 353 | !list_entry(neighbor->aff_list.next, struct spu_context, |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 354 | aff_list)->aff_head) { |
| 355 | err = ERR_PTR(-EEXIST); |
| 356 | goto out_put_neighbor; |
| 357 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 358 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 359 | if (gang != neighbor->gang) { |
| 360 | err = ERR_PTR(-EINVAL); |
| 361 | goto out_put_neighbor; |
| 362 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 363 | |
| 364 | count = 1; |
| 365 | list_for_each_entry(tmp, &gang->aff_list_head, aff_list) |
| 366 | count++; |
| 367 | if (list_empty(&neighbor->aff_list)) |
| 368 | count++; |
| 369 | |
| 370 | for (node = 0; node < MAX_NUMNODES; node++) { |
| 371 | if ((cbe_spu_info[node].n_spus - atomic_read( |
| 372 | &cbe_spu_info[node].reserved_spus)) >= count) |
| 373 | break; |
| 374 | } |
| 375 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 376 | if (node == MAX_NUMNODES) { |
| 377 | err = ERR_PTR(-EEXIST); |
| 378 | goto out_put_neighbor; |
| 379 | } |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | return neighbor; |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 383 | |
| 384 | out_put_neighbor: |
| 385 | put_spu_context(neighbor); |
| 386 | return err; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void |
| 390 | spufs_set_affinity(unsigned int flags, struct spu_context *ctx, |
| 391 | struct spu_context *neighbor) |
| 392 | { |
| 393 | if (flags & SPU_CREATE_AFFINITY_MEM) |
| 394 | ctx->gang->aff_ref_ctx = ctx; |
| 395 | |
| 396 | if (flags & SPU_CREATE_AFFINITY_SPU) { |
| 397 | if (list_empty(&neighbor->aff_list)) { |
| 398 | list_add_tail(&neighbor->aff_list, |
| 399 | &ctx->gang->aff_list_head); |
| 400 | neighbor->aff_head = 1; |
| 401 | } |
| 402 | |
| 403 | if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head) |
| 404 | || list_entry(neighbor->aff_list.next, struct spu_context, |
| 405 | aff_list)->aff_head) { |
| 406 | list_add(&ctx->aff_list, &neighbor->aff_list); |
| 407 | } else { |
| 408 | list_add_tail(&ctx->aff_list, &neighbor->aff_list); |
| 409 | if (neighbor->aff_head) { |
| 410 | neighbor->aff_head = 0; |
| 411 | ctx->aff_head = 1; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (!ctx->gang->aff_ref_ctx) |
| 416 | ctx->gang->aff_ref_ctx = ctx; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | static int |
| 421 | spufs_create_context(struct inode *inode, struct dentry *dentry, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 422 | struct vfsmount *mnt, int flags, umode_t mode, |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 423 | struct file *aff_filp) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 424 | { |
| 425 | int ret; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 426 | int affinity; |
| 427 | struct spu_gang *gang; |
| 428 | struct spu_context *neighbor; |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 429 | struct path path = {.mnt = mnt, .dentry = dentry}; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 430 | |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 431 | if ((flags & SPU_CREATE_NOSCHED) && |
| 432 | !capable(CAP_SYS_NICE)) |
Al Viro | 1ba44cc | 2012-07-19 16:12:22 +0400 | [diff] [blame] | 433 | return -EPERM; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 434 | |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 435 | if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE)) |
| 436 | == SPU_CREATE_ISOLATE) |
Al Viro | 1ba44cc | 2012-07-19 16:12:22 +0400 | [diff] [blame] | 437 | return -EINVAL; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 438 | |
Jeremy Kerr | bd2e5f8 | 2006-11-27 19:18:52 +0100 | [diff] [blame] | 439 | if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader) |
Al Viro | 1ba44cc | 2012-07-19 16:12:22 +0400 | [diff] [blame] | 440 | return -ENODEV; |
Jeremy Kerr | bd2e5f8 | 2006-11-27 19:18:52 +0100 | [diff] [blame] | 441 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 442 | gang = NULL; |
| 443 | neighbor = NULL; |
| 444 | affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU); |
| 445 | if (affinity) { |
| 446 | gang = SPUFS_I(inode)->i_gang; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 447 | if (!gang) |
Al Viro | 1ba44cc | 2012-07-19 16:12:22 +0400 | [diff] [blame] | 448 | return -EINVAL; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 449 | mutex_lock(&gang->aff_mutex); |
| 450 | neighbor = spufs_assert_affinity(flags, gang, aff_filp); |
| 451 | if (IS_ERR(neighbor)) { |
| 452 | ret = PTR_ERR(neighbor); |
| 453 | goto out_aff_unlock; |
| 454 | } |
| 455 | } |
| 456 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 457 | ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO); |
| 458 | if (ret) |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 459 | goto out_aff_unlock; |
| 460 | |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 461 | if (affinity) { |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 462 | spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx, |
| 463 | neighbor); |
Andre Detsch | 5811906 | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 464 | if (neighbor) |
| 465 | put_spu_context(neighbor); |
| 466 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 467 | |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 468 | ret = spufs_context_open(&path); |
Al Viro | 66ec7b2 | 2012-07-19 16:07:30 +0400 | [diff] [blame] | 469 | if (ret < 0) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 470 | WARN_ON(spufs_rmdir(inode, dentry)); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 471 | |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 472 | out_aff_unlock: |
| 473 | if (affinity) |
| 474 | mutex_unlock(&gang->aff_mutex); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 478 | static int |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 479 | spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 480 | { |
| 481 | int ret; |
| 482 | struct inode *inode; |
| 483 | struct spu_gang *gang; |
| 484 | |
| 485 | ret = -ENOSPC; |
| 486 | inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR); |
| 487 | if (!inode) |
| 488 | goto out; |
| 489 | |
| 490 | ret = 0; |
| 491 | if (dir->i_mode & S_ISGID) { |
| 492 | inode->i_gid = dir->i_gid; |
| 493 | inode->i_mode &= S_ISGID; |
| 494 | } |
| 495 | gang = alloc_spu_gang(); |
| 496 | SPUFS_I(inode)->i_ctx = NULL; |
| 497 | SPUFS_I(inode)->i_gang = gang; |
| 498 | if (!gang) |
| 499 | goto out_iput; |
| 500 | |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 501 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 502 | inode->i_fop = &simple_dir_operations; |
| 503 | |
| 504 | d_instantiate(dentry, inode); |
Jeremy Kerr | ba0b996 | 2008-10-09 10:39:21 +1100 | [diff] [blame] | 505 | inc_nlink(dir); |
| 506 | inc_nlink(dentry->d_inode); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 507 | return ret; |
| 508 | |
| 509 | out_iput: |
| 510 | iput(inode); |
| 511 | out: |
| 512 | return ret; |
| 513 | } |
| 514 | |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 515 | static int spufs_gang_open(struct path *path) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 516 | { |
| 517 | int ret; |
| 518 | struct file *filp; |
| 519 | |
| 520 | ret = get_unused_fd(); |
Al Viro | bf349a4 | 2012-06-25 11:46:13 +0400 | [diff] [blame] | 521 | if (ret < 0) |
| 522 | return ret; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 523 | |
Al Viro | bf349a4 | 2012-06-25 11:46:13 +0400 | [diff] [blame] | 524 | /* |
| 525 | * get references for dget and mntget, will be released |
| 526 | * in error path of *_open(). |
| 527 | */ |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 528 | filp = dentry_open(path, O_RDONLY, current_cred()); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 529 | if (IS_ERR(filp)) { |
| 530 | put_unused_fd(ret); |
Al Viro | bf349a4 | 2012-06-25 11:46:13 +0400 | [diff] [blame] | 531 | return PTR_ERR(filp); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Jeremy Kerr | 877907d | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 534 | filp->f_op = &simple_dir_operations; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 535 | fd_install(ret, filp); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 536 | return ret; |
| 537 | } |
| 538 | |
| 539 | static int spufs_create_gang(struct inode *inode, |
| 540 | struct dentry *dentry, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 541 | struct vfsmount *mnt, umode_t mode) |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 542 | { |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 543 | struct path path = {.mnt = mnt, .dentry = dentry}; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 544 | int ret; |
| 545 | |
| 546 | ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO); |
Al Viro | 1ba44cc | 2012-07-19 16:12:22 +0400 | [diff] [blame] | 547 | if (!ret) { |
| 548 | ret = spufs_gang_open(&path); |
| 549 | if (ret < 0) { |
| 550 | int err = simple_rmdir(inode, dentry); |
| 551 | WARN_ON(err); |
| 552 | } |
Jeremy Kerr | 877907d | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 553 | } |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | |
Arnd Bergmann | 346f4d3 | 2006-01-04 20:31:26 +0100 | [diff] [blame] | 558 | static struct file_system_type spufs_type; |
| 559 | |
Al Viro | 1ba1068 | 2011-06-26 11:54:58 -0400 | [diff] [blame] | 560 | long spufs_create(struct path *path, struct dentry *dentry, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 561 | unsigned int flags, umode_t mode, struct file *filp) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 562 | { |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 563 | struct inode *dir = path->dentry->d_inode; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 564 | int ret; |
| 565 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 566 | /* check if we are on spufs */ |
Al Viro | 1ba1068 | 2011-06-26 11:54:58 -0400 | [diff] [blame] | 567 | if (path->dentry->d_sb->s_type != &spufs_type) |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 568 | return -EINVAL; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 569 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 570 | /* don't accept undefined flags */ |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 571 | if (flags & (~SPU_CREATE_FLAG_ALL)) |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 572 | return -EINVAL; |
arnd@arndb.de | c983294 | 2006-06-19 20:33:34 +0200 | [diff] [blame] | 573 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 574 | /* only threads can be underneath a gang */ |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 575 | if (path->dentry != path->dentry->d_sb->s_root) |
| 576 | if ((flags & SPU_CREATE_GANG) || !SPUFS_I(dir)->i_gang) |
| 577 | return -EINVAL; |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 578 | |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 579 | mode &= ~current_umask(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 580 | |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 581 | if (flags & SPU_CREATE_GANG) |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 582 | ret = spufs_create_gang(dir, dentry, path->mnt, mode); |
Arnd Bergmann | 6263203 | 2006-10-04 17:26:15 +0200 | [diff] [blame] | 583 | else |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 584 | ret = spufs_create_context(dir, dentry, path->mnt, flags, mode, |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 585 | filp); |
Christoph Hellwig | 826be06 | 2008-05-06 09:24:24 +1000 | [diff] [blame] | 586 | if (ret >= 0) |
Al Viro | 25b2692 | 2012-07-19 16:23:13 +0400 | [diff] [blame] | 587 | fsnotify_mkdir(dir, dentry); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 588 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 589 | return ret; |
| 590 | } |
| 591 | |
| 592 | /* File system initialization */ |
| 593 | enum { |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 594 | Opt_uid, Opt_gid, Opt_mode, Opt_debug, Opt_err, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 595 | }; |
| 596 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 597 | static const match_table_t spufs_tokens = { |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 598 | { Opt_uid, "uid=%d" }, |
| 599 | { Opt_gid, "gid=%d" }, |
| 600 | { Opt_mode, "mode=%o" }, |
| 601 | { Opt_debug, "debug" }, |
| 602 | { Opt_err, NULL }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | static int |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 606 | spufs_parse_options(struct super_block *sb, char *options, struct inode *root) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 607 | { |
| 608 | char *p; |
| 609 | substring_t args[MAX_OPT_ARGS]; |
| 610 | |
| 611 | while ((p = strsep(&options, ",")) != NULL) { |
| 612 | int token, option; |
| 613 | |
| 614 | if (!*p) |
| 615 | continue; |
| 616 | |
| 617 | token = match_token(p, spufs_tokens, args); |
| 618 | switch (token) { |
| 619 | case Opt_uid: |
| 620 | if (match_int(&args[0], &option)) |
| 621 | return 0; |
| 622 | root->i_uid = option; |
| 623 | break; |
| 624 | case Opt_gid: |
| 625 | if (match_int(&args[0], &option)) |
| 626 | return 0; |
| 627 | root->i_gid = option; |
| 628 | break; |
Jeremy Kerr | f11f5ee | 2007-04-23 21:08:23 +0200 | [diff] [blame] | 629 | case Opt_mode: |
| 630 | if (match_octal(&args[0], &option)) |
| 631 | return 0; |
| 632 | root->i_mode = option | S_IFDIR; |
| 633 | break; |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 634 | case Opt_debug: |
| 635 | spufs_get_sb_info(sb)->debug = 1; |
| 636 | break; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 637 | default: |
| 638 | return 0; |
| 639 | } |
| 640 | } |
| 641 | return 1; |
| 642 | } |
| 643 | |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 644 | static void spufs_exit_isolated_loader(void) |
| 645 | { |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 646 | free_pages((unsigned long) isolated_loader, |
| 647 | get_order(isolated_loader_size)); |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 648 | } |
| 649 | |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 650 | static void |
| 651 | spufs_init_isolated_loader(void) |
| 652 | { |
| 653 | struct device_node *dn; |
| 654 | const char *loader; |
| 655 | int size; |
| 656 | |
| 657 | dn = of_find_node_by_path("/spu-isolation"); |
| 658 | if (!dn) |
| 659 | return; |
| 660 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 661 | loader = of_get_property(dn, "loader", &size); |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 662 | if (!loader) |
| 663 | return; |
| 664 | |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 665 | /* the loader must be align on a 16 byte boundary */ |
| 666 | isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size)); |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 667 | if (!isolated_loader) |
| 668 | return; |
| 669 | |
Sebastian Siewior | 8b0d312 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 670 | isolated_loader_size = size; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 671 | memcpy(isolated_loader, loader, size); |
| 672 | printk(KERN_INFO "spufs: SPU isolation mode enabled\n"); |
| 673 | } |
| 674 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 675 | static int |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 676 | spufs_create_root(struct super_block *sb, void *data) |
| 677 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 678 | struct inode *inode; |
| 679 | int ret; |
| 680 | |
Arnd Bergmann | 8f18a15 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 681 | ret = -ENODEV; |
| 682 | if (!spu_management_ops) |
| 683 | goto out; |
| 684 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 685 | ret = -ENOMEM; |
| 686 | inode = spufs_new_inode(sb, S_IFDIR | 0775); |
| 687 | if (!inode) |
| 688 | goto out; |
| 689 | |
Jeremy Kerr | b8c295f | 2007-06-29 10:57:59 +1000 | [diff] [blame] | 690 | inode->i_op = &simple_dir_inode_operations; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 691 | inode->i_fop = &simple_dir_operations; |
| 692 | SPUFS_I(inode)->i_ctx = NULL; |
Jeremy Kerr | e2ed6e4 | 2008-10-07 18:26:55 +1100 | [diff] [blame] | 693 | inc_nlink(inode); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 694 | |
| 695 | ret = -EINVAL; |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 696 | if (!spufs_parse_options(sb, data, inode)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 697 | goto out_iput; |
| 698 | |
| 699 | ret = -ENOMEM; |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 700 | sb->s_root = d_make_root(inode); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 701 | if (!sb->s_root) |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 702 | goto out; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 703 | |
| 704 | return 0; |
| 705 | out_iput: |
| 706 | iput(inode); |
| 707 | out: |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | static int |
| 712 | spufs_fill_super(struct super_block *sb, void *data, int silent) |
| 713 | { |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 714 | struct spufs_sb_info *info; |
Alexey Dobriyan | b87221d | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 715 | static const struct super_operations s_ops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 716 | .alloc_inode = spufs_alloc_inode, |
| 717 | .destroy_inode = spufs_destroy_inode, |
| 718 | .statfs = simple_statfs, |
Al Viro | 0f3f63a | 2010-06-05 21:20:32 -0400 | [diff] [blame] | 719 | .evict_inode = spufs_evict_inode, |
Miklos Szeredi | 90d09e1 | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 720 | .show_options = generic_show_options, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 721 | }; |
| 722 | |
Miklos Szeredi | 90d09e1 | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 723 | save_mount_options(sb, data); |
| 724 | |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 725 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 726 | if (!info) |
| 727 | return -ENOMEM; |
| 728 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 729 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 730 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 731 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 732 | sb->s_magic = SPUFS_MAGIC; |
| 733 | sb->s_op = &s_ops; |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 734 | sb->s_fs_info = info; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 735 | |
| 736 | return spufs_create_root(sb, data); |
| 737 | } |
| 738 | |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 739 | static struct dentry * |
| 740 | spufs_mount(struct file_system_type *fstype, int flags, |
| 741 | const char *name, void *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 742 | { |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 743 | return mount_single(fstype, flags, data, spufs_fill_super); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static struct file_system_type spufs_type = { |
| 747 | .owner = THIS_MODULE, |
| 748 | .name = "spufs", |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 749 | .mount = spufs_mount, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 750 | .kill_sb = kill_litter_super, |
| 751 | }; |
| 752 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 753 | static int __init spufs_init(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 754 | { |
| 755 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 756 | |
Jeremy Kerr | ccf17e9 | 2007-04-23 21:08:29 +0200 | [diff] [blame] | 757 | ret = -ENODEV; |
| 758 | if (!spu_management_ops) |
| 759 | goto out; |
| 760 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 761 | ret = -ENOMEM; |
| 762 | spufs_inode_cache = kmem_cache_create("spufs_inode_cache", |
| 763 | sizeof(struct spufs_inode_info), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 764 | SLAB_HWCACHE_ALIGN, spufs_init_once); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 765 | |
| 766 | if (!spufs_inode_cache) |
| 767 | goto out; |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 768 | ret = spu_sched_init(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 769 | if (ret) |
| 770 | goto out_cache; |
| 771 | ret = register_spu_syscalls(&spufs_calls); |
| 772 | if (ret) |
Al Viro | 640045a | 2012-03-17 01:37:51 -0400 | [diff] [blame] | 773 | goto out_sched; |
| 774 | ret = register_filesystem(&spufs_type); |
| 775 | if (ret) |
| 776 | goto out_syscalls; |
arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 777 | |
| 778 | spufs_init_isolated_loader(); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 779 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 780 | return 0; |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 781 | |
Al Viro | 640045a | 2012-03-17 01:37:51 -0400 | [diff] [blame] | 782 | out_syscalls: |
| 783 | unregister_spu_syscalls(&spufs_calls); |
Akinobu Mita | c99c199 | 2007-04-23 21:08:19 +0200 | [diff] [blame] | 784 | out_sched: |
| 785 | spu_sched_exit(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 786 | out_cache: |
| 787 | kmem_cache_destroy(spufs_inode_cache); |
| 788 | out: |
| 789 | return ret; |
| 790 | } |
| 791 | module_init(spufs_init); |
| 792 | |
Arnd Bergmann | e78b47a | 2006-03-27 21:27:40 +0200 | [diff] [blame] | 793 | static void __exit spufs_exit(void) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 794 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 795 | spu_sched_exit(); |
Akinobu Mita | db1384b40 | 2007-04-23 21:08:20 +0200 | [diff] [blame] | 796 | spufs_exit_isolated_loader(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 797 | unregister_spu_syscalls(&spufs_calls); |
| 798 | unregister_filesystem(&spufs_type); |
| 799 | kmem_cache_destroy(spufs_inode_cache); |
| 800 | } |
| 801 | module_exit(spufs_exit); |
| 802 | |
| 803 | MODULE_LICENSE("GPL"); |
| 804 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |
| 805 | |