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 | |
| 27 | struct afs_mount_params { |
| 28 | int rwpath; |
| 29 | struct afs_cell *default_cell; |
| 30 | struct afs_volume *volume; |
| 31 | }; |
| 32 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 33 | static void afs_i_init_once(void *foo, struct kmem_cache *cachep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | unsigned long flags); |
| 35 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 36 | static int afs_get_sb(struct file_system_type *fs_type, |
| 37 | int flags, const char *dev_name, |
| 38 | void *data, struct vfsmount *mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | static struct inode *afs_alloc_inode(struct super_block *sb); |
| 41 | |
| 42 | static void afs_put_super(struct super_block *sb); |
| 43 | |
| 44 | static void afs_destroy_inode(struct inode *inode); |
| 45 | |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 46 | struct file_system_type afs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | .owner = THIS_MODULE, |
| 48 | .name = "afs", |
| 49 | .get_sb = afs_get_sb, |
| 50 | .kill_sb = kill_anon_super, |
| 51 | .fs_flags = FS_BINARY_MOUNTDATA, |
| 52 | }; |
| 53 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 54 | static const struct super_operations afs_super_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .statfs = simple_statfs, |
| 56 | .alloc_inode = afs_alloc_inode, |
| 57 | .drop_inode = generic_delete_inode, |
| 58 | .destroy_inode = afs_destroy_inode, |
| 59 | .clear_inode = afs_clear_inode, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 60 | .umount_begin = afs_umount_begin, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | .put_super = afs_put_super, |
| 62 | }; |
| 63 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 64 | static struct kmem_cache *afs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static atomic_t afs_count_active_inodes; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * initialise the filesystem |
| 69 | */ |
| 70 | int __init afs_fs_init(void) |
| 71 | { |
| 72 | int ret; |
| 73 | |
| 74 | _enter(""); |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* create ourselves an inode cache */ |
| 77 | atomic_set(&afs_count_active_inodes, 0); |
| 78 | |
| 79 | ret = -ENOMEM; |
| 80 | afs_inode_cachep = kmem_cache_create("afs_inode_cache", |
| 81 | sizeof(struct afs_vnode), |
| 82 | 0, |
| 83 | SLAB_HWCACHE_ALIGN, |
| 84 | afs_i_init_once, |
| 85 | NULL); |
| 86 | if (!afs_inode_cachep) { |
| 87 | printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n"); |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | /* now export our filesystem to lesser mortals */ |
| 92 | ret = register_filesystem(&afs_fs_type); |
| 93 | if (ret < 0) { |
| 94 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 95 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return ret; |
| 97 | } |
| 98 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 99 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* |
| 104 | * clean up the filesystem |
| 105 | */ |
| 106 | void __exit afs_fs_exit(void) |
| 107 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 108 | _enter(""); |
| 109 | |
| 110 | afs_mntpt_kill_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | unregister_filesystem(&afs_fs_type); |
| 112 | |
| 113 | if (atomic_read(&afs_count_active_inodes) != 0) { |
| 114 | printk("kAFS: %d active inode objects still present\n", |
| 115 | atomic_read(&afs_count_active_inodes)); |
| 116 | BUG(); |
| 117 | } |
| 118 | |
| 119 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 120 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * check that an argument has a value |
| 125 | */ |
| 126 | static int want_arg(char **_value, const char *option) |
| 127 | { |
| 128 | if (!_value || !*_value || !**_value) { |
| 129 | printk(KERN_NOTICE "kAFS: %s: argument missing\n", option); |
| 130 | return 0; |
| 131 | } |
| 132 | return 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* |
| 136 | * check that there's no subsequent value |
| 137 | */ |
| 138 | static int want_no_value(char *const *_value, const char *option) |
| 139 | { |
| 140 | if (*_value && **_value) { |
| 141 | printk(KERN_NOTICE "kAFS: %s: Invalid argument: %s\n", |
| 142 | option, *_value); |
| 143 | return 0; |
| 144 | } |
| 145 | return 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /* |
| 149 | * parse the mount options |
| 150 | * - this function has been shamelessly adapted from the ext3 fs which |
| 151 | * shamelessly adapted it from the msdos fs |
| 152 | */ |
| 153 | static int afs_super_parse_options(struct afs_mount_params *params, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 154 | char *options, const char **devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 156 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | char *key, *value; |
| 158 | int ret; |
| 159 | |
| 160 | _enter("%s", options); |
| 161 | |
| 162 | options[PAGE_SIZE - 1] = 0; |
| 163 | |
| 164 | ret = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 165 | while ((key = strsep(&options, ","))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | value = strchr(key, '='); |
| 167 | if (value) |
| 168 | *value++ = 0; |
| 169 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 170 | _debug("kAFS: KEY: %s, VAL:%s", key, value ?: "-"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | if (strcmp(key, "rwpath") == 0) { |
| 173 | if (!want_no_value(&value, "rwpath")) |
| 174 | return -EINVAL; |
| 175 | params->rwpath = 1; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 176 | } else if (strcmp(key, "vol") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (!want_arg(&value, "vol")) |
| 178 | return -EINVAL; |
| 179 | *devname = value; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 180 | } else if (strcmp(key, "cell") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (!want_arg(&value, "cell")) |
| 182 | return -EINVAL; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 183 | cell = afs_cell_lookup(value, strlen(value)); |
| 184 | if (IS_ERR(cell)) |
| 185 | return PTR_ERR(cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | afs_put_cell(params->default_cell); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 187 | params->default_cell = cell; |
| 188 | } else { |
| 189 | printk("kAFS: Unknown mount option: '%s'\n", key); |
| 190 | ret = -EINVAL; |
| 191 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | ret = 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 196 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | _leave(" = %d", ret); |
| 198 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* |
| 202 | * check a superblock to see if it's the one we're looking for |
| 203 | */ |
| 204 | static int afs_test_super(struct super_block *sb, void *data) |
| 205 | { |
| 206 | struct afs_mount_params *params = data; |
| 207 | struct afs_super_info *as = sb->s_fs_info; |
| 208 | |
| 209 | return as->volume == params->volume; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* |
| 213 | * fill in the superblock |
| 214 | */ |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame^] | 215 | static int afs_fill_super(struct super_block *sb, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | struct afs_mount_params *params = data; |
| 218 | struct afs_super_info *as = NULL; |
| 219 | struct afs_fid fid; |
| 220 | struct dentry *root = NULL; |
| 221 | struct inode *inode = NULL; |
| 222 | int ret; |
| 223 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 224 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* allocate a superblock info record */ |
Yan Burman | b593e48 | 2006-12-06 20:40:32 -0800 | [diff] [blame] | 227 | as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (!as) { |
| 229 | _leave(" = -ENOMEM"); |
| 230 | return -ENOMEM; |
| 231 | } |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | afs_get_volume(params->volume); |
| 234 | as->volume = params->volume; |
| 235 | |
| 236 | /* fill in the superblock */ |
| 237 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 238 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 239 | sb->s_magic = AFS_FS_MAGIC; |
| 240 | sb->s_op = &afs_super_ops; |
| 241 | sb->s_fs_info = as; |
| 242 | |
| 243 | /* allocate the root inode and dentry */ |
| 244 | fid.vid = as->volume->vid; |
| 245 | fid.vnode = 1; |
| 246 | fid.unique = 1; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 247 | inode = afs_iget(sb, &fid); |
| 248 | if (IS_ERR(inode)) |
| 249 | goto error_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | ret = -ENOMEM; |
| 252 | root = d_alloc_root(inode); |
| 253 | if (!root) |
| 254 | goto error; |
| 255 | |
| 256 | sb->s_root = root; |
| 257 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 258 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | return 0; |
| 260 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 261 | error_inode: |
| 262 | ret = PTR_ERR(inode); |
| 263 | inode = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 264 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | iput(inode); |
| 266 | afs_put_volume(as->volume); |
| 267 | kfree(as); |
| 268 | |
| 269 | sb->s_fs_info = NULL; |
| 270 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 271 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* |
| 276 | * get an AFS superblock |
| 277 | * - TODO: don't use get_sb_nodev(), but rather call sget() directly |
| 278 | */ |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 279 | static int afs_get_sb(struct file_system_type *fs_type, |
| 280 | int flags, |
| 281 | const char *dev_name, |
| 282 | void *options, |
| 283 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
| 285 | struct afs_mount_params params; |
| 286 | struct super_block *sb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 287 | struct afs_volume *vol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | int ret; |
| 289 | |
| 290 | _enter(",,%s,%p", dev_name, options); |
| 291 | |
| 292 | memset(¶ms, 0, sizeof(params)); |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /* parse the options */ |
| 295 | if (options) { |
| 296 | ret = afs_super_parse_options(¶ms, options, &dev_name); |
| 297 | if (ret < 0) |
| 298 | goto error; |
| 299 | if (!dev_name) { |
| 300 | printk("kAFS: no volume name specified\n"); |
| 301 | ret = -EINVAL; |
| 302 | goto error; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /* parse the device name */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 307 | vol = afs_volume_lookup(dev_name, params.default_cell, params.rwpath); |
| 308 | if (IS_ERR(vol)) { |
| 309 | ret = PTR_ERR(vol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | params.volume = vol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | /* allocate a deviceless superblock */ |
| 316 | sb = sget(fs_type, afs_test_super, set_anon_super, ¶ms); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 317 | if (IS_ERR(sb)) { |
| 318 | ret = PTR_ERR(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame^] | 322 | if (!sb->s_root) { |
| 323 | /* initial superblock/root creation */ |
| 324 | _debug("create"); |
| 325 | sb->s_flags = flags; |
| 326 | ret = afs_fill_super(sb, ¶ms); |
| 327 | if (ret < 0) { |
| 328 | up_write(&sb->s_umount); |
| 329 | deactivate_super(sb); |
| 330 | goto error; |
| 331 | } |
| 332 | sb->s_flags |= MS_ACTIVE; |
| 333 | } else { |
| 334 | _debug("reuse"); |
| 335 | ASSERTCMP(sb->s_flags, &, MS_ACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame^] | 338 | simple_set_mnt(mnt, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | afs_put_volume(params.volume); |
| 340 | afs_put_cell(params.default_cell); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 341 | _leave(" = 0 [%p]", sb); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 342 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 344 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | afs_put_volume(params.volume); |
| 346 | afs_put_cell(params.default_cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | _leave(" = %d", ret); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 348 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* |
| 352 | * finish the unmounting process on the superblock |
| 353 | */ |
| 354 | static void afs_put_super(struct super_block *sb) |
| 355 | { |
| 356 | struct afs_super_info *as = sb->s_fs_info; |
| 357 | |
| 358 | _enter(""); |
| 359 | |
| 360 | afs_put_volume(as->volume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | /* |
| 366 | * initialise an inode cache slab element prior to any use |
| 367 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 368 | static void afs_i_init_once(void *_vnode, struct kmem_cache *cachep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | unsigned long flags) |
| 370 | { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 371 | struct afs_vnode *vnode = _vnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 374 | SLAB_CTOR_CONSTRUCTOR) { |
| 375 | memset(vnode, 0, sizeof(*vnode)); |
| 376 | inode_init_once(&vnode->vfs_inode); |
| 377 | init_waitqueue_head(&vnode->update_waitq); |
| 378 | spin_lock_init(&vnode->lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 379 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); |
| 380 | mutex_init(&vnode->cb_broken_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /* |
| 385 | * allocate an AFS inode struct from our slab cache |
| 386 | */ |
| 387 | static struct inode *afs_alloc_inode(struct super_block *sb) |
| 388 | { |
| 389 | struct afs_vnode *vnode; |
| 390 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 391 | vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (!vnode) |
| 393 | return NULL; |
| 394 | |
| 395 | atomic_inc(&afs_count_active_inodes); |
| 396 | |
| 397 | memset(&vnode->fid, 0, sizeof(vnode->fid)); |
| 398 | memset(&vnode->status, 0, sizeof(vnode->status)); |
| 399 | |
| 400 | vnode->volume = NULL; |
| 401 | vnode->update_cnt = 0; |
| 402 | vnode->flags = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 403 | vnode->cb_promised = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | return &vnode->vfs_inode; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* |
| 409 | * destroy an AFS inode struct |
| 410 | */ |
| 411 | static void afs_destroy_inode(struct inode *inode) |
| 412 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 413 | struct afs_vnode *vnode = AFS_FS_I(inode); |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | _enter("{%lu}", inode->i_ino); |
| 416 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 417 | _debug("DESTROY INODE %p", inode); |
| 418 | |
| 419 | ASSERTCMP(vnode->server, ==, NULL); |
| 420 | |
| 421 | kmem_cache_free(afs_inode_cachep, vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | atomic_dec(&afs_count_active_inodes); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 423 | } |