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 Woodhouse | 44d1b98 | 2008-06-05 22:46:18 -0700 | [diff] [blame] | 13 | * David Woodhouse <dwmw2@infradead.org> |
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> |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 19 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/fs.h> |
| 23 | #include <linux/pagemap.h> |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 24 | #include <linux/parser.h> |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 25 | #include <linux/statfs.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 26 | #include <linux/sched.h> |
Eric W. Biederman | f74f70f | 2013-01-31 04:23:54 -0800 | [diff] [blame] | 27 | #include <linux/nsproxy.h> |
| 28 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "internal.h" |
| 30 | |
| 31 | #define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */ |
| 32 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 33 | static void afs_i_init_once(void *foo); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 34 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
| 35 | int flags, const char *dev_name, void *data); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 36 | static void afs_kill_super(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static struct inode *afs_alloc_inode(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static void afs_destroy_inode(struct inode *inode); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 39 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame^] | 40 | static int afs_show_devname(struct seq_file *m, struct dentry *root); |
| 41 | static int afs_show_options(struct seq_file *m, struct dentry *root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 43 | struct file_system_type afs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .owner = THIS_MODULE, |
| 45 | .name = "afs", |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 46 | .mount = afs_mount, |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 47 | .kill_sb = afs_kill_super, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 48 | .fs_flags = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 50 | MODULE_ALIAS_FS("afs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 52 | static const struct super_operations afs_super_ops = { |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 53 | .statfs = afs_statfs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | .alloc_inode = afs_alloc_inode, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 55 | .drop_inode = afs_drop_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .destroy_inode = afs_destroy_inode, |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 57 | .evict_inode = afs_evict_inode, |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame^] | 58 | .show_devname = afs_show_devname, |
| 59 | .show_options = afs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 62 | static struct kmem_cache *afs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static atomic_t afs_count_active_inodes; |
| 64 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 65 | enum { |
| 66 | afs_no_opt, |
| 67 | afs_opt_cell, |
| 68 | afs_opt_rwpath, |
| 69 | afs_opt_vol, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 70 | afs_opt_autocell, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 73 | static const match_table_t afs_options_list = { |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 74 | { afs_opt_cell, "cell=%s" }, |
| 75 | { afs_opt_rwpath, "rwpath" }, |
| 76 | { afs_opt_vol, "vol=%s" }, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 77 | { afs_opt_autocell, "autocell" }, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 78 | { afs_no_opt, NULL }, |
| 79 | }; |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* |
| 82 | * initialise the filesystem |
| 83 | */ |
| 84 | int __init afs_fs_init(void) |
| 85 | { |
| 86 | int ret; |
| 87 | |
| 88 | _enter(""); |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* create ourselves an inode cache */ |
| 91 | atomic_set(&afs_count_active_inodes, 0); |
| 92 | |
| 93 | ret = -ENOMEM; |
| 94 | afs_inode_cachep = kmem_cache_create("afs_inode_cache", |
| 95 | sizeof(struct afs_vnode), |
| 96 | 0, |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 97 | SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 98 | afs_i_init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (!afs_inode_cachep) { |
| 100 | printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n"); |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | /* now export our filesystem to lesser mortals */ |
| 105 | ret = register_filesystem(&afs_fs_type); |
| 106 | if (ret < 0) { |
| 107 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 108 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return ret; |
| 110 | } |
| 111 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 112 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* |
| 117 | * clean up the filesystem |
| 118 | */ |
| 119 | void __exit afs_fs_exit(void) |
| 120 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 121 | _enter(""); |
| 122 | |
| 123 | afs_mntpt_kill_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | unregister_filesystem(&afs_fs_type); |
| 125 | |
| 126 | if (atomic_read(&afs_count_active_inodes) != 0) { |
| 127 | printk("kAFS: %d active inode objects still present\n", |
| 128 | atomic_read(&afs_count_active_inodes)); |
| 129 | BUG(); |
| 130 | } |
| 131 | |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 132 | /* |
| 133 | * Make sure all delayed rcu free inodes are flushed before we |
| 134 | * destroy cache. |
| 135 | */ |
| 136 | rcu_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 138 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame^] | 142 | * Display the mount device name in /proc/mounts. |
| 143 | */ |
| 144 | static int afs_show_devname(struct seq_file *m, struct dentry *root) |
| 145 | { |
| 146 | struct afs_super_info *as = root->d_sb->s_fs_info; |
| 147 | struct afs_volume *volume = as->volume; |
| 148 | struct afs_cell *cell = volume->cell; |
| 149 | const char *suf = ""; |
| 150 | char pref = '%'; |
| 151 | |
| 152 | switch (volume->type) { |
| 153 | case AFSVL_RWVOL: |
| 154 | break; |
| 155 | case AFSVL_ROVOL: |
| 156 | pref = '#'; |
| 157 | if (volume->type_force) |
| 158 | suf = ".readonly"; |
| 159 | break; |
| 160 | case AFSVL_BACKVOL: |
| 161 | pref = '#'; |
| 162 | suf = ".backup"; |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->vlocation->vldb.name, suf); |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Display the mount options in /proc/mounts. |
| 172 | */ |
| 173 | static int afs_show_options(struct seq_file *m, struct dentry *root) |
| 174 | { |
| 175 | if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(d_inode(root))->flags)) |
| 176 | seq_puts(m, "autocell"); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * parse the mount options |
| 182 | * - this function has been shamelessly adapted from the ext3 fs which |
| 183 | * shamelessly adapted it from the msdos fs |
| 184 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 185 | static int afs_parse_options(struct afs_mount_params *params, |
| 186 | char *options, const char **devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 188 | struct afs_cell *cell; |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 189 | substring_t args[MAX_OPT_ARGS]; |
| 190 | char *p; |
| 191 | int token; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | _enter("%s", options); |
| 194 | |
| 195 | options[PAGE_SIZE - 1] = 0; |
| 196 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 197 | while ((p = strsep(&options, ","))) { |
| 198 | if (!*p) |
| 199 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 201 | token = match_token(p, afs_options_list, args); |
| 202 | switch (token) { |
| 203 | case afs_opt_cell: |
| 204 | cell = afs_cell_lookup(args[0].from, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 205 | args[0].to - args[0].from, |
| 206 | false); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 207 | if (IS_ERR(cell)) |
| 208 | return PTR_ERR(cell); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 209 | afs_put_cell(params->cell); |
| 210 | params->cell = cell; |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 211 | break; |
| 212 | |
| 213 | case afs_opt_rwpath: |
| 214 | params->rwpath = 1; |
| 215 | break; |
| 216 | |
| 217 | case afs_opt_vol: |
| 218 | *devname = args[0].from; |
| 219 | break; |
| 220 | |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 221 | case afs_opt_autocell: |
| 222 | params->autocell = 1; |
| 223 | break; |
| 224 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 225 | default: |
| 226 | printk(KERN_ERR "kAFS:" |
| 227 | " Unknown or invalid mount option: '%s'\n", p); |
| 228 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 232 | _leave(" = 0"); |
| 233 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 237 | * parse a device name to get cell name, volume name, volume type and R/W |
| 238 | * selector |
| 239 | * - this can be one of the following: |
| 240 | * "%[cell:]volume[.]" R/W volume |
| 241 | * "#[cell:]volume[.]" R/O or R/W volume (rwpath=0), |
| 242 | * or R/W (rwpath=1) volume |
| 243 | * "%[cell:]volume.readonly" R/O volume |
| 244 | * "#[cell:]volume.readonly" R/O volume |
| 245 | * "%[cell:]volume.backup" Backup volume |
| 246 | * "#[cell:]volume.backup" Backup volume |
| 247 | */ |
| 248 | static int afs_parse_device_name(struct afs_mount_params *params, |
| 249 | const char *name) |
| 250 | { |
| 251 | struct afs_cell *cell; |
| 252 | const char *cellname, *suffix; |
| 253 | int cellnamesz; |
| 254 | |
| 255 | _enter(",%s", name); |
| 256 | |
| 257 | if (!name) { |
| 258 | printk(KERN_ERR "kAFS: no volume name specified\n"); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
| 262 | if ((name[0] != '%' && name[0] != '#') || !name[1]) { |
| 263 | printk(KERN_ERR "kAFS: unparsable volume name\n"); |
| 264 | return -EINVAL; |
| 265 | } |
| 266 | |
| 267 | /* determine the type of volume we're looking for */ |
| 268 | params->type = AFSVL_ROVOL; |
| 269 | params->force = false; |
| 270 | if (params->rwpath || name[0] == '%') { |
| 271 | params->type = AFSVL_RWVOL; |
| 272 | params->force = true; |
| 273 | } |
| 274 | name++; |
| 275 | |
| 276 | /* split the cell name out if there is one */ |
| 277 | params->volname = strchr(name, ':'); |
| 278 | if (params->volname) { |
| 279 | cellname = name; |
| 280 | cellnamesz = params->volname - name; |
| 281 | params->volname++; |
| 282 | } else { |
| 283 | params->volname = name; |
| 284 | cellname = NULL; |
| 285 | cellnamesz = 0; |
| 286 | } |
| 287 | |
| 288 | /* the volume type is further affected by a possible suffix */ |
| 289 | suffix = strrchr(params->volname, '.'); |
| 290 | if (suffix) { |
| 291 | if (strcmp(suffix, ".readonly") == 0) { |
| 292 | params->type = AFSVL_ROVOL; |
| 293 | params->force = true; |
| 294 | } else if (strcmp(suffix, ".backup") == 0) { |
| 295 | params->type = AFSVL_BACKVOL; |
| 296 | params->force = true; |
| 297 | } else if (suffix[1] == 0) { |
| 298 | } else { |
| 299 | suffix = NULL; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | params->volnamesz = suffix ? |
| 304 | suffix - params->volname : strlen(params->volname); |
| 305 | |
| 306 | _debug("cell %*.*s [%p]", |
| 307 | cellnamesz, cellnamesz, cellname ?: "", params->cell); |
| 308 | |
| 309 | /* lookup the cell record */ |
| 310 | if (cellname || !params->cell) { |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 311 | cell = afs_cell_lookup(cellname, cellnamesz, true); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 312 | if (IS_ERR(cell)) { |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 313 | printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n", |
| 314 | cellnamesz, cellnamesz, cellname ?: ""); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 315 | return PTR_ERR(cell); |
| 316 | } |
| 317 | afs_put_cell(params->cell); |
| 318 | params->cell = cell; |
| 319 | } |
| 320 | |
| 321 | _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s", |
| 322 | params->cell->name, params->cell, |
| 323 | params->volnamesz, params->volnamesz, params->volname, |
| 324 | suffix ?: "-", params->type, params->force ? " FORCE" : ""); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | * check a superblock to see if it's the one we're looking for |
| 331 | */ |
| 332 | static int afs_test_super(struct super_block *sb, void *data) |
| 333 | { |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 334 | struct afs_super_info *as1 = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | struct afs_super_info *as = sb->s_fs_info; |
| 336 | |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 337 | return as->volume == as1->volume; |
| 338 | } |
| 339 | |
| 340 | static int afs_set_super(struct super_block *sb, void *data) |
| 341 | { |
| 342 | sb->s_fs_info = data; |
| 343 | return set_anon_super(sb, NULL); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | /* |
| 347 | * fill in the superblock |
| 348 | */ |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 349 | static int afs_fill_super(struct super_block *sb, |
| 350 | struct afs_mount_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 352 | struct afs_super_info *as = sb->s_fs_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | struct afs_fid fid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | struct inode *inode = NULL; |
| 355 | int ret; |
| 356 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 357 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /* fill in the superblock */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 360 | sb->s_blocksize = PAGE_SIZE; |
| 361 | sb->s_blocksize_bits = PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | sb->s_magic = AFS_FS_MAGIC; |
| 363 | sb->s_op = &afs_super_ops; |
Jan Kara | edd3ba9 | 2017-04-12 12:24:36 +0200 | [diff] [blame] | 364 | ret = super_setup_bdi(sb); |
| 365 | if (ret) |
| 366 | return ret; |
| 367 | sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE; |
David Howells | 2e41ae2 | 2011-06-14 00:38:44 +0100 | [diff] [blame] | 368 | strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | /* allocate the root inode and dentry */ |
| 371 | fid.vid = as->volume->vid; |
| 372 | fid.vnode = 1; |
| 373 | fid.unique = 1; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 374 | inode = afs_iget(sb, params->key, &fid, NULL, NULL); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 375 | if (IS_ERR(inode)) |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 376 | return PTR_ERR(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 378 | if (params->autocell) |
| 379 | set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags); |
| 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | ret = -ENOMEM; |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 382 | sb->s_root = d_make_root(inode); |
| 383 | if (!sb->s_root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | goto error; |
| 385 | |
Al Viro | d61dcce | 2011-01-12 20:04:20 -0500 | [diff] [blame] | 386 | sb->s_d_op = &afs_fs_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 388 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return 0; |
| 390 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 391 | error: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 392 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /* |
| 397 | * get an AFS superblock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | */ |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 399 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
| 400 | int flags, const char *dev_name, void *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | struct afs_mount_params params; |
| 403 | struct super_block *sb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 404 | struct afs_volume *vol; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 405 | struct key *key; |
Miklos Szeredi | 969729d | 2008-02-08 04:21:37 -0800 | [diff] [blame] | 406 | char *new_opts = kstrdup(options, GFP_KERNEL); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 407 | struct afs_super_info *as; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | int ret; |
| 409 | |
| 410 | _enter(",,%s,%p", dev_name, options); |
| 411 | |
| 412 | memset(¶ms, 0, sizeof(params)); |
| 413 | |
Eric W. Biederman | f74f70f | 2013-01-31 04:23:54 -0800 | [diff] [blame] | 414 | ret = -EINVAL; |
| 415 | if (current->nsproxy->net_ns != &init_net) |
| 416 | goto error; |
| 417 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 418 | /* parse the options and device name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (options) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 420 | ret = afs_parse_options(¶ms, options, &dev_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | if (ret < 0) |
| 422 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 425 | ret = afs_parse_device_name(¶ms, dev_name); |
| 426 | if (ret < 0) |
| 427 | goto error; |
| 428 | |
| 429 | /* try and do the mount securely */ |
| 430 | key = afs_request_key(params.cell); |
| 431 | if (IS_ERR(key)) { |
| 432 | _leave(" = %ld [key]", PTR_ERR(key)); |
| 433 | ret = PTR_ERR(key); |
| 434 | goto error; |
| 435 | } |
| 436 | params.key = key; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* parse the device name */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 439 | vol = afs_volume_lookup(¶ms); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 440 | if (IS_ERR(vol)) { |
| 441 | ret = PTR_ERR(vol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 443 | } |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 444 | |
| 445 | /* allocate a superblock info record */ |
| 446 | as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); |
| 447 | if (!as) { |
| 448 | ret = -ENOMEM; |
| 449 | afs_put_volume(vol); |
| 450 | goto error; |
| 451 | } |
| 452 | as->volume = vol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
| 454 | /* allocate a deviceless superblock */ |
David Howells | 9249e17 | 2012-06-25 12:55:37 +0100 | [diff] [blame] | 455 | sb = sget(fs_type, afs_test_super, afs_set_super, flags, as); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 456 | if (IS_ERR(sb)) { |
| 457 | ret = PTR_ERR(sb); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 458 | afs_put_volume(vol); |
| 459 | kfree(as); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | goto error; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 463 | if (!sb->s_root) { |
| 464 | /* initial superblock/root creation */ |
| 465 | _debug("create"); |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 466 | ret = afs_fill_super(sb, ¶ms); |
| 467 | if (ret < 0) { |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 468 | deactivate_locked_super(sb); |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 469 | goto error; |
| 470 | } |
| 471 | sb->s_flags |= MS_ACTIVE; |
| 472 | } else { |
| 473 | _debug("reuse"); |
| 474 | ASSERTCMP(sb->s_flags, &, MS_ACTIVE); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 475 | afs_put_volume(vol); |
| 476 | kfree(as); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 479 | afs_put_cell(params.cell); |
Al Viro | 2a32ceb | 2009-05-08 16:05:57 -0400 | [diff] [blame] | 480 | kfree(new_opts); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 481 | _leave(" = 0 [%p]", sb); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 482 | return dget(sb->s_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 484 | error: |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 485 | afs_put_cell(params.cell); |
| 486 | key_put(params.key); |
Miklos Szeredi | 969729d | 2008-02-08 04:21:37 -0800 | [diff] [blame] | 487 | kfree(new_opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | _leave(" = %d", ret); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 489 | return ERR_PTR(ret); |
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 | |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 492 | static void afs_kill_super(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
| 494 | struct afs_super_info *as = sb->s_fs_info; |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 495 | kill_anon_super(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | afs_put_volume(as->volume); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 497 | kfree(as); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | /* |
| 501 | * initialise an inode cache slab element prior to any use |
| 502 | */ |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 503 | static void afs_i_init_once(void *_vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 505 | struct afs_vnode *vnode = _vnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 507 | memset(vnode, 0, sizeof(*vnode)); |
| 508 | inode_init_once(&vnode->vfs_inode); |
| 509 | init_waitqueue_head(&vnode->update_waitq); |
| 510 | mutex_init(&vnode->permits_lock); |
| 511 | mutex_init(&vnode->validate_lock); |
| 512 | spin_lock_init(&vnode->writeback_lock); |
| 513 | spin_lock_init(&vnode->lock); |
| 514 | INIT_LIST_HEAD(&vnode->writebacks); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 515 | INIT_LIST_HEAD(&vnode->pending_locks); |
| 516 | INIT_LIST_HEAD(&vnode->granted_locks); |
| 517 | INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work); |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 518 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* |
| 522 | * allocate an AFS inode struct from our slab cache |
| 523 | */ |
| 524 | static struct inode *afs_alloc_inode(struct super_block *sb) |
| 525 | { |
| 526 | struct afs_vnode *vnode; |
| 527 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 528 | vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | if (!vnode) |
| 530 | return NULL; |
| 531 | |
| 532 | atomic_inc(&afs_count_active_inodes); |
| 533 | |
| 534 | memset(&vnode->fid, 0, sizeof(vnode->fid)); |
| 535 | memset(&vnode->status, 0, sizeof(vnode->status)); |
| 536 | |
| 537 | vnode->volume = NULL; |
| 538 | vnode->update_cnt = 0; |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 539 | vnode->flags = 1 << AFS_VNODE_UNSET; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 540 | vnode->cb_promised = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 542 | _leave(" = %p", &vnode->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return &vnode->vfs_inode; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 546 | static void afs_i_callback(struct rcu_head *head) |
| 547 | { |
| 548 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 549 | struct afs_vnode *vnode = AFS_FS_I(inode); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 550 | kmem_cache_free(afs_inode_cachep, vnode); |
| 551 | } |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* |
| 554 | * destroy an AFS inode struct |
| 555 | */ |
| 556 | static void afs_destroy_inode(struct inode *inode) |
| 557 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 558 | struct afs_vnode *vnode = AFS_FS_I(inode); |
| 559 | |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 560 | _enter("%p{%x:%u}", inode, vnode->fid.vid, vnode->fid.vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 562 | _debug("DESTROY INODE %p", inode); |
| 563 | |
| 564 | ASSERTCMP(vnode->server, ==, NULL); |
| 565 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 566 | call_rcu(&inode->i_rcu, afs_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | atomic_dec(&afs_count_active_inodes); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 568 | } |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * return information about an AFS volume |
| 572 | */ |
| 573 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 574 | { |
| 575 | struct afs_volume_status vs; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 576 | struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 577 | struct key *key; |
| 578 | int ret; |
| 579 | |
| 580 | key = afs_request_key(vnode->volume->cell); |
| 581 | if (IS_ERR(key)) |
| 582 | return PTR_ERR(key); |
| 583 | |
| 584 | ret = afs_vnode_get_volume_status(vnode, key, &vs); |
| 585 | key_put(key); |
| 586 | if (ret < 0) { |
| 587 | _leave(" = %d", ret); |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | buf->f_type = dentry->d_sb->s_magic; |
| 592 | buf->f_bsize = AFS_BLOCK_SIZE; |
| 593 | buf->f_namelen = AFSNAMEMAX - 1; |
| 594 | |
| 595 | if (vs.max_quota == 0) |
| 596 | buf->f_blocks = vs.part_max_blocks; |
| 597 | else |
| 598 | buf->f_blocks = vs.max_quota; |
| 599 | buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use; |
| 600 | return 0; |
| 601 | } |