fscache.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* NFS filesystem cache interface definitions
  2. *
  3. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _NFS_FSCACHE_H
  12. #define _NFS_FSCACHE_H
  13. #include <linux/nfs_fs.h>
  14. #include <linux/nfs_mount.h>
  15. #include <linux/nfs4_mount.h>
  16. #include <linux/fscache.h>
  17. #ifdef CONFIG_NFS_FSCACHE
  18. /*
  19. * set of NFS FS-Cache objects that form a superblock key
  20. */
  21. struct nfs_fscache_key {
  22. struct rb_node node;
  23. struct nfs_client *nfs_client; /* the server */
  24. /* the elements of the unique key - as used by nfs_compare_super() and
  25. * nfs_compare_mount_options() to distinguish superblocks */
  26. struct {
  27. struct {
  28. unsigned long s_flags; /* various flags
  29. * (& NFS_MS_MASK) */
  30. } super;
  31. struct {
  32. struct nfs_fsid fsid;
  33. int flags;
  34. unsigned int rsize; /* read size */
  35. unsigned int wsize; /* write size */
  36. unsigned int acregmin; /* attr cache timeouts */
  37. unsigned int acregmax;
  38. unsigned int acdirmin;
  39. unsigned int acdirmax;
  40. } nfs_server;
  41. struct {
  42. rpc_authflavor_t au_flavor;
  43. } rpc_auth;
  44. /* uniquifier - can be used if nfs_server.flags includes
  45. * NFS_MOUNT_UNSHARED */
  46. u8 uniq_len;
  47. char uniquifier[0];
  48. } key;
  49. };
  50. /*
  51. * fscache-index.c
  52. */
  53. extern struct fscache_netfs nfs_fscache_netfs;
  54. extern const struct fscache_cookie_def nfs_fscache_server_index_def;
  55. extern const struct fscache_cookie_def nfs_fscache_super_index_def;
  56. extern const struct fscache_cookie_def nfs_fscache_inode_object_def;
  57. extern int nfs_fscache_register(void);
  58. extern void nfs_fscache_unregister(void);
  59. /*
  60. * fscache.c
  61. */
  62. extern void nfs_fscache_get_client_cookie(struct nfs_client *);
  63. extern void nfs_fscache_release_client_cookie(struct nfs_client *);
  64. extern void nfs_fscache_get_super_cookie(struct super_block *,
  65. const char *,
  66. struct nfs_clone_mount *);
  67. extern void nfs_fscache_release_super_cookie(struct super_block *);
  68. extern void nfs_fscache_init_inode_cookie(struct inode *);
  69. extern void nfs_fscache_release_inode_cookie(struct inode *);
  70. extern void nfs_fscache_zap_inode_cookie(struct inode *);
  71. extern void nfs_fscache_set_inode_cookie(struct inode *, struct file *);
  72. extern void nfs_fscache_reset_inode_cookie(struct inode *);
  73. extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);
  74. extern int nfs_fscache_release_page(struct page *, gfp_t);
  75. extern int __nfs_readpage_from_fscache(struct nfs_open_context *,
  76. struct inode *, struct page *);
  77. extern int __nfs_readpages_from_fscache(struct nfs_open_context *,
  78. struct inode *, struct address_space *,
  79. struct list_head *, unsigned *);
  80. extern void __nfs_readpage_to_fscache(struct inode *, struct page *, int);
  81. /*
  82. * wait for a page to complete writing to the cache
  83. */
  84. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  85. struct page *page)
  86. {
  87. if (PageFsCache(page))
  88. fscache_wait_on_page_write(nfsi->fscache, page);
  89. }
  90. /*
  91. * release the caching state associated with a page if undergoing complete page
  92. * invalidation
  93. */
  94. static inline void nfs_fscache_invalidate_page(struct page *page,
  95. struct inode *inode)
  96. {
  97. if (PageFsCache(page))
  98. __nfs_fscache_invalidate_page(page, inode);
  99. }
  100. /*
  101. * Retrieve a page from an inode data storage object.
  102. */
  103. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  104. struct inode *inode,
  105. struct page *page)
  106. {
  107. if (NFS_I(inode)->fscache)
  108. return __nfs_readpage_from_fscache(ctx, inode, page);
  109. return -ENOBUFS;
  110. }
  111. /*
  112. * Retrieve a set of pages from an inode data storage object.
  113. */
  114. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  115. struct inode *inode,
  116. struct address_space *mapping,
  117. struct list_head *pages,
  118. unsigned *nr_pages)
  119. {
  120. if (NFS_I(inode)->fscache)
  121. return __nfs_readpages_from_fscache(ctx, inode, mapping, pages,
  122. nr_pages);
  123. return -ENOBUFS;
  124. }
  125. /*
  126. * Store a page newly fetched from the server in an inode data storage object
  127. * in the cache.
  128. */
  129. static inline void nfs_readpage_to_fscache(struct inode *inode,
  130. struct page *page,
  131. int sync)
  132. {
  133. if (PageFsCache(page))
  134. __nfs_readpage_to_fscache(inode, page, sync);
  135. }
  136. /*
  137. * indicate the client caching state as readable text
  138. */
  139. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  140. {
  141. if (server->fscache && (server->options & NFS_OPTION_FSCACHE))
  142. return "yes";
  143. return "no ";
  144. }
  145. #else /* CONFIG_NFS_FSCACHE */
  146. static inline int nfs_fscache_register(void) { return 0; }
  147. static inline void nfs_fscache_unregister(void) {}
  148. static inline void nfs_fscache_get_client_cookie(struct nfs_client *clp) {}
  149. static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {}
  150. static inline void nfs_fscache_get_super_cookie(
  151. struct super_block *sb,
  152. const char *uniq,
  153. struct nfs_clone_mount *mntdata)
  154. {
  155. }
  156. static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
  157. static inline void nfs_fscache_init_inode_cookie(struct inode *inode) {}
  158. static inline void nfs_fscache_release_inode_cookie(struct inode *inode) {}
  159. static inline void nfs_fscache_zap_inode_cookie(struct inode *inode) {}
  160. static inline void nfs_fscache_set_inode_cookie(struct inode *inode,
  161. struct file *filp) {}
  162. static inline void nfs_fscache_reset_inode_cookie(struct inode *inode) {}
  163. static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
  164. {
  165. return 1; /* True: may release page */
  166. }
  167. static inline void nfs_fscache_invalidate_page(struct page *page,
  168. struct inode *inode) {}
  169. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  170. struct page *page) {}
  171. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  172. struct inode *inode,
  173. struct page *page)
  174. {
  175. return -ENOBUFS;
  176. }
  177. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  178. struct inode *inode,
  179. struct address_space *mapping,
  180. struct list_head *pages,
  181. unsigned *nr_pages)
  182. {
  183. return -ENOBUFS;
  184. }
  185. static inline void nfs_readpage_to_fscache(struct inode *inode,
  186. struct page *page, int sync) {}
  187. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  188. {
  189. return "no ";
  190. }
  191. #endif /* CONFIG_NFS_FSCACHE */
  192. #endif /* _NFS_FSCACHE_H */