xref: /openbmc/linux/fs/nfsd/cache.h (revision b79e3569)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
29a74af21SBoaz Harrosh /*
39a74af21SBoaz Harrosh  * Request reply cache. This was heavily inspired by the
49a74af21SBoaz Harrosh  * implementation in 4.3BSD/4.4BSD.
59a74af21SBoaz Harrosh  *
69a74af21SBoaz Harrosh  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
79a74af21SBoaz Harrosh  */
89a74af21SBoaz Harrosh 
99a74af21SBoaz Harrosh #ifndef NFSCACHE_H
109a74af21SBoaz Harrosh #define NFSCACHE_H
119a74af21SBoaz Harrosh 
129a74af21SBoaz Harrosh #include <linux/sunrpc/svc.h>
133ba75830SJ. Bruce Fields #include "netns.h"
149a74af21SBoaz Harrosh 
159a74af21SBoaz Harrosh /*
169a74af21SBoaz Harrosh  * Representation of a reply cache entry.
177b9e8522SJeff Layton  *
187b9e8522SJeff Layton  * Note that we use a sockaddr_in6 to hold the address instead of the more
197b9e8522SJeff Layton  * typical sockaddr_storage. This is for space reasons, since sockaddr_storage
207b9e8522SJeff Layton  * is much larger than a sockaddr_in6.
219a74af21SBoaz Harrosh  */
22e7421ce7SChuck Lever struct nfsd_cacherep {
23ed00c2f6STrond Myklebust 	struct {
24ed00c2f6STrond Myklebust 		/* Keep often-read xid, csum in the same cache line: */
25ed00c2f6STrond Myklebust 		__be32			k_xid;
26ed00c2f6STrond Myklebust 		__wsum			k_csum;
27ed00c2f6STrond Myklebust 		u32			k_proc;
28ed00c2f6STrond Myklebust 		u32			k_prot;
29ed00c2f6STrond Myklebust 		u32			k_vers;
30ed00c2f6STrond Myklebust 		unsigned int		k_len;
31ed00c2f6STrond Myklebust 		struct sockaddr_in6	k_addr;
32ed00c2f6STrond Myklebust 	} c_key;
339a74af21SBoaz Harrosh 
34736c6625STrond Myklebust 	struct rb_node		c_node;
35ed00c2f6STrond Myklebust 	struct list_head	c_lru;
369a74af21SBoaz Harrosh 	unsigned char		c_state,	/* unused, inprog, done */
379a74af21SBoaz Harrosh 				c_type,		/* status, buffer */
389a74af21SBoaz Harrosh 				c_secure : 1;	/* req came from port < 1024 */
399a74af21SBoaz Harrosh 	unsigned long		c_timestamp;
409a74af21SBoaz Harrosh 	union {
419a74af21SBoaz Harrosh 		struct kvec	u_vec;
429a74af21SBoaz Harrosh 		__be32		u_status;
439a74af21SBoaz Harrosh 	}			c_u;
449a74af21SBoaz Harrosh };
459a74af21SBoaz Harrosh 
469a74af21SBoaz Harrosh #define c_replvec		c_u.u_vec
479a74af21SBoaz Harrosh #define c_replstat		c_u.u_status
489a74af21SBoaz Harrosh 
499a74af21SBoaz Harrosh /* cache entry states */
509a74af21SBoaz Harrosh enum {
519a74af21SBoaz Harrosh 	RC_UNUSED,
529a74af21SBoaz Harrosh 	RC_INPROG,
539a74af21SBoaz Harrosh 	RC_DONE
549a74af21SBoaz Harrosh };
559a74af21SBoaz Harrosh 
569a74af21SBoaz Harrosh /* return values */
579a74af21SBoaz Harrosh enum {
589a74af21SBoaz Harrosh 	RC_DROPIT,
599a74af21SBoaz Harrosh 	RC_REPLY,
6009662d58SJeff Layton 	RC_DOIT
619a74af21SBoaz Harrosh };
629a74af21SBoaz Harrosh 
639a74af21SBoaz Harrosh /*
649a74af21SBoaz Harrosh  * Cache types.
659a74af21SBoaz Harrosh  * We may want to add more types one day, e.g. for diropres and
669a74af21SBoaz Harrosh  * attrstat replies. Using cache entries with fixed length instead
679a74af21SBoaz Harrosh  * of buffer pointers may be more efficient.
689a74af21SBoaz Harrosh  */
699a74af21SBoaz Harrosh enum {
709a74af21SBoaz Harrosh 	RC_NOCACHE,
719a74af21SBoaz Harrosh 	RC_REPLSTAT,
729a74af21SBoaz Harrosh 	RC_REPLBUFF,
739a74af21SBoaz Harrosh };
749a74af21SBoaz Harrosh 
75d1a0774dSJeff Layton /* Cache entries expire after this time period */
76d1a0774dSJeff Layton #define RC_EXPIRE		(120 * HZ)
77d1a0774dSJeff Layton 
7801a7decfSJeff Layton /* Checksum this amount of the request */
7901a7decfSJeff Layton #define RC_CSUMLEN		(256U)
8001a7decfSJeff Layton 
81027690c7SJ. Bruce Fields int	nfsd_drc_slab_create(void);
82027690c7SJ. Bruce Fields void	nfsd_drc_slab_free(void);
83ed9ab734SJeff Layton int	nfsd_net_reply_cache_init(struct nfsd_net *nn);
84ed9ab734SJeff Layton void	nfsd_net_reply_cache_destroy(struct nfsd_net *nn);
853ba75830SJ. Bruce Fields int	nfsd_reply_cache_init(struct nfsd_net *);
863ba75830SJ. Bruce Fields void	nfsd_reply_cache_shutdown(struct nfsd_net *);
87*b79e3569SChuck Lever int	nfsd_cache_lookup(struct svc_rqst *rqstp, unsigned int start,
88*b79e3569SChuck Lever 			  unsigned int len, struct nfsd_cacherep **cacherep);
89e7421ce7SChuck Lever void	nfsd_cache_update(struct svc_rqst *rqstp, struct nfsd_cacherep *rp,
90cb18eca4SChuck Lever 			  int cachetype, __be32 *statp);
9164776611SChenXiaoSong int	nfsd_reply_cache_stats_show(struct seq_file *m, void *v);
929a74af21SBoaz Harrosh 
939a74af21SBoaz Harrosh #endif /* NFSCACHE_H */
94