cache.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 ([email protected])
  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 void ceph_fscache_unpin_writeback(struct inode *inode,
  36. struct writeback_control *wbc)
  37. {
  38. fscache_unpin_writeback(wbc, ceph_fscache_cookie(ceph_inode(inode)));
  39. }
  40. static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
  41. struct folio *folio)
  42. {
  43. struct ceph_inode_info *ci = ceph_inode(mapping->host);
  44. return fscache_dirty_folio(mapping, folio, ceph_fscache_cookie(ci));
  45. }
  46. static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
  47. {
  48. struct fscache_cookie *cookie = ceph_fscache_cookie(ceph_inode(rreq->inode));
  49. return fscache_begin_read_operation(&rreq->cache_resources, cookie);
  50. }
  51. static inline bool ceph_is_cache_enabled(struct inode *inode)
  52. {
  53. return fscache_cookie_enabled(ceph_fscache_cookie(ceph_inode(inode)));
  54. }
  55. static inline void ceph_fscache_note_page_release(struct inode *inode)
  56. {
  57. struct ceph_inode_info *ci = ceph_inode(inode);
  58. fscache_note_page_release(ceph_fscache_cookie(ci));
  59. }
  60. #else /* CONFIG_CEPH_FSCACHE */
  61. static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
  62. struct fs_context *fc)
  63. {
  64. return 0;
  65. }
  66. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  67. {
  68. }
  69. static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
  70. {
  71. }
  72. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  73. {
  74. }
  75. static inline void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
  76. {
  77. }
  78. static inline void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
  79. {
  80. }
  81. static inline void ceph_fscache_update(struct inode *inode)
  82. {
  83. }
  84. static inline void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
  85. {
  86. }
  87. static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
  88. {
  89. return NULL;
  90. }
  91. static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
  92. {
  93. }
  94. static inline void ceph_fscache_unpin_writeback(struct inode *inode,
  95. struct writeback_control *wbc)
  96. {
  97. }
  98. static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
  99. struct folio *folio)
  100. {
  101. return filemap_dirty_folio(mapping, folio);
  102. }
  103. static inline bool ceph_is_cache_enabled(struct inode *inode)
  104. {
  105. return false;
  106. }
  107. static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
  108. {
  109. return -ENOBUFS;
  110. }
  111. static inline void ceph_fscache_note_page_release(struct inode *inode)
  112. {
  113. }
  114. #endif /* CONFIG_CEPH_FSCACHE */
  115. #endif