cache.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Request reply cache. This was heavily inspired by the
  4. * implementation in 4.3BSD/4.4BSD.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #ifndef NFSCACHE_H
  9. #define NFSCACHE_H
  10. #include <linux/sunrpc/svc.h>
  11. /*
  12. * Representation of a reply cache entry.
  13. *
  14. * Note that we use a sockaddr_in6 to hold the address instead of the more
  15. * typical sockaddr_storage. This is for space reasons, since sockaddr_storage
  16. * is much larger than a sockaddr_in6.
  17. */
  18. struct svc_cacherep {
  19. struct list_head c_lru;
  20. unsigned char c_state, /* unused, inprog, done */
  21. c_type, /* status, buffer */
  22. c_secure : 1; /* req came from port < 1024 */
  23. struct sockaddr_in6 c_addr;
  24. __be32 c_xid;
  25. u32 c_prot;
  26. u32 c_proc;
  27. u32 c_vers;
  28. unsigned int c_len;
  29. __wsum c_csum;
  30. unsigned long c_timestamp;
  31. union {
  32. struct kvec u_vec;
  33. __be32 u_status;
  34. } c_u;
  35. };
  36. #define c_replvec c_u.u_vec
  37. #define c_replstat c_u.u_status
  38. /* cache entry states */
  39. enum {
  40. RC_UNUSED,
  41. RC_INPROG,
  42. RC_DONE
  43. };
  44. /* return values */
  45. enum {
  46. RC_DROPIT,
  47. RC_REPLY,
  48. RC_DOIT
  49. };
  50. /*
  51. * Cache types.
  52. * We may want to add more types one day, e.g. for diropres and
  53. * attrstat replies. Using cache entries with fixed length instead
  54. * of buffer pointers may be more efficient.
  55. */
  56. enum {
  57. RC_NOCACHE,
  58. RC_REPLSTAT,
  59. RC_REPLBUFF,
  60. };
  61. /* Cache entries expire after this time period */
  62. #define RC_EXPIRE (120 * HZ)
  63. /* Checksum this amount of the request */
  64. #define RC_CSUMLEN (256U)
  65. int nfsd_reply_cache_init(void);
  66. void nfsd_reply_cache_shutdown(void);
  67. int nfsd_cache_lookup(struct svc_rqst *);
  68. void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
  69. int nfsd_reply_cache_stats_open(struct inode *, struct file *);
  70. #endif /* NFSCACHE_H */