blob: 35d7e550b29cb055b8b442f3a9648217e003ef62 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS superblock handling
2 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (c) 2002, 2007 Red Hat, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * This software may be freely redistributed under the terms of the
6 * GNU General Public License.
7 *
8 * You should have received a copy of the GNU General Public License
9 * along with this program; if not, write to the Free Software
10 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
11 *
12 * Authors: David Howells <dhowells@redhat.com>
David Woodhouse44d1b982008-06-05 22:46:18 -070013 * David Woodhouse <dwmw2@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
wangleibec5eb62010-08-11 09:38:04 +010019#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/fs.h>
23#include <linux/pagemap.h>
David Howells80c72fe2007-05-03 03:11:29 -070024#include <linux/parser.h>
David Howells45222b92007-05-10 22:22:20 -070025#include <linux/statfs.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040026#include <linux/sched.h>
Eric W. Biedermanf74f70f2013-01-31 04:23:54 -080027#include <linux/nsproxy.h>
28#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "internal.h"
30
31#define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */
32
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070033static void afs_i_init_once(void *foo);
Al Virof7442b32010-07-26 14:16:21 +040034static struct dentry *afs_mount(struct file_system_type *fs_type,
35 int flags, const char *dev_name, void *data);
Al Virodde194a2011-06-12 16:01:21 -040036static void afs_kill_super(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static struct inode *afs_alloc_inode(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static void afs_destroy_inode(struct inode *inode);
David Howells45222b92007-05-10 22:22:20 -070039static int afs_statfs(struct dentry *dentry, struct kstatfs *buf);
David Howells677018a2017-07-05 16:25:23 +010040static int afs_show_devname(struct seq_file *m, struct dentry *root);
41static int afs_show_options(struct seq_file *m, struct dentry *root);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Trond Myklebust1f5ce9e2006-06-09 09:34:16 -040043struct file_system_type afs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .owner = THIS_MODULE,
45 .name = "afs",
Al Virof7442b32010-07-26 14:16:21 +040046 .mount = afs_mount,
Al Virodde194a2011-06-12 16:01:21 -040047 .kill_sb = afs_kill_super,
David Howells80c72fe2007-05-03 03:11:29 -070048 .fs_flags = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
Eric W. Biederman7f78e032013-03-02 19:39:14 -080050MODULE_ALIAS_FS("afs");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -080052static const struct super_operations afs_super_ops = {
David Howells45222b92007-05-10 22:22:20 -070053 .statfs = afs_statfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .alloc_inode = afs_alloc_inode,
wangleibec5eb62010-08-11 09:38:04 +010055 .drop_inode = afs_drop_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .destroy_inode = afs_destroy_inode,
Al Virob57922d2010-06-07 14:34:48 -040057 .evict_inode = afs_evict_inode,
David Howells677018a2017-07-05 16:25:23 +010058 .show_devname = afs_show_devname,
59 .show_options = afs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
Christoph Lametere18b8902006-12-06 20:33:20 -080062static struct kmem_cache *afs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static atomic_t afs_count_active_inodes;
64
David Howells80c72fe2007-05-03 03:11:29 -070065enum {
66 afs_no_opt,
67 afs_opt_cell,
68 afs_opt_rwpath,
69 afs_opt_vol,
wangleibec5eb62010-08-11 09:38:04 +010070 afs_opt_autocell,
David Howells80c72fe2007-05-03 03:11:29 -070071};
72
Steven Whitehousea447c092008-10-13 10:46:57 +010073static const match_table_t afs_options_list = {
David Howells80c72fe2007-05-03 03:11:29 -070074 { afs_opt_cell, "cell=%s" },
75 { afs_opt_rwpath, "rwpath" },
76 { afs_opt_vol, "vol=%s" },
wangleibec5eb62010-08-11 09:38:04 +010077 { afs_opt_autocell, "autocell" },
David Howells80c72fe2007-05-03 03:11:29 -070078 { afs_no_opt, NULL },
79};
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/*
82 * initialise the filesystem
83 */
84int __init afs_fs_init(void)
85{
86 int ret;
87
88 _enter("");
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* create ourselves an inode cache */
91 atomic_set(&afs_count_active_inodes, 0);
92
93 ret = -ENOMEM;
94 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
95 sizeof(struct afs_vnode),
96 0,
Vladimir Davydov5d097052016-01-14 15:18:21 -080097 SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
Paul Mundt20c2df82007-07-20 10:11:58 +090098 afs_i_init_once);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (!afs_inode_cachep) {
100 printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
101 return ret;
102 }
103
104 /* now export our filesystem to lesser mortals */
105 ret = register_filesystem(&afs_fs_type);
106 if (ret < 0) {
107 kmem_cache_destroy(afs_inode_cachep);
David Howells08e0e7c2007-04-26 15:55:03 -0700108 _leave(" = %d", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return ret;
110 }
111
David Howells08e0e7c2007-04-26 15:55:03 -0700112 _leave(" = 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return 0;
David Howellsec268152007-04-26 15:49:28 -0700114}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/*
117 * clean up the filesystem
118 */
119void __exit afs_fs_exit(void)
120{
David Howells08e0e7c2007-04-26 15:55:03 -0700121 _enter("");
122
123 afs_mntpt_kill_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 unregister_filesystem(&afs_fs_type);
125
126 if (atomic_read(&afs_count_active_inodes) != 0) {
127 printk("kAFS: %d active inode objects still present\n",
128 atomic_read(&afs_count_active_inodes));
129 BUG();
130 }
131
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000132 /*
133 * Make sure all delayed rcu free inodes are flushed before we
134 * destroy cache.
135 */
136 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 kmem_cache_destroy(afs_inode_cachep);
David Howells08e0e7c2007-04-26 15:55:03 -0700138 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700139}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/*
David Howells677018a2017-07-05 16:25:23 +0100142 * Display the mount device name in /proc/mounts.
143 */
144static int afs_show_devname(struct seq_file *m, struct dentry *root)
145{
146 struct afs_super_info *as = root->d_sb->s_fs_info;
147 struct afs_volume *volume = as->volume;
148 struct afs_cell *cell = volume->cell;
149 const char *suf = "";
150 char pref = '%';
151
152 switch (volume->type) {
153 case AFSVL_RWVOL:
154 break;
155 case AFSVL_ROVOL:
156 pref = '#';
157 if (volume->type_force)
158 suf = ".readonly";
159 break;
160 case AFSVL_BACKVOL:
161 pref = '#';
162 suf = ".backup";
163 break;
164 }
165
166 seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->vlocation->vldb.name, suf);
167 return 0;
168}
169
170/*
171 * Display the mount options in /proc/mounts.
172 */
173static int afs_show_options(struct seq_file *m, struct dentry *root)
174{
175 if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(d_inode(root))->flags))
176 seq_puts(m, "autocell");
177 return 0;
178}
179
180/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * parse the mount options
182 * - this function has been shamelessly adapted from the ext3 fs which
183 * shamelessly adapted it from the msdos fs
184 */
David Howells00d3b7a2007-04-26 15:57:07 -0700185static int afs_parse_options(struct afs_mount_params *params,
186 char *options, const char **devname)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
David Howells08e0e7c2007-04-26 15:55:03 -0700188 struct afs_cell *cell;
David Howells80c72fe2007-05-03 03:11:29 -0700189 substring_t args[MAX_OPT_ARGS];
190 char *p;
191 int token;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 _enter("%s", options);
194
195 options[PAGE_SIZE - 1] = 0;
196
David Howells80c72fe2007-05-03 03:11:29 -0700197 while ((p = strsep(&options, ","))) {
198 if (!*p)
199 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
David Howells80c72fe2007-05-03 03:11:29 -0700201 token = match_token(p, afs_options_list, args);
202 switch (token) {
203 case afs_opt_cell:
204 cell = afs_cell_lookup(args[0].from,
wangleibec5eb62010-08-11 09:38:04 +0100205 args[0].to - args[0].from,
206 false);
David Howells08e0e7c2007-04-26 15:55:03 -0700207 if (IS_ERR(cell))
208 return PTR_ERR(cell);
David Howells00d3b7a2007-04-26 15:57:07 -0700209 afs_put_cell(params->cell);
210 params->cell = cell;
David Howells80c72fe2007-05-03 03:11:29 -0700211 break;
212
213 case afs_opt_rwpath:
214 params->rwpath = 1;
215 break;
216
217 case afs_opt_vol:
218 *devname = args[0].from;
219 break;
220
wangleibec5eb62010-08-11 09:38:04 +0100221 case afs_opt_autocell:
222 params->autocell = 1;
223 break;
224
David Howells80c72fe2007-05-03 03:11:29 -0700225 default:
226 printk(KERN_ERR "kAFS:"
227 " Unknown or invalid mount option: '%s'\n", p);
228 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231
David Howells80c72fe2007-05-03 03:11:29 -0700232 _leave(" = 0");
233 return 0;
David Howellsec268152007-04-26 15:49:28 -0700234}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236/*
David Howells00d3b7a2007-04-26 15:57:07 -0700237 * parse a device name to get cell name, volume name, volume type and R/W
238 * selector
239 * - this can be one of the following:
240 * "%[cell:]volume[.]" R/W volume
241 * "#[cell:]volume[.]" R/O or R/W volume (rwpath=0),
242 * or R/W (rwpath=1) volume
243 * "%[cell:]volume.readonly" R/O volume
244 * "#[cell:]volume.readonly" R/O volume
245 * "%[cell:]volume.backup" Backup volume
246 * "#[cell:]volume.backup" Backup volume
247 */
248static int afs_parse_device_name(struct afs_mount_params *params,
249 const char *name)
250{
251 struct afs_cell *cell;
252 const char *cellname, *suffix;
253 int cellnamesz;
254
255 _enter(",%s", name);
256
257 if (!name) {
258 printk(KERN_ERR "kAFS: no volume name specified\n");
259 return -EINVAL;
260 }
261
262 if ((name[0] != '%' && name[0] != '#') || !name[1]) {
263 printk(KERN_ERR "kAFS: unparsable volume name\n");
264 return -EINVAL;
265 }
266
267 /* determine the type of volume we're looking for */
268 params->type = AFSVL_ROVOL;
269 params->force = false;
270 if (params->rwpath || name[0] == '%') {
271 params->type = AFSVL_RWVOL;
272 params->force = true;
273 }
274 name++;
275
276 /* split the cell name out if there is one */
277 params->volname = strchr(name, ':');
278 if (params->volname) {
279 cellname = name;
280 cellnamesz = params->volname - name;
281 params->volname++;
282 } else {
283 params->volname = name;
284 cellname = NULL;
285 cellnamesz = 0;
286 }
287
288 /* the volume type is further affected by a possible suffix */
289 suffix = strrchr(params->volname, '.');
290 if (suffix) {
291 if (strcmp(suffix, ".readonly") == 0) {
292 params->type = AFSVL_ROVOL;
293 params->force = true;
294 } else if (strcmp(suffix, ".backup") == 0) {
295 params->type = AFSVL_BACKVOL;
296 params->force = true;
297 } else if (suffix[1] == 0) {
298 } else {
299 suffix = NULL;
300 }
301 }
302
303 params->volnamesz = suffix ?
304 suffix - params->volname : strlen(params->volname);
305
306 _debug("cell %*.*s [%p]",
307 cellnamesz, cellnamesz, cellname ?: "", params->cell);
308
309 /* lookup the cell record */
310 if (cellname || !params->cell) {
wangleibec5eb62010-08-11 09:38:04 +0100311 cell = afs_cell_lookup(cellname, cellnamesz, true);
David Howells00d3b7a2007-04-26 15:57:07 -0700312 if (IS_ERR(cell)) {
wangleibec5eb62010-08-11 09:38:04 +0100313 printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n",
314 cellnamesz, cellnamesz, cellname ?: "");
David Howells00d3b7a2007-04-26 15:57:07 -0700315 return PTR_ERR(cell);
316 }
317 afs_put_cell(params->cell);
318 params->cell = cell;
319 }
320
321 _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
322 params->cell->name, params->cell,
323 params->volnamesz, params->volnamesz, params->volname,
324 suffix ?: "-", params->type, params->force ? " FORCE" : "");
325
326 return 0;
327}
328
329/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 * check a superblock to see if it's the one we're looking for
331 */
332static int afs_test_super(struct super_block *sb, void *data)
333{
Al Virodde194a2011-06-12 16:01:21 -0400334 struct afs_super_info *as1 = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 struct afs_super_info *as = sb->s_fs_info;
336
Al Virodde194a2011-06-12 16:01:21 -0400337 return as->volume == as1->volume;
338}
339
340static int afs_set_super(struct super_block *sb, void *data)
341{
342 sb->s_fs_info = data;
343 return set_anon_super(sb, NULL);
David Howellsec268152007-04-26 15:49:28 -0700344}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346/*
347 * fill in the superblock
348 */
Al Virodde194a2011-06-12 16:01:21 -0400349static int afs_fill_super(struct super_block *sb,
350 struct afs_mount_params *params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Al Virodde194a2011-06-12 16:01:21 -0400352 struct afs_super_info *as = sb->s_fs_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct afs_fid fid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 struct inode *inode = NULL;
355 int ret;
356
David Howells08e0e7c2007-04-26 15:55:03 -0700357 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 /* fill in the superblock */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300360 sb->s_blocksize = PAGE_SIZE;
361 sb->s_blocksize_bits = PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 sb->s_magic = AFS_FS_MAGIC;
363 sb->s_op = &afs_super_ops;
Jan Karaedd3ba92017-04-12 12:24:36 +0200364 ret = super_setup_bdi(sb);
365 if (ret)
366 return ret;
367 sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE;
David Howells2e41ae22011-06-14 00:38:44 +0100368 strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 /* allocate the root inode and dentry */
371 fid.vid = as->volume->vid;
372 fid.vnode = 1;
373 fid.unique = 1;
David Howells260a9802007-04-26 15:59:35 -0700374 inode = afs_iget(sb, params->key, &fid, NULL, NULL);
David Howells08e0e7c2007-04-26 15:55:03 -0700375 if (IS_ERR(inode))
Al Virodde194a2011-06-12 16:01:21 -0400376 return PTR_ERR(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
wangleibec5eb62010-08-11 09:38:04 +0100378 if (params->autocell)
379 set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags);
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 ret = -ENOMEM;
Al Viro48fde702012-01-08 22:15:13 -0500382 sb->s_root = d_make_root(inode);
383 if (!sb->s_root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 goto error;
385
Al Virod61dcce2011-01-12 20:04:20 -0500386 sb->s_d_op = &afs_fs_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
David Howells08e0e7c2007-04-26 15:55:03 -0700388 _leave(" = 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return 0;
390
David Howellsec268152007-04-26 15:49:28 -0700391error:
David Howells08e0e7c2007-04-26 15:55:03 -0700392 _leave(" = %d", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return ret;
David Howellsec268152007-04-26 15:49:28 -0700394}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396/*
397 * get an AFS superblock
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 */
Al Virof7442b32010-07-26 14:16:21 +0400399static struct dentry *afs_mount(struct file_system_type *fs_type,
400 int flags, const char *dev_name, void *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 struct afs_mount_params params;
403 struct super_block *sb;
David Howells08e0e7c2007-04-26 15:55:03 -0700404 struct afs_volume *vol;
David Howells00d3b7a2007-04-26 15:57:07 -0700405 struct key *key;
Miklos Szeredi969729d2008-02-08 04:21:37 -0800406 char *new_opts = kstrdup(options, GFP_KERNEL);
Al Virodde194a2011-06-12 16:01:21 -0400407 struct afs_super_info *as;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 int ret;
409
410 _enter(",,%s,%p", dev_name, options);
411
412 memset(&params, 0, sizeof(params));
413
Eric W. Biedermanf74f70f2013-01-31 04:23:54 -0800414 ret = -EINVAL;
415 if (current->nsproxy->net_ns != &init_net)
416 goto error;
417
David Howells00d3b7a2007-04-26 15:57:07 -0700418 /* parse the options and device name */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (options) {
David Howells00d3b7a2007-04-26 15:57:07 -0700420 ret = afs_parse_options(&params, options, &dev_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (ret < 0)
422 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
David Howells00d3b7a2007-04-26 15:57:07 -0700425 ret = afs_parse_device_name(&params, dev_name);
426 if (ret < 0)
427 goto error;
428
429 /* try and do the mount securely */
430 key = afs_request_key(params.cell);
431 if (IS_ERR(key)) {
432 _leave(" = %ld [key]", PTR_ERR(key));
433 ret = PTR_ERR(key);
434 goto error;
435 }
436 params.key = key;
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 /* parse the device name */
David Howells00d3b7a2007-04-26 15:57:07 -0700439 vol = afs_volume_lookup(&params);
David Howells08e0e7c2007-04-26 15:55:03 -0700440 if (IS_ERR(vol)) {
441 ret = PTR_ERR(vol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 goto error;
David Howells08e0e7c2007-04-26 15:55:03 -0700443 }
Al Virodde194a2011-06-12 16:01:21 -0400444
445 /* allocate a superblock info record */
446 as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
447 if (!as) {
448 ret = -ENOMEM;
449 afs_put_volume(vol);
450 goto error;
451 }
452 as->volume = vol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 /* allocate a deviceless superblock */
David Howells9249e172012-06-25 12:55:37 +0100455 sb = sget(fs_type, afs_test_super, afs_set_super, flags, as);
David Howells08e0e7c2007-04-26 15:55:03 -0700456 if (IS_ERR(sb)) {
457 ret = PTR_ERR(sb);
Al Virodde194a2011-06-12 16:01:21 -0400458 afs_put_volume(vol);
459 kfree(as);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 goto error;
David Howells08e0e7c2007-04-26 15:55:03 -0700461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
David Howells436058a2007-04-26 15:56:24 -0700463 if (!sb->s_root) {
464 /* initial superblock/root creation */
465 _debug("create");
David Howells436058a2007-04-26 15:56:24 -0700466 ret = afs_fill_super(sb, &params);
467 if (ret < 0) {
Al Viro6f5bbff2009-05-06 01:34:22 -0400468 deactivate_locked_super(sb);
David Howells436058a2007-04-26 15:56:24 -0700469 goto error;
470 }
471 sb->s_flags |= MS_ACTIVE;
472 } else {
473 _debug("reuse");
474 ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
Al Virodde194a2011-06-12 16:01:21 -0400475 afs_put_volume(vol);
476 kfree(as);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
David Howells00d3b7a2007-04-26 15:57:07 -0700479 afs_put_cell(params.cell);
Al Viro2a32ceb2009-05-08 16:05:57 -0400480 kfree(new_opts);
David Howells08e0e7c2007-04-26 15:55:03 -0700481 _leave(" = 0 [%p]", sb);
Al Virof7442b32010-07-26 14:16:21 +0400482 return dget(sb->s_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
David Howellsec268152007-04-26 15:49:28 -0700484error:
David Howells00d3b7a2007-04-26 15:57:07 -0700485 afs_put_cell(params.cell);
486 key_put(params.key);
Miklos Szeredi969729d2008-02-08 04:21:37 -0800487 kfree(new_opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 _leave(" = %d", ret);
Al Virof7442b32010-07-26 14:16:21 +0400489 return ERR_PTR(ret);
David Howellsec268152007-04-26 15:49:28 -0700490}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Al Virodde194a2011-06-12 16:01:21 -0400492static void afs_kill_super(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 struct afs_super_info *as = sb->s_fs_info;
Al Virodde194a2011-06-12 16:01:21 -0400495 kill_anon_super(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 afs_put_volume(as->volume);
Al Virodde194a2011-06-12 16:01:21 -0400497 kfree(as);
David Howellsec268152007-04-26 15:49:28 -0700498}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500/*
501 * initialise an inode cache slab element prior to any use
502 */
Alexey Dobriyan51cc5062008-07-25 19:45:34 -0700503static void afs_i_init_once(void *_vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
David Howellsec268152007-04-26 15:49:28 -0700505 struct afs_vnode *vnode = _vnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Christoph Lametera35afb82007-05-16 22:10:57 -0700507 memset(vnode, 0, sizeof(*vnode));
508 inode_init_once(&vnode->vfs_inode);
509 init_waitqueue_head(&vnode->update_waitq);
510 mutex_init(&vnode->permits_lock);
511 mutex_init(&vnode->validate_lock);
512 spin_lock_init(&vnode->writeback_lock);
513 spin_lock_init(&vnode->lock);
514 INIT_LIST_HEAD(&vnode->writebacks);
David Howellse8d6c552007-07-15 23:40:12 -0700515 INIT_LIST_HEAD(&vnode->pending_locks);
516 INIT_LIST_HEAD(&vnode->granted_locks);
517 INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work);
Christoph Lametera35afb82007-05-16 22:10:57 -0700518 INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work);
David Howellsec268152007-04-26 15:49:28 -0700519}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521/*
522 * allocate an AFS inode struct from our slab cache
523 */
524static struct inode *afs_alloc_inode(struct super_block *sb)
525{
526 struct afs_vnode *vnode;
527
David Howellsec268152007-04-26 15:49:28 -0700528 vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (!vnode)
530 return NULL;
531
532 atomic_inc(&afs_count_active_inodes);
533
534 memset(&vnode->fid, 0, sizeof(vnode->fid));
535 memset(&vnode->status, 0, sizeof(vnode->status));
536
537 vnode->volume = NULL;
538 vnode->update_cnt = 0;
David Howells260a9802007-04-26 15:59:35 -0700539 vnode->flags = 1 << AFS_VNODE_UNSET;
David Howells08e0e7c2007-04-26 15:55:03 -0700540 vnode->cb_promised = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
David Howells0f300ca2007-05-10 22:22:20 -0700542 _leave(" = %p", &vnode->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return &vnode->vfs_inode;
David Howellsec268152007-04-26 15:49:28 -0700544}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100546static void afs_i_callback(struct rcu_head *head)
547{
548 struct inode *inode = container_of(head, struct inode, i_rcu);
549 struct afs_vnode *vnode = AFS_FS_I(inode);
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100550 kmem_cache_free(afs_inode_cachep, vnode);
551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553/*
554 * destroy an AFS inode struct
555 */
556static void afs_destroy_inode(struct inode *inode)
557{
David Howells08e0e7c2007-04-26 15:55:03 -0700558 struct afs_vnode *vnode = AFS_FS_I(inode);
559
David Howells0f300ca2007-05-10 22:22:20 -0700560 _enter("%p{%x:%u}", inode, vnode->fid.vid, vnode->fid.vnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
David Howells08e0e7c2007-04-26 15:55:03 -0700562 _debug("DESTROY INODE %p", inode);
563
564 ASSERTCMP(vnode->server, ==, NULL);
565
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100566 call_rcu(&inode->i_rcu, afs_i_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 atomic_dec(&afs_count_active_inodes);
David Howellsec268152007-04-26 15:49:28 -0700568}
David Howells45222b92007-05-10 22:22:20 -0700569
570/*
571 * return information about an AFS volume
572 */
573static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
574{
575 struct afs_volume_status vs;
David Howells2b0143b2015-03-17 22:25:59 +0000576 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
David Howells45222b92007-05-10 22:22:20 -0700577 struct key *key;
578 int ret;
579
580 key = afs_request_key(vnode->volume->cell);
581 if (IS_ERR(key))
582 return PTR_ERR(key);
583
584 ret = afs_vnode_get_volume_status(vnode, key, &vs);
585 key_put(key);
586 if (ret < 0) {
587 _leave(" = %d", ret);
588 return ret;
589 }
590
591 buf->f_type = dentry->d_sb->s_magic;
592 buf->f_bsize = AFS_BLOCK_SIZE;
593 buf->f_namelen = AFSNAMEMAX - 1;
594
595 if (vs.max_quota == 0)
596 buf->f_blocks = vs.part_max_blocks;
597 else
598 buf->f_blocks = vs.max_quota;
599 buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use;
600 return 0;
601}