xref: /openbmc/linux/fs/afs/super.c (revision 80c72fe415698049a477314ac82790c1af0fa7e3)
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>
23*80c72fe4SDavid 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,
46*80c72fe4SDavid 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,
531da177e4SLinus Torvalds 	.destroy_inode	= afs_destroy_inode,
541da177e4SLinus Torvalds 	.clear_inode	= afs_clear_inode,
5508e0e7c8SDavid Howells 	.umount_begin	= afs_umount_begin,
561da177e4SLinus Torvalds 	.put_super	= afs_put_super,
571da177e4SLinus Torvalds };
581da177e4SLinus Torvalds 
59e18b890bSChristoph Lameter static struct kmem_cache *afs_inode_cachep;
601da177e4SLinus Torvalds static atomic_t afs_count_active_inodes;
611da177e4SLinus Torvalds 
62*80c72fe4SDavid Howells enum {
63*80c72fe4SDavid Howells 	afs_no_opt,
64*80c72fe4SDavid Howells 	afs_opt_cell,
65*80c72fe4SDavid Howells 	afs_opt_rwpath,
66*80c72fe4SDavid Howells 	afs_opt_vol,
67*80c72fe4SDavid Howells };
68*80c72fe4SDavid Howells 
69*80c72fe4SDavid Howells static const match_table_t afs_options_list = {
70*80c72fe4SDavid Howells 	{ afs_opt_cell,		"cell=%s"	},
71*80c72fe4SDavid Howells 	{ afs_opt_rwpath,	"rwpath"	},
72*80c72fe4SDavid Howells 	{ afs_opt_vol,		"vol=%s"	},
73*80c72fe4SDavid Howells 	{ afs_no_opt,		NULL		},
74*80c72fe4SDavid Howells };
75*80c72fe4SDavid Howells 
761da177e4SLinus Torvalds /*
771da177e4SLinus Torvalds  * initialise the filesystem
781da177e4SLinus Torvalds  */
791da177e4SLinus Torvalds int __init afs_fs_init(void)
801da177e4SLinus Torvalds {
811da177e4SLinus Torvalds 	int ret;
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 	_enter("");
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds 	/* create ourselves an inode cache */
861da177e4SLinus Torvalds 	atomic_set(&afs_count_active_inodes, 0);
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds 	ret = -ENOMEM;
891da177e4SLinus Torvalds 	afs_inode_cachep = kmem_cache_create("afs_inode_cache",
901da177e4SLinus Torvalds 					     sizeof(struct afs_vnode),
911da177e4SLinus Torvalds 					     0,
921da177e4SLinus Torvalds 					     SLAB_HWCACHE_ALIGN,
931da177e4SLinus Torvalds 					     afs_i_init_once,
941da177e4SLinus Torvalds 					     NULL);
951da177e4SLinus Torvalds 	if (!afs_inode_cachep) {
961da177e4SLinus Torvalds 		printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
971da177e4SLinus Torvalds 		return ret;
981da177e4SLinus Torvalds 	}
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 	/* now export our filesystem to lesser mortals */
1011da177e4SLinus Torvalds 	ret = register_filesystem(&afs_fs_type);
1021da177e4SLinus Torvalds 	if (ret < 0) {
1031da177e4SLinus Torvalds 		kmem_cache_destroy(afs_inode_cachep);
10408e0e7c8SDavid Howells 		_leave(" = %d", ret);
1051da177e4SLinus Torvalds 		return ret;
1061da177e4SLinus Torvalds 	}
1071da177e4SLinus Torvalds 
10808e0e7c8SDavid Howells 	_leave(" = 0");
1091da177e4SLinus Torvalds 	return 0;
110ec26815aSDavid Howells }
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds /*
1131da177e4SLinus Torvalds  * clean up the filesystem
1141da177e4SLinus Torvalds  */
1151da177e4SLinus Torvalds void __exit afs_fs_exit(void)
1161da177e4SLinus Torvalds {
11708e0e7c8SDavid Howells 	_enter("");
11808e0e7c8SDavid Howells 
11908e0e7c8SDavid Howells 	afs_mntpt_kill_timer();
1201da177e4SLinus Torvalds 	unregister_filesystem(&afs_fs_type);
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds 	if (atomic_read(&afs_count_active_inodes) != 0) {
1231da177e4SLinus Torvalds 		printk("kAFS: %d active inode objects still present\n",
1241da177e4SLinus Torvalds 		       atomic_read(&afs_count_active_inodes));
1251da177e4SLinus Torvalds 		BUG();
1261da177e4SLinus Torvalds 	}
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds 	kmem_cache_destroy(afs_inode_cachep);
12908e0e7c8SDavid Howells 	_leave("");
130ec26815aSDavid Howells }
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds /*
1331da177e4SLinus Torvalds  * parse the mount options
1341da177e4SLinus Torvalds  * - this function has been shamelessly adapted from the ext3 fs which
1351da177e4SLinus Torvalds  *   shamelessly adapted it from the msdos fs
1361da177e4SLinus Torvalds  */
13700d3b7a4SDavid Howells static int afs_parse_options(struct afs_mount_params *params,
13808e0e7c8SDavid Howells 			     char *options, const char **devname)
1391da177e4SLinus Torvalds {
14008e0e7c8SDavid Howells 	struct afs_cell *cell;
141*80c72fe4SDavid Howells 	substring_t args[MAX_OPT_ARGS];
142*80c72fe4SDavid Howells 	char *p;
143*80c72fe4SDavid Howells 	int token;
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds 	_enter("%s", options);
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	options[PAGE_SIZE - 1] = 0;
1481da177e4SLinus Torvalds 
149*80c72fe4SDavid Howells 	while ((p = strsep(&options, ","))) {
150*80c72fe4SDavid Howells 		if (!*p)
151*80c72fe4SDavid Howells 			continue;
1521da177e4SLinus Torvalds 
153*80c72fe4SDavid Howells 		token = match_token(p, afs_options_list, args);
154*80c72fe4SDavid Howells 		switch (token) {
155*80c72fe4SDavid Howells 		case afs_opt_cell:
156*80c72fe4SDavid Howells 			cell = afs_cell_lookup(args[0].from,
157*80c72fe4SDavid Howells 					       args[0].to - args[0].from);
15808e0e7c8SDavid Howells 			if (IS_ERR(cell))
15908e0e7c8SDavid Howells 				return PTR_ERR(cell);
16000d3b7a4SDavid Howells 			afs_put_cell(params->cell);
16100d3b7a4SDavid Howells 			params->cell = cell;
162*80c72fe4SDavid Howells 			break;
163*80c72fe4SDavid Howells 
164*80c72fe4SDavid Howells 		case afs_opt_rwpath:
165*80c72fe4SDavid Howells 			params->rwpath = 1;
166*80c72fe4SDavid Howells 			break;
167*80c72fe4SDavid Howells 
168*80c72fe4SDavid Howells 		case afs_opt_vol:
169*80c72fe4SDavid Howells 			*devname = args[0].from;
170*80c72fe4SDavid Howells 			break;
171*80c72fe4SDavid Howells 
172*80c72fe4SDavid Howells 		default:
173*80c72fe4SDavid Howells 			printk(KERN_ERR "kAFS:"
174*80c72fe4SDavid Howells 			       " Unknown or invalid mount option: '%s'\n", p);
175*80c72fe4SDavid Howells 			return -EINVAL;
1761da177e4SLinus Torvalds 		}
17708e0e7c8SDavid Howells 	}
1781da177e4SLinus Torvalds 
179*80c72fe4SDavid Howells 	_leave(" = 0");
180*80c72fe4SDavid Howells 	return 0;
181ec26815aSDavid Howells }
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds /*
18400d3b7a4SDavid Howells  * parse a device name to get cell name, volume name, volume type and R/W
18500d3b7a4SDavid Howells  * selector
18600d3b7a4SDavid Howells  * - this can be one of the following:
18700d3b7a4SDavid Howells  *	"%[cell:]volume[.]"		R/W volume
18800d3b7a4SDavid Howells  *	"#[cell:]volume[.]"		R/O or R/W volume (rwpath=0),
18900d3b7a4SDavid Howells  *					 or R/W (rwpath=1) volume
19000d3b7a4SDavid Howells  *	"%[cell:]volume.readonly"	R/O volume
19100d3b7a4SDavid Howells  *	"#[cell:]volume.readonly"	R/O volume
19200d3b7a4SDavid Howells  *	"%[cell:]volume.backup"		Backup volume
19300d3b7a4SDavid Howells  *	"#[cell:]volume.backup"		Backup volume
19400d3b7a4SDavid Howells  */
19500d3b7a4SDavid Howells static int afs_parse_device_name(struct afs_mount_params *params,
19600d3b7a4SDavid Howells 				 const char *name)
19700d3b7a4SDavid Howells {
19800d3b7a4SDavid Howells 	struct afs_cell *cell;
19900d3b7a4SDavid Howells 	const char *cellname, *suffix;
20000d3b7a4SDavid Howells 	int cellnamesz;
20100d3b7a4SDavid Howells 
20200d3b7a4SDavid Howells 	_enter(",%s", name);
20300d3b7a4SDavid Howells 
20400d3b7a4SDavid Howells 	if (!name) {
20500d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: no volume name specified\n");
20600d3b7a4SDavid Howells 		return -EINVAL;
20700d3b7a4SDavid Howells 	}
20800d3b7a4SDavid Howells 
20900d3b7a4SDavid Howells 	if ((name[0] != '%' && name[0] != '#') || !name[1]) {
21000d3b7a4SDavid Howells 		printk(KERN_ERR "kAFS: unparsable volume name\n");
21100d3b7a4SDavid Howells 		return -EINVAL;
21200d3b7a4SDavid Howells 	}
21300d3b7a4SDavid Howells 
21400d3b7a4SDavid Howells 	/* determine the type of volume we're looking for */
21500d3b7a4SDavid Howells 	params->type = AFSVL_ROVOL;
21600d3b7a4SDavid Howells 	params->force = false;
21700d3b7a4SDavid Howells 	if (params->rwpath || name[0] == '%') {
21800d3b7a4SDavid Howells 		params->type = AFSVL_RWVOL;
21900d3b7a4SDavid Howells 		params->force = true;
22000d3b7a4SDavid Howells 	}
22100d3b7a4SDavid Howells 	name++;
22200d3b7a4SDavid Howells 
22300d3b7a4SDavid Howells 	/* split the cell name out if there is one */
22400d3b7a4SDavid Howells 	params->volname = strchr(name, ':');
22500d3b7a4SDavid Howells 	if (params->volname) {
22600d3b7a4SDavid Howells 		cellname = name;
22700d3b7a4SDavid Howells 		cellnamesz = params->volname - name;
22800d3b7a4SDavid Howells 		params->volname++;
22900d3b7a4SDavid Howells 	} else {
23000d3b7a4SDavid Howells 		params->volname = name;
23100d3b7a4SDavid Howells 		cellname = NULL;
23200d3b7a4SDavid Howells 		cellnamesz = 0;
23300d3b7a4SDavid Howells 	}
23400d3b7a4SDavid Howells 
23500d3b7a4SDavid Howells 	/* the volume type is further affected by a possible suffix */
23600d3b7a4SDavid Howells 	suffix = strrchr(params->volname, '.');
23700d3b7a4SDavid Howells 	if (suffix) {
23800d3b7a4SDavid Howells 		if (strcmp(suffix, ".readonly") == 0) {
23900d3b7a4SDavid Howells 			params->type = AFSVL_ROVOL;
24000d3b7a4SDavid Howells 			params->force = true;
24100d3b7a4SDavid Howells 		} else if (strcmp(suffix, ".backup") == 0) {
24200d3b7a4SDavid Howells 			params->type = AFSVL_BACKVOL;
24300d3b7a4SDavid Howells 			params->force = true;
24400d3b7a4SDavid Howells 		} else if (suffix[1] == 0) {
24500d3b7a4SDavid Howells 		} else {
24600d3b7a4SDavid Howells 			suffix = NULL;
24700d3b7a4SDavid Howells 		}
24800d3b7a4SDavid Howells 	}
24900d3b7a4SDavid Howells 
25000d3b7a4SDavid Howells 	params->volnamesz = suffix ?
25100d3b7a4SDavid Howells 		suffix - params->volname : strlen(params->volname);
25200d3b7a4SDavid Howells 
25300d3b7a4SDavid Howells 	_debug("cell %*.*s [%p]",
25400d3b7a4SDavid Howells 	       cellnamesz, cellnamesz, cellname ?: "", params->cell);
25500d3b7a4SDavid Howells 
25600d3b7a4SDavid Howells 	/* lookup the cell record */
25700d3b7a4SDavid Howells 	if (cellname || !params->cell) {
25800d3b7a4SDavid Howells 		cell = afs_cell_lookup(cellname, cellnamesz);
25900d3b7a4SDavid Howells 		if (IS_ERR(cell)) {
26000d3b7a4SDavid Howells 			printk(KERN_ERR "kAFS: unable to lookup cell '%s'\n",
26100d3b7a4SDavid Howells 			       cellname ?: "");
26200d3b7a4SDavid Howells 			return PTR_ERR(cell);
26300d3b7a4SDavid Howells 		}
26400d3b7a4SDavid Howells 		afs_put_cell(params->cell);
26500d3b7a4SDavid Howells 		params->cell = cell;
26600d3b7a4SDavid Howells 	}
26700d3b7a4SDavid Howells 
26800d3b7a4SDavid Howells 	_debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
26900d3b7a4SDavid Howells 	       params->cell->name, params->cell,
27000d3b7a4SDavid Howells 	       params->volnamesz, params->volnamesz, params->volname,
27100d3b7a4SDavid Howells 	       suffix ?: "-", params->type, params->force ? " FORCE" : "");
27200d3b7a4SDavid Howells 
27300d3b7a4SDavid Howells 	return 0;
27400d3b7a4SDavid Howells }
27500d3b7a4SDavid Howells 
27600d3b7a4SDavid Howells /*
2771da177e4SLinus Torvalds  * check a superblock to see if it's the one we're looking for
2781da177e4SLinus Torvalds  */
2791da177e4SLinus Torvalds static int afs_test_super(struct super_block *sb, void *data)
2801da177e4SLinus Torvalds {
2811da177e4SLinus Torvalds 	struct afs_mount_params *params = data;
2821da177e4SLinus Torvalds 	struct afs_super_info *as = sb->s_fs_info;
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds 	return as->volume == params->volume;
285ec26815aSDavid Howells }
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds /*
2881da177e4SLinus Torvalds  * fill in the superblock
2891da177e4SLinus Torvalds  */
290436058a4SDavid Howells static int afs_fill_super(struct super_block *sb, void *data)
2911da177e4SLinus Torvalds {
2921da177e4SLinus Torvalds 	struct afs_mount_params *params = data;
2931da177e4SLinus Torvalds 	struct afs_super_info *as = NULL;
2941da177e4SLinus Torvalds 	struct afs_fid fid;
2951da177e4SLinus Torvalds 	struct dentry *root = NULL;
2961da177e4SLinus Torvalds 	struct inode *inode = NULL;
2971da177e4SLinus Torvalds 	int ret;
2981da177e4SLinus Torvalds 
29908e0e7c8SDavid Howells 	_enter("");
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds 	/* allocate a superblock info record */
302b593e48dSYan Burman 	as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
3031da177e4SLinus Torvalds 	if (!as) {
3041da177e4SLinus Torvalds 		_leave(" = -ENOMEM");
3051da177e4SLinus Torvalds 		return -ENOMEM;
3061da177e4SLinus Torvalds 	}
3071da177e4SLinus Torvalds 
3081da177e4SLinus Torvalds 	afs_get_volume(params->volume);
3091da177e4SLinus Torvalds 	as->volume = params->volume;
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	/* fill in the superblock */
3121da177e4SLinus Torvalds 	sb->s_blocksize		= PAGE_CACHE_SIZE;
3131da177e4SLinus Torvalds 	sb->s_blocksize_bits	= PAGE_CACHE_SHIFT;
3141da177e4SLinus Torvalds 	sb->s_magic		= AFS_FS_MAGIC;
3151da177e4SLinus Torvalds 	sb->s_op		= &afs_super_ops;
3161da177e4SLinus Torvalds 	sb->s_fs_info		= as;
3171da177e4SLinus Torvalds 
3181da177e4SLinus Torvalds 	/* allocate the root inode and dentry */
3191da177e4SLinus Torvalds 	fid.vid		= as->volume->vid;
3201da177e4SLinus Torvalds 	fid.vnode	= 1;
3211da177e4SLinus Torvalds 	fid.unique	= 1;
322260a9803SDavid Howells 	inode = afs_iget(sb, params->key, &fid, NULL, NULL);
32308e0e7c8SDavid Howells 	if (IS_ERR(inode))
32408e0e7c8SDavid Howells 		goto error_inode;
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	ret = -ENOMEM;
3271da177e4SLinus Torvalds 	root = d_alloc_root(inode);
3281da177e4SLinus Torvalds 	if (!root)
3291da177e4SLinus Torvalds 		goto error;
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	sb->s_root = root;
3321da177e4SLinus Torvalds 
33308e0e7c8SDavid Howells 	_leave(" = 0");
3341da177e4SLinus Torvalds 	return 0;
3351da177e4SLinus Torvalds 
33608e0e7c8SDavid Howells error_inode:
33708e0e7c8SDavid Howells 	ret = PTR_ERR(inode);
33808e0e7c8SDavid Howells 	inode = NULL;
3391da177e4SLinus Torvalds error:
3401da177e4SLinus Torvalds 	iput(inode);
3411da177e4SLinus Torvalds 	afs_put_volume(as->volume);
3421da177e4SLinus Torvalds 	kfree(as);
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	sb->s_fs_info = NULL;
3451da177e4SLinus Torvalds 
34608e0e7c8SDavid Howells 	_leave(" = %d", ret);
3471da177e4SLinus Torvalds 	return ret;
348ec26815aSDavid Howells }
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds /*
3511da177e4SLinus Torvalds  * get an AFS superblock
3521da177e4SLinus Torvalds  */
353454e2398SDavid Howells static int afs_get_sb(struct file_system_type *fs_type,
3541da177e4SLinus Torvalds 		      int flags,
3551da177e4SLinus Torvalds 		      const char *dev_name,
356454e2398SDavid Howells 		      void *options,
357454e2398SDavid Howells 		      struct vfsmount *mnt)
3581da177e4SLinus Torvalds {
3591da177e4SLinus Torvalds 	struct afs_mount_params params;
3601da177e4SLinus Torvalds 	struct super_block *sb;
36108e0e7c8SDavid Howells 	struct afs_volume *vol;
36200d3b7a4SDavid Howells 	struct key *key;
3631da177e4SLinus Torvalds 	int ret;
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds 	_enter(",,%s,%p", dev_name, options);
3661da177e4SLinus Torvalds 
3671da177e4SLinus Torvalds 	memset(&params, 0, sizeof(params));
3681da177e4SLinus Torvalds 
36900d3b7a4SDavid Howells 	/* parse the options and device name */
3701da177e4SLinus Torvalds 	if (options) {
37100d3b7a4SDavid Howells 		ret = afs_parse_options(&params, options, &dev_name);
3721da177e4SLinus Torvalds 		if (ret < 0)
3731da177e4SLinus Torvalds 			goto error;
3741da177e4SLinus Torvalds 	}
3751da177e4SLinus Torvalds 
37600d3b7a4SDavid Howells 	ret = afs_parse_device_name(&params, dev_name);
37700d3b7a4SDavid Howells 	if (ret < 0)
37800d3b7a4SDavid Howells 		goto error;
37900d3b7a4SDavid Howells 
38000d3b7a4SDavid Howells 	/* try and do the mount securely */
38100d3b7a4SDavid Howells 	key = afs_request_key(params.cell);
38200d3b7a4SDavid Howells 	if (IS_ERR(key)) {
38300d3b7a4SDavid Howells 		_leave(" = %ld [key]", PTR_ERR(key));
38400d3b7a4SDavid Howells 		ret = PTR_ERR(key);
38500d3b7a4SDavid Howells 		goto error;
38600d3b7a4SDavid Howells 	}
38700d3b7a4SDavid Howells 	params.key = key;
38800d3b7a4SDavid Howells 
3891da177e4SLinus Torvalds 	/* parse the device name */
39000d3b7a4SDavid Howells 	vol = afs_volume_lookup(&params);
39108e0e7c8SDavid Howells 	if (IS_ERR(vol)) {
39208e0e7c8SDavid Howells 		ret = PTR_ERR(vol);
3931da177e4SLinus Torvalds 		goto error;
39408e0e7c8SDavid Howells 	}
39508e0e7c8SDavid Howells 	params.volume = vol;
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	/* allocate a deviceless superblock */
3981da177e4SLinus Torvalds 	sb = sget(fs_type, afs_test_super, set_anon_super, &params);
39908e0e7c8SDavid Howells 	if (IS_ERR(sb)) {
40008e0e7c8SDavid Howells 		ret = PTR_ERR(sb);
4011da177e4SLinus Torvalds 		goto error;
40208e0e7c8SDavid Howells 	}
4031da177e4SLinus Torvalds 
404436058a4SDavid Howells 	if (!sb->s_root) {
405436058a4SDavid Howells 		/* initial superblock/root creation */
406436058a4SDavid Howells 		_debug("create");
4071da177e4SLinus Torvalds 		sb->s_flags = flags;
408436058a4SDavid Howells 		ret = afs_fill_super(sb, &params);
4091da177e4SLinus Torvalds 		if (ret < 0) {
4101da177e4SLinus Torvalds 			up_write(&sb->s_umount);
4111da177e4SLinus Torvalds 			deactivate_super(sb);
4121da177e4SLinus Torvalds 			goto error;
4131da177e4SLinus Torvalds 		}
4141da177e4SLinus Torvalds 		sb->s_flags |= MS_ACTIVE;
415436058a4SDavid Howells 	} else {
416436058a4SDavid Howells 		_debug("reuse");
417436058a4SDavid Howells 		ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
418436058a4SDavid Howells 	}
4191da177e4SLinus Torvalds 
420436058a4SDavid Howells 	simple_set_mnt(mnt, sb);
4211da177e4SLinus Torvalds 	afs_put_volume(params.volume);
42200d3b7a4SDavid Howells 	afs_put_cell(params.cell);
42308e0e7c8SDavid Howells 	_leave(" = 0 [%p]", sb);
424454e2398SDavid Howells 	return 0;
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds error:
4271da177e4SLinus Torvalds 	afs_put_volume(params.volume);
42800d3b7a4SDavid Howells 	afs_put_cell(params.cell);
42900d3b7a4SDavid Howells 	key_put(params.key);
4301da177e4SLinus Torvalds 	_leave(" = %d", ret);
431454e2398SDavid Howells 	return ret;
432ec26815aSDavid Howells }
4331da177e4SLinus Torvalds 
4341da177e4SLinus Torvalds /*
4351da177e4SLinus Torvalds  * finish the unmounting process on the superblock
4361da177e4SLinus Torvalds  */
4371da177e4SLinus Torvalds static void afs_put_super(struct super_block *sb)
4381da177e4SLinus Torvalds {
4391da177e4SLinus Torvalds 	struct afs_super_info *as = sb->s_fs_info;
4401da177e4SLinus Torvalds 
4411da177e4SLinus Torvalds 	_enter("");
4421da177e4SLinus Torvalds 
4431da177e4SLinus Torvalds 	afs_put_volume(as->volume);
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds 	_leave("");
446ec26815aSDavid Howells }
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds /*
4491da177e4SLinus Torvalds  * initialise an inode cache slab element prior to any use
4501da177e4SLinus Torvalds  */
451e18b890bSChristoph Lameter static void afs_i_init_once(void *_vnode, struct kmem_cache *cachep,
4521da177e4SLinus Torvalds 			    unsigned long flags)
4531da177e4SLinus Torvalds {
454ec26815aSDavid Howells 	struct afs_vnode *vnode = _vnode;
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds 	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
4571da177e4SLinus Torvalds 	    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);
4631da177e4SLinus Torvalds 		spin_lock_init(&vnode->lock);
46408e0e7c8SDavid Howells 		INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work);
4651da177e4SLinus Torvalds 	}
466ec26815aSDavid Howells }
4671da177e4SLinus Torvalds 
4681da177e4SLinus Torvalds /*
4691da177e4SLinus Torvalds  * allocate an AFS inode struct from our slab cache
4701da177e4SLinus Torvalds  */
4711da177e4SLinus Torvalds static struct inode *afs_alloc_inode(struct super_block *sb)
4721da177e4SLinus Torvalds {
4731da177e4SLinus Torvalds 	struct afs_vnode *vnode;
4741da177e4SLinus Torvalds 
475ec26815aSDavid Howells 	vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
4761da177e4SLinus Torvalds 	if (!vnode)
4771da177e4SLinus Torvalds 		return NULL;
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds 	atomic_inc(&afs_count_active_inodes);
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds 	memset(&vnode->fid, 0, sizeof(vnode->fid));
4821da177e4SLinus Torvalds 	memset(&vnode->status, 0, sizeof(vnode->status));
4831da177e4SLinus Torvalds 
4841da177e4SLinus Torvalds 	vnode->volume		= NULL;
4851da177e4SLinus Torvalds 	vnode->update_cnt	= 0;
486260a9803SDavid Howells 	vnode->flags		= 1 << AFS_VNODE_UNSET;
48708e0e7c8SDavid Howells 	vnode->cb_promised	= false;
4881da177e4SLinus Torvalds 
4891da177e4SLinus Torvalds 	return &vnode->vfs_inode;
490ec26815aSDavid Howells }
4911da177e4SLinus Torvalds 
4921da177e4SLinus Torvalds /*
4931da177e4SLinus Torvalds  * destroy an AFS inode struct
4941da177e4SLinus Torvalds  */
4951da177e4SLinus Torvalds static void afs_destroy_inode(struct inode *inode)
4961da177e4SLinus Torvalds {
49708e0e7c8SDavid Howells 	struct afs_vnode *vnode = AFS_FS_I(inode);
49808e0e7c8SDavid Howells 
4991da177e4SLinus Torvalds 	_enter("{%lu}", inode->i_ino);
5001da177e4SLinus Torvalds 
50108e0e7c8SDavid Howells 	_debug("DESTROY INODE %p", inode);
50208e0e7c8SDavid Howells 
50308e0e7c8SDavid Howells 	ASSERTCMP(vnode->server, ==, NULL);
50408e0e7c8SDavid Howells 
50508e0e7c8SDavid Howells 	kmem_cache_free(afs_inode_cachep, vnode);
5061da177e4SLinus Torvalds 	atomic_dec(&afs_count_active_inodes);
507ec26815aSDavid Howells }
508