cache.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * V9FS cache definitions.
  3. *
  4. * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to:
  17. * Free Software Foundation
  18. * 51 Franklin Street, Fifth Floor
  19. * Boston, MA 02111-1301 USA
  20. *
  21. */
  22. #ifndef _9P_CACHE_H
  23. #define _9P_CACHE_H
  24. #ifdef CONFIG_9P_FSCACHE
  25. #include <linux/fscache.h>
  26. #include <linux/spinlock.h>
  27. extern struct fscache_netfs v9fs_cache_netfs;
  28. extern const struct fscache_cookie_def v9fs_cache_session_index_def;
  29. extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
  30. extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
  31. extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
  32. extern void v9fs_cache_inode_get_cookie(struct inode *inode);
  33. extern void v9fs_cache_inode_put_cookie(struct inode *inode);
  34. extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
  35. extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
  36. extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
  37. extern int __v9fs_cache_register(void);
  38. extern void __v9fs_cache_unregister(void);
  39. extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
  40. extern void __v9fs_fscache_invalidate_page(struct page *page);
  41. extern int __v9fs_readpage_from_fscache(struct inode *inode,
  42. struct page *page);
  43. extern int __v9fs_readpages_from_fscache(struct inode *inode,
  44. struct address_space *mapping,
  45. struct list_head *pages,
  46. unsigned *nr_pages);
  47. extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
  48. extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
  49. struct page *page);
  50. static inline int v9fs_fscache_release_page(struct page *page,
  51. gfp_t gfp)
  52. {
  53. return __v9fs_fscache_release_page(page, gfp);
  54. }
  55. static inline void v9fs_fscache_invalidate_page(struct page *page)
  56. {
  57. __v9fs_fscache_invalidate_page(page);
  58. }
  59. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  60. struct page *page)
  61. {
  62. return __v9fs_readpage_from_fscache(inode, page);
  63. }
  64. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  65. struct address_space *mapping,
  66. struct list_head *pages,
  67. unsigned *nr_pages)
  68. {
  69. return __v9fs_readpages_from_fscache(inode, mapping, pages,
  70. nr_pages);
  71. }
  72. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  73. struct page *page)
  74. {
  75. if (PageFsCache(page))
  76. __v9fs_readpage_to_fscache(inode, page);
  77. }
  78. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  79. {
  80. struct v9fs_inode *v9inode = V9FS_I(inode);
  81. fscache_uncache_page(v9inode->fscache, page);
  82. BUG_ON(PageFsCache(page));
  83. }
  84. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  85. struct page *page)
  86. {
  87. return __v9fs_fscache_wait_on_page_write(inode, page);
  88. }
  89. #else /* CONFIG_9P_FSCACHE */
  90. static inline void v9fs_cache_inode_get_cookie(struct inode *inode)
  91. {
  92. }
  93. static inline void v9fs_cache_inode_put_cookie(struct inode *inode)
  94. {
  95. }
  96. static inline void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *file)
  97. {
  98. }
  99. static inline int v9fs_fscache_release_page(struct page *page,
  100. gfp_t gfp) {
  101. return 1;
  102. }
  103. static inline void v9fs_fscache_invalidate_page(struct page *page) {}
  104. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  105. struct page *page)
  106. {
  107. return -ENOBUFS;
  108. }
  109. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  110. struct address_space *mapping,
  111. struct list_head *pages,
  112. unsigned *nr_pages)
  113. {
  114. return -ENOBUFS;
  115. }
  116. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  117. struct page *page)
  118. {}
  119. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  120. {}
  121. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  122. struct page *page)
  123. {
  124. return;
  125. }
  126. #endif /* CONFIG_9P_FSCACHE */
  127. #endif /* _9P_CACHE_H */