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