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