cache.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * V9FS cache definitions.
  4. *
  5. * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
  6. */
  7. #include <linux/jiffies.h>
  8. #include <linux/file.h>
  9. #include <linux/slab.h>
  10. #include <linux/stat.h>
  11. #include <linux/sched.h>
  12. #include <linux/fs.h>
  13. #include <net/9p/9p.h>
  14. #include "v9fs.h"
  15. #include "cache.h"
  16. int v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses,
  17. const char *dev_name)
  18. {
  19. struct fscache_volume *vcookie;
  20. char *name, *p;
  21. name = kasprintf(GFP_KERNEL, "9p,%s,%s",
  22. dev_name, v9ses->cachetag ?: v9ses->aname);
  23. if (!name)
  24. return -ENOMEM;
  25. for (p = name; *p; p++)
  26. if (*p == '/')
  27. *p = ';';
  28. vcookie = fscache_acquire_volume(name, NULL, NULL, 0);
  29. p9_debug(P9_DEBUG_FSC, "session %p get volume %p (%s)\n",
  30. v9ses, vcookie, name);
  31. if (IS_ERR(vcookie)) {
  32. if (vcookie != ERR_PTR(-EBUSY)) {
  33. kfree(name);
  34. return PTR_ERR(vcookie);
  35. }
  36. pr_err("Cache volume key already in use (%s)\n", name);
  37. vcookie = NULL;
  38. }
  39. v9ses->fscache = vcookie;
  40. kfree(name);
  41. return 0;
  42. }
  43. void v9fs_cache_inode_get_cookie(struct inode *inode)
  44. {
  45. struct v9fs_inode *v9inode = V9FS_I(inode);
  46. struct v9fs_session_info *v9ses;
  47. __le32 version;
  48. __le64 path;
  49. if (!S_ISREG(inode->i_mode))
  50. return;
  51. if (WARN_ON(v9fs_inode_cookie(v9inode)))
  52. return;
  53. version = cpu_to_le32(v9inode->qid.version);
  54. path = cpu_to_le64(v9inode->qid.path);
  55. v9ses = v9fs_inode2v9ses(inode);
  56. v9inode->netfs.cache =
  57. fscache_acquire_cookie(v9fs_session_cache(v9ses),
  58. 0,
  59. &path, sizeof(path),
  60. &version, sizeof(version),
  61. i_size_read(&v9inode->netfs.inode));
  62. if (v9inode->netfs.cache)
  63. mapping_set_release_always(inode->i_mapping);
  64. p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
  65. inode, v9fs_inode_cookie(v9inode));
  66. }