xref: /openbmc/linux/fs/afs/super.c (revision b485275f1aca8a9da37fd35e4fad673935e827da)
1ec26815aSDavid Howells /* AFS superblock handling
2ec26815aSDavid Howells  *
313fcc683SDavid Howells  * Copyright (c) 2002, 2007, 2018 Red Hat, Inc. All rights reserved.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * This software may be freely redistributed under the terms of the
61da177e4SLinus Torvalds  * GNU General Public License.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
91da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
101da177e4SLinus Torvalds  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * Authors: David Howells <dhowells@redhat.com>
1344d1b980SDavid Woodhouse  *          David Woodhouse <dwmw2@infradead.org>
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #include <linux/kernel.h>
181da177e4SLinus Torvalds #include <linux/module.h>
19bec5eb61Swanglei #include <linux/mount.h>
201da177e4SLinus Torvalds #include <linux/init.h>
211da177e4SLinus Torvalds #include <linux/slab.h>
221da177e4SLinus Torvalds #include <linux/fs.h>
231da177e4SLinus Torvalds #include <linux/pagemap.h>
2413fcc683SDavid Howells #include <linux/fs_parser.h>
2545222b9eSDavid Howells #include <linux/statfs.h>
26e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
27f74f70f8SEric W. Biederman #include <linux/nsproxy.h>
28f044c884SDavid Howells #include <linux/magic.h>
29f74f70f8SEric W. Biederman #include <net/net_namespace.h>
301da177e4SLinus Torvalds #include "internal.h"
311da177e4SLinus Torvalds 
3251cc5068SAlexey Dobriyan static void afs_i_init_once(void *foo);
33dde194a6SAl Viro static void afs_kill_super(struct super_block *sb);
341da177e4SLinus Torvalds static struct inode *afs_alloc_inode(struct super_block *sb);
351da177e4SLinus Torvalds static void afs_destroy_inode(struct inode *inode);
3651b9fe48SAl Viro static void afs_free_inode(struct inode *inode);
3745222b9eSDavid Howells static int afs_statfs(struct dentry *dentry, struct kstatfs *buf);
38677018a6SDavid Howells static int afs_show_devname(struct seq_file *m, struct dentry *root);
39677018a6SDavid Howells static int afs_show_options(struct seq_file *m, struct dentry *root);
4013fcc683SDavid Howells static int afs_init_fs_context(struct fs_context *fc);
4113fcc683SDavid Howells static const struct fs_parameter_description afs_fs_parameters;
421da177e4SLinus Torvalds 
431f5ce9e9STrond Myklebust struct file_system_type afs_fs_type = {
441da177e4SLinus Torvalds 	.owner			= THIS_MODULE,
451da177e4SLinus Torvalds 	.name			= "afs",
4613fcc683SDavid Howells 	.init_fs_context	= afs_init_fs_context,
4713fcc683SDavid Howells 	.parameters		= &afs_fs_parameters,
48dde194a6SAl Viro 	.kill_sb		= afs_kill_super,
4979ddbfa5SDavid Howells 	.fs_flags		= FS_RENAME_DOES_D_MOVE,
501da177e4SLinus Torvalds };
517f78e035SEric W. Biederman MODULE_ALIAS_FS("afs");
521da177e4SLinus Torvalds 
535b86d4ffSDavid Howells int afs_net_id;
545b86d4ffSDavid Howells 
55ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations afs_super_ops = {
5645222b9eSDavid Howells 	.statfs		= afs_statfs,
571da177e4SLinus Torvalds 	.alloc_inode	= afs_alloc_inode,
58bec5eb61Swanglei 	.drop_inode	= afs_drop_inode,
591da177e4SLinus Torvalds 	.destroy_inode	= afs_destroy_inode,
6051b9fe48SAl Viro 	.free_inode	= afs_free_inode,
61b57922d9SAl Viro 	.evict_inode	= afs_evict_inode,
62677018a6SDavid Howells 	.show_devname	= afs_show_devname,
63677018a6SDavid Howells 	.show_options	= afs_show_options,
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds 
66e18b890bSChristoph Lameter static struct kmem_cache *afs_inode_cachep;
671da177e4SLinus Torvalds static atomic_t afs_count_active_inodes;
681da177e4SLinus Torvalds 
6913fcc683SDavid Howells enum afs_param {
7013fcc683SDavid Howells 	Opt_autocell,
7113fcc683SDavid Howells 	Opt_dyn,
726c6c1d63SDavid Howells 	Opt_flock,
7313fcc683SDavid Howells 	Opt_source,
7480c72fe4SDavid Howells };
7580c72fe4SDavid Howells 
7613fcc683SDavid Howells static const struct fs_parameter_spec afs_param_specs[] = {
7713fcc683SDavid Howells 	fsparam_flag  ("autocell",	Opt_autocell),
7813fcc683SDavid Howells 	fsparam_flag  ("dyn",		Opt_dyn),
796c6c1d63SDavid Howells 	fsparam_enum  ("flock",		Opt_flock),
8013fcc683SDavid Howells 	fsparam_string("source",	Opt_source),
8113fcc683SDavid Howells 	{}
8213fcc683SDavid Howells };
8313fcc683SDavid Howells 
846c6c1d63SDavid Howells static const struct fs_parameter_enum afs_param_enums[] = {
856c6c1d63SDavid Howells 	{ Opt_flock,	"local",	afs_flock_mode_local },
866c6c1d63SDavid Howells 	{ Opt_flock,	"openafs",	afs_flock_mode_openafs },
876c6c1d63SDavid Howells 	{ Opt_flock,	"strict",	afs_flock_mode_strict },
886c6c1d63SDavid Howells 	{ Opt_flock,	"write",	afs_flock_mode_write },
896c6c1d63SDavid Howells 	{}
906c6c1d63SDavid Howells };
916c6c1d63SDavid Howells 
9213fcc683SDavid Howells static const struct fs_parameter_description afs_fs_parameters = {
9313fcc683SDavid Howells 	.name		= "kAFS",
9413fcc683SDavid Howells 	.specs		= afs_param_specs,
956c6c1d63SDavid Howells 	.enums		= afs_param_enums,
9680c72fe4SDavid Howells };
9780c72fe4SDavid Howells 
981da177e4SLinus Torvalds /*
991da177e4SLinus Torvalds  * initialise the filesystem
1001da177e4SLinus Torvalds  */
1011da177e4SLinus Torvalds int __init afs_fs_init(void)
1021da177e4SLinus Torvalds {
1031da177e4SLinus Torvalds 	int ret;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	_enter("");
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	/* create ourselves an inode cache */
1081da177e4SLinus Torvalds 	atomic_set(&afs_count_active_inodes, 0);
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 	ret = -ENOMEM;
1111da177e4SLinus Torvalds 	afs_inode_cachep = kmem_cache_create("afs_inode_cache",
1121da177e4SLinus Torvalds 					     sizeof(struct afs_vnode),
1131da177e4SLinus Torvalds 					     0,
1145d097056SVladimir Davydov 					     SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
11520c2df83SPaul Mundt 					     afs_i_init_once);
1161da177e4SLinus Torvalds 	if (!afs_inode_cachep) {
1171da177e4SLinus Torvalds 		printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
1181da177e4SLinus Torvalds 		return ret;
1191da177e4SLinus Torvalds 	}
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds 	/* now export our filesystem to lesser mortals */
1221da177e4SLinus Torvalds 	ret = register_filesystem(&afs_fs_type);
1231da177e4SLinus Torvalds 	if (ret < 0) {
1241da177e4SLinus Torvalds 		kmem_cache_destroy(afs_inode_cachep);
12508e0e7c8SDavid Howells 		_leave(" = %d", ret);
1261da177e4SLinus Torvalds 		return ret;
1271da177e4SLinus Torvalds 	}
1281da177e4SLinus Torvalds 
12908e0e7c8SDavid Howells 	_leave(" = 0");
1301da177e4SLinus Torvalds 	return 0;
131ec26815aSDavid Howells }
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds /*
1341da177e4SLinus Torvalds  * clean up the filesystem
1351da177e4SLinus Torvalds  */
1365b86d4ffSDavid Howells void afs_fs_exit(void)
1371da177e4SLinus Torvalds {
13808e0e7c8SDavid Howells 	_enter("");
13908e0e7c8SDavid Howells 
14008e0e7c8SDavid Howells 	afs_mntpt_kill_timer();
1411da177e4SLinus Torvalds 	unregister_filesystem(&afs_fs_type);
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds 	if (atomic_read(&afs_count_active_inodes) != 0) {
1441da177e4SLinus Torvalds 		printk("kAFS: %d active inode objects still present\n",
1451da177e4SLinus Torvalds 		       atomic_read(&afs_count_active_inodes));
1461da177e4SLinus Torvalds 		BUG();
1471da177e4SLinus Torvalds 	}
1481da177e4SLinus Torvalds 
1498c0a8537SKirill A. Shutemov 	/*
1508c0a8537SKirill A. Shutemov 	 * Make sure all delayed rcu free inodes are flushed before we
1518c0a8537SKirill A. Shutemov 	 * destroy cache.
1528c0a8537SKirill A. Shutemov 	 */
1538c0a8537SKirill A. Shutemov 	rcu_barrier();
1541da177e4SLinus Torvalds 	kmem_cache_destroy(afs_inode_cachep);
15508e0e7c8SDavid Howells 	_leave("");
156ec26815aSDavid Howells }
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds /*
159677018a6SDavid Howells  * Display the mount device name in /proc/mounts.
160677018a6SDavid Howells  */
161677018a6SDavid Howells static int afs_show_devname(struct seq_file *m, struct dentry *root)
162677018a6SDavid Howells {
163d2ddc776SDavid Howells 	struct afs_super_info *as = AFS_FS_S(root->d_sb);
164677018a6SDavid Howells 	struct afs_volume *volume = as->volume;
165d2ddc776SDavid Howells 	struct afs_cell *cell = as->cell;
166677018a6SDavid Howells 	const char *suf = "";
167677018a6SDavid Howells 	char pref = '%';
168677018a6SDavid Howells 
1694d673da1SDavid Howells 	if (as->dyn_root) {
1704d673da1SDavid Howells 		seq_puts(m, "none");
1714d673da1SDavid Howells 		return 0;
1724d673da1SDavid Howells 	}
1734d673da1SDavid Howells 
174677018a6SDavid Howells 	switch (volume->type) {
175677018a6SDavid Howells 	case AFSVL_RWVOL:
176677018a6SDavid Howells 		break;
177677018a6SDavid Howells 	case AFSVL_ROVOL:
178677018a6SDavid Howells 		pref = '#';
179677018a6SDavid Howells 		if (volume->type_force)
180677018a6SDavid Howells 			suf = ".readonly";
181677018a6SDavid Howells 		break;
182677018a6SDavid Howells 	case AFSVL_BACKVOL:
183677018a6SDavid Howells 		pref = '#';
184677018a6SDavid Howells 		suf = ".backup";
185677018a6SDavid Howells 		break;
186677018a6SDavid Howells 	}
187677018a6SDavid Howells 
188d2ddc776SDavid Howells 	seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf);
189677018a6SDavid Howells 	return 0;
190677018a6SDavid Howells }
191677018a6SDavid Howells 
192677018a6SDavid Howells /*
193677018a6SDavid Howells  * Display the mount options in /proc/mounts.
194677018a6SDavid Howells  */
195677018a6SDavid Howells static int afs_show_options(struct seq_file *m, struct dentry *root)
196677018a6SDavid Howells {
1974d673da1SDavid Howells 	struct afs_super_info *as = AFS_FS_S(root->d_sb);
1986c6c1d63SDavid Howells 	const char *p = NULL;
1994d673da1SDavid Howells 
2004d673da1SDavid Howells 	if (as->dyn_root)
2014d673da1SDavid Howells 		seq_puts(m, ",dyn");
202677018a6SDavid Howells 	if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(d_inode(root))->flags))
2034d673da1SDavid Howells 		seq_puts(m, ",autocell");
2046c6c1d63SDavid Howells 	switch (as->flock_mode) {
2056c6c1d63SDavid Howells 	case afs_flock_mode_unset:	break;
2066c6c1d63SDavid Howells 	case afs_flock_mode_local:	p = "local";	break;
2076c6c1d63SDavid Howells 	case afs_flock_mode_openafs:	p = "openafs";	break;
2086c6c1d63SDavid Howells 	case afs_flock_mode_strict:	p = "strict";	break;
2096c6c1d63SDavid Howells 	case afs_flock_mode_write:	p = "write";	break;
2106c6c1d63SDavid Howells 	}
2116c6c1d63SDavid Howells 	if (p)
2126c6c1d63SDavid Howells 		seq_printf(m, ",flock=%s", p);
2136c6c1d63SDavid Howells 
214677018a6SDavid Howells 	return 0;
215677018a6SDavid Howells }
216677018a6SDavid Howells 
217677018a6SDavid Howells /*
21813fcc683SDavid Howells  * Parse the source name to get cell name, volume name, volume type and R/W
21913fcc683SDavid Howells  * selector.
22013fcc683SDavid Howells  *
22113fcc683SDavid Howells  * This can be one of the following:
22200d3b7a4SDavid Howells  *	"%[cell:]volume[.]"		R/W volume
223c99c2171SDavid Howells  *	"#[cell:]volume[.]"		R/O or R/W volume (R/O parent),
224c99c2171SDavid Howells  *					 or R/W (R/W parent) volume
22500d3b7a4SDavid Howells  *	"%[cell:]volume.readonly"	R/O volume
22600d3b7a4SDavid Howells  *	"#[cell:]volume.readonly"	R/O volume
22700d3b7a4SDavid Howells  *	"%[cell:]volume.backup"		Backup volume
22800d3b7a4SDavid Howells  *	"#[cell:]volume.backup"		Backup volume
22900d3b7a4SDavid Howells  */
23013fcc683SDavid Howells static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param)
23100d3b7a4SDavid Howells {
23213fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
23300d3b7a4SDavid Howells 	struct afs_cell *cell;
23413fcc683SDavid Howells 	const char *cellname, *suffix, *name = param->string;
23500d3b7a4SDavid Howells 	int cellnamesz;
23600d3b7a4SDavid Howells 
23700d3b7a4SDavid Howells 	_enter(",%s", name);
23800d3b7a4SDavid Howells 
23900d3b7a4SDavid Howells 	if (!name) {
24000d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: no volume name specified\n");
24100d3b7a4SDavid Howells 		return -EINVAL;
24200d3b7a4SDavid Howells 	}
24300d3b7a4SDavid Howells 
24400d3b7a4SDavid Howells 	if ((name[0] != '%' && name[0] != '#') || !name[1]) {
24513fcc683SDavid Howells 		/* To use dynroot, we don't want to have to provide a source */
24613fcc683SDavid Howells 		if (strcmp(name, "none") == 0) {
24713fcc683SDavid Howells 			ctx->no_cell = true;
24813fcc683SDavid Howells 			return 0;
24913fcc683SDavid Howells 		}
25000d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: unparsable volume name\n");
25100d3b7a4SDavid Howells 		return -EINVAL;
25200d3b7a4SDavid Howells 	}
25300d3b7a4SDavid Howells 
25400d3b7a4SDavid Howells 	/* determine the type of volume we're looking for */
255c99c2171SDavid Howells 	if (name[0] == '%') {
25613fcc683SDavid Howells 		ctx->type = AFSVL_RWVOL;
25713fcc683SDavid Howells 		ctx->force = true;
25800d3b7a4SDavid Howells 	}
25900d3b7a4SDavid Howells 	name++;
26000d3b7a4SDavid Howells 
26100d3b7a4SDavid Howells 	/* split the cell name out if there is one */
26213fcc683SDavid Howells 	ctx->volname = strchr(name, ':');
26313fcc683SDavid Howells 	if (ctx->volname) {
26400d3b7a4SDavid Howells 		cellname = name;
26513fcc683SDavid Howells 		cellnamesz = ctx->volname - name;
26613fcc683SDavid Howells 		ctx->volname++;
26700d3b7a4SDavid Howells 	} else {
26813fcc683SDavid Howells 		ctx->volname = name;
26900d3b7a4SDavid Howells 		cellname = NULL;
27000d3b7a4SDavid Howells 		cellnamesz = 0;
27100d3b7a4SDavid Howells 	}
27200d3b7a4SDavid Howells 
27300d3b7a4SDavid Howells 	/* the volume type is further affected by a possible suffix */
27413fcc683SDavid Howells 	suffix = strrchr(ctx->volname, '.');
27500d3b7a4SDavid Howells 	if (suffix) {
27600d3b7a4SDavid Howells 		if (strcmp(suffix, ".readonly") == 0) {
27713fcc683SDavid Howells 			ctx->type = AFSVL_ROVOL;
27813fcc683SDavid Howells 			ctx->force = true;
27900d3b7a4SDavid Howells 		} else if (strcmp(suffix, ".backup") == 0) {
28013fcc683SDavid Howells 			ctx->type = AFSVL_BACKVOL;
28113fcc683SDavid Howells 			ctx->force = true;
28200d3b7a4SDavid Howells 		} else if (suffix[1] == 0) {
28300d3b7a4SDavid Howells 		} else {
28400d3b7a4SDavid Howells 			suffix = NULL;
28500d3b7a4SDavid Howells 		}
28600d3b7a4SDavid Howells 	}
28700d3b7a4SDavid Howells 
28813fcc683SDavid Howells 	ctx->volnamesz = suffix ?
28913fcc683SDavid Howells 		suffix - ctx->volname : strlen(ctx->volname);
29000d3b7a4SDavid Howells 
29100d3b7a4SDavid Howells 	_debug("cell %*.*s [%p]",
29213fcc683SDavid Howells 	       cellnamesz, cellnamesz, cellname ?: "", ctx->cell);
29300d3b7a4SDavid Howells 
29400d3b7a4SDavid Howells 	/* lookup the cell record */
29513fcc683SDavid Howells 	if (cellname) {
29613fcc683SDavid Howells 		cell = afs_lookup_cell(ctx->net, cellname, cellnamesz,
297989782dcSDavid Howells 				       NULL, false);
29800d3b7a4SDavid Howells 		if (IS_ERR(cell)) {
29913fcc683SDavid Howells 			pr_err("kAFS: unable to lookup cell '%*.*s'\n",
300bec5eb61Swanglei 			       cellnamesz, cellnamesz, cellname ?: "");
30100d3b7a4SDavid Howells 			return PTR_ERR(cell);
30200d3b7a4SDavid Howells 		}
30313fcc683SDavid Howells 		afs_put_cell(ctx->net, ctx->cell);
30413fcc683SDavid Howells 		ctx->cell = cell;
30500d3b7a4SDavid Howells 	}
30600d3b7a4SDavid Howells 
30700d3b7a4SDavid Howells 	_debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
30813fcc683SDavid Howells 	       ctx->cell->name, ctx->cell,
30913fcc683SDavid Howells 	       ctx->volnamesz, ctx->volnamesz, ctx->volname,
31013fcc683SDavid Howells 	       suffix ?: "-", ctx->type, ctx->force ? " FORCE" : "");
31113fcc683SDavid Howells 
31213fcc683SDavid Howells 	fc->source = param->string;
31313fcc683SDavid Howells 	param->string = NULL;
31413fcc683SDavid Howells 	return 0;
31513fcc683SDavid Howells }
31613fcc683SDavid Howells 
31713fcc683SDavid Howells /*
31813fcc683SDavid Howells  * Parse a single mount parameter.
31913fcc683SDavid Howells  */
32013fcc683SDavid Howells static int afs_parse_param(struct fs_context *fc, struct fs_parameter *param)
32113fcc683SDavid Howells {
32213fcc683SDavid Howells 	struct fs_parse_result result;
32313fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
32413fcc683SDavid Howells 	int opt;
32513fcc683SDavid Howells 
32613fcc683SDavid Howells 	opt = fs_parse(fc, &afs_fs_parameters, param, &result);
32713fcc683SDavid Howells 	if (opt < 0)
32813fcc683SDavid Howells 		return opt;
32913fcc683SDavid Howells 
33013fcc683SDavid Howells 	switch (opt) {
33113fcc683SDavid Howells 	case Opt_source:
33213fcc683SDavid Howells 		return afs_parse_source(fc, param);
33313fcc683SDavid Howells 
33413fcc683SDavid Howells 	case Opt_autocell:
33513fcc683SDavid Howells 		ctx->autocell = true;
33613fcc683SDavid Howells 		break;
33713fcc683SDavid Howells 
33813fcc683SDavid Howells 	case Opt_dyn:
33913fcc683SDavid Howells 		ctx->dyn_root = true;
34013fcc683SDavid Howells 		break;
34113fcc683SDavid Howells 
3426c6c1d63SDavid Howells 	case Opt_flock:
3436c6c1d63SDavid Howells 		ctx->flock_mode = result.uint_32;
3446c6c1d63SDavid Howells 		break;
3456c6c1d63SDavid Howells 
34613fcc683SDavid Howells 	default:
34713fcc683SDavid Howells 		return -EINVAL;
34813fcc683SDavid Howells 	}
34913fcc683SDavid Howells 
35013fcc683SDavid Howells 	_leave(" = 0");
35113fcc683SDavid Howells 	return 0;
35213fcc683SDavid Howells }
35313fcc683SDavid Howells 
35413fcc683SDavid Howells /*
35513fcc683SDavid Howells  * Validate the options, get the cell key and look up the volume.
35613fcc683SDavid Howells  */
35713fcc683SDavid Howells static int afs_validate_fc(struct fs_context *fc)
35813fcc683SDavid Howells {
35913fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
36013fcc683SDavid Howells 	struct afs_volume *volume;
36113fcc683SDavid Howells 	struct key *key;
36213fcc683SDavid Howells 
36313fcc683SDavid Howells 	if (!ctx->dyn_root) {
36413fcc683SDavid Howells 		if (ctx->no_cell) {
36513fcc683SDavid Howells 			pr_warn("kAFS: Can only specify source 'none' with -o dyn\n");
36613fcc683SDavid Howells 			return -EINVAL;
36713fcc683SDavid Howells 		}
36813fcc683SDavid Howells 
36913fcc683SDavid Howells 		if (!ctx->cell) {
37013fcc683SDavid Howells 			pr_warn("kAFS: No cell specified\n");
37113fcc683SDavid Howells 			return -EDESTADDRREQ;
37213fcc683SDavid Howells 		}
37313fcc683SDavid Howells 
37413fcc683SDavid Howells 		/* We try to do the mount securely. */
37513fcc683SDavid Howells 		key = afs_request_key(ctx->cell);
37613fcc683SDavid Howells 		if (IS_ERR(key))
37713fcc683SDavid Howells 			return PTR_ERR(key);
37813fcc683SDavid Howells 
37913fcc683SDavid Howells 		ctx->key = key;
38013fcc683SDavid Howells 
38113fcc683SDavid Howells 		if (ctx->volume) {
38213fcc683SDavid Howells 			afs_put_volume(ctx->cell, ctx->volume);
38313fcc683SDavid Howells 			ctx->volume = NULL;
38413fcc683SDavid Howells 		}
38513fcc683SDavid Howells 
38613fcc683SDavid Howells 		volume = afs_create_volume(ctx);
38713fcc683SDavid Howells 		if (IS_ERR(volume))
38813fcc683SDavid Howells 			return PTR_ERR(volume);
38913fcc683SDavid Howells 
39013fcc683SDavid Howells 		ctx->volume = volume;
39113fcc683SDavid Howells 	}
39200d3b7a4SDavid Howells 
39300d3b7a4SDavid Howells 	return 0;
39400d3b7a4SDavid Howells }
39500d3b7a4SDavid Howells 
39600d3b7a4SDavid Howells /*
3971da177e4SLinus Torvalds  * check a superblock to see if it's the one we're looking for
3981da177e4SLinus Torvalds  */
39913fcc683SDavid Howells static int afs_test_super(struct super_block *sb, struct fs_context *fc)
4001da177e4SLinus Torvalds {
40113fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
402d2ddc776SDavid Howells 	struct afs_super_info *as = AFS_FS_S(sb);
4031da177e4SLinus Torvalds 
40413fcc683SDavid Howells 	return (as->net_ns == fc->net_ns &&
4054d673da1SDavid Howells 		as->volume &&
40613fcc683SDavid Howells 		as->volume->vid == ctx->volume->vid &&
4070da0b7fdSDavid Howells 		!as->dyn_root);
4084d673da1SDavid Howells }
4094d673da1SDavid Howells 
41013fcc683SDavid Howells static int afs_dynroot_test_super(struct super_block *sb, struct fs_context *fc)
4114d673da1SDavid Howells {
4120da0b7fdSDavid Howells 	struct afs_super_info *as = AFS_FS_S(sb);
4130da0b7fdSDavid Howells 
41413fcc683SDavid Howells 	return (as->net_ns == fc->net_ns &&
4150da0b7fdSDavid Howells 		as->dyn_root);
416dde194a6SAl Viro }
417dde194a6SAl Viro 
41813fcc683SDavid Howells static int afs_set_super(struct super_block *sb, struct fs_context *fc)
419dde194a6SAl Viro {
420dde194a6SAl Viro 	return set_anon_super(sb, NULL);
421ec26815aSDavid Howells }
4221da177e4SLinus Torvalds 
4231da177e4SLinus Torvalds /*
4241da177e4SLinus Torvalds  * fill in the superblock
4251da177e4SLinus Torvalds  */
42613fcc683SDavid Howells static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)
4271da177e4SLinus Torvalds {
428d2ddc776SDavid Howells 	struct afs_super_info *as = AFS_FS_S(sb);
429b8359153SDavid Howells 	struct afs_iget_data iget_data;
4301da177e4SLinus Torvalds 	struct inode *inode = NULL;
4311da177e4SLinus Torvalds 	int ret;
4321da177e4SLinus Torvalds 
43308e0e7c8SDavid Howells 	_enter("");
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds 	/* fill in the superblock */
43609cbfeafSKirill A. Shutemov 	sb->s_blocksize		= PAGE_SIZE;
43709cbfeafSKirill A. Shutemov 	sb->s_blocksize_bits	= PAGE_SHIFT;
438*b485275fSMarc Dionne 	sb->s_maxbytes		= MAX_LFS_FILESIZE;
4391da177e4SLinus Torvalds 	sb->s_magic		= AFS_FS_MAGIC;
4401da177e4SLinus Torvalds 	sb->s_op		= &afs_super_ops;
4414d673da1SDavid Howells 	if (!as->dyn_root)
442d3e3b7eaSDavid Howells 		sb->s_xattr	= afs_xattr_handlers;
443edd3ba94SJan Kara 	ret = super_setup_bdi(sb);
444edd3ba94SJan Kara 	if (ret)
445edd3ba94SJan Kara 		return ret;
446b5420237SNikolay Borisov 	sb->s_bdi->ra_pages	= VM_READAHEAD_PAGES;
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds 	/* allocate the root inode and dentry */
4494d673da1SDavid Howells 	if (as->dyn_root) {
4504d673da1SDavid Howells 		inode = afs_iget_pseudo_dir(sb, true);
4514d673da1SDavid Howells 		sb->s_flags	|= SB_RDONLY;
4524d673da1SDavid Howells 	} else {
4533b6492dfSDavid Howells 		sprintf(sb->s_id, "%llu", as->volume->vid);
4544d673da1SDavid Howells 		afs_activate_volume(as->volume);
455b8359153SDavid Howells 		iget_data.fid.vid	= as->volume->vid;
456b8359153SDavid Howells 		iget_data.fid.vnode	= 1;
457b8359153SDavid Howells 		iget_data.fid.vnode_hi	= 0;
458b8359153SDavid Howells 		iget_data.fid.unique	= 1;
459b8359153SDavid Howells 		iget_data.cb_v_break	= as->volume->cb_v_break;
460b8359153SDavid Howells 		iget_data.cb_s_break	= 0;
461b8359153SDavid Howells 		inode = afs_iget(sb, ctx->key, &iget_data, NULL, NULL, NULL);
4624d673da1SDavid Howells 	}
4634d673da1SDavid Howells 
46408e0e7c8SDavid Howells 	if (IS_ERR(inode))
465dde194a6SAl Viro 		return PTR_ERR(inode);
4661da177e4SLinus Torvalds 
46713fcc683SDavid Howells 	if (ctx->autocell || as->dyn_root)
468bec5eb61Swanglei 		set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags);
469bec5eb61Swanglei 
4701da177e4SLinus Torvalds 	ret = -ENOMEM;
47148fde701SAl Viro 	sb->s_root = d_make_root(inode);
47248fde701SAl Viro 	if (!sb->s_root)
4731da177e4SLinus Torvalds 		goto error;
4741da177e4SLinus Torvalds 
4750da0b7fdSDavid Howells 	if (as->dyn_root) {
47666c7e1d3SDavid Howells 		sb->s_d_op = &afs_dynroot_dentry_operations;
4770da0b7fdSDavid Howells 		ret = afs_dynroot_populate(sb);
4780da0b7fdSDavid Howells 		if (ret < 0)
4790da0b7fdSDavid Howells 			goto error;
4800da0b7fdSDavid Howells 	} else {
481d61dcce2SAl Viro 		sb->s_d_op = &afs_fs_dentry_operations;
4820da0b7fdSDavid Howells 	}
4831da177e4SLinus Torvalds 
48408e0e7c8SDavid Howells 	_leave(" = 0");
4851da177e4SLinus Torvalds 	return 0;
4861da177e4SLinus Torvalds 
4871da177e4SLinus Torvalds error:
48808e0e7c8SDavid Howells 	_leave(" = %d", ret);
4891da177e4SLinus Torvalds 	return ret;
490ec26815aSDavid Howells }
4911da177e4SLinus Torvalds 
49213fcc683SDavid Howells static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc)
49349566f6fSDavid Howells {
49413fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
49549566f6fSDavid Howells 	struct afs_super_info *as;
49649566f6fSDavid Howells 
49749566f6fSDavid Howells 	as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
49849566f6fSDavid Howells 	if (as) {
49913fcc683SDavid Howells 		as->net_ns = get_net(fc->net_ns);
5006c6c1d63SDavid Howells 		as->flock_mode = ctx->flock_mode;
50113fcc683SDavid Howells 		if (ctx->dyn_root) {
5024d673da1SDavid Howells 			as->dyn_root = true;
50313fcc683SDavid Howells 		} else {
50413fcc683SDavid Howells 			as->cell = afs_get_cell(ctx->cell);
50513fcc683SDavid Howells 			as->volume = __afs_get_volume(ctx->volume);
50613fcc683SDavid Howells 		}
50749566f6fSDavid Howells 	}
50849566f6fSDavid Howells 	return as;
50949566f6fSDavid Howells }
51049566f6fSDavid Howells 
51149566f6fSDavid Howells static void afs_destroy_sbi(struct afs_super_info *as)
51249566f6fSDavid Howells {
51349566f6fSDavid Howells 	if (as) {
5149ed900b1SDavid Howells 		afs_put_volume(as->cell, as->volume);
5155b86d4ffSDavid Howells 		afs_put_cell(afs_net(as->net_ns), as->cell);
5165b86d4ffSDavid Howells 		put_net(as->net_ns);
51749566f6fSDavid Howells 		kfree(as);
51849566f6fSDavid Howells 	}
51949566f6fSDavid Howells }
52049566f6fSDavid Howells 
5210da0b7fdSDavid Howells static void afs_kill_super(struct super_block *sb)
5220da0b7fdSDavid Howells {
5230da0b7fdSDavid Howells 	struct afs_super_info *as = AFS_FS_S(sb);
5240da0b7fdSDavid Howells 	struct afs_net *net = afs_net(as->net_ns);
5250da0b7fdSDavid Howells 
5260da0b7fdSDavid Howells 	if (as->dyn_root)
5270da0b7fdSDavid Howells 		afs_dynroot_depopulate(sb);
5280da0b7fdSDavid Howells 
5290da0b7fdSDavid Howells 	/* Clear the callback interests (which will do ilookup5) before
5300da0b7fdSDavid Howells 	 * deactivating the superblock.
5310da0b7fdSDavid Howells 	 */
5320da0b7fdSDavid Howells 	if (as->volume)
5330da0b7fdSDavid Howells 		afs_clear_callback_interests(net, as->volume->servers);
5340da0b7fdSDavid Howells 	kill_anon_super(sb);
5350da0b7fdSDavid Howells 	if (as->volume)
5360da0b7fdSDavid Howells 		afs_deactivate_volume(as->volume);
5370da0b7fdSDavid Howells 	afs_destroy_sbi(as);
5380da0b7fdSDavid Howells }
5390da0b7fdSDavid Howells 
5401da177e4SLinus Torvalds /*
54113fcc683SDavid Howells  * Get an AFS superblock and root directory.
5421da177e4SLinus Torvalds  */
54313fcc683SDavid Howells static int afs_get_tree(struct fs_context *fc)
5441da177e4SLinus Torvalds {
54513fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
5461da177e4SLinus Torvalds 	struct super_block *sb;
547dde194a6SAl Viro 	struct afs_super_info *as;
5481da177e4SLinus Torvalds 	int ret;
5491da177e4SLinus Torvalds 
55013fcc683SDavid Howells 	ret = afs_validate_fc(fc);
55113fcc683SDavid Howells 	if (ret)
55200d3b7a4SDavid Howells 		goto error;
55300d3b7a4SDavid Howells 
55413fcc683SDavid Howells 	_enter("");
55500d3b7a4SDavid Howells 
55649566f6fSDavid Howells 	/* allocate a superblock info record */
55749566f6fSDavid Howells 	ret = -ENOMEM;
55813fcc683SDavid Howells 	as = afs_alloc_sbi(fc);
55949566f6fSDavid Howells 	if (!as)
56013fcc683SDavid Howells 		goto error;
56113fcc683SDavid Howells 	fc->s_fs_info = as;
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds 	/* allocate a deviceless superblock */
56413fcc683SDavid Howells 	sb = sget_fc(fc,
5654d673da1SDavid Howells 		     as->dyn_root ? afs_dynroot_test_super : afs_test_super,
56613fcc683SDavid Howells 		     afs_set_super);
56708e0e7c8SDavid Howells 	if (IS_ERR(sb)) {
56808e0e7c8SDavid Howells 		ret = PTR_ERR(sb);
56913fcc683SDavid Howells 		goto error;
57008e0e7c8SDavid Howells 	}
5711da177e4SLinus Torvalds 
572436058a4SDavid Howells 	if (!sb->s_root) {
573436058a4SDavid Howells 		/* initial superblock/root creation */
574436058a4SDavid Howells 		_debug("create");
57513fcc683SDavid Howells 		ret = afs_fill_super(sb, ctx);
576f044c884SDavid Howells 		if (ret < 0)
577f044c884SDavid Howells 			goto error_sb;
5781751e8a6SLinus Torvalds 		sb->s_flags |= SB_ACTIVE;
579436058a4SDavid Howells 	} else {
580436058a4SDavid Howells 		_debug("reuse");
5811751e8a6SLinus Torvalds 		ASSERTCMP(sb->s_flags, &, SB_ACTIVE);
582436058a4SDavid Howells 	}
5831da177e4SLinus Torvalds 
58413fcc683SDavid Howells 	fc->root = dget(sb->s_root);
58580548b03SDavid Howells 	trace_afs_get_tree(as->cell, as->volume);
58608e0e7c8SDavid Howells 	_leave(" = 0 [%p]", sb);
58713fcc683SDavid Howells 	return 0;
5881da177e4SLinus Torvalds 
589f044c884SDavid Howells error_sb:
590f044c884SDavid Howells 	deactivate_locked_super(sb);
5911da177e4SLinus Torvalds error:
5921da177e4SLinus Torvalds 	_leave(" = %d", ret);
59313fcc683SDavid Howells 	return ret;
59413fcc683SDavid Howells }
59513fcc683SDavid Howells 
59613fcc683SDavid Howells static void afs_free_fc(struct fs_context *fc)
59713fcc683SDavid Howells {
59813fcc683SDavid Howells 	struct afs_fs_context *ctx = fc->fs_private;
59913fcc683SDavid Howells 
60013fcc683SDavid Howells 	afs_destroy_sbi(fc->s_fs_info);
60113fcc683SDavid Howells 	afs_put_volume(ctx->cell, ctx->volume);
60213fcc683SDavid Howells 	afs_put_cell(ctx->net, ctx->cell);
60313fcc683SDavid Howells 	key_put(ctx->key);
60413fcc683SDavid Howells 	kfree(ctx);
60513fcc683SDavid Howells }
60613fcc683SDavid Howells 
60713fcc683SDavid Howells static const struct fs_context_operations afs_context_ops = {
60813fcc683SDavid Howells 	.free		= afs_free_fc,
60913fcc683SDavid Howells 	.parse_param	= afs_parse_param,
61013fcc683SDavid Howells 	.get_tree	= afs_get_tree,
61113fcc683SDavid Howells };
61213fcc683SDavid Howells 
61313fcc683SDavid Howells /*
61413fcc683SDavid Howells  * Set up the filesystem mount context.
61513fcc683SDavid Howells  */
61613fcc683SDavid Howells static int afs_init_fs_context(struct fs_context *fc)
61713fcc683SDavid Howells {
61813fcc683SDavid Howells 	struct afs_fs_context *ctx;
61913fcc683SDavid Howells 	struct afs_cell *cell;
62013fcc683SDavid Howells 
62113fcc683SDavid Howells 	ctx = kzalloc(sizeof(struct afs_fs_context), GFP_KERNEL);
62213fcc683SDavid Howells 	if (!ctx)
62313fcc683SDavid Howells 		return -ENOMEM;
62413fcc683SDavid Howells 
62513fcc683SDavid Howells 	ctx->type = AFSVL_ROVOL;
62613fcc683SDavid Howells 	ctx->net = afs_net(fc->net_ns);
62713fcc683SDavid Howells 
62813fcc683SDavid Howells 	/* Default to the workstation cell. */
62913fcc683SDavid Howells 	rcu_read_lock();
63013fcc683SDavid Howells 	cell = afs_lookup_cell_rcu(ctx->net, NULL, 0);
63113fcc683SDavid Howells 	rcu_read_unlock();
63213fcc683SDavid Howells 	if (IS_ERR(cell))
63313fcc683SDavid Howells 		cell = NULL;
63413fcc683SDavid Howells 	ctx->cell = cell;
63513fcc683SDavid Howells 
63613fcc683SDavid Howells 	fc->fs_private = ctx;
63713fcc683SDavid Howells 	fc->ops = &afs_context_ops;
63813fcc683SDavid Howells 	return 0;
639ec26815aSDavid Howells }
6401da177e4SLinus Torvalds 
6411da177e4SLinus Torvalds /*
642f8de483eSDavid Howells  * Initialise an inode cache slab element prior to any use.  Note that
643f8de483eSDavid Howells  * afs_alloc_inode() *must* reset anything that could incorrectly leak from one
644f8de483eSDavid Howells  * inode to another.
6451da177e4SLinus Torvalds  */
64651cc5068SAlexey Dobriyan static void afs_i_init_once(void *_vnode)
6471da177e4SLinus Torvalds {
648ec26815aSDavid Howells 	struct afs_vnode *vnode = _vnode;
6491da177e4SLinus Torvalds 
6501da177e4SLinus Torvalds 	memset(vnode, 0, sizeof(*vnode));
6511da177e4SLinus Torvalds 	inode_init_once(&vnode->vfs_inode);
652d2ddc776SDavid Howells 	mutex_init(&vnode->io_lock);
653b61f7dcfSDavid Howells 	init_rwsem(&vnode->validate_lock);
6544343d008SDavid Howells 	spin_lock_init(&vnode->wb_lock);
6551da177e4SLinus Torvalds 	spin_lock_init(&vnode->lock);
6564343d008SDavid Howells 	INIT_LIST_HEAD(&vnode->wb_keys);
657e8d6c554SDavid Howells 	INIT_LIST_HEAD(&vnode->pending_locks);
658e8d6c554SDavid Howells 	INIT_LIST_HEAD(&vnode->granted_locks);
659e8d6c554SDavid Howells 	INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work);
660c435ee34SDavid Howells 	seqlock_init(&vnode->cb_lock);
6611da177e4SLinus Torvalds }
6621da177e4SLinus Torvalds 
6631da177e4SLinus Torvalds /*
6641da177e4SLinus Torvalds  * allocate an AFS inode struct from our slab cache
6651da177e4SLinus Torvalds  */
6661da177e4SLinus Torvalds static struct inode *afs_alloc_inode(struct super_block *sb)
6671da177e4SLinus Torvalds {
6681da177e4SLinus Torvalds 	struct afs_vnode *vnode;
6691da177e4SLinus Torvalds 
670ec26815aSDavid Howells 	vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
6711da177e4SLinus Torvalds 	if (!vnode)
6721da177e4SLinus Torvalds 		return NULL;
6731da177e4SLinus Torvalds 
6741da177e4SLinus Torvalds 	atomic_inc(&afs_count_active_inodes);
6751da177e4SLinus Torvalds 
676f8de483eSDavid Howells 	/* Reset anything that shouldn't leak from one inode to the next. */
6771da177e4SLinus Torvalds 	memset(&vnode->fid, 0, sizeof(vnode->fid));
6781da177e4SLinus Torvalds 	memset(&vnode->status, 0, sizeof(vnode->status));
6791da177e4SLinus Torvalds 
6801da177e4SLinus Torvalds 	vnode->volume		= NULL;
681f8de483eSDavid Howells 	vnode->lock_key		= NULL;
682f8de483eSDavid Howells 	vnode->permit_cache	= NULL;
683f642404aSDavid Howells 	RCU_INIT_POINTER(vnode->cb_interest, NULL);
684f8de483eSDavid Howells #ifdef CONFIG_AFS_FSCACHE
685f8de483eSDavid Howells 	vnode->cache		= NULL;
686f8de483eSDavid Howells #endif
687f8de483eSDavid Howells 
688260a9803SDavid Howells 	vnode->flags		= 1 << AFS_VNODE_UNSET;
689f8de483eSDavid Howells 	vnode->lock_state	= AFS_VNODE_LOCK_NONE;
6901da177e4SLinus Torvalds 
69179ddbfa5SDavid Howells 	init_rwsem(&vnode->rmdir_lock);
69279ddbfa5SDavid Howells 
6930f300ca9SDavid Howells 	_leave(" = %p", &vnode->vfs_inode);
6941da177e4SLinus Torvalds 	return &vnode->vfs_inode;
695ec26815aSDavid Howells }
6961da177e4SLinus Torvalds 
69751b9fe48SAl Viro static void afs_free_inode(struct inode *inode)
698fa0d7e3dSNick Piggin {
69951b9fe48SAl Viro 	kmem_cache_free(afs_inode_cachep, AFS_FS_I(inode));
700fa0d7e3dSNick Piggin }
701fa0d7e3dSNick Piggin 
7021da177e4SLinus Torvalds /*
7031da177e4SLinus Torvalds  * destroy an AFS inode struct
7041da177e4SLinus Torvalds  */
7051da177e4SLinus Torvalds static void afs_destroy_inode(struct inode *inode)
7061da177e4SLinus Torvalds {
70708e0e7c8SDavid Howells 	struct afs_vnode *vnode = AFS_FS_I(inode);
70808e0e7c8SDavid Howells 
7093b6492dfSDavid Howells 	_enter("%p{%llx:%llu}", inode, vnode->fid.vid, vnode->fid.vnode);
7101da177e4SLinus Torvalds 
71108e0e7c8SDavid Howells 	_debug("DESTROY INODE %p", inode);
71208e0e7c8SDavid Howells 
713f642404aSDavid Howells 	ASSERTCMP(rcu_access_pointer(vnode->cb_interest), ==, NULL);
71408e0e7c8SDavid Howells 
7151da177e4SLinus Torvalds 	atomic_dec(&afs_count_active_inodes);
716ec26815aSDavid Howells }
71745222b9eSDavid Howells 
71845222b9eSDavid Howells /*
71945222b9eSDavid Howells  * return information about an AFS volume
72045222b9eSDavid Howells  */
72145222b9eSDavid Howells static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
72245222b9eSDavid Howells {
7234d673da1SDavid Howells 	struct afs_super_info *as = AFS_FS_S(dentry->d_sb);
724d2ddc776SDavid Howells 	struct afs_fs_cursor fc;
72545222b9eSDavid Howells 	struct afs_volume_status vs;
7262b0143b5SDavid Howells 	struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
72745222b9eSDavid Howells 	struct key *key;
72845222b9eSDavid Howells 	int ret;
72945222b9eSDavid Howells 
7304d673da1SDavid Howells 	buf->f_type	= dentry->d_sb->s_magic;
7314d673da1SDavid Howells 	buf->f_bsize	= AFS_BLOCK_SIZE;
7324d673da1SDavid Howells 	buf->f_namelen	= AFSNAMEMAX - 1;
7334d673da1SDavid Howells 
7344d673da1SDavid Howells 	if (as->dyn_root) {
7354d673da1SDavid Howells 		buf->f_blocks	= 1;
7364d673da1SDavid Howells 		buf->f_bavail	= 0;
7374d673da1SDavid Howells 		buf->f_bfree	= 0;
7384d673da1SDavid Howells 		return 0;
7394d673da1SDavid Howells 	}
7404d673da1SDavid Howells 
74145222b9eSDavid Howells 	key = afs_request_key(vnode->volume->cell);
74245222b9eSDavid Howells 	if (IS_ERR(key))
74345222b9eSDavid Howells 		return PTR_ERR(key);
74445222b9eSDavid Howells 
745d2ddc776SDavid Howells 	ret = -ERESTARTSYS;
74620b8391fSDavid Howells 	if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
747d2ddc776SDavid Howells 		fc.flags |= AFS_FS_CURSOR_NO_VSLEEP;
748d2ddc776SDavid Howells 		while (afs_select_fileserver(&fc)) {
74968251f0aSDavid Howells 			fc.cb_break = afs_calc_vnode_cb_break(vnode);
750d2ddc776SDavid Howells 			afs_fs_get_volume_status(&fc, &vs);
75145222b9eSDavid Howells 		}
75245222b9eSDavid Howells 
753d2ddc776SDavid Howells 		afs_check_for_remote_deletion(&fc, fc.vnode);
754d2ddc776SDavid Howells 		ret = afs_end_vnode_operation(&fc);
755d2ddc776SDavid Howells 	}
756d2ddc776SDavid Howells 
757d2ddc776SDavid Howells 	key_put(key);
758d2ddc776SDavid Howells 
759d2ddc776SDavid Howells 	if (ret == 0) {
76045222b9eSDavid Howells 		if (vs.max_quota == 0)
76145222b9eSDavid Howells 			buf->f_blocks = vs.part_max_blocks;
76245222b9eSDavid Howells 		else
76345222b9eSDavid Howells 			buf->f_blocks = vs.max_quota;
76445222b9eSDavid Howells 		buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use;
765d2ddc776SDavid Howells 	}
766d2ddc776SDavid Howells 
767d2ddc776SDavid Howells 	return ret;
76845222b9eSDavid Howells }
769