cache.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #ifdef CONFIG_9P_FSCACHE
  24. #include <linux/fscache.h>
  25. #include <linux/spinlock.h>
  26. extern struct fscache_netfs v9fs_cache_netfs;
  27. extern const struct fscache_cookie_def v9fs_cache_session_index_def;
  28. extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
  29. extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
  30. extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
  31. extern void v9fs_cache_inode_get_cookie(struct inode *inode);
  32. extern void v9fs_cache_inode_put_cookie(struct inode *inode);
  33. extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
  34. extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
  35. extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
  36. extern int __v9fs_cache_register(void);
  37. extern void __v9fs_cache_unregister(void);
  38. extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
  39. extern void __v9fs_fscache_invalidate_page(struct page *page);
  40. extern int __v9fs_readpage_from_fscache(struct inode *inode,
  41. struct page *page);
  42. extern int __v9fs_readpages_from_fscache(struct inode *inode,
  43. struct address_space *mapping,
  44. struct list_head *pages,
  45. unsigned *nr_pages);
  46. extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
  47. extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
  48. struct page *page);
  49. static inline int v9fs_fscache_release_page(struct page *page,
  50. gfp_t gfp)
  51. {
  52. return __v9fs_fscache_release_page(page, gfp);
  53. }
  54. static inline void v9fs_fscache_invalidate_page(struct page *page)
  55. {
  56. __v9fs_fscache_invalidate_page(page);
  57. }
  58. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  59. struct page *page)
  60. {
  61. return __v9fs_readpage_from_fscache(inode, page);
  62. }
  63. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  64. struct address_space *mapping,
  65. struct list_head *pages,
  66. unsigned *nr_pages)
  67. {
  68. return __v9fs_readpages_from_fscache(inode, mapping, pages,
  69. nr_pages);
  70. }
  71. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  72. struct page *page)
  73. {
  74. if (PageFsCache(page))
  75. __v9fs_readpage_to_fscache(inode, page);
  76. }
  77. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  78. {
  79. struct v9fs_inode *v9inode = V9FS_I(inode);
  80. fscache_uncache_page(v9inode->fscache, page);
  81. BUG_ON(PageFsCache(page));
  82. }
  83. static inline void v9fs_fscache_set_key(struct inode *inode,
  84. struct p9_qid *qid)
  85. {
  86. struct v9fs_inode *v9inode = V9FS_I(inode);
  87. spin_lock(&v9inode->fscache_lock);
  88. v9inode->fscache_key = qid;
  89. spin_unlock(&v9inode->fscache_lock);
  90. }
  91. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  92. struct page *page)
  93. {
  94. return __v9fs_fscache_wait_on_page_write(inode, page);
  95. }
  96. #else /* CONFIG_9P_FSCACHE */
  97. static inline int v9fs_fscache_release_page(struct page *page,
  98. gfp_t gfp) {
  99. return 1;
  100. }
  101. static inline void v9fs_fscache_invalidate_page(struct page *page) {}
  102. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  103. struct page *page)
  104. {
  105. return -ENOBUFS;
  106. }
  107. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  108. struct address_space *mapping,
  109. struct list_head *pages,
  110. unsigned *nr_pages)
  111. {
  112. return -ENOBUFS;
  113. }
  114. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  115. struct page *page)
  116. {}
  117. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  118. {}
  119. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  120. struct page *page)
  121. {
  122. return;
  123. }
  124. #endif /* CONFIG_9P_FSCACHE */
  125. #endif /* _9P_CACHE_H */