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 EB |
27 | #include <linux/nsproxy.h> |
28 | #include <net/net_namespace.h> | |
1da177e4 LT |
29 | #include "internal.h" |
30 | ||
31 | #define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */ | |
32 | ||
51cc5068 | 33 | static void afs_i_init_once(void *foo); |
f7442b3b AV |
34 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
35 | int flags, const char *dev_name, void *data); | |
dde194a6 | 36 | static void afs_kill_super(struct super_block *sb); |
1da177e4 | 37 | static struct inode *afs_alloc_inode(struct super_block *sb); |
1da177e4 | 38 | static void afs_destroy_inode(struct inode *inode); |
45222b9e | 39 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf); |
677018a6 DH |
40 | static int afs_show_devname(struct seq_file *m, struct dentry *root); |
41 | static int afs_show_options(struct seq_file *m, struct dentry *root); | |
1da177e4 | 42 | |
1f5ce9e9 | 43 | struct file_system_type afs_fs_type = { |
1da177e4 LT |
44 | .owner = THIS_MODULE, |
45 | .name = "afs", | |
f7442b3b | 46 | .mount = afs_mount, |
dde194a6 | 47 | .kill_sb = afs_kill_super, |
80c72fe4 | 48 | .fs_flags = 0, |
1da177e4 | 49 | }; |
7f78e035 | 50 | MODULE_ALIAS_FS("afs"); |
1da177e4 | 51 | |
ee9b6d61 | 52 | static const struct super_operations afs_super_ops = { |
45222b9e | 53 | .statfs = afs_statfs, |
1da177e4 | 54 | .alloc_inode = afs_alloc_inode, |
bec5eb61 | 55 | .drop_inode = afs_drop_inode, |
1da177e4 | 56 | .destroy_inode = afs_destroy_inode, |
b57922d9 | 57 | .evict_inode = afs_evict_inode, |
677018a6 DH |
58 | .show_devname = afs_show_devname, |
59 | .show_options = afs_show_options, | |
1da177e4 LT |
60 | }; |
61 | ||
e18b890b | 62 | static struct kmem_cache *afs_inode_cachep; |
1da177e4 LT |
63 | static atomic_t afs_count_active_inodes; |
64 | ||
80c72fe4 DH |
65 | enum { |
66 | afs_no_opt, | |
67 | afs_opt_cell, | |
68 | afs_opt_rwpath, | |
69 | afs_opt_vol, | |
bec5eb61 | 70 | afs_opt_autocell, |
80c72fe4 DH |
71 | }; |
72 | ||
a447c093 | 73 | static const match_table_t afs_options_list = { |
80c72fe4 DH |
74 | { afs_opt_cell, "cell=%s" }, |
75 | { afs_opt_rwpath, "rwpath" }, | |
76 | { afs_opt_vol, "vol=%s" }, | |
bec5eb61 | 77 | { afs_opt_autocell, "autocell" }, |
80c72fe4 DH |
78 | { afs_no_opt, NULL }, |
79 | }; | |
80 | ||
1da177e4 LT |
81 | /* |
82 | * initialise the filesystem | |
83 | */ | |
84 | int __init afs_fs_init(void) | |
85 | { | |
86 | int ret; | |
87 | ||
88 | _enter(""); | |
89 | ||
1da177e4 LT |
90 | /* 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, | |
5d097056 | 97 | SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, |
20c2df83 | 98 | afs_i_init_once); |
1da177e4 LT |
99 | 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); | |
08e0e7c8 | 108 | _leave(" = %d", ret); |
1da177e4 LT |
109 | return ret; |
110 | } | |
111 | ||
08e0e7c8 | 112 | _leave(" = 0"); |
1da177e4 | 113 | return 0; |
ec26815a | 114 | } |
1da177e4 | 115 | |
1da177e4 LT |
116 | /* |
117 | * clean up the filesystem | |
118 | */ | |
119 | void __exit afs_fs_exit(void) | |
120 | { | |
08e0e7c8 DH |
121 | _enter(""); |
122 | ||
123 | afs_mntpt_kill_timer(); | |
1da177e4 LT |
124 | 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 | ||
8c0a8537 KS |
132 | /* |
133 | * Make sure all delayed rcu free inodes are flushed before we | |
134 | * destroy cache. | |
135 | */ | |
136 | rcu_barrier(); | |
1da177e4 | 137 | kmem_cache_destroy(afs_inode_cachep); |
08e0e7c8 | 138 | _leave(""); |
ec26815a | 139 | } |
1da177e4 | 140 | |
677018a6 DH |
141 | /* |
142 | * Display the mount device name in /proc/mounts. | |
143 | */ | |
144 | static 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 | */ | |
173 | static 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 | ||
1da177e4 LT |
180 | /* |
181 | * 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 | */ | |
00d3b7a4 DH |
185 | static int afs_parse_options(struct afs_mount_params *params, |
186 | char *options, const char **devname) | |
1da177e4 | 187 | { |
08e0e7c8 | 188 | struct afs_cell *cell; |
80c72fe4 DH |
189 | substring_t args[MAX_OPT_ARGS]; |
190 | char *p; | |
191 | int token; | |
1da177e4 LT |
192 | |
193 | _enter("%s", options); | |
194 | ||
195 | options[PAGE_SIZE - 1] = 0; | |
196 | ||
80c72fe4 DH |
197 | while ((p = strsep(&options, ","))) { |
198 | if (!*p) | |
199 | continue; | |
1da177e4 | 200 | |
80c72fe4 DH |
201 | token = match_token(p, afs_options_list, args); |
202 | switch (token) { | |
203 | case afs_opt_cell: | |
204 | cell = afs_cell_lookup(args[0].from, | |
bec5eb61 | 205 | args[0].to - args[0].from, |
206 | false); | |
08e0e7c8 DH |
207 | if (IS_ERR(cell)) |
208 | return PTR_ERR(cell); | |
00d3b7a4 DH |
209 | afs_put_cell(params->cell); |
210 | params->cell = cell; | |
80c72fe4 DH |
211 | 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 | ||
bec5eb61 | 221 | case afs_opt_autocell: |
222 | params->autocell = 1; | |
223 | break; | |
224 | ||
80c72fe4 DH |
225 | default: |
226 | printk(KERN_ERR "kAFS:" | |
227 | " Unknown or invalid mount option: '%s'\n", p); | |
228 | return -EINVAL; | |
1da177e4 | 229 | } |
1da177e4 LT |
230 | } |
231 | ||
80c72fe4 DH |
232 | _leave(" = 0"); |
233 | return 0; | |
ec26815a | 234 | } |
1da177e4 | 235 | |
00d3b7a4 DH |
236 | /* |
237 | * 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 | */ | |
248 | static 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) { | |
bec5eb61 | 311 | cell = afs_cell_lookup(cellname, cellnamesz, true); |
00d3b7a4 | 312 | if (IS_ERR(cell)) { |
bec5eb61 | 313 | printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n", |
314 | cellnamesz, cellnamesz, cellname ?: ""); | |
00d3b7a4 DH |
315 | 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 | ||
1da177e4 LT |
329 | /* |
330 | * check a superblock to see if it's the one we're looking for | |
331 | */ | |
332 | static int afs_test_super(struct super_block *sb, void *data) | |
333 | { | |
dde194a6 | 334 | struct afs_super_info *as1 = data; |
1da177e4 LT |
335 | struct afs_super_info *as = sb->s_fs_info; |
336 | ||
dde194a6 AV |
337 | return as->volume == as1->volume; |
338 | } | |
339 | ||
340 | static int afs_set_super(struct super_block *sb, void *data) | |
341 | { | |
342 | sb->s_fs_info = data; | |
343 | return set_anon_super(sb, NULL); | |
ec26815a | 344 | } |
1da177e4 | 345 | |
1da177e4 LT |
346 | /* |
347 | * fill in the superblock | |
348 | */ | |
dde194a6 AV |
349 | static int afs_fill_super(struct super_block *sb, |
350 | struct afs_mount_params *params) | |
1da177e4 | 351 | { |
dde194a6 | 352 | struct afs_super_info *as = sb->s_fs_info; |
1da177e4 | 353 | struct afs_fid fid; |
1da177e4 LT |
354 | struct inode *inode = NULL; |
355 | int ret; | |
356 | ||
08e0e7c8 | 357 | _enter(""); |
1da177e4 | 358 | |
1da177e4 | 359 | /* fill in the superblock */ |
09cbfeaf KS |
360 | sb->s_blocksize = PAGE_SIZE; |
361 | sb->s_blocksize_bits = PAGE_SHIFT; | |
1da177e4 LT |
362 | sb->s_magic = AFS_FS_MAGIC; |
363 | sb->s_op = &afs_super_ops; | |
d3e3b7ea | 364 | sb->s_xattr = afs_xattr_handlers; |
edd3ba94 JK |
365 | ret = super_setup_bdi(sb); |
366 | if (ret) | |
367 | return ret; | |
368 | sb->s_bdi->ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_SIZE; | |
2e41ae22 | 369 | strlcpy(sb->s_id, as->volume->vlocation->vldb.name, sizeof(sb->s_id)); |
1da177e4 LT |
370 | |
371 | /* allocate the root inode and dentry */ | |
372 | fid.vid = as->volume->vid; | |
373 | fid.vnode = 1; | |
374 | fid.unique = 1; | |
260a9803 | 375 | inode = afs_iget(sb, params->key, &fid, NULL, NULL); |
08e0e7c8 | 376 | if (IS_ERR(inode)) |
dde194a6 | 377 | return PTR_ERR(inode); |
1da177e4 | 378 | |
bec5eb61 | 379 | if (params->autocell) |
380 | set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags); | |
381 | ||
1da177e4 | 382 | ret = -ENOMEM; |
48fde701 AV |
383 | sb->s_root = d_make_root(inode); |
384 | if (!sb->s_root) | |
1da177e4 LT |
385 | goto error; |
386 | ||
d61dcce2 | 387 | sb->s_d_op = &afs_fs_dentry_operations; |
1da177e4 | 388 | |
08e0e7c8 | 389 | _leave(" = 0"); |
1da177e4 LT |
390 | return 0; |
391 | ||
ec26815a | 392 | error: |
08e0e7c8 | 393 | _leave(" = %d", ret); |
1da177e4 | 394 | return ret; |
ec26815a | 395 | } |
1da177e4 | 396 | |
1da177e4 LT |
397 | /* |
398 | * get an AFS superblock | |
1da177e4 | 399 | */ |
f7442b3b AV |
400 | static struct dentry *afs_mount(struct file_system_type *fs_type, |
401 | int flags, const char *dev_name, void *options) | |
1da177e4 LT |
402 | { |
403 | struct afs_mount_params params; | |
404 | struct super_block *sb; | |
08e0e7c8 | 405 | struct afs_volume *vol; |
00d3b7a4 | 406 | struct key *key; |
969729d5 | 407 | char *new_opts = kstrdup(options, GFP_KERNEL); |
dde194a6 | 408 | struct afs_super_info *as; |
1da177e4 LT |
409 | int ret; |
410 | ||
411 | _enter(",,%s,%p", dev_name, options); | |
412 | ||
413 | memset(¶ms, 0, sizeof(params)); | |
414 | ||
f74f70f8 EB |
415 | ret = -EINVAL; |
416 | if (current->nsproxy->net_ns != &init_net) | |
417 | goto error; | |
418 | ||
00d3b7a4 | 419 | /* parse the options and device name */ |
1da177e4 | 420 | if (options) { |
00d3b7a4 | 421 | ret = afs_parse_options(¶ms, options, &dev_name); |
1da177e4 LT |
422 | if (ret < 0) |
423 | goto error; | |
1da177e4 LT |
424 | } |
425 | ||
00d3b7a4 DH |
426 | ret = afs_parse_device_name(¶ms, dev_name); |
427 | if (ret < 0) | |
428 | goto error; | |
429 | ||
430 | /* try and do the mount securely */ | |
431 | key = afs_request_key(params.cell); | |
432 | if (IS_ERR(key)) { | |
433 | _leave(" = %ld [key]", PTR_ERR(key)); | |
434 | ret = PTR_ERR(key); | |
435 | goto error; | |
436 | } | |
437 | params.key = key; | |
438 | ||
1da177e4 | 439 | /* parse the device name */ |
00d3b7a4 | 440 | vol = afs_volume_lookup(¶ms); |
08e0e7c8 DH |
441 | if (IS_ERR(vol)) { |
442 | ret = PTR_ERR(vol); | |
1da177e4 | 443 | goto error; |
08e0e7c8 | 444 | } |
dde194a6 AV |
445 | |
446 | /* allocate a superblock info record */ | |
447 | as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL); | |
448 | if (!as) { | |
449 | ret = -ENOMEM; | |
450 | afs_put_volume(vol); | |
451 | goto error; | |
452 | } | |
453 | as->volume = vol; | |
1da177e4 LT |
454 | |
455 | /* allocate a deviceless superblock */ | |
9249e17f | 456 | sb = sget(fs_type, afs_test_super, afs_set_super, flags, as); |
08e0e7c8 DH |
457 | if (IS_ERR(sb)) { |
458 | ret = PTR_ERR(sb); | |
dde194a6 AV |
459 | afs_put_volume(vol); |
460 | kfree(as); | |
1da177e4 | 461 | goto error; |
08e0e7c8 | 462 | } |
1da177e4 | 463 | |
436058a4 DH |
464 | if (!sb->s_root) { |
465 | /* initial superblock/root creation */ | |
466 | _debug("create"); | |
436058a4 DH |
467 | ret = afs_fill_super(sb, ¶ms); |
468 | if (ret < 0) { | |
6f5bbff9 | 469 | deactivate_locked_super(sb); |
436058a4 DH |
470 | goto error; |
471 | } | |
472 | sb->s_flags |= MS_ACTIVE; | |
473 | } else { | |
474 | _debug("reuse"); | |
475 | ASSERTCMP(sb->s_flags, &, MS_ACTIVE); | |
dde194a6 AV |
476 | afs_put_volume(vol); |
477 | kfree(as); | |
1da177e4 | 478 | } |
1da177e4 | 479 | |
00d3b7a4 | 480 | afs_put_cell(params.cell); |
2a32cebd | 481 | kfree(new_opts); |
08e0e7c8 | 482 | _leave(" = 0 [%p]", sb); |
f7442b3b | 483 | return dget(sb->s_root); |
1da177e4 | 484 | |
ec26815a | 485 | error: |
00d3b7a4 DH |
486 | afs_put_cell(params.cell); |
487 | key_put(params.key); | |
969729d5 | 488 | kfree(new_opts); |
1da177e4 | 489 | _leave(" = %d", ret); |
f7442b3b | 490 | return ERR_PTR(ret); |
ec26815a | 491 | } |
1da177e4 | 492 | |
dde194a6 | 493 | static void afs_kill_super(struct super_block *sb) |
1da177e4 LT |
494 | { |
495 | struct afs_super_info *as = sb->s_fs_info; | |
dde194a6 | 496 | kill_anon_super(sb); |
1da177e4 | 497 | afs_put_volume(as->volume); |
dde194a6 | 498 | kfree(as); |
ec26815a | 499 | } |
1da177e4 | 500 | |
1da177e4 LT |
501 | /* |
502 | * initialise an inode cache slab element prior to any use | |
503 | */ | |
51cc5068 | 504 | static void afs_i_init_once(void *_vnode) |
1da177e4 | 505 | { |
ec26815a | 506 | struct afs_vnode *vnode = _vnode; |
1da177e4 | 507 | |
a35afb83 CL |
508 | memset(vnode, 0, sizeof(*vnode)); |
509 | inode_init_once(&vnode->vfs_inode); | |
510 | init_waitqueue_head(&vnode->update_waitq); | |
511 | mutex_init(&vnode->permits_lock); | |
512 | mutex_init(&vnode->validate_lock); | |
513 | spin_lock_init(&vnode->writeback_lock); | |
514 | spin_lock_init(&vnode->lock); | |
515 | INIT_LIST_HEAD(&vnode->writebacks); | |
e8d6c554 DH |
516 | INIT_LIST_HEAD(&vnode->pending_locks); |
517 | INIT_LIST_HEAD(&vnode->granted_locks); | |
518 | INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work); | |
a35afb83 | 519 | INIT_WORK(&vnode->cb_broken_work, afs_broken_callback_work); |
ec26815a | 520 | } |
1da177e4 | 521 | |
1da177e4 LT |
522 | /* |
523 | * allocate an AFS inode struct from our slab cache | |
524 | */ | |
525 | static struct inode *afs_alloc_inode(struct super_block *sb) | |
526 | { | |
527 | struct afs_vnode *vnode; | |
528 | ||
ec26815a | 529 | vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL); |
1da177e4 LT |
530 | if (!vnode) |
531 | return NULL; | |
532 | ||
533 | atomic_inc(&afs_count_active_inodes); | |
534 | ||
535 | memset(&vnode->fid, 0, sizeof(vnode->fid)); | |
536 | memset(&vnode->status, 0, sizeof(vnode->status)); | |
537 | ||
538 | vnode->volume = NULL; | |
539 | vnode->update_cnt = 0; | |
260a9803 | 540 | vnode->flags = 1 << AFS_VNODE_UNSET; |
08e0e7c8 | 541 | vnode->cb_promised = false; |
1da177e4 | 542 | |
0f300ca9 | 543 | _leave(" = %p", &vnode->vfs_inode); |
1da177e4 | 544 | return &vnode->vfs_inode; |
ec26815a | 545 | } |
1da177e4 | 546 | |
fa0d7e3d NP |
547 | static void afs_i_callback(struct rcu_head *head) |
548 | { | |
549 | struct inode *inode = container_of(head, struct inode, i_rcu); | |
550 | struct afs_vnode *vnode = AFS_FS_I(inode); | |
fa0d7e3d NP |
551 | kmem_cache_free(afs_inode_cachep, vnode); |
552 | } | |
553 | ||
1da177e4 LT |
554 | /* |
555 | * destroy an AFS inode struct | |
556 | */ | |
557 | static void afs_destroy_inode(struct inode *inode) | |
558 | { | |
08e0e7c8 DH |
559 | struct afs_vnode *vnode = AFS_FS_I(inode); |
560 | ||
0f300ca9 | 561 | _enter("%p{%x:%u}", inode, vnode->fid.vid, vnode->fid.vnode); |
1da177e4 | 562 | |
08e0e7c8 DH |
563 | _debug("DESTROY INODE %p", inode); |
564 | ||
565 | ASSERTCMP(vnode->server, ==, NULL); | |
566 | ||
fa0d7e3d | 567 | call_rcu(&inode->i_rcu, afs_i_callback); |
1da177e4 | 568 | atomic_dec(&afs_count_active_inodes); |
ec26815a | 569 | } |
45222b9e DH |
570 | |
571 | /* | |
572 | * return information about an AFS volume | |
573 | */ | |
574 | static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
575 | { | |
576 | struct afs_volume_status vs; | |
2b0143b5 | 577 | struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); |
45222b9e DH |
578 | struct key *key; |
579 | int ret; | |
580 | ||
581 | key = afs_request_key(vnode->volume->cell); | |
582 | if (IS_ERR(key)) | |
583 | return PTR_ERR(key); | |
584 | ||
585 | ret = afs_vnode_get_volume_status(vnode, key, &vs); | |
586 | key_put(key); | |
587 | if (ret < 0) { | |
588 | _leave(" = %d", ret); | |
589 | return ret; | |
590 | } | |
591 | ||
592 | buf->f_type = dentry->d_sb->s_magic; | |
593 | buf->f_bsize = AFS_BLOCK_SIZE; | |
594 | buf->f_namelen = AFSNAMEMAX - 1; | |
595 | ||
596 | if (vs.max_quota == 0) | |
597 | buf->f_blocks = vs.part_max_blocks; | |
598 | else | |
599 | buf->f_blocks = vs.max_quota; | |
600 | buf->f_bavail = buf->f_bfree = buf->f_blocks - vs.blocks_in_use; | |
601 | return 0; | |
602 | } |