fscache.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. * Definition of the auxiliary data attached to NFS inode storage objects
  52. * within the cache.
  53. *
  54. * The contents of this struct are recorded in the on-disk local cache in the
  55. * auxiliary data attached to the data storage object backing an inode. This
  56. * permits coherency to be managed when a new inode binds to an already extant
  57. * cache object.
  58. */
  59. struct nfs_fscache_inode_auxdata {
  60. s64 mtime_sec;
  61. s64 mtime_nsec;
  62. s64 ctime_sec;
  63. s64 ctime_nsec;
  64. u64 change_attr;
  65. };
  66. /*
  67. * fscache-index.c
  68. */
  69. extern struct fscache_netfs nfs_fscache_netfs;
  70. extern const struct fscache_cookie_def nfs_fscache_server_index_def;
  71. extern const struct fscache_cookie_def nfs_fscache_super_index_def;
  72. extern const struct fscache_cookie_def nfs_fscache_inode_object_def;
  73. extern int nfs_fscache_register(void);
  74. extern void nfs_fscache_unregister(void);
  75. /*
  76. * fscache.c
  77. */
  78. extern void nfs_fscache_get_client_cookie(struct nfs_client *);
  79. extern void nfs_fscache_release_client_cookie(struct nfs_client *);
  80. extern void nfs_fscache_get_super_cookie(struct super_block *, const char *, int);
  81. extern void nfs_fscache_release_super_cookie(struct super_block *);
  82. extern void nfs_fscache_init_inode(struct inode *);
  83. extern void nfs_fscache_clear_inode(struct inode *);
  84. extern void nfs_fscache_open_file(struct inode *, struct file *);
  85. extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);
  86. extern int nfs_fscache_release_page(struct page *, gfp_t);
  87. extern int __nfs_readpage_from_fscache(struct nfs_open_context *,
  88. struct inode *, struct page *);
  89. extern int __nfs_readpages_from_fscache(struct nfs_open_context *,
  90. struct inode *, struct address_space *,
  91. struct list_head *, unsigned *);
  92. extern void __nfs_readpage_to_fscache(struct inode *, struct page *, int);
  93. /*
  94. * wait for a page to complete writing to the cache
  95. */
  96. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  97. struct page *page)
  98. {
  99. if (PageFsCache(page))
  100. fscache_wait_on_page_write(nfsi->fscache, page);
  101. }
  102. /*
  103. * release the caching state associated with a page if undergoing complete page
  104. * invalidation
  105. */
  106. static inline void nfs_fscache_invalidate_page(struct page *page,
  107. struct inode *inode)
  108. {
  109. if (PageFsCache(page))
  110. __nfs_fscache_invalidate_page(page, inode);
  111. }
  112. /*
  113. * Retrieve a page from an inode data storage object.
  114. */
  115. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  116. struct inode *inode,
  117. struct page *page)
  118. {
  119. if (NFS_I(inode)->fscache)
  120. return __nfs_readpage_from_fscache(ctx, inode, page);
  121. return -ENOBUFS;
  122. }
  123. /*
  124. * Retrieve a set of pages from an inode data storage object.
  125. */
  126. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  127. struct inode *inode,
  128. struct address_space *mapping,
  129. struct list_head *pages,
  130. unsigned *nr_pages)
  131. {
  132. if (NFS_I(inode)->fscache)
  133. return __nfs_readpages_from_fscache(ctx, inode, mapping, pages,
  134. nr_pages);
  135. return -ENOBUFS;
  136. }
  137. /*
  138. * Store a page newly fetched from the server in an inode data storage object
  139. * in the cache.
  140. */
  141. static inline void nfs_readpage_to_fscache(struct inode *inode,
  142. struct page *page,
  143. int sync)
  144. {
  145. if (PageFsCache(page))
  146. __nfs_readpage_to_fscache(inode, page, sync);
  147. }
  148. /*
  149. * Invalidate the contents of fscache for this inode. This will not sleep.
  150. */
  151. static inline void nfs_fscache_invalidate(struct inode *inode)
  152. {
  153. fscache_invalidate(NFS_I(inode)->fscache);
  154. }
  155. /*
  156. * Wait for an object to finish being invalidated.
  157. */
  158. static inline void nfs_fscache_wait_on_invalidate(struct inode *inode)
  159. {
  160. fscache_wait_on_invalidate(NFS_I(inode)->fscache);
  161. }
  162. /*
  163. * indicate the client caching state as readable text
  164. */
  165. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  166. {
  167. if (server->fscache)
  168. return "yes";
  169. return "no ";
  170. }
  171. #else /* CONFIG_NFS_FSCACHE */
  172. static inline int nfs_fscache_register(void) { return 0; }
  173. static inline void nfs_fscache_unregister(void) {}
  174. static inline void nfs_fscache_get_client_cookie(struct nfs_client *clp) {}
  175. static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {}
  176. static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
  177. static inline void nfs_fscache_init_inode(struct inode *inode) {}
  178. static inline void nfs_fscache_clear_inode(struct inode *inode) {}
  179. static inline void nfs_fscache_open_file(struct inode *inode,
  180. struct file *filp) {}
  181. static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
  182. {
  183. return 1; /* True: may release page */
  184. }
  185. static inline void nfs_fscache_invalidate_page(struct page *page,
  186. struct inode *inode) {}
  187. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  188. struct page *page) {}
  189. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  190. struct inode *inode,
  191. struct page *page)
  192. {
  193. return -ENOBUFS;
  194. }
  195. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  196. struct inode *inode,
  197. struct address_space *mapping,
  198. struct list_head *pages,
  199. unsigned *nr_pages)
  200. {
  201. return -ENOBUFS;
  202. }
  203. static inline void nfs_readpage_to_fscache(struct inode *inode,
  204. struct page *page, int sync) {}
  205. static inline void nfs_fscache_invalidate(struct inode *inode) {}
  206. static inline void nfs_fscache_wait_on_invalidate(struct inode *inode) {}
  207. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  208. {
  209. return "no ";
  210. }
  211. #endif /* CONFIG_NFS_FSCACHE */
  212. #endif /* _NFS_FSCACHE_H */