cache.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_inode_init(struct ceph_inode_info *ci);
  32. void ceph_fscache_register_inode_cookie(struct ceph_fs_client* fsc,
  33. struct ceph_inode_info* ci);
  34. void ceph_fscache_unregister_inode_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. void ceph_queue_revalidate(struct inode *inode);
  43. static inline void ceph_fscache_update_objectsize(struct inode *inode)
  44. {
  45. struct ceph_inode_info *ci = ceph_inode(inode);
  46. fscache_attr_changed(ci->fscache);
  47. }
  48. static inline void ceph_fscache_invalidate(struct inode *inode)
  49. {
  50. fscache_invalidate(ceph_inode(inode)->fscache);
  51. }
  52. static inline void ceph_fscache_uncache_page(struct inode *inode,
  53. struct page *page)
  54. {
  55. struct ceph_inode_info *ci = ceph_inode(inode);
  56. return fscache_uncache_page(ci->fscache, page);
  57. }
  58. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  59. {
  60. struct inode* inode = page->mapping->host;
  61. struct ceph_inode_info *ci = ceph_inode(inode);
  62. return fscache_maybe_release_page(ci->fscache, page, gfp);
  63. }
  64. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  65. struct page *page)
  66. {
  67. struct ceph_inode_info *ci = ceph_inode(inode);
  68. if (fscache_cookie_valid(ci->fscache) && PageFsCache(page))
  69. __fscache_uncache_page(ci->fscache, page);
  70. }
  71. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  72. struct list_head *pages)
  73. {
  74. struct ceph_inode_info *ci = ceph_inode(inode);
  75. return fscache_readpages_cancel(ci->fscache, pages);
  76. }
  77. #else
  78. static inline int ceph_fscache_register(void)
  79. {
  80. return 0;
  81. }
  82. static inline void ceph_fscache_unregister(void)
  83. {
  84. }
  85. static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc)
  86. {
  87. return 0;
  88. }
  89. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  90. {
  91. }
  92. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  93. {
  94. }
  95. static inline void ceph_fscache_register_inode_cookie(struct ceph_fs_client* parent_fsc,
  96. struct ceph_inode_info* ci)
  97. {
  98. }
  99. static inline void ceph_fscache_uncache_page(struct inode *inode,
  100. struct page *pages)
  101. {
  102. }
  103. static inline int ceph_readpage_from_fscache(struct inode* inode,
  104. struct page *page)
  105. {
  106. return -ENOBUFS;
  107. }
  108. static inline int ceph_readpages_from_fscache(struct inode *inode,
  109. struct address_space *mapping,
  110. struct list_head *pages,
  111. unsigned *nr_pages)
  112. {
  113. return -ENOBUFS;
  114. }
  115. static inline void ceph_readpage_to_fscache(struct inode *inode,
  116. struct page *page)
  117. {
  118. }
  119. static inline void ceph_fscache_update_objectsize(struct inode *inode)
  120. {
  121. }
  122. static inline void ceph_fscache_invalidate(struct inode *inode)
  123. {
  124. }
  125. static inline void ceph_invalidate_fscache_page(struct inode *inode,
  126. struct page *page)
  127. {
  128. }
  129. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  130. {
  131. }
  132. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  133. {
  134. return 1;
  135. }
  136. static inline void ceph_fscache_readpage_cancel(struct inode *inode,
  137. struct page *page)
  138. {
  139. }
  140. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  141. struct list_head *pages)
  142. {
  143. }
  144. static inline void ceph_queue_revalidate(struct inode *inode)
  145. {
  146. }
  147. #endif
  148. #endif