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