xref: /freebsd/sys/fs/nfs/nfsrvcache.h (revision eb69d1f144a6fcc765d1b9d44a5ae8082353e70b)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36 
37 #ifndef _NFS_NFSRVCACHE_H_
38 #define	_NFS_NFSRVCACHE_H_
39 
40 /*
41  * Definitions for the server recent request cache
42  */
43 #define	NFSRVCACHE_MAX_SIZE	2048
44 #define	NFSRVCACHE_MIN_SIZE	  64
45 
46 #define	NFSRVCACHE_HASHSIZE	500
47 
48 /* Cache table entry. */
49 struct nfsrvcache {
50 	LIST_ENTRY(nfsrvcache) rc_hash;		/* Hash chain */
51 	LIST_ENTRY(nfsrvcache) rc_ahash;	/* ACK hash chain */
52 	TAILQ_ENTRY(nfsrvcache)	rc_lru;		/* UDP lru chain */
53 	u_int32_t	rc_xid;			/* rpc id number */
54 	time_t		rc_timestamp;		/* Time done */
55 	union {
56 		mbuf_t repmb;			/* Reply mbuf list OR */
57 		int repstat;			/* Reply status */
58 	} rc_un;
59 	union {
60 		struct {
61 			union nethostaddr haddr; /* Host address */
62 		} udp;
63 		struct {
64 			u_int64_t	sockref;
65 			u_int32_t	len;
66 			u_int32_t	tcpseq;
67 			int16_t		refcnt;
68 			u_int16_t	cksum;
69 			time_t		cachetime;
70 			int		acked;
71 		} ot;
72 	} rc_un2;
73 	u_int16_t	rc_proc;		/* rpc proc number */
74 	u_int16_t	rc_flag;		/* Flag bits */
75 };
76 
77 #define	rc_reply	rc_un.repmb
78 #define	rc_status	rc_un.repstat
79 #define	rc_inet		rc_un2.udp.haddr.had_inet.s_addr
80 #define	rc_inet6	rc_un2.udp.haddr.had_inet6
81 #define	rc_haddr	rc_un2.udp.haddr
82 #define	rc_sockref	rc_un2.ot.sockref
83 #define	rc_tcpseq	rc_un2.ot.tcpseq
84 #define	rc_refcnt	rc_un2.ot.refcnt
85 #define	rc_reqlen	rc_un2.ot.len
86 #define	rc_cksum	rc_un2.ot.cksum
87 #define	rc_cachetime	rc_un2.ot.cachetime
88 #define	rc_acked	rc_un2.ot.acked
89 
90 /* TCP ACK values */
91 #define	RC_NO_SEQ		0
92 #define	RC_NO_ACK		1
93 #define	RC_ACK			2
94 #define	RC_NACK			3
95 
96 /* Return values */
97 #define	RC_DROPIT		0
98 #define	RC_REPLY		1
99 #define	RC_DOIT			2
100 
101 /* Flag bits */
102 #define	RC_LOCKED	0x0001
103 #define	RC_WANTED	0x0002
104 #define	RC_REPSTATUS	0x0004
105 #define	RC_REPMBUF	0x0008
106 #define	RC_UDP		0x0010
107 #define	RC_INETIPV6	0x0020
108 #define	RC_INPROG	0x0040
109 #define	RC_NFSV2	0x0100
110 #define	RC_NFSV3	0x0200
111 #define	RC_NFSV4	0x0400
112 #define	RC_NFSVERS	(RC_NFSV2 | RC_NFSV3 | RC_NFSV4)
113 #define	RC_REFCNT	0x0800
114 #define	RC_SAMETCPCONN	0x1000
115 
116 LIST_HEAD(nfsrvhashhead, nfsrvcache);
117 
118 /* The fine-grained locked cache hash table for TCP. */
119 struct nfsrchash_bucket {
120 	struct mtx		mtx;
121 	struct nfsrvhashhead	tbl;
122 };
123 
124 #endif	/* _NFS_NFSRVCACHE_H_ */
125