xref: /openbmc/linux/fs/afs/super.c (revision 0f300ca9284caabdd2c07c7f91b90f1f530f614e)
1ec26815aSDavid Howells /* AFS superblock handling
2ec26815aSDavid Howells  *
308e0e7c8SDavid Howells  * Copyright (c) 2002, 2007 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>
13ec26815aSDavid Howells  *          David Woodhouse <dwmw2@redhat.com>
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #include <linux/kernel.h>
181da177e4SLinus Torvalds #include <linux/module.h>
191da177e4SLinus Torvalds #include <linux/init.h>
201da177e4SLinus Torvalds #include <linux/slab.h>
211da177e4SLinus Torvalds #include <linux/fs.h>
221da177e4SLinus Torvalds #include <linux/pagemap.h>
2380c72fe4SDavid Howells #include <linux/parser.h>
241da177e4SLinus Torvalds #include "internal.h"
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */
271da177e4SLinus Torvalds 
28e18b890bSChristoph Lameter static void afs_i_init_once(void *foo, struct kmem_cache *cachep,
291da177e4SLinus Torvalds 			    unsigned long flags);
301da177e4SLinus Torvalds 
31454e2398SDavid Howells static int afs_get_sb(struct file_system_type *fs_type,
321da177e4SLinus Torvalds 		      int flags, const char *dev_name,
33454e2398SDavid Howells 		      void *data, struct vfsmount *mnt);
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds static struct inode *afs_alloc_inode(struct super_block *sb);
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds static void afs_put_super(struct super_block *sb);
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds static void afs_destroy_inode(struct inode *inode);
401da177e4SLinus Torvalds 
411f5ce9e9STrond Myklebust struct file_system_type afs_fs_type = {
421da177e4SLinus Torvalds 	.owner		= THIS_MODULE,
431da177e4SLinus Torvalds 	.name		= "afs",
441da177e4SLinus Torvalds 	.get_sb		= afs_get_sb,
451da177e4SLinus Torvalds 	.kill_sb	= kill_anon_super,
4680c72fe4SDavid Howells 	.fs_flags	= 0,
471da177e4SLinus Torvalds };
481da177e4SLinus Torvalds 
49ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations afs_super_ops = {
501da177e4SLinus Torvalds 	.statfs		= simple_statfs,
511da177e4SLinus Torvalds 	.alloc_inode	= afs_alloc_inode,
521da177e4SLinus Torvalds 	.drop_inode	= generic_delete_inode,
5331143d5dSDavid Howells 	.write_inode	= afs_write_inode,
541da177e4SLinus Torvalds 	.destroy_inode	= afs_destroy_inode,
551da177e4SLinus Torvalds 	.clear_inode	= afs_clear_inode,
5608e0e7c8SDavid Howells 	.umount_begin	= afs_umount_begin,
571da177e4SLinus Torvalds 	.put_super	= afs_put_super,
581da177e4SLinus Torvalds };
591da177e4SLinus Torvalds 
60e18b890bSChristoph Lameter static struct kmem_cache *afs_inode_cachep;
611da177e4SLinus Torvalds static atomic_t afs_count_active_inodes;
621da177e4SLinus Torvalds 
6380c72fe4SDavid Howells enum {
6480c72fe4SDavid Howells 	afs_no_opt,
6580c72fe4SDavid Howells 	afs_opt_cell,
6680c72fe4SDavid Howells 	afs_opt_rwpath,
6780c72fe4SDavid Howells 	afs_opt_vol,
6880c72fe4SDavid Howells };
6980c72fe4SDavid Howells 
7031143d5dSDavid Howells static match_table_t afs_options_list = {
7180c72fe4SDavid Howells 	{ afs_opt_cell,		"cell=%s"	},
7280c72fe4SDavid Howells 	{ afs_opt_rwpath,	"rwpath"	},
7380c72fe4SDavid Howells 	{ afs_opt_vol,		"vol=%s"	},
7480c72fe4SDavid Howells 	{ afs_no_opt,		NULL		},
7580c72fe4SDavid Howells };
7680c72fe4SDavid Howells 
771da177e4SLinus Torvalds /*
781da177e4SLinus Torvalds  * initialise the filesystem
791da177e4SLinus Torvalds  */
801da177e4SLinus Torvalds int __init afs_fs_init(void)
811da177e4SLinus Torvalds {
821da177e4SLinus Torvalds 	int ret;
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds 	_enter("");
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds 	/* create ourselves an inode cache */
871da177e4SLinus Torvalds 	atomic_set(&afs_count_active_inodes, 0);
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds 	ret = -ENOMEM;
901da177e4SLinus Torvalds 	afs_inode_cachep = kmem_cache_create("afs_inode_cache",
911da177e4SLinus Torvalds 					     sizeof(struct afs_vnode),
921da177e4SLinus Torvalds 					     0,
931da177e4SLinus Torvalds 					     SLAB_HWCACHE_ALIGN,
941da177e4SLinus Torvalds 					     afs_i_init_once,
951da177e4SLinus Torvalds 					     NULL);
961da177e4SLinus Torvalds 	if (!afs_inode_cachep) {
971da177e4SLinus Torvalds 		printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
981da177e4SLinus Torvalds 		return ret;
991da177e4SLinus Torvalds 	}
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds 	/* now export our filesystem to lesser mortals */
1021da177e4SLinus Torvalds 	ret = register_filesystem(&afs_fs_type);
1031da177e4SLinus Torvalds 	if (ret < 0) {
1041da177e4SLinus Torvalds 		kmem_cache_destroy(afs_inode_cachep);
10508e0e7c8SDavid Howells 		_leave(" = %d", ret);
1061da177e4SLinus Torvalds 		return ret;
1071da177e4SLinus Torvalds 	}
1081da177e4SLinus Torvalds 
10908e0e7c8SDavid Howells 	_leave(" = 0");
1101da177e4SLinus Torvalds 	return 0;
111ec26815aSDavid Howells }
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds /*
1141da177e4SLinus Torvalds  * clean up the filesystem
1151da177e4SLinus Torvalds  */
1161da177e4SLinus Torvalds void __exit afs_fs_exit(void)
1171da177e4SLinus Torvalds {
11808e0e7c8SDavid Howells 	_enter("");
11908e0e7c8SDavid Howells 
12008e0e7c8SDavid Howells 	afs_mntpt_kill_timer();
1211da177e4SLinus Torvalds 	unregister_filesystem(&afs_fs_type);
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds 	if (atomic_read(&afs_count_active_inodes) != 0) {
1241da177e4SLinus Torvalds 		printk("kAFS: %d active inode objects still present\n",
1251da177e4SLinus Torvalds 		       atomic_read(&afs_count_active_inodes));
1261da177e4SLinus Torvalds 		BUG();
1271da177e4SLinus Torvalds 	}
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds 	kmem_cache_destroy(afs_inode_cachep);
13008e0e7c8SDavid Howells 	_leave("");
131ec26815aSDavid Howells }
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds /*
1341da177e4SLinus Torvalds  * parse the mount options
1351da177e4SLinus Torvalds  * - this function has been shamelessly adapted from the ext3 fs which
1361da177e4SLinus Torvalds  *   shamelessly adapted it from the msdos fs
1371da177e4SLinus Torvalds  */
13800d3b7a4SDavid Howells static int afs_parse_options(struct afs_mount_params *params,
13908e0e7c8SDavid Howells 			     char *options, const char **devname)
1401da177e4SLinus Torvalds {
14108e0e7c8SDavid Howells 	struct afs_cell *cell;
14280c72fe4SDavid Howells 	substring_t args[MAX_OPT_ARGS];
14380c72fe4SDavid Howells 	char *p;
14480c72fe4SDavid Howells 	int token;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	_enter("%s", options);
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	options[PAGE_SIZE - 1] = 0;
1491da177e4SLinus Torvalds 
15080c72fe4SDavid Howells 	while ((p = strsep(&options, ","))) {
15180c72fe4SDavid Howells 		if (!*p)
15280c72fe4SDavid Howells 			continue;
1531da177e4SLinus Torvalds 
15480c72fe4SDavid Howells 		token = match_token(p, afs_options_list, args);
15580c72fe4SDavid Howells 		switch (token) {
15680c72fe4SDavid Howells 		case afs_opt_cell:
15780c72fe4SDavid Howells 			cell = afs_cell_lookup(args[0].from,
15880c72fe4SDavid Howells 					       args[0].to - args[0].from);
15908e0e7c8SDavid Howells 			if (IS_ERR(cell))
16008e0e7c8SDavid Howells 				return PTR_ERR(cell);
16100d3b7a4SDavid Howells 			afs_put_cell(params->cell);
16200d3b7a4SDavid Howells 			params->cell = cell;
16380c72fe4SDavid Howells 			break;
16480c72fe4SDavid Howells 
16580c72fe4SDavid Howells 		case afs_opt_rwpath:
16680c72fe4SDavid Howells 			params->rwpath = 1;
16780c72fe4SDavid Howells 			break;
16880c72fe4SDavid Howells 
16980c72fe4SDavid Howells 		case afs_opt_vol:
17080c72fe4SDavid Howells 			*devname = args[0].from;
17180c72fe4SDavid Howells 			break;
17280c72fe4SDavid Howells 
17380c72fe4SDavid Howells 		default:
17480c72fe4SDavid Howells 			printk(KERN_ERR "kAFS:"
17580c72fe4SDavid Howells 			       " Unknown or invalid mount option: '%s'\n", p);
17680c72fe4SDavid Howells 			return -EINVAL;
1771da177e4SLinus Torvalds 		}
17808e0e7c8SDavid Howells 	}
1791da177e4SLinus Torvalds 
18080c72fe4SDavid Howells 	_leave(" = 0");
18180c72fe4SDavid Howells 	return 0;
182ec26815aSDavid Howells }
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds /*
18500d3b7a4SDavid Howells  * parse a device name to get cell name, volume name, volume type and R/W
18600d3b7a4SDavid Howells  * selector
18700d3b7a4SDavid Howells  * - this can be one of the following:
18800d3b7a4SDavid Howells  *	"%[cell:]volume[.]"		R/W volume
18900d3b7a4SDavid Howells  *	"#[cell:]volume[.]"		R/O or R/W volume (rwpath=0),
19000d3b7a4SDavid Howells  *					 or R/W (rwpath=1) volume
19100d3b7a4SDavid Howells  *	"%[cell:]volume.readonly"	R/O volume
19200d3b7a4SDavid Howells  *	"#[cell:]volume.readonly"	R/O volume
19300d3b7a4SDavid Howells  *	"%[cell:]volume.backup"		Backup volume
19400d3b7a4SDavid Howells  *	"#[cell:]volume.backup"		Backup volume
19500d3b7a4SDavid Howells  */
19600d3b7a4SDavid Howells static int afs_parse_device_name(struct afs_mount_params *params,
19700d3b7a4SDavid Howells 				 const char *name)
19800d3b7a4SDavid Howells {
19900d3b7a4SDavid Howells 	struct afs_cell *cell;
20000d3b7a4SDavid Howells 	const char *cellname, *suffix;
20100d3b7a4SDavid Howells 	int cellnamesz;
20200d3b7a4SDavid Howells 
20300d3b7a4SDavid Howells 	_enter(",%s", name);
20400d3b7a4SDavid Howells 
20500d3b7a4SDavid Howells 	if (!name) {
20600d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: no volume name specified\n");
20700d3b7a4SDavid Howells 		return -EINVAL;
20800d3b7a4SDavid Howells 	}
20900d3b7a4SDavid Howells 
21000d3b7a4SDavid Howells 	if ((name[0] != '%' && name[0] != '#') || !name[1]) {
21100d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: unparsable volume name\n");
21200d3b7a4SDavid Howells 		return -EINVAL;
21300d3b7a4SDavid Howells 	}
21400d3b7a4SDavid Howells 
21500d3b7a4SDavid Howells 	/* determine the type of volume we're looking for */
21600d3b7a4SDavid Howells 	params->type = AFSVL_ROVOL;
21700d3b7a4SDavid Howells 	params->force = false;
21800d3b7a4SDavid Howells 	if (params->rwpath || name[0] == '%') {
21900d3b7a4SDavid Howells 		params->type = AFSVL_RWVOL;
22000d3b7a4SDavid Howells 		params->force = true;
22100d3b7a4SDavid Howells 	}
22200d3b7a4SDavid Howells 	name++;
22300d3b7a4SDavid Howells 
22400d3b7a4SDavid Howells 	/* split the cell name out if there is one */
22500d3b7a4SDavid Howells 	params->volname = strchr(name, ':');
22600d3b7a4SDavid Howells 	if (params->volname) {
22700d3b7a4SDavid Howells 		cellname = name;
22800d3b7a4SDavid Howells 		cellnamesz = params->volname - name;
22900d3b7a4SDavid Howells 		params->volname++;
23000d3b7a4SDavid Howells 	} else {
23100d3b7a4SDavid Howells 		params->volname = name;
23200d3b7a4SDavid Howells 		cellname = NULL;
23300d3b7a4SDavid Howells 		cellnamesz = 0;
23400d3b7a4SDavid Howells 	}
23500d3b7a4SDavid Howells 
23600d3b7a4SDavid Howells 	/* the volume type is further affected by a possible suffix */
23700d3b7a4SDavid Howells 	suffix = strrchr(params->volname, '.');
23800d3b7a4SDavid Howells 	if (suffix) {
23900d3b7a4SDavid Howells 		if (strcmp(suffix, ".readonly") == 0) {
24000d3b7a4SDavid Howells 			params->type = AFSVL_ROVOL;
24100d3b7a4SDavid Howells 			params->force = true;
24200d3b7a4SDavid Howells 		} else if (strcmp(suffix, ".backup") == 0) {
24300d3b7a4SDavid Howells 			params->type = AFSVL_BACKVOL;
24400d3b7a4SDavid Howells 			params->force = true;
24500d3b7a4SDavid Howells 		} else if (suffix[1] == 0) {
24600d3b7a4SDavid Howells 		} else {
24700d3b7a4SDavid Howells 			suffix = NULL;
24800d3b7a4SDavid Howells 		}
24900d3b7a4SDavid Howells 	}
25000d3b7a4SDavid Howells 
25100d3b7a4SDavid Howells 	params->volnamesz = suffix ?
25200d3b7a4SDavid Howells 		suffix - params->volname : strlen(params->volname);
25300d3b7a4SDavid Howells 
25400d3b7a4SDavid Howells 	_debug("cell %*.*s [%p]",
25500d3b7a4SDavid Howells 	       cellnamesz, cellnamesz, cellname ?: "", params->cell);
25600d3b7a4SDavid Howells 
25700d3b7a4SDavid Howells 	/* lookup the cell record */
25800d3b7a4SDavid Howells 	if (cellname || !params->cell) {
25900d3b7a4SDavid Howells 		cell = afs_cell_lookup(cellname, cellnamesz);
26000d3b7a4SDavid Howells 		if (IS_ERR(cell)) {
26100d3b7a4SDavid Howells 			printk(KERN_ERR "kAFS: unable to lookup cell '%s'\n",
26200d3b7a4SDavid Howells 			       cellname ?: "");
26300d3b7a4SDavid Howells 			return PTR_ERR(cell);
26400d3b7a4SDavid Howells 		}
26500d3b7a4SDavid Howells 		afs_put_cell(params->cell);
26600d3b7a4SDavid Howells 		params->cell = cell;
26700d3b7a4SDavid Howells 	}
26800d3b7a4SDavid Howells 
26900d3b7a4SDavid Howells 	_debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
27000d3b7a4SDavid Howells 	       params->cell->name, params->cell,
27100d3b7a4SDavid Howells 	       params->volnamesz, params->volnamesz, params->volname,
27200d3b7a4SDavid Howells 	       suffix ?: "-", params->type, params->force ? " FORCE" : "");
27300d3b7a4SDavid Howells 
27400d3b7a4SDavid Howells 	return 0;
27500d3b7a4SDavid Howells }
27600d3b7a4SDavid Howells 
27700d3b7a4SDavid Howells /*
2781da177e4SLinus Torvalds  * check a superblock to see if it's the one we're looking for
2791da177e4SLinus Torvalds  */
2801da177e4SLinus Torvalds static int afs_test_super(struct super_block *sb, void *data)
2811da177e4SLinus Torvalds {
2821da177e4SLinus Torvalds 	struct afs_mount_params *params = data;
2831da177e4SLinus Torvalds 	struct afs_super_info *as = sb->s_fs_info;
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds 	return as->volume == params->volume;
286ec26815aSDavid Howells }
2871da177e4SLinus Torvalds 
2881da177e4SLinus Torvalds /*
2891da177e4SLinus Torvalds  * fill in the superblock
2901da177e4SLinus Torvalds  */
291436058a4SDavid Howells static int afs_fill_super(struct super_block *sb, void *data)
2921da177e4SLinus Torvalds {
2931da177e4SLinus Torvalds 	struct afs_mount_params *params = data;
2941da177e4SLinus Torvalds 	struct afs_super_info *as = NULL;
2951da177e4SLinus Torvalds 	struct afs_fid fid;
2961da177e4SLinus Torvalds 	struct dentry *root = NULL;
2971da177e4SLinus Torvalds 	struct inode *inode = NULL;
2981da177e4SLinus Torvalds 	int ret;
2991da177e4SLinus Torvalds 
30008e0e7c8SDavid Howells 	_enter("");
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds 	/* allocate a superblock info record */
303b593e48dSYan Burman 	as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
3041da177e4SLinus Torvalds 	if (!as) {
3051da177e4SLinus Torvalds 		_leave(" = -ENOMEM");
3061da177e4SLinus Torvalds 		return -ENOMEM;
3071da177e4SLinus Torvalds 	}
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds 	afs_get_volume(params->volume);
3101da177e4SLinus Torvalds 	as->volume = params->volume;
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	/* fill in the superblock */
3131da177e4SLinus Torvalds 	sb->s_blocksize		= PAGE_CACHE_SIZE;
3141da177e4SLinus Torvalds 	sb->s_blocksize_bits	= PAGE_CACHE_SHIFT;
3151da177e4SLinus Torvalds 	sb->s_magic		= AFS_FS_MAGIC;
3161da177e4SLinus Torvalds 	sb->s_op		= &afs_super_ops;
3171da177e4SLinus Torvalds 	sb->s_fs_info		= as;
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds 	/* allocate the root inode and dentry */
3201da177e4SLinus Torvalds 	fid.vid		= as->volume->vid;
3211da177e4SLinus Torvalds 	fid.vnode	= 1;
3221da177e4SLinus Torvalds 	fid.unique	= 1;
323260a9803SDavid Howells 	inode = afs_iget(sb, params->key, &fid, NULL, NULL);
32408e0e7c8SDavid Howells 	if (IS_ERR(inode))
32508e0e7c8SDavid Howells 		goto error_inode;
3261da177e4SLinus Torvalds 
3271da177e4SLinus Torvalds 	ret = -ENOMEM;
3281da177e4SLinus Torvalds 	root = d_alloc_root(inode);
3291da177e4SLinus Torvalds 	if (!root)
3301da177e4SLinus Torvalds 		goto error;
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds 	sb->s_root = root;
3331da177e4SLinus Torvalds 
33408e0e7c8SDavid Howells 	_leave(" = 0");
3351da177e4SLinus Torvalds 	return 0;
3361da177e4SLinus Torvalds 
33708e0e7c8SDavid Howells error_inode:
33808e0e7c8SDavid Howells 	ret = PTR_ERR(inode);
33908e0e7c8SDavid Howells 	inode = NULL;
3401da177e4SLinus Torvalds error:
3411da177e4SLinus Torvalds 	iput(inode);
3421da177e4SLinus Torvalds 	afs_put_volume(as->volume);
3431da177e4SLinus Torvalds 	kfree(as);
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds 	sb->s_fs_info = NULL;
3461da177e4SLinus Torvalds 
34708e0e7c8SDavid Howells 	_leave(" = %d", ret);
3481da177e4SLinus Torvalds 	return ret;
349ec26815aSDavid Howells }
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds /*
3521da177e4SLinus Torvalds  * get an AFS superblock
3531da177e4SLinus Torvalds  */
354454e2398SDavid Howells static int afs_get_sb(struct file_system_type *fs_type,
3551da177e4SLinus Torvalds 		      int flags,
3561da177e4SLinus Torvalds 		      const char *dev_name,
357454e2398SDavid Howells 		      void *options,
358454e2398SDavid Howells 		      struct vfsmount *mnt)
3591da177e4SLinus Torvalds {
3601da177e4SLinus Torvalds 	struct afs_mount_params params;
3611da177e4SLinus Torvalds 	struct super_block *sb;
36208e0e7c8SDavid Howells 	struct afs_volume *vol;
36300d3b7a4SDavid Howells 	struct key *key;
3641da177e4SLinus Torvalds 	int ret;
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	_enter(",,%s,%p", dev_name, options);
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds 	memset(&params, 0, sizeof(params));
3691da177e4SLinus Torvalds 
37000d3b7a4SDavid Howells 	/* parse the options and device name */
3711da177e4SLinus Torvalds 	if (options) {
37200d3b7a4SDavid Howells 		ret = afs_parse_options(&params, options, &dev_name);
3731da177e4SLinus Torvalds 		if (ret < 0)
3741da177e4SLinus Torvalds 			goto error;
3751da177e4SLinus Torvalds 	}
3761da177e4SLinus Torvalds 
37700d3b7a4SDavid Howells 	ret = afs_parse_device_name(&params, dev_name);
37800d3b7a4SDavid Howells 	if (ret < 0)
37900d3b7a4SDavid Howells 		goto error;
38000d3b7a4SDavid Howells 
38100d3b7a4SDavid Howells 	/* try and do the mount securely */
38200d3b7a4SDavid Howells 	key = afs_request_key(params.cell);
38300d3b7a4SDavid Howells 	if (IS_ERR(key)) {
38400d3b7a4SDavid Howells 		_leave(" = %ld [key]", PTR_ERR(key));
38500d3b7a4SDavid Howells 		ret = PTR_ERR(key);
38600d3b7a4SDavid Howells 		goto error;
38700d3b7a4SDavid Howells 	}
38800d3b7a4SDavid Howells 	params.key = key;
38900d3b7a4SDavid Howells 
3901da177e4SLinus Torvalds 	/* parse the device name */
39100d3b7a4SDavid Howells 	vol = afs_volume_lookup(&params);
39208e0e7c8SDavid Howells 	if (IS_ERR(vol)) {
39308e0e7c8SDavid Howells 		ret = PTR_ERR(vol);
3941da177e4SLinus Torvalds 		goto error;
39508e0e7c8SDavid Howells 	}
39608e0e7c8SDavid Howells 	params.volume = vol;
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds 	/* allocate a deviceless superblock */
3991da177e4SLinus Torvalds 	sb = sget(fs_type, afs_test_super, set_anon_super, &params);
40008e0e7c8SDavid Howells 	if (IS_ERR(sb)) {
40108e0e7c8SDavid Howells 		ret = PTR_ERR(sb);
4021da177e4SLinus Torvalds 		goto error;
40308e0e7c8SDavid Howells 	}
4041da177e4SLinus Torvalds 
405436058a4SDavid Howells 	if (!sb->s_root) {
406436058a4SDavid Howells 		/* initial superblock/root creation */
407436058a4SDavid Howells 		_debug("create");
4081da177e4SLinus Torvalds 		sb->s_flags = flags;
409436058a4SDavid Howells 		ret = afs_fill_super(sb, &params);
4101da177e4SLinus Torvalds 		if (ret < 0) {
4111da177e4SLinus Torvalds 			up_write(&sb->s_umount);
4121da177e4SLinus Torvalds 			deactivate_super(sb);
4131da177e4SLinus Torvalds 			goto error;
4141da177e4SLinus Torvalds 		}
4151da177e4SLinus Torvalds 		sb->s_flags |= MS_ACTIVE;
416436058a4SDavid Howells 	} else {
417436058a4SDavid Howells 		_debug("reuse");
418436058a4SDavid Howells 		ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
419436058a4SDavid Howells 	}
4201da177e4SLinus Torvalds 
421436058a4SDavid Howells 	simple_set_mnt(mnt, sb);
4221da177e4SLinus Torvalds 	afs_put_volume(params.volume);
42300d3b7a4SDavid Howells 	afs_put_cell(params.cell);
42408e0e7c8SDavid Howells 	_leave(" = 0 [%p]", sb);
425454e2398SDavid Howells 	return 0;
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds error:
4281da177e4SLinus Torvalds 	afs_put_volume(params.volume);
42900d3b7a4SDavid Howells 	afs_put_cell(params.cell);
43000d3b7a4SDavid Howells 	key_put(params.key);
4311da177e4SLinus Torvalds 	_leave(" = %d", ret);
432454e2398SDavid Howells 	return ret;
433ec26815aSDavid Howells }
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds /*
4361da177e4SLinus Torvalds  * finish the unmounting process on the superblock
4371da177e4SLinus Torvalds  */
4381da177e4SLinus Torvalds static void afs_put_super(struct super_block *sb)
4391da177e4SLinus Torvalds {
4401da177e4SLinus Torvalds 	struct afs_super_info *as = sb->s_fs_info;
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds 	_enter("");
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds 	afs_put_volume(as->volume);
4451da177e4SLinus Torvalds 
4461da177e4SLinus Torvalds 	_leave("");
447ec26815aSDavid Howells }
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds /*
4501da177e4SLinus Torvalds  * initialise an inode cache slab element prior to any use
4511da177e4SLinus Torvalds  */
452e18b890bSChristoph Lameter static void afs_i_init_once(void *_vnode, struct kmem_cache *cachep,
4531da177e4SLinus Torvalds 			    unsigned long flags)
4541da177e4SLinus Torvalds {
455ec26815aSDavid Howells 	struct afs_vnode *vnode = _vnode;
4561da177e4SLinus Torvalds 
45750953fe9SChristoph Lameter 	if (flags & SLAB_CTOR_CONSTRUCTOR) {
4581da177e4SLinus Torvalds 		memset(vnode, 0, sizeof(*vnode));
4591da177e4SLinus Torvalds 		inode_init_once(&vnode->vfs_inode);
4601da177e4SLinus Torvalds 		init_waitqueue_head(&vnode->update_waitq);
46100d3b7a4SDavid Howells 		mutex_init(&vnode->permits_lock);
462260a9803SDavid Howells 		mutex_init(&vnode->validate_lock);
46331143d5dSDavid Howells 		spin_lock_init(&vnode->writeback_lock);
4641da177e4SLinus Torvalds 		spin_lock_init(&vnode->lock);
46531143d5dSDavid Howells 		INIT_LIST_HEAD(&vnode->writebacks);
46608e0e7c8SDavid Howells 		INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work);
4671da177e4SLinus Torvalds 	}
468ec26815aSDavid Howells }
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds /*
4711da177e4SLinus Torvalds  * allocate an AFS inode struct from our slab cache
4721da177e4SLinus Torvalds  */
4731da177e4SLinus Torvalds static struct inode *afs_alloc_inode(struct super_block *sb)
4741da177e4SLinus Torvalds {
4751da177e4SLinus Torvalds 	struct afs_vnode *vnode;
4761da177e4SLinus Torvalds 
477ec26815aSDavid Howells 	vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
4781da177e4SLinus Torvalds 	if (!vnode)
4791da177e4SLinus Torvalds 		return NULL;
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds 	atomic_inc(&afs_count_active_inodes);
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds 	memset(&vnode->fid, 0, sizeof(vnode->fid));
4841da177e4SLinus Torvalds 	memset(&vnode->status, 0, sizeof(vnode->status));
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	vnode->volume		= NULL;
4871da177e4SLinus Torvalds 	vnode->update_cnt	= 0;
488260a9803SDavid Howells 	vnode->flags		= 1 << AFS_VNODE_UNSET;
48908e0e7c8SDavid Howells 	vnode->cb_promised	= false;
4901da177e4SLinus Torvalds 
491*0f300ca9SDavid Howells 	_leave(" = %p", &vnode->vfs_inode);
4921da177e4SLinus Torvalds 	return &vnode->vfs_inode;
493ec26815aSDavid Howells }
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds /*
4961da177e4SLinus Torvalds  * destroy an AFS inode struct
4971da177e4SLinus Torvalds  */
4981da177e4SLinus Torvalds static void afs_destroy_inode(struct inode *inode)
4991da177e4SLinus Torvalds {
50008e0e7c8SDavid Howells 	struct afs_vnode *vnode = AFS_FS_I(inode);
50108e0e7c8SDavid Howells 
502*0f300ca9SDavid Howells 	_enter("%p{%x:%u}", inode, vnode->fid.vid, vnode->fid.vnode);
5031da177e4SLinus Torvalds 
50408e0e7c8SDavid Howells 	_debug("DESTROY INODE %p", inode);
50508e0e7c8SDavid Howells 
50608e0e7c8SDavid Howells 	ASSERTCMP(vnode->server, ==, NULL);
50708e0e7c8SDavid Howells 
50808e0e7c8SDavid Howells 	kmem_cache_free(afs_inode_cachep, vnode);
5091da177e4SLinus Torvalds 	atomic_dec(&afs_count_active_inodes);
510ec26815aSDavid Howells }
511