super.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /* AFS superblock handling
  2. *
  3. * Copyright (c) 2002, 2007, 2018 Red Hat, Inc. All rights reserved.
  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>
  13. * David Woodhouse <dwmw2@infradead.org>
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/mount.h>
  19. #include <linux/init.h>
  20. #include <linux/slab.h>
  21. #include <linux/fs.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/fs_parser.h>
  24. #include <linux/statfs.h>
  25. #include <linux/sched.h>
  26. #include <linux/nsproxy.h>
  27. #include <linux/magic.h>
  28. #include <net/net_namespace.h>
  29. #include "internal.h"
  30. static void afs_i_init_once(void *foo);
  31. static void afs_kill_super(struct super_block *sb);
  32. static struct inode *afs_alloc_inode(struct super_block *sb);
  33. static void afs_destroy_inode(struct inode *inode);
  34. static void afs_free_inode(struct inode *inode);
  35. static int afs_statfs(struct dentry *dentry, struct kstatfs *buf);
  36. static int afs_show_devname(struct seq_file *m, struct dentry *root);
  37. static int afs_show_options(struct seq_file *m, struct dentry *root);
  38. static int afs_init_fs_context(struct fs_context *fc);
  39. static const struct fs_parameter_spec afs_fs_parameters[];
  40. struct file_system_type afs_fs_type = {
  41. .owner = THIS_MODULE,
  42. .name = "afs",
  43. .init_fs_context = afs_init_fs_context,
  44. .parameters = afs_fs_parameters,
  45. .kill_sb = afs_kill_super,
  46. .fs_flags = FS_RENAME_DOES_D_MOVE,
  47. };
  48. MODULE_ALIAS_FS("afs");
  49. int afs_net_id;
  50. static const struct super_operations afs_super_ops = {
  51. .statfs = afs_statfs,
  52. .alloc_inode = afs_alloc_inode,
  53. .write_inode = netfs_unpin_writeback,
  54. .drop_inode = afs_drop_inode,
  55. .destroy_inode = afs_destroy_inode,
  56. .free_inode = afs_free_inode,
  57. .evict_inode = afs_evict_inode,
  58. .show_devname = afs_show_devname,
  59. .show_options = afs_show_options,
  60. };
  61. static struct kmem_cache *afs_inode_cachep;
  62. static atomic_t afs_count_active_inodes;
  63. enum afs_param {
  64. Opt_autocell,
  65. Opt_dyn,
  66. Opt_flock,
  67. Opt_source,
  68. };
  69. static const struct constant_table afs_param_flock[] = {
  70. {"local", afs_flock_mode_local },
  71. {"openafs", afs_flock_mode_openafs },
  72. {"strict", afs_flock_mode_strict },
  73. {"write", afs_flock_mode_write },
  74. {}
  75. };
  76. static const struct fs_parameter_spec afs_fs_parameters[] = {
  77. fsparam_flag ("autocell", Opt_autocell),
  78. fsparam_flag ("dyn", Opt_dyn),
  79. fsparam_enum ("flock", Opt_flock, afs_param_flock),
  80. fsparam_string("source", Opt_source),
  81. {}
  82. };
  83. /*
  84. * initialise the filesystem
  85. */
  86. int __init afs_fs_init(void)
  87. {
  88. int ret;
  89. _enter("");
  90. /* create ourselves an inode cache */
  91. atomic_set(&afs_count_active_inodes, 0);
  92. ret = -ENOMEM;
  93. afs_inode_cachep = kmem_cache_create("afs_inode_cache",
  94. sizeof(struct afs_vnode),
  95. 0,
  96. SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
  97. afs_i_init_once);
  98. if (!afs_inode_cachep) {
  99. printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
  100. return ret;
  101. }
  102. /* now export our filesystem to lesser mortals */
  103. ret = register_filesystem(&afs_fs_type);
  104. if (ret < 0) {
  105. kmem_cache_destroy(afs_inode_cachep);
  106. _leave(" = %d", ret);
  107. return ret;
  108. }
  109. _leave(" = 0");
  110. return 0;
  111. }
  112. /*
  113. * clean up the filesystem
  114. */
  115. void afs_fs_exit(void)
  116. {
  117. _enter("");
  118. afs_mntpt_kill_timer();
  119. unregister_filesystem(&afs_fs_type);
  120. if (atomic_read(&afs_count_active_inodes) != 0) {
  121. printk("kAFS: %d active inode objects still present\n",
  122. atomic_read(&afs_count_active_inodes));
  123. BUG();
  124. }
  125. /*
  126. * Make sure all delayed rcu free inodes are flushed before we
  127. * destroy cache.
  128. */
  129. rcu_barrier();
  130. kmem_cache_destroy(afs_inode_cachep);
  131. _leave("");
  132. }
  133. /*
  134. * Display the mount device name in /proc/mounts.
  135. */
  136. static int afs_show_devname(struct seq_file *m, struct dentry *root)
  137. {
  138. struct afs_super_info *as = AFS_FS_S(root->d_sb);
  139. struct afs_volume *volume = as->volume;
  140. struct afs_cell *cell = as->cell;
  141. const char *suf = "";
  142. char pref = '%';
  143. if (as->dyn_root) {
  144. seq_puts(m, "none");
  145. return 0;
  146. }
  147. switch (volume->type) {
  148. case AFSVL_RWVOL:
  149. break;
  150. case AFSVL_ROVOL:
  151. pref = '#';
  152. if (volume->type_force)
  153. suf = ".readonly";
  154. break;
  155. case AFSVL_BACKVOL:
  156. pref = '#';
  157. suf = ".backup";
  158. break;
  159. }
  160. seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf);
  161. return 0;
  162. }
  163. /*
  164. * Display the mount options in /proc/mounts.
  165. */
  166. static int afs_show_options(struct seq_file *m, struct dentry *root)
  167. {
  168. struct afs_super_info *as = AFS_FS_S(root->d_sb);
  169. const char *p = NULL;
  170. if (as->dyn_root)
  171. seq_puts(m, ",dyn");
  172. switch (as->flock_mode) {
  173. case afs_flock_mode_unset: break;
  174. case afs_flock_mode_local: p = "local"; break;
  175. case afs_flock_mode_openafs: p = "openafs"; break;
  176. case afs_flock_mode_strict: p = "strict"; break;
  177. case afs_flock_mode_write: p = "write"; break;
  178. }
  179. if (p)
  180. seq_printf(m, ",flock=%s", p);
  181. return 0;
  182. }
  183. /*
  184. * Parse the source name to get cell name, volume name, volume type and R/W
  185. * selector.
  186. *
  187. * This can be one of the following:
  188. * "%[cell:]volume[.]" R/W volume
  189. * "#[cell:]volume[.]" R/O or R/W volume (R/O parent),
  190. * or R/W (R/W parent) volume
  191. * "%[cell:]volume.readonly" R/O volume
  192. * "#[cell:]volume.readonly" R/O volume
  193. * "%[cell:]volume.backup" Backup volume
  194. * "#[cell:]volume.backup" Backup volume
  195. */
  196. static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param)
  197. {
  198. struct afs_fs_context *ctx = fc->fs_private;
  199. struct afs_cell *cell;
  200. const char *cellname, *suffix, *name = param->string;
  201. int cellnamesz;
  202. _enter(",%s", name);
  203. if (fc->source)
  204. return invalf(fc, "kAFS: Multiple sources not supported");
  205. if (!name) {
  206. printk(KERN_ERR "kAFS: no volume name specified\n");
  207. return -EINVAL;
  208. }
  209. if ((name[0] != '%' && name[0] != '#') || !name[1]) {
  210. /* To use dynroot, we don't want to have to provide a source */
  211. if (strcmp(name, "none") == 0) {
  212. ctx->no_cell = true;
  213. return 0;
  214. }
  215. printk(KERN_ERR "kAFS: unparsable volume name\n");
  216. return -EINVAL;
  217. }
  218. /* determine the type of volume we're looking for */
  219. if (name[0] == '%') {
  220. ctx->type = AFSVL_RWVOL;
  221. ctx->force = true;
  222. }
  223. name++;
  224. /* split the cell name out if there is one */
  225. ctx->volname = strchr(name, ':');
  226. if (ctx->volname) {
  227. cellname = name;
  228. cellnamesz = ctx->volname - name;
  229. ctx->volname++;
  230. } else {
  231. ctx->volname = name;
  232. cellname = NULL;
  233. cellnamesz = 0;
  234. }
  235. /* the volume type is further affected by a possible suffix */
  236. suffix = strrchr(ctx->volname, '.');
  237. if (suffix) {
  238. if (strcmp(suffix, ".readonly") == 0) {
  239. ctx->type = AFSVL_ROVOL;
  240. ctx->force = true;
  241. } else if (strcmp(suffix, ".backup") == 0) {
  242. ctx->type = AFSVL_BACKVOL;
  243. ctx->force = true;
  244. } else if (suffix[1] == 0) {
  245. } else {
  246. suffix = NULL;
  247. }
  248. }
  249. ctx->volnamesz = suffix ?
  250. suffix - ctx->volname : strlen(ctx->volname);
  251. _debug("cell %*.*s [%p]",
  252. cellnamesz, cellnamesz, cellname ?: "", ctx->cell);
  253. /* lookup the cell record */
  254. if (cellname) {
  255. cell = afs_lookup_cell(ctx->net, cellname, cellnamesz,
  256. NULL, AFS_LOOKUP_CELL_DIRECT_MOUNT,
  257. afs_cell_trace_use_lookup_mount);
  258. if (IS_ERR(cell)) {
  259. pr_err("kAFS: unable to lookup cell '%*.*s'\n",
  260. cellnamesz, cellnamesz, cellname ?: "");
  261. return PTR_ERR(cell);
  262. }
  263. afs_unuse_cell(ctx->cell, afs_cell_trace_unuse_parse);
  264. afs_see_cell(cell, afs_cell_trace_see_source);
  265. ctx->cell = cell;
  266. }
  267. _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
  268. ctx->cell->name, ctx->cell,
  269. ctx->volnamesz, ctx->volnamesz, ctx->volname,
  270. suffix ?: "-", ctx->type, ctx->force ? " FORCE" : "");
  271. fc->source = param->string;
  272. param->string = NULL;
  273. return 0;
  274. }
  275. /*
  276. * Parse a single mount parameter.
  277. */
  278. static int afs_parse_param(struct fs_context *fc, struct fs_parameter *param)
  279. {
  280. struct fs_parse_result result;
  281. struct afs_fs_context *ctx = fc->fs_private;
  282. int opt;
  283. opt = fs_parse(fc, afs_fs_parameters, param, &result);
  284. if (opt < 0)
  285. return opt;
  286. switch (opt) {
  287. case Opt_source:
  288. return afs_parse_source(fc, param);
  289. case Opt_autocell:
  290. ctx->autocell = true;
  291. break;
  292. case Opt_dyn:
  293. ctx->dyn_root = true;
  294. break;
  295. case Opt_flock:
  296. ctx->flock_mode = result.uint_32;
  297. break;
  298. default:
  299. return -EINVAL;
  300. }
  301. _leave(" = 0");
  302. return 0;
  303. }
  304. /*
  305. * Validate the options, get the cell key and look up the volume.
  306. */
  307. static int afs_validate_fc(struct fs_context *fc)
  308. {
  309. struct afs_fs_context *ctx = fc->fs_private;
  310. struct afs_volume *volume;
  311. struct afs_cell *cell;
  312. struct key *key;
  313. int ret;
  314. if (!ctx->dyn_root) {
  315. if (ctx->no_cell) {
  316. pr_warn("kAFS: Can only specify source 'none' with -o dyn\n");
  317. return -EINVAL;
  318. }
  319. if (!ctx->cell) {
  320. pr_warn("kAFS: No cell specified\n");
  321. return -EDESTADDRREQ;
  322. }
  323. reget_key:
  324. /* We try to do the mount securely. */
  325. key = afs_request_key(ctx->cell);
  326. if (IS_ERR(key))
  327. return PTR_ERR(key);
  328. ctx->key = key;
  329. if (ctx->volume) {
  330. afs_put_volume(ctx->volume, afs_volume_trace_put_validate_fc);
  331. ctx->volume = NULL;
  332. }
  333. if (test_bit(AFS_CELL_FL_CHECK_ALIAS, &ctx->cell->flags)) {
  334. ret = afs_cell_detect_alias(ctx->cell, key);
  335. if (ret < 0)
  336. return ret;
  337. if (ret == 1) {
  338. _debug("switch to alias");
  339. key_put(ctx->key);
  340. ctx->key = NULL;
  341. cell = afs_use_cell(ctx->cell->alias_of,
  342. afs_cell_trace_use_fc_alias);
  343. afs_unuse_cell(ctx->cell, afs_cell_trace_unuse_fc);
  344. ctx->cell = cell;
  345. goto reget_key;
  346. }
  347. }
  348. volume = afs_create_volume(ctx);
  349. if (IS_ERR(volume))
  350. return PTR_ERR(volume);
  351. ctx->volume = volume;
  352. if (volume->type != AFSVL_RWVOL) {
  353. ctx->flock_mode = afs_flock_mode_local;
  354. fc->sb_flags |= SB_RDONLY;
  355. }
  356. }
  357. return 0;
  358. }
  359. /*
  360. * check a superblock to see if it's the one we're looking for
  361. */
  362. static int afs_test_super(struct super_block *sb, struct fs_context *fc)
  363. {
  364. struct afs_fs_context *ctx = fc->fs_private;
  365. struct afs_super_info *as = AFS_FS_S(sb);
  366. return (as->net_ns == fc->net_ns &&
  367. as->volume &&
  368. as->volume->vid == ctx->volume->vid &&
  369. as->cell == ctx->cell &&
  370. !as->dyn_root);
  371. }
  372. static int afs_dynroot_test_super(struct super_block *sb, struct fs_context *fc)
  373. {
  374. struct afs_super_info *as = AFS_FS_S(sb);
  375. return (as->net_ns == fc->net_ns &&
  376. as->dyn_root);
  377. }
  378. static int afs_set_super(struct super_block *sb, struct fs_context *fc)
  379. {
  380. return set_anon_super(sb, NULL);
  381. }
  382. /*
  383. * fill in the superblock
  384. */
  385. static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)
  386. {
  387. struct afs_super_info *as = AFS_FS_S(sb);
  388. struct inode *inode = NULL;
  389. int ret;
  390. _enter("");
  391. /* fill in the superblock */
  392. sb->s_blocksize = PAGE_SIZE;
  393. sb->s_blocksize_bits = PAGE_SHIFT;
  394. sb->s_maxbytes = MAX_LFS_FILESIZE;
  395. sb->s_magic = AFS_FS_MAGIC;
  396. sb->s_op = &afs_super_ops;
  397. if (!as->dyn_root)
  398. sb->s_xattr = afs_xattr_handlers;
  399. ret = super_setup_bdi(sb);
  400. if (ret)
  401. return ret;
  402. /* allocate the root inode and dentry */
  403. if (as->dyn_root) {
  404. inode = afs_dynroot_iget_root(sb);
  405. } else {
  406. sprintf(sb->s_id, "%llu", as->volume->vid);
  407. afs_activate_volume(as->volume);
  408. inode = afs_root_iget(sb, ctx->key);
  409. }
  410. if (IS_ERR(inode))
  411. return PTR_ERR(inode);
  412. ret = -ENOMEM;
  413. sb->s_root = d_make_root(inode);
  414. if (!sb->s_root)
  415. goto error;
  416. if (as->dyn_root) {
  417. set_default_d_op(sb, &afs_dynroot_dentry_operations);
  418. } else {
  419. set_default_d_op(sb, &afs_fs_dentry_operations);
  420. rcu_assign_pointer(as->volume->sb, sb);
  421. }
  422. _leave(" = 0");
  423. return 0;
  424. error:
  425. _leave(" = %d", ret);
  426. return ret;
  427. }
  428. static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc)
  429. {
  430. struct afs_fs_context *ctx = fc->fs_private;
  431. struct afs_super_info *as;
  432. as = kzalloc_obj(struct afs_super_info);
  433. if (as) {
  434. as->net_ns = get_net(fc->net_ns);
  435. as->flock_mode = ctx->flock_mode;
  436. if (ctx->dyn_root) {
  437. as->dyn_root = true;
  438. } else {
  439. as->cell = afs_use_cell(ctx->cell, afs_cell_trace_use_sbi);
  440. as->volume = afs_get_volume(ctx->volume,
  441. afs_volume_trace_get_alloc_sbi);
  442. }
  443. }
  444. return as;
  445. }
  446. static void afs_destroy_sbi(struct afs_super_info *as)
  447. {
  448. if (as) {
  449. afs_put_volume(as->volume, afs_volume_trace_put_destroy_sbi);
  450. afs_unuse_cell(as->cell, afs_cell_trace_unuse_sbi);
  451. put_net(as->net_ns);
  452. kfree(as);
  453. }
  454. }
  455. static void afs_kill_super(struct super_block *sb)
  456. {
  457. struct afs_super_info *as = AFS_FS_S(sb);
  458. /* Clear the callback interests (which will do ilookup5) before
  459. * deactivating the superblock.
  460. */
  461. if (as->volume)
  462. rcu_assign_pointer(as->volume->sb, NULL);
  463. kill_anon_super(sb);
  464. if (as->volume)
  465. afs_deactivate_volume(as->volume);
  466. afs_destroy_sbi(as);
  467. }
  468. /*
  469. * Get an AFS superblock and root directory.
  470. */
  471. static int afs_get_tree(struct fs_context *fc)
  472. {
  473. struct afs_fs_context *ctx = fc->fs_private;
  474. struct super_block *sb;
  475. struct afs_super_info *as;
  476. int ret;
  477. ret = afs_validate_fc(fc);
  478. if (ret)
  479. goto error;
  480. _enter("");
  481. /* allocate a superblock info record */
  482. ret = -ENOMEM;
  483. as = afs_alloc_sbi(fc);
  484. if (!as)
  485. goto error;
  486. fc->s_fs_info = as;
  487. /* allocate a deviceless superblock */
  488. sb = sget_fc(fc,
  489. as->dyn_root ? afs_dynroot_test_super : afs_test_super,
  490. afs_set_super);
  491. if (IS_ERR(sb)) {
  492. ret = PTR_ERR(sb);
  493. goto error;
  494. }
  495. if (!sb->s_root) {
  496. /* initial superblock/root creation */
  497. _debug("create");
  498. ret = afs_fill_super(sb, ctx);
  499. if (ret < 0)
  500. goto error_sb;
  501. sb->s_flags |= SB_ACTIVE;
  502. } else {
  503. _debug("reuse");
  504. ASSERTCMP(sb->s_flags, &, SB_ACTIVE);
  505. }
  506. fc->root = dget(sb->s_root);
  507. trace_afs_get_tree(as->cell, as->volume);
  508. _leave(" = 0 [%p]", sb);
  509. return 0;
  510. error_sb:
  511. deactivate_locked_super(sb);
  512. error:
  513. _leave(" = %d", ret);
  514. return ret;
  515. }
  516. static void afs_free_fc(struct fs_context *fc)
  517. {
  518. struct afs_fs_context *ctx = fc->fs_private;
  519. afs_destroy_sbi(fc->s_fs_info);
  520. afs_put_volume(ctx->volume, afs_volume_trace_put_free_fc);
  521. afs_unuse_cell(ctx->cell, afs_cell_trace_unuse_fc);
  522. key_put(ctx->key);
  523. kfree(ctx);
  524. }
  525. static const struct fs_context_operations afs_context_ops = {
  526. .free = afs_free_fc,
  527. .parse_param = afs_parse_param,
  528. .get_tree = afs_get_tree,
  529. };
  530. /*
  531. * Set up the filesystem mount context.
  532. */
  533. static int afs_init_fs_context(struct fs_context *fc)
  534. {
  535. struct afs_fs_context *ctx;
  536. struct afs_cell *cell;
  537. ctx = kzalloc_obj(struct afs_fs_context);
  538. if (!ctx)
  539. return -ENOMEM;
  540. ctx->type = AFSVL_ROVOL;
  541. ctx->net = afs_net(fc->net_ns);
  542. /* Default to the workstation cell. */
  543. cell = afs_find_cell(ctx->net, NULL, 0, afs_cell_trace_use_fc);
  544. if (IS_ERR(cell))
  545. cell = NULL;
  546. ctx->cell = cell;
  547. fc->fs_private = ctx;
  548. fc->ops = &afs_context_ops;
  549. return 0;
  550. }
  551. /*
  552. * Initialise an inode cache slab element prior to any use. Note that
  553. * afs_alloc_inode() *must* reset anything that could incorrectly leak from one
  554. * inode to another.
  555. */
  556. static void afs_i_init_once(void *_vnode)
  557. {
  558. struct afs_vnode *vnode = _vnode;
  559. memset(vnode, 0, sizeof(*vnode));
  560. inode_init_once(&vnode->netfs.inode);
  561. INIT_LIST_HEAD(&vnode->io_lock_waiters);
  562. init_rwsem(&vnode->validate_lock);
  563. spin_lock_init(&vnode->wb_lock);
  564. spin_lock_init(&vnode->lock);
  565. INIT_LIST_HEAD(&vnode->wb_keys);
  566. INIT_LIST_HEAD(&vnode->pending_locks);
  567. INIT_LIST_HEAD(&vnode->granted_locks);
  568. INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work);
  569. INIT_LIST_HEAD(&vnode->cb_mmap_link);
  570. seqlock_init(&vnode->cb_lock);
  571. }
  572. /*
  573. * allocate an AFS inode struct from our slab cache
  574. */
  575. static struct inode *afs_alloc_inode(struct super_block *sb)
  576. {
  577. struct afs_vnode *vnode;
  578. vnode = alloc_inode_sb(sb, afs_inode_cachep, GFP_KERNEL);
  579. if (!vnode)
  580. return NULL;
  581. atomic_inc(&afs_count_active_inodes);
  582. /* Reset anything that shouldn't leak from one inode to the next. */
  583. memset(&vnode->fid, 0, sizeof(vnode->fid));
  584. memset(&vnode->status, 0, sizeof(vnode->status));
  585. afs_vnode_set_cache(vnode, NULL);
  586. vnode->volume = NULL;
  587. vnode->lock_key = NULL;
  588. vnode->permit_cache = NULL;
  589. vnode->directory = NULL;
  590. vnode->directory_size = 0;
  591. vnode->flags = 1 << AFS_VNODE_UNSET;
  592. vnode->lock_state = AFS_VNODE_LOCK_NONE;
  593. init_rwsem(&vnode->rmdir_lock);
  594. INIT_WORK(&vnode->cb_work, afs_invalidate_mmap_work);
  595. _leave(" = %p", &vnode->netfs.inode);
  596. return &vnode->netfs.inode;
  597. }
  598. static void afs_free_inode(struct inode *inode)
  599. {
  600. kmem_cache_free(afs_inode_cachep, AFS_FS_I(inode));
  601. }
  602. /*
  603. * destroy an AFS inode struct
  604. */
  605. static void afs_destroy_inode(struct inode *inode)
  606. {
  607. struct afs_vnode *vnode = AFS_FS_I(inode);
  608. _enter("%p{%llx:%llu}", inode, vnode->fid.vid, vnode->fid.vnode);
  609. _debug("DESTROY INODE %p", inode);
  610. atomic_dec(&afs_count_active_inodes);
  611. }
  612. static void afs_get_volume_status_success(struct afs_operation *op)
  613. {
  614. struct afs_volume_status *vs = &op->volstatus.vs;
  615. struct kstatfs *buf = op->volstatus.buf;
  616. if (vs->max_quota == 0)
  617. buf->f_blocks = vs->part_max_blocks;
  618. else
  619. buf->f_blocks = vs->max_quota;
  620. if (buf->f_blocks > vs->blocks_in_use)
  621. buf->f_bavail = buf->f_bfree =
  622. buf->f_blocks - vs->blocks_in_use;
  623. }
  624. static const struct afs_operation_ops afs_get_volume_status_operation = {
  625. .issue_afs_rpc = afs_fs_get_volume_status,
  626. .issue_yfs_rpc = yfs_fs_get_volume_status,
  627. .success = afs_get_volume_status_success,
  628. };
  629. /*
  630. * return information about an AFS volume
  631. */
  632. static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
  633. {
  634. struct afs_super_info *as = AFS_FS_S(dentry->d_sb);
  635. struct afs_operation *op;
  636. struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
  637. buf->f_type = dentry->d_sb->s_magic;
  638. buf->f_bsize = AFS_BLOCK_SIZE;
  639. buf->f_namelen = AFSNAMEMAX - 1;
  640. if (as->dyn_root) {
  641. buf->f_blocks = 1;
  642. buf->f_bavail = 0;
  643. buf->f_bfree = 0;
  644. return 0;
  645. }
  646. op = afs_alloc_operation(NULL, as->volume);
  647. if (IS_ERR(op))
  648. return PTR_ERR(op);
  649. afs_op_set_vnode(op, 0, vnode);
  650. op->nr_files = 1;
  651. op->volstatus.buf = buf;
  652. op->ops = &afs_get_volume_status_operation;
  653. return afs_do_sync_operation(op);
  654. }