cache.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <[email protected]>
  7. */
  8. #ifndef NFSCACHE_H
  9. #define NFSCACHE_H
  10. #include <linux/sunrpc/svc.h>
  11. #include "netns.h"
  12. /*
  13. * Representation of a reply cache entry.
  14. *
  15. * Note that we use a sockaddr_in6 to hold the address instead of the more
  16. * typical sockaddr_storage. This is for space reasons, since sockaddr_storage
  17. * is much larger than a sockaddr_in6.
  18. */
  19. struct svc_cacherep {
  20. struct {
  21. /* Keep often-read xid, csum in the same cache line: */
  22. __be32 k_xid;
  23. __wsum k_csum;
  24. u32 k_proc;
  25. u32 k_prot;
  26. u32 k_vers;
  27. unsigned int k_len;
  28. struct sockaddr_in6 k_addr;
  29. } c_key;
  30. struct rb_node c_node;
  31. struct list_head c_lru;
  32. unsigned char c_state, /* unused, inprog, done */
  33. c_type, /* status, buffer */
  34. c_secure : 1; /* req came from port < 1024 */
  35. unsigned long c_timestamp;
  36. union {
  37. struct kvec u_vec;
  38. __be32 u_status;
  39. } c_u;
  40. };
  41. #define c_replvec c_u.u_vec
  42. #define c_replstat c_u.u_status
  43. /* cache entry states */
  44. enum {
  45. RC_UNUSED,
  46. RC_INPROG,
  47. RC_DONE
  48. };
  49. /* return values */
  50. enum {
  51. RC_DROPIT,
  52. RC_REPLY,
  53. RC_DOIT
  54. };
  55. /*
  56. * Cache types.
  57. * We may want to add more types one day, e.g. for diropres and
  58. * attrstat replies. Using cache entries with fixed length instead
  59. * of buffer pointers may be more efficient.
  60. */
  61. enum {
  62. RC_NOCACHE,
  63. RC_REPLSTAT,
  64. RC_REPLBUFF,
  65. };
  66. /* Cache entries expire after this time period */
  67. #define RC_EXPIRE (120 * HZ)
  68. /* Checksum this amount of the request */
  69. #define RC_CSUMLEN (256U)
  70. int nfsd_drc_slab_create(void);
  71. void nfsd_drc_slab_free(void);
  72. int nfsd_reply_cache_init(struct nfsd_net *);
  73. void nfsd_reply_cache_shutdown(struct nfsd_net *);
  74. int nfsd_cache_lookup(struct svc_rqst *rqstp, unsigned int start,
  75. unsigned int len);
  76. void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
  77. int nfsd_reply_cache_stats_show(struct seq_file *m, void *v);
  78. #endif /* NFSCACHE_H */