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