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