cache.h 4.3 KB

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