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