cache.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 kmem_cache *vcookie_cache;
  27. struct v9fs_cookie {
  28. spinlock_t lock;
  29. struct inode inode;
  30. struct fscache_cookie *fscache;
  31. struct p9_qid *qid;
  32. };
  33. static inline struct v9fs_cookie *v9fs_inode2cookie(const struct inode *inode)
  34. {
  35. return container_of(inode, struct v9fs_cookie, inode);
  36. }
  37. extern struct fscache_netfs v9fs_cache_netfs;
  38. extern const struct fscache_cookie_def v9fs_cache_session_index_def;
  39. extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
  40. extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
  41. extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
  42. extern void v9fs_cache_inode_get_cookie(struct inode *inode);
  43. extern void v9fs_cache_inode_put_cookie(struct inode *inode);
  44. extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
  45. extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
  46. extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
  47. extern int __v9fs_cache_register(void);
  48. extern void __v9fs_cache_unregister(void);
  49. extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
  50. extern void __v9fs_fscache_invalidate_page(struct page *page);
  51. extern int __v9fs_readpage_from_fscache(struct inode *inode,
  52. struct page *page);
  53. extern int __v9fs_readpages_from_fscache(struct inode *inode,
  54. struct address_space *mapping,
  55. struct list_head *pages,
  56. unsigned *nr_pages);
  57. extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
  58. /**
  59. * v9fs_cache_register - Register v9fs file system with the cache
  60. */
  61. static inline int v9fs_cache_register(void)
  62. {
  63. return __v9fs_cache_register();
  64. }
  65. /**
  66. * v9fs_cache_unregister - Unregister v9fs from the cache
  67. */
  68. static inline void v9fs_cache_unregister(void)
  69. {
  70. __v9fs_cache_unregister();
  71. }
  72. static inline int v9fs_fscache_release_page(struct page *page,
  73. gfp_t gfp)
  74. {
  75. return __v9fs_fscache_release_page(page, gfp);
  76. }
  77. static inline void v9fs_fscache_invalidate_page(struct page *page)
  78. {
  79. __v9fs_fscache_invalidate_page(page);
  80. }
  81. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  82. struct page *page)
  83. {
  84. return __v9fs_readpage_from_fscache(inode, page);
  85. }
  86. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  87. struct address_space *mapping,
  88. struct list_head *pages,
  89. unsigned *nr_pages)
  90. {
  91. return __v9fs_readpages_from_fscache(inode, mapping, pages,
  92. nr_pages);
  93. }
  94. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  95. struct page *page)
  96. {
  97. if (PageFsCache(page))
  98. __v9fs_readpage_to_fscache(inode, page);
  99. }
  100. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  101. {
  102. struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
  103. fscache_uncache_page(vcookie->fscache, page);
  104. BUG_ON(PageFsCache(page));
  105. }
  106. static inline void v9fs_vcookie_set_qid(struct inode *inode,
  107. struct p9_qid *qid)
  108. {
  109. struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
  110. spin_lock(&vcookie->lock);
  111. vcookie->qid = qid;
  112. spin_unlock(&vcookie->lock);
  113. }
  114. #else /* CONFIG_9P_FSCACHE */
  115. static inline int v9fs_cache_register(void)
  116. {
  117. return 1;
  118. }
  119. static inline void v9fs_cache_unregister(void) {}
  120. static inline int v9fs_fscache_release_page(struct page *page,
  121. gfp_t gfp) {
  122. return 1;
  123. }
  124. static inline void v9fs_fscache_invalidate_page(struct page *page) {}
  125. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  126. struct page *page)
  127. {
  128. return -ENOBUFS;
  129. }
  130. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  131. struct address_space *mapping,
  132. struct list_head *pages,
  133. unsigned *nr_pages)
  134. {
  135. return -ENOBUFS;
  136. }
  137. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  138. struct page *page)
  139. {}
  140. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  141. {}
  142. static inline void v9fs_vcookie_set_qid(struct inode *inode,
  143. struct p9_qid *qid)
  144. {}
  145. #endif /* CONFIG_9P_FSCACHE */
  146. #endif /* _9P_CACHE_H */