cache.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_readpages_cancel(struct inode *inode,
  60. struct list_head *pages)
  61. {
  62. struct ceph_inode_info *ci = ceph_inode(inode);
  63. return fscache_readpages_cancel(ci->fscache, pages);
  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. {
  75. return 0;
  76. }
  77. static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
  78. {
  79. }
  80. static inline void ceph_fscache_inode_init(struct ceph_inode_info *ci)
  81. {
  82. }
  83. static inline void ceph_fscache_register_inode_cookie(struct ceph_fs_client* parent_fsc,
  84. struct ceph_inode_info* ci)
  85. {
  86. }
  87. static inline void ceph_fscache_uncache_page(struct inode *inode,
  88. struct page *pages)
  89. {
  90. }
  91. static inline int ceph_readpage_from_fscache(struct inode* inode,
  92. struct page *page)
  93. {
  94. return -ENOBUFS;
  95. }
  96. static inline int ceph_readpages_from_fscache(struct inode *inode,
  97. struct address_space *mapping,
  98. struct list_head *pages,
  99. unsigned *nr_pages)
  100. {
  101. return -ENOBUFS;
  102. }
  103. static inline void ceph_readpage_to_fscache(struct inode *inode,
  104. struct page *page)
  105. {
  106. }
  107. static inline void ceph_fscache_invalidate(struct inode *inode)
  108. {
  109. }
  110. static inline void ceph_invalidate_fscache_page(struct inode *inode,
  111. struct page *page)
  112. {
  113. }
  114. static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
  115. {
  116. }
  117. static inline int ceph_release_fscache_page(struct page *page, gfp_t gfp)
  118. {
  119. return 1;
  120. }
  121. static inline void ceph_fscache_readpages_cancel(struct inode *inode,
  122. struct list_head *pages)
  123. {
  124. }
  125. static inline void ceph_queue_revalidate(struct inode *inode)
  126. {
  127. }
  128. #endif
  129. #endif