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