cache.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Ceph cache definitions.
  3. *
  4. * Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
  5. * Written by Milosz Tanski (milosz@adfin.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to:
  18. * Free Software Foundation
  19. * 51 Franklin Street, Fifth Floor
  20. * Boston, MA 02111-1301 USA
  21. *
  22. */
  23. #ifndef _CEPH_CACHE_H
  24. #define _CEPH_CACHE_H
  25. #ifdef CONFIG_CEPH_FSCACHE
  26. extern struct fscache_netfs ceph_cache_netfs;
  27. int ceph_fscache_register(void);
  28. void ceph_fscache_unregister(void);
  29. int ceph_fscache_register_fs(struct ceph_fs_client* fsc);
  30. void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc);
  31. void ceph_fscache_register_inode_cookie(struct inode *inode);
  32. void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci);
  33. void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp);
  34. void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci);
  35. int ceph_readpage_from_fscache(struct inode *inode, struct page *page);
  36. int ceph_readpages_from_fscache(struct inode *inode,
  37. struct address_space *mapping,
  38. struct list_head *pages,
  39. unsigned *nr_pages);
  40. void ceph_readpage_to_fscache(struct inode *inode, struct page *page);
  41. void ceph_invalidate_fscache_page(struct inode* inode, struct page *page);
  42. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  43. {
  44. ci->fscache = NULL;
  45. ci->i_fscache_gen = 0;
  46. }
  47. static inline void ceph_fscache_invalidate(struct inode *inode)
  48. {
  49. fscache_invalidate(ceph_inode(inode)->fscache);
  50. }
  51. static inline void ceph_fscache_uncache_page(struct inode *inode,
  52. struct page *page)
  53. {
  54. struct ceph_inode_info *ci = ceph_inode(inode);
  55. return fscache_uncache_page(ci->fscache, page);
  56. }
  57. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  58. {
  59. struct inode* inode = page->mapping->host;
  60. struct ceph_inode_info *ci = ceph_inode(inode);
  61. return fscache_maybe_release_page(ci->fscache, page, gfp);
  62. }
  63. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  64. struct page *page)
  65. {
  66. struct ceph_inode_info *ci = ceph_inode(inode);
  67. if (fscache_cookie_valid(ci->fscache) && PageFsCache(page))
  68. __fscache_uncache_page(ci->fscache, page);
  69. }
  70. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  71. struct list_head *pages)
  72. {
  73. struct ceph_inode_info *ci = ceph_inode(inode);
  74. return fscache_readpages_cancel(ci->fscache, pages);
  75. }
  76. static inline void ceph_disable_fscache_readpage(struct ceph_inode_info *ci)
  77. {
  78. ci->i_fscache_gen = ci->i_rdcache_gen - 1;
  79. }
  80. #else
  81. static inline int ceph_fscache_register(void)
  82. {
  83. return 0;
  84. }
  85. static inline void ceph_fscache_unregister(void)
  86. {
  87. }
  88. static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
  89. {
  90. return 0;
  91. }
  92. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  93. {
  94. }
  95. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  96. {
  97. }
  98. static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
  99. {
  100. }
  101. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  102. {
  103. }
  104. static inline void ceph_fscache_file_set_cookie(struct inode *inode,
  105. struct file *filp)
  106. {
  107. }
  108. static inline void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci)
  109. {
  110. }
  111. static inline void ceph_fscache_uncache_page(struct inode *inode,
  112. struct page *pages)
  113. {
  114. }
  115. static inline int ceph_readpage_from_fscache(struct inode* inode,
  116. struct page *page)
  117. {
  118. return -ENOBUFS;
  119. }
  120. static inline int ceph_readpages_from_fscache(struct inode *inode,
  121. struct address_space *mapping,
  122. struct list_head *pages,
  123. unsigned *nr_pages)
  124. {
  125. return -ENOBUFS;
  126. }
  127. static inline void ceph_readpage_to_fscache(struct inode *inode,
  128. struct page *page)
  129. {
  130. }
  131. static inline void ceph_fscache_invalidate(struct inode *inode)
  132. {
  133. }
  134. static inline void ceph_invalidate_fscache_page(struct inode *inode,
  135. struct page *page)
  136. {
  137. }
  138. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  139. {
  140. return 1;
  141. }
  142. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  143. struct page *page)
  144. {
  145. }
  146. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  147. struct list_head *pages)
  148. {
  149. }
  150. static inline void ceph_disable_fscache_readpage(struct ceph_inode_info *ci)
  151. {
  152. }
  153. #endif
  154. #endif