18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Request reply cache. This was heavily inspired by the
48c2ecf20Sopenharmony_ci * implementation in 4.3BSD/4.4BSD.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef NFSCACHE_H
108c2ecf20Sopenharmony_ci#define NFSCACHE_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/sunrpc/svc.h>
138c2ecf20Sopenharmony_ci#include "netns.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * Representation of a reply cache entry.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * Note that we use a sockaddr_in6 to hold the address instead of the more
198c2ecf20Sopenharmony_ci * typical sockaddr_storage. This is for space reasons, since sockaddr_storage
208c2ecf20Sopenharmony_ci * is much larger than a sockaddr_in6.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_cistruct svc_cacherep {
238c2ecf20Sopenharmony_ci	struct {
248c2ecf20Sopenharmony_ci		/* Keep often-read xid, csum in the same cache line: */
258c2ecf20Sopenharmony_ci		__be32			k_xid;
268c2ecf20Sopenharmony_ci		__wsum			k_csum;
278c2ecf20Sopenharmony_ci		u32			k_proc;
288c2ecf20Sopenharmony_ci		u32			k_prot;
298c2ecf20Sopenharmony_ci		u32			k_vers;
308c2ecf20Sopenharmony_ci		unsigned int		k_len;
318c2ecf20Sopenharmony_ci		struct sockaddr_in6	k_addr;
328c2ecf20Sopenharmony_ci	} c_key;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	struct rb_node		c_node;
358c2ecf20Sopenharmony_ci	struct list_head	c_lru;
368c2ecf20Sopenharmony_ci	unsigned char		c_state,	/* unused, inprog, done */
378c2ecf20Sopenharmony_ci				c_type,		/* status, buffer */
388c2ecf20Sopenharmony_ci				c_secure : 1;	/* req came from port < 1024 */
398c2ecf20Sopenharmony_ci	unsigned long		c_timestamp;
408c2ecf20Sopenharmony_ci	union {
418c2ecf20Sopenharmony_ci		struct kvec	u_vec;
428c2ecf20Sopenharmony_ci		__be32		u_status;
438c2ecf20Sopenharmony_ci	}			c_u;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define c_replvec		c_u.u_vec
478c2ecf20Sopenharmony_ci#define c_replstat		c_u.u_status
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* cache entry states */
508c2ecf20Sopenharmony_cienum {
518c2ecf20Sopenharmony_ci	RC_UNUSED,
528c2ecf20Sopenharmony_ci	RC_INPROG,
538c2ecf20Sopenharmony_ci	RC_DONE
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* return values */
578c2ecf20Sopenharmony_cienum {
588c2ecf20Sopenharmony_ci	RC_DROPIT,
598c2ecf20Sopenharmony_ci	RC_REPLY,
608c2ecf20Sopenharmony_ci	RC_DOIT
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/*
648c2ecf20Sopenharmony_ci * Cache types.
658c2ecf20Sopenharmony_ci * We may want to add more types one day, e.g. for diropres and
668c2ecf20Sopenharmony_ci * attrstat replies. Using cache entries with fixed length instead
678c2ecf20Sopenharmony_ci * of buffer pointers may be more efficient.
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_cienum {
708c2ecf20Sopenharmony_ci	RC_NOCACHE,
718c2ecf20Sopenharmony_ci	RC_REPLSTAT,
728c2ecf20Sopenharmony_ci	RC_REPLBUFF,
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* Cache entries expire after this time period */
768c2ecf20Sopenharmony_ci#define RC_EXPIRE		(120 * HZ)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* Checksum this amount of the request */
798c2ecf20Sopenharmony_ci#define RC_CSUMLEN		(256U)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciint	nfsd_drc_slab_create(void);
828c2ecf20Sopenharmony_civoid	nfsd_drc_slab_free(void);
838c2ecf20Sopenharmony_ciint	nfsd_reply_cache_init(struct nfsd_net *);
848c2ecf20Sopenharmony_civoid	nfsd_reply_cache_shutdown(struct nfsd_net *);
858c2ecf20Sopenharmony_ciint	nfsd_cache_lookup(struct svc_rqst *);
868c2ecf20Sopenharmony_civoid	nfsd_cache_update(struct svc_rqst *, int, __be32 *);
878c2ecf20Sopenharmony_ciint	nfsd_reply_cache_stats_open(struct inode *, struct file *);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#endif /* NFSCACHE_H */
90