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