cache.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 {
  20. /* Keep often-read xid, csum in the same cache line: */
  21. __be32 k_xid;
  22. __wsum k_csum;
  23. u32 k_proc;
  24. u32 k_prot;
  25. u32 k_vers;
  26. unsigned int k_len;
  27. struct sockaddr_in6 k_addr;
  28. } c_key;
  29. struct rb_node c_node;
  30. struct list_head c_lru;
  31. unsigned char c_state, /* unused, inprog, done */
  32. c_type, /* status, buffer */
  33. c_secure : 1; /* req came from port < 1024 */
  34. unsigned long c_timestamp;
  35. union {
  36. struct kvec u_vec;
  37. __be32 u_status;
  38. } c_u;
  39. };
  40. #define c_replvec c_u.u_vec
  41. #define c_replstat c_u.u_status
  42. /* cache entry states */
  43. enum {
  44. RC_UNUSED,
  45. RC_INPROG,
  46. RC_DONE
  47. };
  48. /* return values */
  49. enum {
  50. RC_DROPIT,
  51. RC_REPLY,
  52. RC_DOIT
  53. };
  54. /*
  55. * Cache types.
  56. * We may want to add more types one day, e.g. for diropres and
  57. * attrstat replies. Using cache entries with fixed length instead
  58. * of buffer pointers may be more efficient.
  59. */
  60. enum {
  61. RC_NOCACHE,
  62. RC_REPLSTAT,
  63. RC_REPLBUFF,
  64. };
  65. /* Cache entries expire after this time period */
  66. #define RC_EXPIRE (120 * HZ)
  67. /* Checksum this amount of the request */
  68. #define RC_CSUMLEN (256U)
  69. int nfsd_reply_cache_init(void);
  70. void nfsd_reply_cache_shutdown(void);
  71. int nfsd_cache_lookup(struct svc_rqst *);
  72. void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
  73. int nfsd_reply_cache_stats_open(struct inode *, struct file *);
  74. #endif /* NFSCACHE_H */