cache.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifdef CONFIG_CEPH_FSCACHE
  11. extern struct fscache_netfs ceph_cache_netfs;
  12. int ceph_fscache_register(void);
  13. void ceph_fscache_unregister(void);
  14. int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc);
  15. void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc);
  16. void ceph_fscache_register_inode_cookie(struct inode *inode);
  17. void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci);
  18. void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp);
  19. void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci);
  20. int ceph_readpage_from_fscache(struct inode *inode, struct page *page);
  21. int ceph_readpages_from_fscache(struct inode *inode,
  22. struct address_space *mapping,
  23. struct list_head *pages,
  24. unsigned *nr_pages);
  25. void ceph_readpage_to_fscache(struct inode *inode, struct page *page);
  26. void ceph_invalidate_fscache_page(struct inode* inode, struct page *page);
  27. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  28. {
  29. ci->fscache = NULL;
  30. ci->i_fscache_gen = 0;
  31. }
  32. static inline void ceph_fscache_invalidate(struct inode *inode)
  33. {
  34. fscache_invalidate(ceph_inode(inode)->fscache);
  35. }
  36. static inline void ceph_fscache_uncache_page(struct inode *inode,
  37. struct page *page)
  38. {
  39. struct ceph_inode_info *ci = ceph_inode(inode);
  40. return fscache_uncache_page(ci->fscache, page);
  41. }
  42. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  43. {
  44. struct inode* inode = page->mapping->host;
  45. struct ceph_inode_info *ci = ceph_inode(inode);
  46. return fscache_maybe_release_page(ci->fscache, page, gfp);
  47. }
  48. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  49. struct page *page)
  50. {
  51. struct ceph_inode_info *ci = ceph_inode(inode);
  52. if (fscache_cookie_valid(ci->fscache) && PageFsCache(page))
  53. __fscache_uncache_page(ci->fscache, page);
  54. }
  55. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  56. struct list_head *pages)
  57. {
  58. struct ceph_inode_info *ci = ceph_inode(inode);
  59. return fscache_readpages_cancel(ci->fscache, pages);
  60. }
  61. static inline void ceph_disable_fscache_readpage(struct ceph_inode_info *ci)
  62. {
  63. ci->i_fscache_gen = ci->i_rdcache_gen - 1;
  64. }
  65. #else
  66. static inline int ceph_fscache_register(void)
  67. {
  68. return 0;
  69. }
  70. static inline void ceph_fscache_unregister(void)
  71. {
  72. }
  73. static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
  74. struct fs_context *fc)
  75. {
  76. return 0;
  77. }
  78. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  79. {
  80. }
  81. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  82. {
  83. }
  84. static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
  85. {
  86. }
  87. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  88. {
  89. }
  90. static inline void ceph_fscache_file_set_cookie(struct inode *inode,
  91. struct file *filp)
  92. {
  93. }
  94. static inline void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci)
  95. {
  96. }
  97. static inline void ceph_fscache_uncache_page(struct inode *inode,
  98. struct page *pages)
  99. {
  100. }
  101. static inline int ceph_readpage_from_fscache(struct inode* inode,
  102. struct page *page)
  103. {
  104. return -ENOBUFS;
  105. }
  106. static inline int ceph_readpages_from_fscache(struct inode *inode,
  107. struct address_space *mapping,
  108. struct list_head *pages,
  109. unsigned *nr_pages)
  110. {
  111. return -ENOBUFS;
  112. }
  113. static inline void ceph_readpage_to_fscache(struct inode *inode,
  114. struct page *page)
  115. {
  116. }
  117. static inline void ceph_fscache_invalidate(struct inode *inode)
  118. {
  119. }
  120. static inline void ceph_invalidate_fscache_page(struct inode *inode,
  121. struct page *page)
  122. {
  123. }
  124. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  125. {
  126. return 1;
  127. }
  128. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  129. struct page *page)
  130. {
  131. }
  132. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  133. struct list_head *pages)
  134. {
  135. }
  136. static inline void ceph_disable_fscache_readpage(struct ceph_inode_info *ci)
  137. {
  138. }
  139. #endif
  140. #endif