cache.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Ceph cache definitions.
  4. *
  5. * Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
  6. * Written by Milosz Tanski (milosz@adfin.com)
  7. */
  8. #ifndef _CEPH_CACHE_H
  9. #define _CEPH_CACHE_H
  10. #include <linux/netfs.h>
  11. #ifdef CONFIG_CEPH_FSCACHE
  12. #include <linux/fscache.h>
  13. int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc);
  14. void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc);
  15. void ceph_fscache_register_inode_cookie(struct inode *inode);
  16. void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci);
  17. void ceph_fscache_use_cookie(struct inode *inode, bool will_modify);
  18. void ceph_fscache_unuse_cookie(struct inode *inode, bool update);
  19. void ceph_fscache_update(struct inode *inode);
  20. void ceph_fscache_invalidate(struct inode *inode, bool dio_write);
  21. static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
  22. {
  23. return netfs_i_cookie(&ci->netfs);
  24. }
  25. static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
  26. {
  27. struct ceph_inode_info *ci = ceph_inode(inode);
  28. struct fscache_cookie *cookie = ceph_fscache_cookie(ci);
  29. if (cookie) {
  30. ceph_fscache_use_cookie(inode, true);
  31. fscache_resize_cookie(cookie, to);
  32. ceph_fscache_unuse_cookie(inode, true);
  33. }
  34. }
  35. static inline int ceph_fscache_unpin_writeback(struct inode *inode,
  36. struct writeback_control *wbc)
  37. {
  38. return netfs_unpin_writeback(inode, wbc);
  39. }
  40. #define ceph_fscache_dirty_folio netfs_dirty_folio
  41. static inline bool ceph_is_cache_enabled(struct inode *inode)
  42. {
  43. return fscache_cookie_enabled(ceph_fscache_cookie(ceph_inode(inode)));
  44. }
  45. #else /* CONFIG_CEPH_FSCACHE */
  46. static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
  47. struct fs_context *fc)
  48. {
  49. return 0;
  50. }
  51. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  52. {
  53. }
  54. static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
  55. {
  56. }
  57. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  58. {
  59. }
  60. static inline void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
  61. {
  62. }
  63. static inline void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
  64. {
  65. }
  66. static inline void ceph_fscache_update(struct inode *inode)
  67. {
  68. }
  69. static inline void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
  70. {
  71. }
  72. static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
  73. {
  74. return NULL;
  75. }
  76. static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
  77. {
  78. }
  79. static inline int ceph_fscache_unpin_writeback(struct inode *inode,
  80. struct writeback_control *wbc)
  81. {
  82. return 0;
  83. }
  84. #define ceph_fscache_dirty_folio filemap_dirty_folio
  85. static inline bool ceph_is_cache_enabled(struct inode *inode)
  86. {
  87. return false;
  88. }
  89. #endif /* CONFIG_CEPH_FSCACHE */
  90. #endif