xref: /original-bsd/sys/nfs/nqnfs.h (revision 17b51d1b)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)nqnfs.h	7.5 (Berkeley) 09/16/92
11  */
12 
13 /*
14  * Definitions for NQNFS (Not Quite NFS) cache consistency protocol.
15  */
16 
17 /* Tunable constants */
18 #define	NQ_CLOCKSKEW	3	/* Clock skew factor (sec) */
19 #define	NQ_WRITESLACK	5	/* Delay for write cache flushing */
20 #define	NQ_MAXLEASE	60	/* Max lease duration (sec) */
21 #define	NQ_MINLEASE	5	/* Min lease duration (sec) */
22 #define	NQ_DEFLEASE	30	/* Default lease duration (sec) */
23 #define	NQ_RENEWAL	3	/* Time before expiry (sec) to renew */
24 #define	NQ_TRYLATERDEL	15	/* Initial try later delay (sec) */
25 #define	NQ_MAXNUMLEASE	2048	/* Upper bound on number of server leases */
26 #define	NQ_DEADTHRESH	5	/* Default nm_deadthresh */
27 #define	NQ_NEVERDEAD	9	/* Greater than max. nm_timeouts */
28 #define	NQLCHSZ		256	/* Server hash table size */
29 
30 #define	NQNFS_PROG	300105	/* As assigned by Sun */
31 #define	NQNFS_VER1	1
32 #define	NQNFS_EVICTSIZ	156	/* Size of eviction request in bytes */
33 
34 /*
35  * Definitions used for saving the "last lease expires" time in Non-volatile
36  * RAM on the server. The default definitions below assume that NOVRAM is not
37  * available.
38  */
39 #define	NQSTORENOVRAM(t)
40 #define	NQLOADNOVRAM(t)
41 
42 /*
43  * Defn and structs used on the server to maintain state for current leases.
44  * The list of host(s) that hold the lease are kept as nqhost structures.
45  * The first one lives in nqlease and any others are held in a linked
46  * list of nqm structures hanging off of nqlease.
47  *
48  * Each nqlease structure is chained into two lists. The first is a list
49  * ordered by increasing expiry time for nqsrv_timer() and the second is a chain
50  * hashed on lc_fh.
51  */
52 #define	LC_MOREHOSTSIZ	10
53 
54 struct nqhost {
55 	union {
56 		struct {
57 			u_short udp_flag;
58 			u_short	udp_port;
59 			union nethostaddr udp_haddr;
60 		} un_udp;
61 		struct {
62 			u_short connless_flag;
63 			u_short connless_spare;
64 			union nethostaddr connless_haddr;
65 		} un_connless;
66 		struct {
67 			u_short conn_flag;
68 			u_short conn_spare;
69 			struct nfssvc_sock *conn_slp;
70 		} un_conn;
71 	} lph_un;
72 };
73 #define	lph_flag	lph_un.un_udp.udp_flag
74 #define	lph_port	lph_un.un_udp.udp_port
75 #define	lph_haddr	lph_un.un_udp.udp_haddr
76 #define	lph_inetaddr	lph_un.un_udp.udp_haddr.had_inetaddr
77 #define	lph_claddr	lph_un.un_connless.connless_haddr
78 #define	lph_nam		lph_un.un_connless.connless_haddr.had_nam
79 #define	lph_slp		lph_un.un_conn.conn_slp
80 
81 struct nqlease {
82 	struct nqlease *lc_chain1[2];	/* Timer queue list (must be first) */
83 	struct nqlease *lc_fhnext;	/* Fhandle hash list */
84 	struct nqlease **lc_fhprev;
85 	time_t		lc_expiry;	/* Expiry time (sec) */
86 	struct nqhost	lc_host;	/* Host that got lease */
87 	struct nqm	*lc_morehosts;	/* Other hosts that share read lease */
88 	fsid_t		lc_fsid;	/* Fhandle */
89 	char		lc_fiddata[MAXFIDSZ];
90 	struct vnode	*lc_vp;		/* Soft reference to associated vnode */
91 };
92 #define	lc_flag		lc_host.lph_un.un_udp.udp_flag
93 
94 /* lc_flag bits */
95 #define	LC_VALID	0x0001	/* Host address valid */
96 #define	LC_WRITE	0x0002	/* Write cache */
97 #define	LC_NONCACHABLE	0x0004	/* Non-cachable lease */
98 #define	LC_LOCKED	0x0008	/* Locked */
99 #define	LC_WANTED	0x0010	/* Lock wanted */
100 #define	LC_EXPIREDWANTED 0x0020	/* Want lease when expired */
101 #define	LC_UDP		0x0040	/* Host address for udp socket */
102 #define	LC_CLTP		0x0080	/* Host address for other connectionless */
103 #define	LC_LOCAL	0x0100	/* Host is server */
104 #define	LC_VACATED	0x0200	/* Host has vacated lease */
105 #define	LC_WRITTEN	0x0400	/* Recently wrote to the leased file */
106 #define	LC_SREF		0x0800	/* Holds a nfssvc_sock reference */
107 
108 struct nqm {
109 	struct nqm	*lpm_next;
110 	struct nqhost	lpm_hosts[LC_MOREHOSTSIZ];
111 };
112 
113 /*
114  * Flag bits for flags argument to nqsrv_getlease.
115  */
116 #define	NQL_READ	LEASE_READ	/* Read Request */
117 #define	NQL_WRITE	LEASE_WRITE	/* Write Request */
118 #define	NQL_CHECK	0x4		/* Check for lease */
119 #define	NQL_NOVAL	0xffffffff	/* Invalid */
120 
121 /*
122  * Special value for slp for local server calls.
123  */
124 #define	NQLOCALSLP	((struct nfssvc_sock *) -1)
125 
126 /*
127  * Server side macros.
128  */
129 #define	nqsrv_getl(v, l) \
130 		(void) nqsrv_getlease((v), &nfsd->nd_duration, \
131 		 ((nfsd->nd_nqlflag != 0 && nfsd->nd_nqlflag != NQL_NOVAL) ? nfsd->nd_nqlflag : \
132 		 ((l) | NQL_CHECK)), \
133 		 nfsd, nam, &cache, &frev, cred)
134 
135 /*
136  * Client side macros that check for a valid lease.
137  */
138 #define	NQNFS_CKINVALID(v, n, f) \
139  ((time.tv_sec > (n)->n_expiry && \
140  VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \
141   || ((f) == NQL_WRITE && ((n)->n_flag & NQNFSWRITE) == 0))
142 
143 #define	NQNFS_CKCACHABLE(v, f) \
144  ((time.tv_sec <= VTONFS(v)->n_expiry || \
145   VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \
146    && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \
147    ((f) == NQL_READ || (VTONFS(v)->n_flag & NQNFSWRITE)))
148 
149 #define	NQNFS_NEEDLEASE(v, p) \
150 		(time.tv_sec > VTONFS(v)->n_expiry ? \
151 		 ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \
152 		 (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \
153 		   nqnfs_piggy[p]) ? \
154 		   ((VTONFS(v)->n_flag & NQNFSWRITE) ? \
155 		    NQL_WRITE : nqnfs_piggy[p]) : 0))
156 
157 /*
158  * List head for timer queue.
159  */
160 extern union nqsrvthead {
161 	union	nqsrvthead *th_head[2];
162 	struct	nqlease *th_chain[2];
163 } nqthead;
164 extern struct nqlease **nqfhead;
165 extern u_long nqfheadhash;
166 
167 /*
168  * Nqnfs return status numbers.
169  */
170 #define	NQNFS_EXPIRED	500
171 #define	NQNFS_TRYLATER	501
172 #define NQNFS_AUTHERR	502
173