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