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> |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 28 | #include <linux/magic.h> |
Eric W. Biederman | f74f70f | 2013-01-31 04:23:54 -0800 | [diff] [blame] | 29 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "internal.h" |
| 31 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 32 | static void afs_i_init_once(void *foo); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 33 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
| 34 | int flags, const char *dev_name, void *data); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 35 | static void afs_kill_super(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static struct inode *afs_alloc_inode(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static void afs_destroy_inode(struct inode *inode); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 38 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 39 | static int afs_show_devname(struct seq_file *m, struct dentry *root); |
| 40 | static int afs_show_options(struct seq_file *m, struct dentry *root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 42 | struct file_system_type afs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | .owner = THIS_MODULE, |
| 44 | .name = "afs", |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 45 | .mount = afs_mount, |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 46 | .kill_sb = afs_kill_super, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 47 | .fs_flags = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 49 | MODULE_ALIAS_FS("afs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 51 | int afs_net_id; |
| 52 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 53 | static const struct super_operations afs_super_ops = { |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 54 | .statfs = afs_statfs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .alloc_inode = afs_alloc_inode, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 56 | .drop_inode = afs_drop_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | .destroy_inode = afs_destroy_inode, |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 58 | .evict_inode = afs_evict_inode, |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 59 | .show_devname = afs_show_devname, |
| 60 | .show_options = afs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 63 | static struct kmem_cache *afs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static atomic_t afs_count_active_inodes; |
| 65 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 66 | enum { |
| 67 | afs_no_opt, |
| 68 | afs_opt_cell, |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 69 | afs_opt_dyn, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 70 | afs_opt_rwpath, |
| 71 | afs_opt_vol, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 72 | afs_opt_autocell, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 75 | static const match_table_t afs_options_list = { |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 76 | { afs_opt_cell, "cell=%s" }, |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 77 | { afs_opt_dyn, "dyn" }, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 78 | { afs_opt_rwpath, "rwpath" }, |
| 79 | { afs_opt_vol, "vol=%s" }, |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 80 | { afs_opt_autocell, "autocell" }, |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 81 | { afs_no_opt, NULL }, |
| 82 | }; |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
| 85 | * initialise the filesystem |
| 86 | */ |
| 87 | int __init afs_fs_init(void) |
| 88 | { |
| 89 | int ret; |
| 90 | |
| 91 | _enter(""); |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* create ourselves an inode cache */ |
| 94 | atomic_set(&afs_count_active_inodes, 0); |
| 95 | |
| 96 | ret = -ENOMEM; |
| 97 | afs_inode_cachep = kmem_cache_create("afs_inode_cache", |
| 98 | sizeof(struct afs_vnode), |
| 99 | 0, |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 100 | SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 101 | afs_i_init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (!afs_inode_cachep) { |
| 103 | printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n"); |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | /* now export our filesystem to lesser mortals */ |
| 108 | ret = register_filesystem(&afs_fs_type); |
| 109 | if (ret < 0) { |
| 110 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 111 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return ret; |
| 113 | } |
| 114 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 115 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | * clean up the filesystem |
| 121 | */ |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 122 | void afs_fs_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 124 | _enter(""); |
| 125 | |
| 126 | afs_mntpt_kill_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | unregister_filesystem(&afs_fs_type); |
| 128 | |
| 129 | if (atomic_read(&afs_count_active_inodes) != 0) { |
| 130 | printk("kAFS: %d active inode objects still present\n", |
| 131 | atomic_read(&afs_count_active_inodes)); |
| 132 | BUG(); |
| 133 | } |
| 134 | |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 135 | /* |
| 136 | * Make sure all delayed rcu free inodes are flushed before we |
| 137 | * destroy cache. |
| 138 | */ |
| 139 | rcu_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | kmem_cache_destroy(afs_inode_cachep); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 141 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 145 | * Display the mount device name in /proc/mounts. |
| 146 | */ |
| 147 | static int afs_show_devname(struct seq_file *m, struct dentry *root) |
| 148 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 149 | struct afs_super_info *as = AFS_FS_S(root->d_sb); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 150 | struct afs_volume *volume = as->volume; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 151 | struct afs_cell *cell = as->cell; |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 152 | const char *suf = ""; |
| 153 | char pref = '%'; |
| 154 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 155 | if (as->dyn_root) { |
| 156 | seq_puts(m, "none"); |
| 157 | return 0; |
| 158 | } |
David Howells | 66c7e1d | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 159 | |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 160 | switch (volume->type) { |
| 161 | case AFSVL_RWVOL: |
| 162 | break; |
| 163 | case AFSVL_ROVOL: |
| 164 | pref = '#'; |
| 165 | if (volume->type_force) |
| 166 | suf = ".readonly"; |
| 167 | break; |
| 168 | case AFSVL_BACKVOL: |
| 169 | pref = '#'; |
| 170 | suf = ".backup"; |
| 171 | break; |
| 172 | } |
| 173 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 174 | seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Display the mount options in /proc/mounts. |
| 180 | */ |
| 181 | static int afs_show_options(struct seq_file *m, struct dentry *root) |
| 182 | { |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 183 | struct afs_super_info *as = AFS_FS_S(root->d_sb); |
| 184 | |
| 185 | if (as->dyn_root) |
| 186 | seq_puts(m, ",dyn"); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 187 | if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(d_inode(root))->flags)) |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 188 | seq_puts(m, ",autocell"); |
David Howells | 677018a | 2017-07-05 16:25:23 +0100 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | * parse the mount options |
| 194 | * - this function has been shamelessly adapted from the ext3 fs which |
| 195 | * shamelessly adapted it from the msdos fs |
| 196 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 197 | static int afs_parse_options(struct afs_mount_params *params, |
| 198 | char *options, const char **devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 200 | struct afs_cell *cell; |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 201 | substring_t args[MAX_OPT_ARGS]; |
| 202 | char *p; |
| 203 | int token; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | _enter("%s", options); |
| 206 | |
| 207 | options[PAGE_SIZE - 1] = 0; |
| 208 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 209 | while ((p = strsep(&options, ","))) { |
| 210 | if (!*p) |
| 211 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 213 | token = match_token(p, afs_options_list, args); |
| 214 | switch (token) { |
| 215 | case afs_opt_cell: |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 216 | rcu_read_lock(); |
| 217 | cell = afs_lookup_cell_rcu(params->net, |
| 218 | args[0].from, |
| 219 | args[0].to - args[0].from); |
| 220 | rcu_read_unlock(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 221 | if (IS_ERR(cell)) |
| 222 | return PTR_ERR(cell); |
David Howells | 9ed900b | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 223 | afs_put_cell(params->net, params->cell); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 224 | params->cell = cell; |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 225 | break; |
| 226 | |
| 227 | case afs_opt_rwpath: |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 228 | params->rwpath = true; |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 229 | break; |
| 230 | |
| 231 | case afs_opt_vol: |
| 232 | *devname = args[0].from; |
| 233 | break; |
| 234 | |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 235 | case afs_opt_autocell: |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 236 | params->autocell = true; |
| 237 | break; |
| 238 | |
| 239 | case afs_opt_dyn: |
| 240 | params->dyn_root = true; |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 241 | break; |
| 242 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 243 | default: |
| 244 | printk(KERN_ERR "kAFS:" |
| 245 | " Unknown or invalid mount option: '%s'\n", p); |
| 246 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
David Howells | 80c72fe | 2007-05-03 03:11:29 -0700 | [diff] [blame] | 250 | _leave(" = 0"); |
| 251 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 255 | * parse a device name to get cell name, volume name, volume type and R/W |
| 256 | * selector |
| 257 | * - this can be one of the following: |
| 258 | * "%[cell:]volume[.]" R/W volume |
| 259 | * "#[cell:]volume[.]" R/O or R/W volume (rwpath=0), |
| 260 | * or R/W (rwpath=1) volume |
| 261 | * "%[cell:]volume.readonly" R/O volume |
| 262 | * "#[cell:]volume.readonly" R/O volume |
| 263 | * "%[cell:]volume.backup" Backup volume |
| 264 | * "#[cell:]volume.backup" Backup volume |
| 265 | */ |
| 266 | static int afs_parse_device_name(struct afs_mount_params *params, |
| 267 | const char *name) |
| 268 | { |
| 269 | struct afs_cell *cell; |
| 270 | const char *cellname, *suffix; |
| 271 | int cellnamesz; |
| 272 | |
| 273 | _enter(",%s", name); |
David Howells | 66c7e1d | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 274 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 275 | if (!name) { |
| 276 | printk(KERN_ERR "kAFS: no volume name specified\n"); |
| 277 | return -EINVAL; |
| 278 | } |
| 279 | |
| 280 | if ((name[0] != '%' && name[0] != '#') || !name[1]) { |
| 281 | printk(KERN_ERR "kAFS: unparsable volume name\n"); |
| 282 | return -EINVAL; |
| 283 | } |
| 284 | |
| 285 | /* determine the type of volume we're looking for */ |
| 286 | params->type = AFSVL_ROVOL; |
| 287 | params->force = false; |
| 288 | if (params->rwpath || name[0] == '%') { |
| 289 | params->type = AFSVL_RWVOL; |
| 290 | params->force = true; |
| 291 | } |
| 292 | name++; |
| 293 | |
| 294 | /* split the cell name out if there is one */ |
| 295 | params->volname = strchr(name, ':'); |
| 296 | if (params->volname) { |
| 297 | cellname = name; |
| 298 | cellnamesz = params->volname - name; |
| 299 | params->volname++; |
| 300 | } else { |
| 301 | params->volname = name; |
| 302 | cellname = NULL; |
| 303 | cellnamesz = 0; |
| 304 | } |
| 305 | |
| 306 | /* the volume type is further affected by a possible suffix */ |
| 307 | suffix = strrchr(params->volname, '.'); |
| 308 | if (suffix) { |
| 309 | if (strcmp(suffix, ".readonly") == 0) { |
| 310 | params->type = AFSVL_ROVOL; |
| 311 | params->force = true; |
| 312 | } else if (strcmp(suffix, ".backup") == 0) { |
| 313 | params->type = AFSVL_BACKVOL; |
| 314 | params->force = true; |
| 315 | } else if (suffix[1] == 0) { |
| 316 | } else { |
| 317 | suffix = NULL; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | params->volnamesz = suffix ? |
| 322 | suffix - params->volname : strlen(params->volname); |
| 323 | |
| 324 | _debug("cell %*.*s [%p]", |
| 325 | cellnamesz, cellnamesz, cellname ?: "", params->cell); |
| 326 | |
| 327 | /* lookup the cell record */ |
| 328 | if (cellname || !params->cell) { |
David Howells | 989782d | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 329 | cell = afs_lookup_cell(params->net, cellname, cellnamesz, |
| 330 | NULL, false); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 331 | if (IS_ERR(cell)) { |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 332 | printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n", |
| 333 | cellnamesz, cellnamesz, cellname ?: ""); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 334 | return PTR_ERR(cell); |
| 335 | } |
David Howells | 9ed900b | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 336 | afs_put_cell(params->net, params->cell); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 337 | params->cell = cell; |
| 338 | } |
| 339 | |
| 340 | _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s", |
| 341 | params->cell->name, params->cell, |
| 342 | params->volnamesz, params->volnamesz, params->volname, |
| 343 | suffix ?: "-", params->type, params->force ? " FORCE" : ""); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | * check a superblock to see if it's the one we're looking for |
| 350 | */ |
| 351 | static int afs_test_super(struct super_block *sb, void *data) |
| 352 | { |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 353 | struct afs_super_info *as1 = data; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 354 | struct afs_super_info *as = AFS_FS_S(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 356 | return (as->net_ns == as1->net_ns && |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 357 | as->volume && |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 358 | as->volume->vid == as1->volume->vid && |
| 359 | !as->dyn_root); |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int afs_dynroot_test_super(struct super_block *sb, void *data) |
| 363 | { |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 364 | struct afs_super_info *as1 = data; |
| 365 | struct afs_super_info *as = AFS_FS_S(sb); |
| 366 | |
| 367 | return (as->net_ns == as1->net_ns && |
| 368 | as->dyn_root); |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static int afs_set_super(struct super_block *sb, void *data) |
| 372 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 373 | struct afs_super_info *as = data; |
| 374 | |
| 375 | sb->s_fs_info = as; |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 376 | return set_anon_super(sb, NULL); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 377 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* |
| 380 | * fill in the superblock |
| 381 | */ |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 382 | static int afs_fill_super(struct super_block *sb, |
| 383 | struct afs_mount_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 385 | struct afs_super_info *as = AFS_FS_S(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | struct afs_fid fid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | struct inode *inode = NULL; |
| 388 | int ret; |
| 389 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 390 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* fill in the superblock */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 393 | sb->s_blocksize = PAGE_SIZE; |
| 394 | sb->s_blocksize_bits = PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | sb->s_magic = AFS_FS_MAGIC; |
| 396 | sb->s_op = &afs_super_ops; |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 397 | if (!as->dyn_root) |
| 398 | sb->s_xattr = afs_xattr_handlers; |
Jan Kara | edd3ba9 | 2017-04-12 12:24:36 +0200 | [diff] [blame] | 399 | ret = super_setup_bdi(sb); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | /* allocate the root inode and dentry */ |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 405 | if (as->dyn_root) { |
| 406 | inode = afs_iget_pseudo_dir(sb, true); |
| 407 | sb->s_flags |= SB_RDONLY; |
| 408 | } else { |
| 409 | sprintf(sb->s_id, "%u", as->volume->vid); |
| 410 | afs_activate_volume(as->volume); |
| 411 | fid.vid = as->volume->vid; |
| 412 | fid.vnode = 1; |
| 413 | fid.unique = 1; |
| 414 | inode = afs_iget(sb, params->key, &fid, NULL, NULL, NULL); |
| 415 | } |
| 416 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 417 | if (IS_ERR(inode)) |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 418 | return PTR_ERR(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 420 | if (params->autocell || params->dyn_root) |
wanglei | bec5eb6 | 2010-08-11 09:38:04 +0100 | [diff] [blame] | 421 | set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags); |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | ret = -ENOMEM; |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 424 | sb->s_root = d_make_root(inode); |
| 425 | if (!sb->s_root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | goto error; |
| 427 | |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 428 | if (as->dyn_root) { |
David Howells | 66c7e1d | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 429 | sb->s_d_op = &afs_dynroot_dentry_operations; |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 430 | ret = afs_dynroot_populate(sb); |
| 431 | if (ret < 0) |
| 432 | goto error; |
| 433 | } else { |
David Howells | 66c7e1d | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 434 | sb->s_d_op = &afs_fs_dentry_operations; |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 437 | _leave(" = 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | return 0; |
| 439 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 440 | error: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 441 | _leave(" = %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 445 | static struct afs_super_info *afs_alloc_sbi(struct afs_mount_params *params) |
| 446 | { |
| 447 | struct afs_super_info *as; |
| 448 | |
| 449 | as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); |
| 450 | if (as) { |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 451 | as->net_ns = get_net(params->net_ns); |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 452 | if (params->dyn_root) |
| 453 | as->dyn_root = true; |
| 454 | else |
| 455 | as->cell = afs_get_cell(params->cell); |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 456 | } |
| 457 | return as; |
| 458 | } |
| 459 | |
| 460 | static void afs_destroy_sbi(struct afs_super_info *as) |
| 461 | { |
| 462 | if (as) { |
David Howells | 9ed900b | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 463 | afs_put_volume(as->cell, as->volume); |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 464 | afs_put_cell(afs_net(as->net_ns), as->cell); |
| 465 | put_net(as->net_ns); |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 466 | kfree(as); |
| 467 | } |
| 468 | } |
| 469 | |
David Howells | 0da0b7f | 2018-06-15 15:19:22 +0100 | [diff] [blame] | 470 | static void afs_kill_super(struct super_block *sb) |
| 471 | { |
| 472 | struct afs_super_info *as = AFS_FS_S(sb); |
| 473 | struct afs_net *net = afs_net(as->net_ns); |
| 474 | |
| 475 | if (as->dyn_root) |
| 476 | afs_dynroot_depopulate(sb); |
| 477 | |
| 478 | /* Clear the callback interests (which will do ilookup5) before |
| 479 | * deactivating the superblock. |
| 480 | */ |
| 481 | if (as->volume) |
| 482 | afs_clear_callback_interests(net, as->volume->servers); |
| 483 | kill_anon_super(sb); |
| 484 | if (as->volume) |
| 485 | afs_deactivate_volume(as->volume); |
| 486 | afs_destroy_sbi(as); |
| 487 | } |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* |
| 490 | * get an AFS superblock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | */ |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 492 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 493 | int flags, const char *dev_name, void *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
| 495 | struct afs_mount_params params; |
| 496 | struct super_block *sb; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 497 | struct afs_volume *candidate; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 498 | struct key *key; |
Al Viro | dde194a | 2011-06-12 16:01:21 -0400 | [diff] [blame] | 499 | struct afs_super_info *as; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | int ret; |
| 501 | |
| 502 | _enter(",,%s,%p", dev_name, options); |
| 503 | |
| 504 | memset(¶ms, 0, sizeof(params)); |
| 505 | |
Eric W. Biederman | f74f70f | 2013-01-31 04:23:54 -0800 | [diff] [blame] | 506 | ret = -EINVAL; |
| 507 | if (current->nsproxy->net_ns != &init_net) |
| 508 | goto error; |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 509 | params.net_ns = current->nsproxy->net_ns; |
| 510 | params.net = afs_net(params.net_ns); |
| 511 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 512 | /* parse the options and device name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (options) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 514 | ret = afs_parse_options(¶ms, options, &dev_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | if (ret < 0) |
| 516 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 519 | if (!params.dyn_root) { |
| 520 | ret = afs_parse_device_name(¶ms, dev_name); |
| 521 | if (ret < 0) |
| 522 | goto error; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 523 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 524 | /* try and do the mount securely */ |
| 525 | key = afs_request_key(params.cell); |
| 526 | if (IS_ERR(key)) { |
| 527 | _leave(" = %ld [key]", PTR_ERR(key)); |
| 528 | ret = PTR_ERR(key); |
| 529 | goto error; |
| 530 | } |
| 531 | params.key = key; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 532 | } |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 533 | |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 534 | /* allocate a superblock info record */ |
| 535 | ret = -ENOMEM; |
| 536 | as = afs_alloc_sbi(¶ms); |
| 537 | if (!as) |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 538 | goto error_key; |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 539 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 540 | if (!params.dyn_root) { |
| 541 | /* Assume we're going to need a volume record; at the very |
| 542 | * least we can use it to update the volume record if we have |
| 543 | * one already. This checks that the volume exists within the |
| 544 | * cell. |
| 545 | */ |
| 546 | candidate = afs_create_volume(¶ms); |
| 547 | if (IS_ERR(candidate)) { |
| 548 | ret = PTR_ERR(candidate); |
| 549 | goto error_as; |
| 550 | } |
| 551 | |
| 552 | as->volume = candidate; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 553 | } |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* allocate a deviceless superblock */ |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 556 | sb = sget(fs_type, |
| 557 | as->dyn_root ? afs_dynroot_test_super : afs_test_super, |
| 558 | afs_set_super, flags, as); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 559 | if (IS_ERR(sb)) { |
| 560 | ret = PTR_ERR(sb); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 561 | goto error_as; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 562 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 564 | if (!sb->s_root) { |
| 565 | /* initial superblock/root creation */ |
| 566 | _debug("create"); |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 567 | ret = afs_fill_super(sb, ¶ms); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 568 | if (ret < 0) |
| 569 | goto error_sb; |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 570 | as = NULL; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 571 | sb->s_flags |= SB_ACTIVE; |
David Howells | 436058a | 2007-04-26 15:56:24 -0700 | [diff] [blame] | 572 | } else { |
| 573 | _debug("reuse"); |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 574 | ASSERTCMP(sb->s_flags, &, SB_ACTIVE); |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 575 | afs_destroy_sbi(as); |
| 576 | as = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
David Howells | 9ed900b | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 579 | afs_put_cell(params.net, params.cell); |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 580 | key_put(params.key); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 581 | _leave(" = 0 [%p]", sb); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 582 | return dget(sb->s_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 584 | error_sb: |
| 585 | deactivate_locked_super(sb); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 586 | goto error_key; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 587 | error_as: |
David Howells | 49566f6 | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 588 | afs_destroy_sbi(as); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 589 | error_key: |
| 590 | key_put(params.key); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 591 | error: |
David Howells | 9ed900b | 2017-11-02 15:27:46 +0000 | [diff] [blame] | 592 | afs_put_cell(params.net, params.cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | _leave(" = %d", ret); |
Al Viro | f7442b3 | 2010-07-26 14:16:21 +0400 | [diff] [blame] | 594 | return ERR_PTR(ret); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 595 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* |
David Howells | f8de483 | 2017-12-01 11:40:43 +0000 | [diff] [blame] | 598 | * Initialise an inode cache slab element prior to any use. Note that |
| 599 | * afs_alloc_inode() *must* reset anything that could incorrectly leak from one |
| 600 | * inode to another. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | */ |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 602 | static void afs_i_init_once(void *_vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 604 | struct afs_vnode *vnode = _vnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 606 | memset(vnode, 0, sizeof(*vnode)); |
| 607 | inode_init_once(&vnode->vfs_inode); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 608 | mutex_init(&vnode->io_lock); |
David Howells | b61f7dc | 2018-04-27 20:46:22 +0100 | [diff] [blame] | 609 | init_rwsem(&vnode->validate_lock); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 610 | spin_lock_init(&vnode->wb_lock); |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 611 | spin_lock_init(&vnode->lock); |
David Howells | 4343d00 | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 612 | INIT_LIST_HEAD(&vnode->wb_keys); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 613 | INIT_LIST_HEAD(&vnode->pending_locks); |
| 614 | INIT_LIST_HEAD(&vnode->granted_locks); |
| 615 | INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work); |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 616 | seqlock_init(&vnode->cb_lock); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | /* |
| 620 | * allocate an AFS inode struct from our slab cache |
| 621 | */ |
| 622 | static struct inode *afs_alloc_inode(struct super_block *sb) |
| 623 | { |
| 624 | struct afs_vnode *vnode; |
| 625 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 626 | vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | if (!vnode) |
| 628 | return NULL; |
| 629 | |
| 630 | atomic_inc(&afs_count_active_inodes); |
| 631 | |
David Howells | f8de483 | 2017-12-01 11:40:43 +0000 | [diff] [blame] | 632 | /* Reset anything that shouldn't leak from one inode to the next. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | memset(&vnode->fid, 0, sizeof(vnode->fid)); |
| 634 | memset(&vnode->status, 0, sizeof(vnode->status)); |
| 635 | |
| 636 | vnode->volume = NULL; |
David Howells | f8de483 | 2017-12-01 11:40:43 +0000 | [diff] [blame] | 637 | vnode->lock_key = NULL; |
| 638 | vnode->permit_cache = NULL; |
| 639 | vnode->cb_interest = NULL; |
| 640 | #ifdef CONFIG_AFS_FSCACHE |
| 641 | vnode->cache = NULL; |
| 642 | #endif |
| 643 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 644 | vnode->flags = 1 << AFS_VNODE_UNSET; |
David Howells | f8de483 | 2017-12-01 11:40:43 +0000 | [diff] [blame] | 645 | vnode->cb_type = 0; |
| 646 | vnode->lock_state = AFS_VNODE_LOCK_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 648 | _leave(" = %p", &vnode->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return &vnode->vfs_inode; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 652 | static void afs_i_callback(struct rcu_head *head) |
| 653 | { |
| 654 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 655 | struct afs_vnode *vnode = AFS_FS_I(inode); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 656 | kmem_cache_free(afs_inode_cachep, vnode); |
| 657 | } |
| 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | /* |
| 660 | * destroy an AFS inode struct |
| 661 | */ |
| 662 | static void afs_destroy_inode(struct inode *inode) |
| 663 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 664 | struct afs_vnode *vnode = AFS_FS_I(inode); |
| 665 | |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 666 | _enter("%p{%x:%u}", inode, vnode->fid.vid, vnode->fid.vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 668 | _debug("DESTROY INODE %p", inode); |
| 669 | |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 670 | ASSERTCMP(vnode->cb_interest, ==, NULL); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 671 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 672 | call_rcu(&inode->i_rcu, afs_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | atomic_dec(&afs_count_active_inodes); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 674 | } |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 675 | |
| 676 | /* |
| 677 | * return information about an AFS volume |
| 678 | */ |
| 679 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 680 | { |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 681 | struct afs_super_info *as = AFS_FS_S(dentry->d_sb); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 682 | struct afs_fs_cursor fc; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 683 | struct afs_volume_status vs; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 684 | struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 685 | struct key *key; |
| 686 | int ret; |
| 687 | |
David Howells | 4d673da | 2018-02-06 06:26:30 +0000 | [diff] [blame] | 688 | buf->f_type = dentry->d_sb->s_magic; |
| 689 | buf->f_bsize = AFS_BLOCK_SIZE; |
| 690 | buf->f_namelen = AFSNAMEMAX - 1; |
| 691 | |
| 692 | if (as->dyn_root) { |
| 693 | buf->f_blocks = 1; |
| 694 | buf->f_bavail = 0; |
| 695 | buf->f_bfree = 0; |
| 696 | return 0; |
| 697 | } |
David Howells | 66c7e1d | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 698 | |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 699 | key = afs_request_key(vnode->volume->cell); |
| 700 | if (IS_ERR(key)) |
| 701 | return PTR_ERR(key); |
| 702 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 703 | ret = -ERESTARTSYS; |
| 704 | if (afs_begin_vnode_operation(&fc, vnode, key)) { |
| 705 | fc.flags |= AFS_FS_CURSOR_NO_VSLEEP; |
| 706 | while (afs_select_fileserver(&fc)) { |
David Howells | 68251f0 | 2018-05-12 22:31:33 +0100 | [diff] [blame] | 707 | fc.cb_break = afs_calc_vnode_cb_break(vnode); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 708 | afs_fs_get_volume_status(&fc, &vs); |
| 709 | } |
| 710 | |
| 711 | afs_check_for_remote_deletion(&fc, fc.vnode); |
| 712 | afs_vnode_commit_status(&fc, vnode, fc.cb_break); |
| 713 | ret = afs_end_vnode_operation(&fc); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 714 | } |
| 715 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 716 | key_put(key); |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 717 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 718 | if (ret == 0) { |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 719 | if (vs.max_quota == 0) |
| 720 | buf->f_blocks = vs.part_max_blocks; |
| 721 | else |
| 722 | buf->f_blocks = vs.max_quota; |
| 723 | buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use; |
| 724 | } |
| 725 | |
| 726 | return ret; |
David Howells | 45222b9 | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 727 | } |