David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* AFS superblock handling |
| 2 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002, 2007 Red Hat, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software may be freely redistributed under the terms of the |
| 6 | * GNU General Public License. |
| 7 | * |
| 8 | * You should have received a copy of the GNU General Public License |
| 9 | * along with this program; if not, write to the Free Software |
| 10 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 11 | * |
| 12 | * Authors: David Howells <dhowells@redhat.com> |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 13 | * David Woodhouse <dwmw2@redhat.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/pagemap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "internal.h" |
| 24 | |
| 25 | #define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */ |
| 26 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 27 | static void afs_i_init_once(void *foo, struct kmem_cache *cachep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | unsigned long flags); |
| 29 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 30 | static int afs_get_sb(struct file_system_type *fs_type, |
| 31 | int flags, const char *dev_name, |
| 32 | void *data, struct vfsmount *mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | static struct inode *afs_alloc_inode(struct super_block *sb); |
| 35 | |
| 36 | static void afs_put_super(struct super_block *sb); |
| 37 | |
| 38 | static void afs_destroy_inode(struct inode *inode); |
| 39 | |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 40 | struct file_system_type afs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | .owner = THIS_MODULE, |
| 42 | .name = "afs", |
| 43 | .get_sb = afs_get_sb, |
| 44 | .kill_sb = kill_anon_super, |
| 45 | .fs_flags = FS_BINARY_MOUNTDATA, |
| 46 | }; |
| 47 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 48 | static const struct super_operations afs_super_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | .statfs = simple_statfs, |
| 50 | .alloc_inode = afs_alloc_inode, |
| 51 | .drop_inode = generic_delete_inode, |
| 52 | .destroy_inode = afs_destroy_inode, |
| 53 | .clear_inode = afs_clear_inode, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | .umount_begin = afs_umount_begin, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .put_super = afs_put_super, |
| 56 | }; |
| 57 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 58 | static struct kmem_cache *afs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static atomic_t afs_count_active_inodes; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 62 | * initialise the filesystem |
| 63 | */ |
| 64 | int __init afs_fs_init(void) |
| 65 | { |
| 66 | int ret; |
| 67 | |
| 68 | _enter(""); |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* create ourselves an inode cache */ |
| 71 | atomic_set(&afs_count_active_inodes, 0); |
| 72 | |
| 73 | ret = -ENOMEM; |
| 74 | afs_inode_cachep = kmem_cache_create("afs_inode_cache", |
| 75 | sizeof(struct afs_vnode), |
| 76 | 0, |
| 77 | SLAB_HWCACHE_ALIGN, |
| 78 | afs_i_init_once, |
| 79 | NULL); |
| 80 | if (!afs_inode_cachep) { |
| 81 | printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n"); |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | /* now export our filesystem to lesser mortals */ |
| 86 | ret = register_filesystem(&afs_fs_type); |
| 87 | if (ret < 0) { |
| 88 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 89 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return ret; |
| 91 | } |
| 92 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 93 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* |
| 98 | * clean up the filesystem |
| 99 | */ |
| 100 | void __exit afs_fs_exit(void) |
| 101 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 102 | _enter(""); |
| 103 | |
| 104 | afs_mntpt_kill_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | unregister_filesystem(&afs_fs_type); |
| 106 | |
| 107 | if (atomic_read(&afs_count_active_inodes) != 0) { |
| 108 | printk("kAFS: %d active inode objects still present\n", |
| 109 | atomic_read(&afs_count_active_inodes)); |
| 110 | BUG(); |
| 111 | } |
| 112 | |
| 113 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 114 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* |
| 118 | * check that an argument has a value |
| 119 | */ |
| 120 | static int want_arg(char **_value, const char *option) |
| 121 | { |
| 122 | if (!_value || !*_value || !**_value) { |
| 123 | printk(KERN_NOTICE "kAFS: %s: argument missing\n", option); |
| 124 | return 0; |
| 125 | } |
| 126 | return 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * check that there's no subsequent value |
| 131 | */ |
| 132 | static int want_no_value(char *const *_value, const char *option) |
| 133 | { |
| 134 | if (*_value && **_value) { |
| 135 | printk(KERN_NOTICE "kAFS: %s: Invalid argument: %s\n", |
| 136 | option, *_value); |
| 137 | return 0; |
| 138 | } |
| 139 | return 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* |
| 143 | * parse the mount options |
| 144 | * - this function has been shamelessly adapted from the ext3 fs which |
| 145 | * shamelessly adapted it from the msdos fs |
| 146 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 147 | static int afs_parse_options(struct afs_mount_params *params, |
| 148 | char *options, const char **devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 150 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | char *key, *value; |
| 152 | int ret; |
| 153 | |
| 154 | _enter("%s", options); |
| 155 | |
| 156 | options[PAGE_SIZE - 1] = 0; |
| 157 | |
| 158 | ret = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 159 | while ((key = strsep(&options, ","))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | value = strchr(key, '='); |
| 161 | if (value) |
| 162 | *value++ = 0; |
| 163 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 164 | _debug("kAFS: KEY: %s, VAL:%s", key, value ?: "-"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | if (strcmp(key, "rwpath") == 0) { |
| 167 | if (!want_no_value(&value, "rwpath")) |
| 168 | return -EINVAL; |
| 169 | params->rwpath = 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 170 | } else if (strcmp(key, "vol") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | if (!want_arg(&value, "vol")) |
| 172 | return -EINVAL; |
| 173 | *devname = value; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 174 | } else if (strcmp(key, "cell") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (!want_arg(&value, "cell")) |
| 176 | return -EINVAL; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 177 | cell = afs_cell_lookup(value, strlen(value)); |
| 178 | if (IS_ERR(cell)) |
| 179 | return PTR_ERR(cell); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 180 | afs_put_cell(params->cell); |
| 181 | params->cell = cell; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 182 | } else { |
| 183 | printk("kAFS: Unknown mount option: '%s'\n", key); |
| 184 | ret = -EINVAL; |
| 185 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | ret = 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 190 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | _leave(" = %d", ret); |
| 192 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /* |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 196 | * parse a device name to get cell name, volume name, volume type and R/W |
| 197 | * selector |
| 198 | * - this can be one of the following: |
| 199 | * "%[cell:]volume[.]" R/W volume |
| 200 | * "#[cell:]volume[.]" R/O or R/W volume (rwpath=0), |
| 201 | * or R/W (rwpath=1) volume |
| 202 | * "%[cell:]volume.readonly" R/O volume |
| 203 | * "#[cell:]volume.readonly" R/O volume |
| 204 | * "%[cell:]volume.backup" Backup volume |
| 205 | * "#[cell:]volume.backup" Backup volume |
| 206 | */ |
| 207 | static int afs_parse_device_name(struct afs_mount_params *params, |
| 208 | const char *name) |
| 209 | { |
| 210 | struct afs_cell *cell; |
| 211 | const char *cellname, *suffix; |
| 212 | int cellnamesz; |
| 213 | |
| 214 | _enter(",%s", name); |
| 215 | |
| 216 | if (!name) { |
| 217 | printk(KERN_ERR "kAFS: no volume name specified\n"); |
| 218 | return -EINVAL; |
| 219 | } |
| 220 | |
| 221 | if ((name[0] != '%' && name[0] != '#') || !name[1]) { |
| 222 | printk(KERN_ERR "kAFS: unparsable volume name\n"); |
| 223 | return -EINVAL; |
| 224 | } |
| 225 | |
| 226 | /* determine the type of volume we're looking for */ |
| 227 | params->type = AFSVL_ROVOL; |
| 228 | params->force = false; |
| 229 | if (params->rwpath || name[0] == '%') { |
| 230 | params->type = AFSVL_RWVOL; |
| 231 | params->force = true; |
| 232 | } |
| 233 | name++; |
| 234 | |
| 235 | /* split the cell name out if there is one */ |
| 236 | params->volname = strchr(name, ':'); |
| 237 | if (params->volname) { |
| 238 | cellname = name; |
| 239 | cellnamesz = params->volname - name; |
| 240 | params->volname++; |
| 241 | } else { |
| 242 | params->volname = name; |
| 243 | cellname = NULL; |
| 244 | cellnamesz = 0; |
| 245 | } |
| 246 | |
| 247 | /* the volume type is further affected by a possible suffix */ |
| 248 | suffix = strrchr(params->volname, '.'); |
| 249 | if (suffix) { |
| 250 | if (strcmp(suffix, ".readonly") == 0) { |
| 251 | params->type = AFSVL_ROVOL; |
| 252 | params->force = true; |
| 253 | } else if (strcmp(suffix, ".backup") == 0) { |
| 254 | params->type = AFSVL_BACKVOL; |
| 255 | params->force = true; |
| 256 | } else if (suffix[1] == 0) { |
| 257 | } else { |
| 258 | suffix = NULL; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | params->volnamesz = suffix ? |
| 263 | suffix - params->volname : strlen(params->volname); |
| 264 | |
| 265 | _debug("cell %*.*s [%p]", |
| 266 | cellnamesz, cellnamesz, cellname ?: "", params->cell); |
| 267 | |
| 268 | /* lookup the cell record */ |
| 269 | if (cellname || !params->cell) { |
| 270 | cell = afs_cell_lookup(cellname, cellnamesz); |
| 271 | if (IS_ERR(cell)) { |
| 272 | printk(KERN_ERR "kAFS: unable to lookup cell '%s'\n", |
| 273 | cellname ?: ""); |
| 274 | return PTR_ERR(cell); |
| 275 | } |
| 276 | afs_put_cell(params->cell); |
| 277 | params->cell = cell; |
| 278 | } |
| 279 | |
| 280 | _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s", |
| 281 | params->cell->name, params->cell, |
| 282 | params->volnamesz, params->volnamesz, params->volname, |
| 283 | suffix ?: "-", params->type, params->force ? " FORCE" : ""); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * check a superblock to see if it's the one we're looking for |
| 290 | */ |
| 291 | static int afs_test_super(struct super_block *sb, void *data) |
| 292 | { |
| 293 | struct afs_mount_params *params = data; |
| 294 | struct afs_super_info *as = sb->s_fs_info; |
| 295 | |
| 296 | return as->volume == params->volume; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * fill in the superblock |
| 301 | */ |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 302 | static int afs_fill_super(struct super_block *sb, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | struct afs_mount_params *params = data; |
| 305 | struct afs_super_info *as = NULL; |
| 306 | struct afs_fid fid; |
| 307 | struct dentry *root = NULL; |
| 308 | struct inode *inode = NULL; |
| 309 | int ret; |
| 310 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 311 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | /* allocate a superblock info record */ |
Yan Burman | b593e48 | 2006-12-06 20:40:32 -0800 | [diff] [blame] | 314 | as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (!as) { |
| 316 | _leave(" = -ENOMEM"); |
| 317 | return -ENOMEM; |
| 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | afs_get_volume(params->volume); |
| 321 | as->volume = params->volume; |
| 322 | |
| 323 | /* fill in the superblock */ |
| 324 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 325 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 326 | sb->s_magic = AFS_FS_MAGIC; |
| 327 | sb->s_op = &afs_super_ops; |
| 328 | sb->s_fs_info = as; |
| 329 | |
| 330 | /* allocate the root inode and dentry */ |
| 331 | fid.vid = as->volume->vid; |
| 332 | fid.vnode = 1; |
| 333 | fid.unique = 1; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 334 | inode = afs_iget(sb, params->key, &fid); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 335 | if (IS_ERR(inode)) |
| 336 | goto error_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | ret = -ENOMEM; |
| 339 | root = d_alloc_root(inode); |
| 340 | if (!root) |
| 341 | goto error; |
| 342 | |
| 343 | sb->s_root = root; |
| 344 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 345 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return 0; |
| 347 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 348 | error_inode: |
| 349 | ret = PTR_ERR(inode); |
| 350 | inode = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 351 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | iput(inode); |
| 353 | afs_put_volume(as->volume); |
| 354 | kfree(as); |
| 355 | |
| 356 | sb->s_fs_info = NULL; |
| 357 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 358 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* |
| 363 | * get an AFS superblock |
| 364 | * - TODO: don't use get_sb_nodev(), but rather call sget() directly |
| 365 | */ |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 366 | static int afs_get_sb(struct file_system_type *fs_type, |
| 367 | int flags, |
| 368 | const char *dev_name, |
| 369 | void *options, |
| 370 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | struct afs_mount_params params; |
| 373 | struct super_block *sb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 374 | struct afs_volume *vol; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 375 | struct key *key; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | int ret; |
| 377 | |
| 378 | _enter(",,%s,%p", dev_name, options); |
| 379 | |
| 380 | memset(¶ms, 0, sizeof(params)); |
| 381 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 382 | /* parse the options and device name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (options) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 384 | ret = afs_parse_options(¶ms, options, &dev_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (ret < 0) |
| 386 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 389 | |
| 390 | ret = afs_parse_device_name(¶ms, dev_name); |
| 391 | if (ret < 0) |
| 392 | goto error; |
| 393 | |
| 394 | /* try and do the mount securely */ |
| 395 | key = afs_request_key(params.cell); |
| 396 | if (IS_ERR(key)) { |
| 397 | _leave(" = %ld [key]", PTR_ERR(key)); |
| 398 | ret = PTR_ERR(key); |
| 399 | goto error; |
| 400 | } |
| 401 | params.key = key; |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | /* parse the device name */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 404 | vol = afs_volume_lookup(¶ms); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 405 | if (IS_ERR(vol)) { |
| 406 | ret = PTR_ERR(vol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 408 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 409 | params.volume = vol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* allocate a deviceless superblock */ |
| 412 | sb = sget(fs_type, afs_test_super, set_anon_super, ¶ms); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 413 | if (IS_ERR(sb)) { |
| 414 | ret = PTR_ERR(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 418 | if (!sb->s_root) { |
| 419 | /* initial superblock/root creation */ |
| 420 | _debug("create"); |
| 421 | sb->s_flags = flags; |
| 422 | ret = afs_fill_super(sb, ¶ms); |
| 423 | if (ret < 0) { |
| 424 | up_write(&sb->s_umount); |
| 425 | deactivate_super(sb); |
| 426 | goto error; |
| 427 | } |
| 428 | sb->s_flags |= MS_ACTIVE; |
| 429 | } else { |
| 430 | _debug("reuse"); |
| 431 | ASSERTCMP(sb->s_flags, &, MS_ACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 434 | simple_set_mnt(mnt, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | afs_put_volume(params.volume); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 436 | afs_put_cell(params.cell); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 437 | _leave(" = 0 [%p]", sb); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 438 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 440 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | afs_put_volume(params.volume); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 442 | afs_put_cell(params.cell); |
| 443 | key_put(params.key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | _leave(" = %d", ret); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 445 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* |
| 449 | * finish the unmounting process on the superblock |
| 450 | */ |
| 451 | static void afs_put_super(struct super_block *sb) |
| 452 | { |
| 453 | struct afs_super_info *as = sb->s_fs_info; |
| 454 | |
| 455 | _enter(""); |
| 456 | |
| 457 | afs_put_volume(as->volume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | /* |
| 463 | * initialise an inode cache slab element prior to any use |
| 464 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 465 | static void afs_i_init_once(void *_vnode, struct kmem_cache *cachep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | unsigned long flags) |
| 467 | { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 468 | struct afs_vnode *vnode = _vnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 471 | SLAB_CTOR_CONSTRUCTOR) { |
| 472 | memset(vnode, 0, sizeof(*vnode)); |
| 473 | inode_init_once(&vnode->vfs_inode); |
| 474 | init_waitqueue_head(&vnode->update_waitq); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame^] | 475 | mutex_init(&vnode->permits_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | spin_lock_init(&vnode->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 477 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); |
| 478 | mutex_init(&vnode->cb_broken_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* |
| 483 | * allocate an AFS inode struct from our slab cache |
| 484 | */ |
| 485 | static struct inode *afs_alloc_inode(struct super_block *sb) |
| 486 | { |
| 487 | struct afs_vnode *vnode; |
| 488 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 489 | vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (!vnode) |
| 491 | return NULL; |
| 492 | |
| 493 | atomic_inc(&afs_count_active_inodes); |
| 494 | |
| 495 | memset(&vnode->fid, 0, sizeof(vnode->fid)); |
| 496 | memset(&vnode->status, 0, sizeof(vnode->status)); |
| 497 | |
| 498 | vnode->volume = NULL; |
| 499 | vnode->update_cnt = 0; |
| 500 | vnode->flags = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 501 | vnode->cb_promised = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | return &vnode->vfs_inode; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | /* |
| 507 | * destroy an AFS inode struct |
| 508 | */ |
| 509 | static void afs_destroy_inode(struct inode *inode) |
| 510 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 511 | struct afs_vnode *vnode = AFS_FS_I(inode); |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | _enter("{%lu}", inode->i_ino); |
| 514 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 515 | _debug("DESTROY INODE %p", inode); |
| 516 | |
| 517 | ASSERTCMP(vnode->server, ==, NULL); |
| 518 | |
| 519 | kmem_cache_free(afs_inode_cachep, vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | atomic_dec(&afs_count_active_inodes); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 521 | } |