cache.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * V9FS cache definitions.
  4. *
  5. * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
  6. */
  7. #ifndef _9P_CACHE_H
  8. #define _9P_CACHE_H
  9. #ifdef CONFIG_9P_FSCACHE
  10. #include <linux/fscache.h>
  11. #include <linux/spinlock.h>
  12. extern struct fscache_netfs v9fs_cache_netfs;
  13. extern const struct fscache_cookie_def v9fs_cache_session_index_def;
  14. extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
  15. extern void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses);
  16. extern void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses);
  17. extern void v9fs_cache_inode_get_cookie(struct inode *inode);
  18. extern void v9fs_cache_inode_put_cookie(struct inode *inode);
  19. extern void v9fs_cache_inode_flush_cookie(struct inode *inode);
  20. extern void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp);
  21. extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
  22. extern int __v9fs_cache_register(void);
  23. extern void __v9fs_cache_unregister(void);
  24. extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
  25. extern void __v9fs_fscache_invalidate_page(struct page *page);
  26. extern int __v9fs_readpage_from_fscache(struct inode *inode,
  27. struct page *page);
  28. extern int __v9fs_readpages_from_fscache(struct inode *inode,
  29. struct address_space *mapping,
  30. struct list_head *pages,
  31. unsigned *nr_pages);
  32. extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
  33. extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
  34. struct page *page);
  35. static inline int v9fs_fscache_release_page(struct page *page,
  36. gfp_t gfp)
  37. {
  38. return __v9fs_fscache_release_page(page, gfp);
  39. }
  40. static inline void v9fs_fscache_invalidate_page(struct page *page)
  41. {
  42. __v9fs_fscache_invalidate_page(page);
  43. }
  44. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  45. struct page *page)
  46. {
  47. return __v9fs_readpage_from_fscache(inode, page);
  48. }
  49. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  50. struct address_space *mapping,
  51. struct list_head *pages,
  52. unsigned *nr_pages)
  53. {
  54. return __v9fs_readpages_from_fscache(inode, mapping, pages,
  55. nr_pages);
  56. }
  57. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  58. struct page *page)
  59. {
  60. if (PageFsCache(page))
  61. __v9fs_readpage_to_fscache(inode, page);
  62. }
  63. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  64. {
  65. struct v9fs_inode *v9inode = V9FS_I(inode);
  66. fscache_uncache_page(v9inode->fscache, page);
  67. BUG_ON(PageFsCache(page));
  68. }
  69. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  70. struct page *page)
  71. {
  72. return __v9fs_fscache_wait_on_page_write(inode, page);
  73. }
  74. #else /* CONFIG_9P_FSCACHE */
  75. static inline void v9fs_cache_inode_get_cookie(struct inode *inode)
  76. {
  77. }
  78. static inline void v9fs_cache_inode_put_cookie(struct inode *inode)
  79. {
  80. }
  81. static inline void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *file)
  82. {
  83. }
  84. static inline int v9fs_fscache_release_page(struct page *page,
  85. gfp_t gfp) {
  86. return 1;
  87. }
  88. static inline void v9fs_fscache_invalidate_page(struct page *page) {}
  89. static inline int v9fs_readpage_from_fscache(struct inode *inode,
  90. struct page *page)
  91. {
  92. return -ENOBUFS;
  93. }
  94. static inline int v9fs_readpages_from_fscache(struct inode *inode,
  95. struct address_space *mapping,
  96. struct list_head *pages,
  97. unsigned *nr_pages)
  98. {
  99. return -ENOBUFS;
  100. }
  101. static inline void v9fs_readpage_to_fscache(struct inode *inode,
  102. struct page *page)
  103. {}
  104. static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
  105. {}
  106. static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
  107. struct page *page)
  108. {
  109. return;
  110. }
  111. #endif /* CONFIG_9P_FSCACHE */
  112. #endif /* _9P_CACHE_H */