fscache.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* NFS filesystem cache interface definitions
  3. *
  4. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #ifndef _NFS_FSCACHE_H
  8. #define _NFS_FSCACHE_H
  9. #include <linux/nfs_fs.h>
  10. #include <linux/nfs_mount.h>
  11. #include <linux/nfs4_mount.h>
  12. #include <linux/fscache.h>
  13. #ifdef CONFIG_NFS_FSCACHE
  14. /*
  15. * set of NFS FS-Cache objects that form a superblock key
  16. */
  17. struct nfs_fscache_key {
  18. struct rb_node node;
  19. struct nfs_client *nfs_client; /* the server */
  20. /* the elements of the unique key - as used by nfs_compare_super() and
  21. * nfs_compare_mount_options() to distinguish superblocks */
  22. struct {
  23. struct {
  24. unsigned long s_flags; /* various flags
  25. * (& NFS_MS_MASK) */
  26. } super;
  27. struct {
  28. struct nfs_fsid fsid;
  29. int flags;
  30. unsigned int rsize; /* read size */
  31. unsigned int wsize; /* write size */
  32. unsigned int acregmin; /* attr cache timeouts */
  33. unsigned int acregmax;
  34. unsigned int acdirmin;
  35. unsigned int acdirmax;
  36. } nfs_server;
  37. struct {
  38. rpc_authflavor_t au_flavor;
  39. } rpc_auth;
  40. /* uniquifier - can be used if nfs_server.flags includes
  41. * NFS_MOUNT_UNSHARED */
  42. u8 uniq_len;
  43. char uniquifier[0];
  44. } key;
  45. };
  46. /*
  47. * Definition of the auxiliary data attached to NFS inode storage objects
  48. * within the cache.
  49. *
  50. * The contents of this struct are recorded in the on-disk local cache in the
  51. * auxiliary data attached to the data storage object backing an inode. This
  52. * permits coherency to be managed when a new inode binds to an already extant
  53. * cache object.
  54. */
  55. struct nfs_fscache_inode_auxdata {
  56. s64 mtime_sec;
  57. s64 mtime_nsec;
  58. s64 ctime_sec;
  59. s64 ctime_nsec;
  60. u64 change_attr;
  61. };
  62. /*
  63. * fscache-index.c
  64. */
  65. extern struct fscache_netfs nfs_fscache_netfs;
  66. extern const struct fscache_cookie_def nfs_fscache_server_index_def;
  67. extern const struct fscache_cookie_def nfs_fscache_super_index_def;
  68. extern const struct fscache_cookie_def nfs_fscache_inode_object_def;
  69. extern int nfs_fscache_register(void);
  70. extern void nfs_fscache_unregister(void);
  71. /*
  72. * fscache.c
  73. */
  74. extern void nfs_fscache_get_client_cookie(struct nfs_client *);
  75. extern void nfs_fscache_release_client_cookie(struct nfs_client *);
  76. extern void nfs_fscache_get_super_cookie(struct super_block *, const char *, int);
  77. extern void nfs_fscache_release_super_cookie(struct super_block *);
  78. extern void nfs_fscache_init_inode(struct inode *);
  79. extern void nfs_fscache_clear_inode(struct inode *);
  80. extern void nfs_fscache_open_file(struct inode *, struct file *);
  81. extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);
  82. extern int nfs_fscache_release_page(struct page *, gfp_t);
  83. extern int __nfs_readpage_from_fscache(struct nfs_open_context *,
  84. struct inode *, struct page *);
  85. extern int __nfs_readpages_from_fscache(struct nfs_open_context *,
  86. struct inode *, struct address_space *,
  87. struct list_head *, unsigned *);
  88. extern void __nfs_readpage_to_fscache(struct inode *, struct page *, int);
  89. /*
  90. * wait for a page to complete writing to the cache
  91. */
  92. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  93. struct page *page)
  94. {
  95. if (PageFsCache(page))
  96. fscache_wait_on_page_write(nfsi->fscache, page);
  97. }
  98. /*
  99. * release the caching state associated with a page if undergoing complete page
  100. * invalidation
  101. */
  102. static inline void nfs_fscache_invalidate_page(struct page *page,
  103. struct inode *inode)
  104. {
  105. if (PageFsCache(page))
  106. __nfs_fscache_invalidate_page(page, inode);
  107. }
  108. /*
  109. * Retrieve a page from an inode data storage object.
  110. */
  111. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  112. struct inode *inode,
  113. struct page *page)
  114. {
  115. if (NFS_I(inode)->fscache)
  116. return __nfs_readpage_from_fscache(ctx, inode, page);
  117. return -ENOBUFS;
  118. }
  119. /*
  120. * Retrieve a set of pages from an inode data storage object.
  121. */
  122. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  123. struct inode *inode,
  124. struct address_space *mapping,
  125. struct list_head *pages,
  126. unsigned *nr_pages)
  127. {
  128. if (NFS_I(inode)->fscache)
  129. return __nfs_readpages_from_fscache(ctx, inode, mapping, pages,
  130. nr_pages);
  131. return -ENOBUFS;
  132. }
  133. /*
  134. * Store a page newly fetched from the server in an inode data storage object
  135. * in the cache.
  136. */
  137. static inline void nfs_readpage_to_fscache(struct inode *inode,
  138. struct page *page,
  139. int sync)
  140. {
  141. if (PageFsCache(page))
  142. __nfs_readpage_to_fscache(inode, page, sync);
  143. }
  144. /*
  145. * Invalidate the contents of fscache for this inode. This will not sleep.
  146. */
  147. static inline void nfs_fscache_invalidate(struct inode *inode)
  148. {
  149. fscache_invalidate(NFS_I(inode)->fscache);
  150. }
  151. /*
  152. * Wait for an object to finish being invalidated.
  153. */
  154. static inline void nfs_fscache_wait_on_invalidate(struct inode *inode)
  155. {
  156. fscache_wait_on_invalidate(NFS_I(inode)->fscache);
  157. }
  158. /*
  159. * indicate the client caching state as readable text
  160. */
  161. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  162. {
  163. if (server->fscache)
  164. return "yes";
  165. return "no ";
  166. }
  167. #else /* CONFIG_NFS_FSCACHE */
  168. static inline int nfs_fscache_register(void) { return 0; }
  169. static inline void nfs_fscache_unregister(void) {}
  170. static inline void nfs_fscache_get_client_cookie(struct nfs_client *clp) {}
  171. static inline void nfs_fscache_release_client_cookie(struct nfs_client *clp) {}
  172. static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
  173. static inline void nfs_fscache_init_inode(struct inode *inode) {}
  174. static inline void nfs_fscache_clear_inode(struct inode *inode) {}
  175. static inline void nfs_fscache_open_file(struct inode *inode,
  176. struct file *filp) {}
  177. static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
  178. {
  179. return 1; /* True: may release page */
  180. }
  181. static inline void nfs_fscache_invalidate_page(struct page *page,
  182. struct inode *inode) {}
  183. static inline void nfs_fscache_wait_on_page_write(struct nfs_inode *nfsi,
  184. struct page *page) {}
  185. static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx,
  186. struct inode *inode,
  187. struct page *page)
  188. {
  189. return -ENOBUFS;
  190. }
  191. static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,
  192. struct inode *inode,
  193. struct address_space *mapping,
  194. struct list_head *pages,
  195. unsigned *nr_pages)
  196. {
  197. return -ENOBUFS;
  198. }
  199. static inline void nfs_readpage_to_fscache(struct inode *inode,
  200. struct page *page, int sync) {}
  201. static inline void nfs_fscache_invalidate(struct inode *inode) {}
  202. static inline void nfs_fscache_wait_on_invalidate(struct inode *inode) {}
  203. static inline const char *nfs_server_fscache_state(struct nfs_server *server)
  204. {
  205. return "no ";
  206. }
  207. #endif /* CONFIG_NFS_FSCACHE */
  208. #endif /* _NFS_FSCACHE_H */