]> git.saurik.com Git - apple/xnu.git/blob - bsd/nfs/nqnfs.h
xnu-517.tar.gz
[apple/xnu.git] / bsd / nfs / nqnfs.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1992, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * This code is derived from software contributed to Berkeley by
31 * Rick Macklem at The University of Guelph.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)nqnfs.h 8.3 (Berkeley) 3/30/95
62 * FreeBSD-Id: nqnfs.h,v 1.14 1997/08/16 19:16:05 wollman Exp $
63 */
64
65
66 #ifndef _NFS_NQNFS_H_
67 #define _NFS_NQNFS_H_
68
69 #include <sys/appleapiopts.h>
70
71 #ifdef __APPLE_API_PRIVATE
72 /*
73 * Definitions for NQNFS (Not Quite NFS) cache consistency protocol.
74 */
75
76 /* Tunable constants */
77 #define NQ_CLOCKSKEW 3 /* Clock skew factor (sec) */
78 #define NQ_WRITESLACK 5 /* Delay for write cache flushing */
79 #define NQ_MAXLEASE 60 /* Max lease duration (sec) */
80 #define NQ_MINLEASE 5 /* Min lease duration (sec) */
81 #define NQ_DEFLEASE 30 /* Default lease duration (sec) */
82 #define NQ_RENEWAL 3 /* Time before expiry (sec) to renew */
83 #define NQ_TRYLATERDEL 15 /* Initial try later delay (sec) */
84 #define NQ_MAXNUMLEASE 2048 /* Upper bound on number of server leases */
85 #define NQ_DEADTHRESH NQ_NEVERDEAD /* Default nm_deadthresh */
86 #define NQ_NEVERDEAD 9 /* Greater than max. nm_timeouts */
87 #define NQLCHSZ 256 /* Server hash table size */
88
89 #define NQNFS_PROG 300105 /* As assigned by Sun */
90 #define NQNFS_VER3 3
91 #define NQNFS_EVICTSIZ 156 /* Size of eviction request in bytes */
92
93 /*
94 * Definitions used for saving the "last lease expires" time in Non-volatile
95 * RAM on the server. The default definitions below assume that NOVRAM is not
96 * available.
97 */
98 #ifdef HASNVRAM
99 # undef HASNVRAM
100 #endif
101 #define NQSTORENOVRAM(t)
102 #define NQLOADNOVRAM(t)
103
104 /*
105 * Defn and structs used on the server to maintain state for current leases.
106 * The list of host(s) that hold the lease are kept as nqhost structures.
107 * The first one lives in nqlease and any others are held in a linked
108 * list of nqm structures hanging off of nqlease.
109 *
110 * Each nqlease structure is chained into two lists. The first is a list
111 * ordered by increasing expiry time for nqsrv_timer() and the second is a chain
112 * hashed on lc_fh.
113 */
114 #define LC_MOREHOSTSIZ 10
115
116 struct nqhost {
117 union {
118 struct {
119 u_short udp_flag;
120 u_short udp_port;
121 union nethostaddr udp_haddr;
122 } un_udp;
123 struct {
124 u_short connless_flag;
125 u_short connless_spare;
126 union nethostaddr connless_haddr;
127 } un_connless;
128 struct {
129 u_short conn_flag;
130 u_short conn_spare;
131 struct nfssvc_sock *conn_slp;
132 } un_conn;
133 } lph_un;
134 };
135 #define lph_flag lph_un.un_udp.udp_flag
136 #define lph_port lph_un.un_udp.udp_port
137 #define lph_haddr lph_un.un_udp.udp_haddr
138 #define lph_inetaddr lph_un.un_udp.udp_haddr.had_inetaddr
139 #define lph_claddr lph_un.un_connless.connless_haddr
140 #define lph_nam lph_un.un_connless.connless_haddr.had_nam
141 #define lph_slp lph_un.un_conn.conn_slp
142
143 struct nqlease {
144 LIST_ENTRY(nqlease) lc_hash; /* Fhandle hash list */
145 CIRCLEQ_ENTRY(nqlease) lc_timer; /* Timer queue list */
146 time_t lc_expiry; /* Expiry time (sec) */
147 struct nqhost lc_host; /* Host that got lease */
148 struct nqm *lc_morehosts; /* Other hosts that share read lease */
149 fsid_t lc_fsid; /* Fhandle */
150 char lc_fiddata[MAXFIDSZ];
151 struct vnode *lc_vp; /* Soft reference to associated vnode */
152 };
153 #define lc_flag lc_host.lph_un.un_udp.udp_flag
154
155 /* lc_flag bits */
156 #define LC_VALID 0x0001 /* Host address valid */
157 #define LC_WRITE 0x0002 /* Write cache */
158 #define LC_NONCACHABLE 0x0004 /* Non-cachable lease */
159 #define LC_LOCKED 0x0008 /* Locked */
160 #define LC_WANTED 0x0010 /* Lock wanted */
161 #define LC_EXPIREDWANTED 0x0020 /* Want lease when expired */
162 #define LC_UDP 0x0040 /* Host address for udp socket */
163 #define LC_CLTP 0x0080 /* Host address for other connectionless */
164 #define LC_LOCAL 0x0100 /* Host is server */
165 #define LC_VACATED 0x0200 /* Host has vacated lease */
166 #define LC_WRITTEN 0x0400 /* Recently wrote to the leased file */
167 #define LC_SREF 0x0800 /* Holds a nfssvc_sock reference */
168
169 struct nqm {
170 struct nqm *lpm_next;
171 struct nqhost lpm_hosts[LC_MOREHOSTSIZ];
172 };
173
174 /*
175 * Special value for slp for local server calls.
176 */
177 #define NQLOCALSLP ((struct nfssvc_sock *) -1)
178
179 /*
180 * Server side macros.
181 */
182 #define nqsrv_getl(v, l) \
183 (void) nqsrv_getlease((v), &nfsd->nd_duration, \
184 ((nfsd->nd_flag & ND_LEASE) ? (nfsd->nd_flag & ND_LEASE) : \
185 ((l) | ND_CHECK)), \
186 slp, procp, nfsd->nd_nam, &cache, &frev, cred)
187
188 /*
189 * Client side macros that check for a valid lease.
190 */
191 #define NQNFS_CKINVALID(v, n, f) \
192 ((time.tv_sec > (n)->n_expiry && \
193 VFSTONFS((v)->v_mount)->nm_timeouts < VFSTONFS((v)->v_mount)->nm_deadthresh) \
194 || ((f) == ND_WRITE && ((n)->n_flag & NQNFSWRITE) == 0))
195
196 #define NQNFS_CKCACHABLE(v, f) \
197 ((time.tv_sec <= VTONFS(v)->n_expiry || \
198 VFSTONFS((v)->v_mount)->nm_timeouts >= VFSTONFS((v)->v_mount)->nm_deadthresh) \
199 && (VTONFS(v)->n_flag & NQNFSNONCACHE) == 0 && \
200 ((f) == ND_READ || (VTONFS(v)->n_flag & NQNFSWRITE)))
201
202 #define NQNFS_NEEDLEASE(v, p) \
203 (time.tv_sec > VTONFS(v)->n_expiry ? \
204 ((VTONFS(v)->n_flag & NQNFSEVICTED) ? 0 : nqnfs_piggy[p]) : \
205 (((time.tv_sec + NQ_RENEWAL) > VTONFS(v)->n_expiry && \
206 nqnfs_piggy[p]) ? \
207 ((VTONFS(v)->n_flag & NQNFSWRITE) ? \
208 ND_WRITE : nqnfs_piggy[p]) : 0))
209
210 /*
211 * List head for timer queue.
212 */
213 extern CIRCLEQ_HEAD(nqtimerhead, nqlease) nqtimerhead;
214
215 /*
216 * List head for the file handle hash table.
217 */
218 #define NQFHHASH(f) \
219 (&nqfhhashtbl[(*((u_long *)(f))) & nqfhhash])
220 extern LIST_HEAD(nqfhhashhead, nqlease) *nqfhhashtbl;
221 extern u_long nqfhhash;
222
223 /*
224 * Nqnfs return status numbers.
225 */
226 #define NQNFS_EXPIRED 500
227 #define NQNFS_TRYLATER 501
228
229 #if defined(KERNEL)
230 void nqnfs_lease_check __P((struct vnode *, struct proc *, struct ucred *, int));
231 void nqnfs_lease_updatetime __P((int));
232 int nqsrv_getlease __P((struct vnode *, u_long *, int,
233 struct nfssvc_sock *, struct proc *,
234 struct mbuf *, int *, u_quad_t *,
235 struct ucred *));
236 int nqnfs_getlease __P((struct vnode *,int,struct ucred *,struct proc *));
237 int nqnfs_callback __P((struct nfsmount *,struct mbuf *,struct mbuf *,caddr_t));
238 int nqnfs_clientd __P((struct nfsmount *,struct ucred *,struct nfsd_cargs *,int,caddr_t,struct proc *));
239 struct nfsnode;
240 void nqnfs_clientlease __P((struct nfsmount *, struct nfsnode *, int, int, time_t, u_quad_t));
241 void nqnfs_serverd __P((void));
242 int nqnfsrv_getlease __P((struct nfsrv_descript *, struct nfssvc_sock *, struct proc *, struct mbuf **));
243 int nqnfsrv_vacated __P((struct nfsrv_descript *, struct nfssvc_sock *, struct proc *, struct mbuf **));
244 #endif
245
246 #endif /* __APPLE_API_PRIVATE */
247 #endif /* _NFS_NQNFS_H_ */