]> git.saurik.com Git - apple/xnu.git/blob - bsd/nfs/nfs.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / nfs / nfs.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23 /*
24 * Copyright (c) 1989, 1993, 1995
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 * @(#)nfs.h 8.4 (Berkeley) 5/1/95
59 * FreeBSD-Id: nfs.h,v 1.32 1997/10/12 20:25:38 phk Exp $
60 */
61
62 #ifndef _NFS_NFS_H_
63 #define _NFS_NFS_H_
64
65 #include <sys/appleapiopts.h>
66
67 #ifdef __APPLE_API_PRIVATE
68 /*
69 * Tunable constants for nfs
70 */
71
72 #define NFS_MAXIOVEC 34
73 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
74 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
75 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
76 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
77 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
78 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
79 #define NFS_MAXREXMIT 100 /* Stop counting after this many */
80 #define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
81 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */
82 #define NFS_MAXGRPS 16 /* Max. size of groups list */
83 #ifndef NFS_MINATTRTIMO
84 #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */
85 #endif
86 #ifndef NFS_MAXATTRTIMO
87 #define NFS_MAXATTRTIMO 60
88 #endif
89 #define NFS_WSIZE 16384 /* Def. write data size <= 16K */
90 #define NFS_RSIZE 16384 /* Def. read data size <= 16K */
91 #define NFS_DGRAM_WSIZE 8192 /* UDP Def. write data size <= 8K */
92 #define NFS_DGRAM_RSIZE 8192 /* UDP Def. read data size <= 8K */
93 #define NFS_READDIRSIZE 8192 /* Def. readdir size */
94 #define NFS_DEFRAHEAD 4 /* Def. read ahead # blocks */
95 #define NFS_MAXRAHEAD 16 /* Max. read ahead # blocks */
96 #define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
97 #define NFS_MAXASYNCDAEMON 32 /* Max. number async_daemons runnable */
98 #define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
99 #ifndef NFS_GATHERDELAY
100 #define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
101 #endif
102 #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
103 #if defined(KERNEL) && !defined(DIRBLKSIZ)
104 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
105 /* can't be larger than NFS_FABLKSIZE */
106 #endif
107
108 /*
109 * Oddballs
110 */
111 #define NMOD(a) ((a) % nfs_asyncdaemons)
112 #define NFS_CMPFH(n, f, s) \
113 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
114 #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
115 #define NFS_SRVMAXDATA(n) \
116 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
117 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
118
119 /*
120 * XXX
121 * The NB_INVAFTERWRITE flag should be set to whatever is required by the
122 * buffer cache code to say "Invalidate the block after it is written back".
123 */
124 #ifdef __FreeBSD__
125 #define NB_INVAFTERWRITE NB_NOCACHE
126 #else
127 #define NB_INVAFTERWRITE NB_INVAL
128 #endif
129
130 /*
131 * The IO_METASYNC flag should be implemented for local file systems.
132 * (Until then, it is nothin at all.)
133 */
134 #ifndef IO_METASYNC
135 #define IO_METASYNC 0
136 #endif
137
138 /*
139 * Expected allocation sizes for major data structures. If the actual size
140 * of the structure exceeds these sizes, then malloc() will be allocating
141 * almost twice the memory required. This is used in nfs_init() to warn
142 * the sysadmin that the size of a structure should be reduced.
143 * (These sizes are always a power of 2. If the kernel malloc() changes
144 * to one that does not allocate space in powers of 2 size, then this all
145 * becomes bunk!).
146 * Note that some of these structures come out of there own nfs zones.
147 */
148 #define NFS_NODEALLOC 512
149 #define NFS_MNTALLOC 512
150 #define NFS_SVCALLOC 256
151 #define NFS_UIDALLOC 128
152
153 /*
154 * Arguments to mount NFS
155 */
156 #define NFS_ARGSVERSION 3 /* change when nfs_args changes */
157 struct nfs_args {
158 int version; /* args structure version number */
159 struct sockaddr *addr; /* file server address */
160 int addrlen; /* length of address */
161 int sotype; /* Socket type */
162 int proto; /* and Protocol */
163 u_char *fh; /* File handle to be mounted */
164 int fhsize; /* Size, in bytes, of fh */
165 int flags; /* flags */
166 int wsize; /* write size in bytes */
167 int rsize; /* read size in bytes */
168 int readdirsize; /* readdir size in bytes */
169 int timeo; /* initial timeout in .1 secs */
170 int retrans; /* times to retry send */
171 int maxgrouplist; /* Max. size of group list */
172 int readahead; /* # of blocks to readahead */
173 int leaseterm; /* Term (sec) of lease */
174 int deadthresh; /* Retrans threshold */
175 char *hostname; /* server's name */
176 };
177
178 /*
179 * NFS mount option flags
180 */
181 #define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
182 #define NFSMNT_WSIZE 0x00000002 /* set write size */
183 #define NFSMNT_RSIZE 0x00000004 /* set read size */
184 #define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
185 #define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
186 #define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
187 #define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
188 #define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
189 #define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
190 #define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
191 #define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
192 #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
193 #define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
194 #define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
195 #define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
196 #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
197 #define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
198 #define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
199 #define NFSMNT_NOLOCKS 0x00040000 /* don't support file locking */
200
201 #define NFSSTA_LOCKTIMEO 0x00002000 /* experienced a lock req timeout */
202 #define NFSSTA_MOUNTED 0x00004000 /* completely mounted */
203 #define NFSSTA_LOCKSWORK 0x00008000 /* lock ops have worked. */
204 #define NFSSTA_TIMEO 0x00010000 /* experienced a timeout. */
205 #define NFSSTA_FORCE 0x00020000 /* doing a forced unmount. */
206 #define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
207 #define NFSSTA_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
208 #define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
209 #define NFSSTA_MNTD 0x00200000 /* Mnt server for mnt point */
210 #define NFSSTA_DISMINPROG 0x00400000 /* Dismount in progress */
211 #define NFSSTA_DISMNT 0x00800000 /* Dismounted */
212 #define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */
213 #define NFSSTA_WANTSND 0x02000000 /* Want above */
214 #define NFSSTA_RCVLOCK 0x04000000 /* Rcv socket lock */
215 #define NFSSTA_WANTRCV 0x08000000 /* Want above */
216 #define NFSSTA_WAITAUTH 0x10000000 /* Wait for authentication */
217 #define NFSSTA_HASAUTH 0x20000000 /* Has authenticator */
218 #define NFSSTA_WANTAUTH 0x40000000 /* Wants an authenticator */
219 #define NFSSTA_AUTHERR 0x80000000 /* Authentication error */
220
221 /*
222 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
223 * should ever try and use it.
224 */
225 struct nfsd_args {
226 int sock; /* Socket to serve */
227 caddr_t name; /* Client addr for connection based sockets */
228 int namelen; /* Length of name */
229 };
230
231 struct nfsd_srvargs {
232 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */
233 uid_t nsd_uid; /* Effective uid mapped to cred */
234 u_long nsd_haddr; /* Ip address of client */
235 struct ucred nsd_cr; /* Cred. uid maps to */
236 int nsd_authlen; /* Length of auth string (ret) */
237 u_char *nsd_authstr; /* Auth string (ret) */
238 int nsd_verflen; /* and the verfier */
239 u_char *nsd_verfstr;
240 struct timeval nsd_timestamp; /* timestamp from verifier */
241 u_long nsd_ttl; /* credential ttl (sec) */
242 NFSKERBKEY_T nsd_key; /* Session key */
243 };
244
245 struct nfsd_cargs {
246 char *ncd_dirp; /* Mount dir path */
247 uid_t ncd_authuid; /* Effective uid */
248 int ncd_authtype; /* Type of authenticator */
249 int ncd_authlen; /* Length of authenticator string */
250 u_char *ncd_authstr; /* Authenticator string */
251 int ncd_verflen; /* and the verifier */
252 u_char *ncd_verfstr;
253 NFSKERBKEY_T ncd_key; /* Session key */
254 };
255
256 /*
257 * XXX to allow amd to include nfs.h without nfsproto.h
258 */
259 #ifdef NFS_NPROCS
260 /*
261 * Stats structure
262 */
263 struct nfsstats {
264 int attrcache_hits;
265 int attrcache_misses;
266 int lookupcache_hits;
267 int lookupcache_misses;
268 int direofcache_hits;
269 int direofcache_misses;
270 int biocache_reads;
271 int read_bios;
272 int read_physios;
273 int biocache_writes;
274 int write_bios;
275 int write_physios;
276 int biocache_readlinks;
277 int readlink_bios;
278 int biocache_readdirs;
279 int readdir_bios;
280 int rpccnt[NFS_NPROCS];
281 int rpcretries;
282 int srvrpccnt[NFS_NPROCS];
283 int srvrpc_errs;
284 int srv_errs;
285 int rpcrequests;
286 int rpctimeouts;
287 int rpcunexpected;
288 int rpcinvalid;
289 int srvcache_inproghits;
290 int srvcache_idemdonehits;
291 int srvcache_nonidemdonehits;
292 int srvcache_misses;
293 int srvnqnfs_leases;
294 int srvnqnfs_maxleases;
295 int srvnqnfs_getleases;
296 int srvvop_writes;
297 int pageins;
298 int pageouts;
299 };
300 #endif
301
302 /*
303 * Flags for nfssvc() system call.
304 */
305 #define NFSSVC_BIOD 0x002
306 #define NFSSVC_NFSD 0x004
307 #define NFSSVC_ADDSOCK 0x008
308 #define NFSSVC_AUTHIN 0x010
309 #define NFSSVC_GOTAUTH 0x040
310 #define NFSSVC_AUTHINFAIL 0x080
311 #define NFSSVC_MNTD 0x100
312
313 /*
314 * Flags for nfsclnt() system call.
315 */
316 #define NFSCLNT_LOCKDANS 0x200
317 #define NFSCLNT_LOCKDFD 0x400
318 #define NFSCLNT_LOCKDWAIT 0x800
319
320 /*
321 * fs.nfs sysctl(3) identifiers
322 */
323 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */
324 #define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
325
326 #define FS_NFS_NAMES { \
327 { 0, 0 }, \
328 { "nfsstats", CTLTYPE_STRUCT }, \
329 { "nfsprivport", CTLTYPE_INT }, \
330 }
331
332 #ifndef NFS_MUIDHASHSIZ
333 #define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
334 #endif
335 #ifndef NFS_WDELAYHASHSIZ
336 #define NFS_WDELAYHASHSIZ 16 /* and with this */
337 #endif
338
339 /*
340 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
341 * What should be in this set is open to debate, but I believe that since
342 * I/O system calls on ufs are never interrupted by signals the set should
343 * be minimal. My reasoning is that many current programs that use signals
344 * such as SIGALRM will not expect file I/O system calls to be interrupted
345 * by them and break.
346 */
347 #ifdef KERNEL
348
349 #ifdef MALLOC_DECLARE
350 MALLOC_DECLARE(M_NFSREQ);
351 MALLOC_DECLARE(M_NFSMNT);
352 MALLOC_DECLARE(M_NFSDIROFF);
353 MALLOC_DECLARE(M_NFSRVDESC);
354 MALLOC_DECLARE(M_NFSUID);
355 MALLOC_DECLARE(M_NQLEASE);
356 MALLOC_DECLARE(M_NFSD);
357 MALLOC_DECLARE(M_NFSBIGFH);
358 #endif
359
360 struct uio; struct vattr; struct nameidata; /* XXX */
361 struct nfsbuf;
362
363 #define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
364 sigmask(SIGHUP)|sigmask(SIGQUIT))
365
366 /*
367 * Socket errors ignored for connectionless sockets??
368 * For now, ignore them all
369 */
370 #define NFSIGNORE_SOERROR(s, e) \
371 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
372 (e) != EIO && ((s) & PR_CONNREQUIRED) == 0)
373
374 /*
375 * Nfs outstanding request list element
376 */
377 struct nfsreq {
378 TAILQ_ENTRY(nfsreq) r_chain;
379 struct mbuf *r_mreq;
380 struct mbuf *r_mrep;
381 struct mbuf *r_md;
382 caddr_t r_dpos;
383 struct nfsmount *r_nmp;
384 struct vnode *r_vp;
385 u_long r_xid;
386 int r_flags; /* flags on request, see below */
387 int r_retry; /* max retransmission count */
388 int r_rexmit; /* current retrans count */
389 int r_timer; /* tick counter on reply */
390 u_int32_t r_procnum; /* NFS procedure number */
391 int r_rtt; /* RTT for rpc */
392 struct proc *r_procp; /* Proc that did I/O system call */
393 long r_lastmsg; /* time of last tprintf */
394 };
395
396 /*
397 * Queue head for nfsreq's
398 */
399 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
400
401 /* Flag values for r_flags */
402 #define R_TIMING 0x0001 /* timing request (in mntp) */
403 #define R_SENT 0x0002 /* request has been sent */
404 #define R_SOFTTERM 0x0004 /* soft mnt, too many retries */
405 #define R_INTR 0x0008 /* intr mnt, signal pending */
406 #define R_SOCKERR 0x0010 /* Fatal error on socket */
407 #define R_TPRINTFMSG 0x0020 /* Did a tprintf msg. */
408 #define R_MUSTRESEND 0x0040 /* Must resend request */
409 #define R_GETONEREP 0x0080 /* Probe for one reply only */
410 #define R_BUSY 0x0100 /* Locked. */
411 #define R_WAITING 0x0200 /* Someone waiting for lock. */
412 #define R_RESENDERR 0x0400 /* resend failed. */
413
414 /*
415 * A list of nfssvc_sock structures is maintained with all the sockets
416 * that require service by the nfsd.
417 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
418 * and uid hash lists.
419 */
420 #ifndef NFS_UIDHASHSIZ
421 #define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */
422 #endif
423 #define NUIDHASH(sock, uid) \
424 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
425 #define NWDELAYHASH(sock, f) \
426 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
427 #define NMUIDHASH(nmp, uid) \
428 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
429 #define NFSNOHASH(fhsum) \
430 (&nfsnodehashtbl[(fhsum) & nfsnodehash])
431
432 /*
433 * Network address hash list element
434 */
435 union nethostaddr {
436 u_long had_inetaddr;
437 struct mbuf *had_nam;
438 };
439
440 struct nfsuid {
441 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
442 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
443 int nu_flag; /* Flags */
444 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
445 struct ucred nu_cr; /* Cred uid mapped to */
446 int nu_expire; /* Expiry time (sec) */
447 struct timeval nu_timestamp; /* Kerb. timestamp */
448 u_long nu_nickname; /* Nickname on server */
449 NFSKERBKEY_T nu_key; /* and session key */
450 };
451
452 #define nu_inetaddr nu_haddr.had_inetaddr
453 #define nu_nam nu_haddr.had_nam
454 /* Bits for nu_flag */
455 #define NU_INETADDR 0x1
456 #define NU_NAM 0x2
457 #define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
458
459 #ifdef notyet
460 /* XXX CSM 12/2/97 When/if we merge queue.h */
461 struct nfsrv_rec {
462 STAILQ_ENTRY(nfsrv_rec) nr_link;
463 struct sockaddr *nr_address;
464 struct mbuf *nr_packet;
465 };
466 #endif
467
468 struct nfssvc_sock {
469 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
470 TAILQ_HEAD(, nfsuid) ns_uidlruhead;
471 struct file *ns_fp;
472 struct socket *ns_so;
473 struct mbuf *ns_nam;
474 struct mbuf *ns_raw;
475 struct mbuf *ns_rawend;
476 struct mbuf *ns_rec;
477 struct mbuf *ns_recend;
478 struct mbuf *ns_frag;
479 short ns_flag; /* modified under kernel funnel */
480 short ns_nflag; /* modified under network funnel */
481 int ns_solock;
482 int ns_cc;
483 int ns_reclen;
484 int ns_numuids;
485 u_long ns_sref;
486 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */
487 LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
488 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
489 };
490
491 /* Bits for "ns_*flag" */
492 #define SLP_VALID 0x01 /* ns_flag */
493 #define SLP_DOREC 0x02 /* ns_flag */
494 #define SLPN_NEEDQ 0x04 /* ns_nflag */
495 #define SLPN_DISCONN 0x08 /* ns_nflag */
496 #define SLPN_GETSTREAM 0x10 /* ns_nflag */
497 #define SLPN_LASTFRAG 0x20 /* ns_nflag */
498 #define SLP_ALLFLAGS 0xff /* ns_flag && ns_nflag */
499
500 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
501 extern int nfssvc_sockhead_flag;
502 #define SLP_INIT 0x01
503 #define SLP_WANTINIT 0x02
504
505 /*
506 * One of these structures is allocated for each nfsd.
507 */
508 struct nfsd {
509 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */
510 int nfsd_flag; /* NFSD_ flags */
511 struct nfssvc_sock *nfsd_slp; /* Current socket */
512 int nfsd_authlen; /* Authenticator len */
513 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
514 int nfsd_verflen; /* and the Verifier */
515 u_char nfsd_verfstr[RPCVERF_MAXSIZ];
516 struct proc *nfsd_procp; /* Proc ptr */
517 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
518 };
519
520 /* Bits for "nfsd_flag" */
521 #define NFSD_WAITING 0x01
522 #define NFSD_REQINPROG 0x02
523 #define NFSD_NEEDAUTH 0x04
524 #define NFSD_AUTHFAIL 0x08
525
526 /*
527 * This structure is used by the server for describing each request.
528 * Some fields are used only when write request gathering is performed.
529 */
530 struct nfsrv_descript {
531 u_quad_t nd_time; /* Write deadline (usec) */
532 off_t nd_off; /* Start byte offset */
533 off_t nd_eoff; /* and end byte offset */
534 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
535 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
536 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
537 struct mbuf *nd_mrep; /* Request mbuf list */
538 struct mbuf *nd_md; /* Current dissect mbuf */
539 struct mbuf *nd_mreq; /* Reply mbuf list */
540 struct mbuf *nd_nam; /* and socket addr */
541 struct mbuf *nd_nam2; /* return socket addr */
542 caddr_t nd_dpos; /* Current dissect pos */
543 u_int32_t nd_procnum; /* RPC # */
544 int nd_stable; /* storage type */
545 int nd_flag; /* nd_flag */
546 int nd_len; /* Length of this write */
547 int nd_repstat; /* Reply status */
548 u_long nd_retxid; /* Reply xid */
549 u_long nd_duration; /* Lease duration */
550 struct timeval nd_starttime; /* Time RPC initiated */
551 fhandle_t nd_fh; /* File handle */
552 struct ucred nd_cr; /* Credentials */
553 };
554
555 /* Bits for "nd_flag" */
556 #define ND_READ LEASE_READ
557 #define ND_WRITE LEASE_WRITE
558 #define ND_CHECK 0x04
559 #define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK)
560 #define ND_NFSV3 0x08
561 #define ND_NQNFS 0x10
562 #define ND_KERBNICK 0x20
563 #define ND_KERBFULL 0x40
564 #define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
565
566 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
567 extern int nfsd_head_flag;
568 #define NFSD_CHECKSLP 0x01
569
570 /*
571 * These macros compare nfsrv_descript structures.
572 */
573 #define NFSW_CONTIG(o, n) \
574 ((o)->nd_eoff >= (n)->nd_off && \
575 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
576
577 #define NFSW_SAMECRED(o, n) \
578 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
579 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
580 sizeof (struct ucred)))
581
582 /*
583 * Defines for WebNFS
584 */
585
586 #define WEBNFS_ESC_CHAR '%'
587 #define WEBNFS_SPECCHAR_START 0x80
588
589 #define WEBNFS_NATIVE_CHAR 0x80
590 /*
591 * ..
592 * Possibly more here in the future.
593 */
594
595 /*
596 * Macro for converting escape characters in WebNFS pathnames.
597 * Should really be in libkern.
598 */
599
600 #define HEXTOC(c) \
601 ((c) >= 'a' ? ((c) - ('a' - 10)) : \
602 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
603 #define HEXSTRTOI(p) \
604 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
605
606 #define NFSDIAG 0
607 #if NFSDIAG
608
609 extern int nfs_debug;
610 #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */
611 #define NFS_DEBUG_WG 2 /* server write gathering */
612 #define NFS_DEBUG_RC 4 /* server request caching */
613 #define NFS_DEBUG_SILLY 8 /* nfs_sillyrename (.nfsXXX aka turd files) */
614 #define NFS_DEBUG_DUP 16 /* debug duplicate requests */
615 #define NFS_DEBUG_ATTR 32
616
617 #define NFS_DPF(cat, args) \
618 do { \
619 if (nfs_debug & NFS_DEBUG_##cat) kprintf args; \
620 } while (0)
621
622 #else
623
624 #define NFS_DPF(cat, args)
625
626 #endif /* NFSDIAG */
627
628 int nfs_init __P((struct vfsconf *vfsp));
629 int nfs_reply __P((struct nfsreq *));
630 int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
631 int nfs_send __P((struct socket *, struct mbuf *, struct mbuf *,
632 struct nfsreq *));
633 int nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
634 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
635 caddr_t *));
636 int nfs_sndlock __P((struct nfsreq *));
637 void nfs_sndunlock __P((struct nfsreq *));
638 int nfs_slplock __P((struct nfssvc_sock *, int));
639 void nfs_slpunlock __P((struct nfssvc_sock *));
640 int nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
641 int nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *,
642 int));
643 int nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
644 int nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
645 int *));
646 int nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
647 int nfs_asyncio __P((struct nfsbuf *, struct ucred *));
648 int nfs_doio __P((struct nfsbuf *, struct ucred *, struct proc *));
649 int nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
650 int nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
651 int nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
652 int nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
653 void nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
654 struct nfs_fattr *));
655 void nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
656 struct vattr *, struct mbuf **, char **));
657 void nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
658 struct mbuf **, char **));
659 int netaddr_match __P((int, union nethostaddr *, struct mbuf *));
660 int nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *,
661 struct ucred *, struct mbuf **, struct mbuf **,
662 caddr_t *, u_int64_t *));
663 int nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
664 struct vattr *, int, u_int64_t *));
665 int nfs_namei __P((struct nameidata *, fhandle_t *, int,
666 struct nfssvc_sock *, struct mbuf *, struct mbuf **,
667 caddr_t *, struct vnode **, struct proc *, int, int));
668 void nfsm_adj __P((struct mbuf *, int, int));
669 int nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
670 void nfsrv_initcache __P((void));
671 int nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
672 char **, int *, char *, int *, NFSKERBKEY_T));
673 int nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
674 int *, char *, int));
675 int nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
676 NFSKERBKEY_T, struct mbuf **, char **,
677 struct mbuf *));
678 int nfs_adv __P((struct mbuf **, caddr_t *, int, int));
679 void nfs_nhinit __P((void));
680 void nfs_timer __P((void*));
681 u_long nfs_hash __P((nfsfh_t *, int));
682 int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
683 struct nfsrv_descript **));
684 int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
685 struct mbuf **));
686 void nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
687 void nfsrv_cleancache __P((void));
688 int nfs_bind_resv_thread_wake __P((void));
689 int nfs_connect __P((struct nfsmount *, struct nfsreq *));
690 void nfs_disconnect __P((struct nfsmount *));
691 int nfs_getattrcache __P((struct vnode *, struct vattr *));
692 int nfsm_strtmbuf __P((struct mbuf **, char **, char *, long));
693 int nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *,
694 int));
695 int nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
696 void nfsrv_init __P((int));
697 int nfs_commit __P((struct vnode *vp, u_quad_t offset, int cnt,
698 struct ucred *cred, struct proc *procp));
699 int nfs_flushcommits(struct vnode *, struct proc *);
700 void nfs_clearcommit __P((struct mount *));
701 int nfsrv_errmap __P((struct nfsrv_descript *, int));
702 void nfsrvw_sort __P((gid_t *, int));
703 void nfsrv_setcred __P((struct ucred *, struct ucred *));
704 int nfs_buf_write __P((struct nfsbuf *));
705 int nfsrv_object_create __P((struct vnode *));
706 void nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
707 int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
708 struct proc *, struct mbuf **));
709 int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
710 struct proc *p));
711
712 int nfsrv3_access __P((struct nfsrv_descript *nfsd,
713 struct nfssvc_sock *slp,
714 struct proc *procp, struct mbuf **mrq));
715 int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
716 struct proc *procp, struct mbuf **mrq));
717 int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
718 struct proc *procp, struct mbuf **mrq));
719 int nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
720 struct nfssvc_sock *, struct mbuf *, int *,
721 int, int));
722 int nfsrv_setpublicfs __P((struct mount *, struct netexport *,
723 struct export_args *));
724 int nfs_ispublicfh __P((fhandle_t *));
725 int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
726 struct proc *procp, struct mbuf **mrq));
727 int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
728 struct proc *procp, struct mbuf **mrq));
729 int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
730 struct proc *procp, struct mbuf **mrq));
731 int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
732 struct proc *procp, struct mbuf **mrq));
733 int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
734 struct proc *procp, struct mbuf **mrq));
735 int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
736 struct proc *procp, struct mbuf **mrq));
737 int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
738 struct proc *procp, struct mbuf **mrq));
739 int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
740 struct proc *procp, struct mbuf **mrq));
741 int nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
742 struct nfssvc_sock *slp, struct proc *procp,
743 struct mbuf **mrq));
744 int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
745 struct proc *procp, struct mbuf **mrq));
746 int nfsrv_readdir __P((struct nfsrv_descript *nfsd,
747 struct nfssvc_sock *slp,
748 struct proc *procp, struct mbuf **mrq));
749 int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
750 struct nfssvc_sock *slp, struct proc *procp,
751 struct mbuf **mrq));
752 int nfsrv_readlink __P((struct nfsrv_descript *nfsd,
753 struct nfssvc_sock *slp, struct proc *procp,
754 struct mbuf **mrq));
755 int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
756 struct proc *procp, struct mbuf **mrq));
757 int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
758 struct proc *procp, struct mbuf **mrq));
759 int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
760 struct proc *procp, struct mbuf **mrq));
761 int nfsrv_setattr __P((struct nfsrv_descript *nfsd,
762 struct nfssvc_sock *slp,
763 struct proc *procp, struct mbuf **mrq));
764 int nfsrv_statfs __P((struct nfsrv_descript *nfsd,
765 struct nfssvc_sock *slp,
766 struct proc *procp, struct mbuf **mrq));
767 int nfsrv_symlink __P((struct nfsrv_descript *nfsd,
768 struct nfssvc_sock *slp,
769 struct proc *procp, struct mbuf **mrq));
770 int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
771 struct proc *procp, struct mbuf **mrq));
772 void nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
773 void nfsrv_slpderef __P((struct nfssvc_sock *slp));
774
775 void nfs_up(struct nfsreq *, struct nfsmount *, struct proc *,
776 const char *, int);
777 void nfs_down(struct nfsreq *, struct nfsmount *, struct proc *,
778 const char *, int, int);
779
780 /*
781 * NFSTRACE points were changed to FSDBG (KERNEL_DEBUG)
782 * But some of this code may prove useful someday...
783 */
784 #undef NFSDIAG
785 #if NFSDIAG
786
787 extern int nfstraceindx;
788 #define NFSTBUFSIZ 8912
789 struct nfstracerec { uint i1, i2, i3, i4; };
790 extern struct nfstracerec nfstracebuf[NFSTBUFSIZ];
791 extern uint nfstracemask; /* 32 bits - trace points over 31 are unconditional */
792
793 /* 0x0000000f nfs_getattrcache trace points */
794 #define NFSTRC_GAC_MISS 0x00 /* 0x00000001 cache miss */
795 #define NFSTRC_GAC_HIT 0x01 /* 0x00000002 cache hit */
796 #define NFSTRC_GAC_NP 0x02 /* 0x00000004 np size mismatch - vp... */
797 /* 0x00000038 nfs_loadattrcache trace points */
798 #define NFSTRC_LAC 0x03 /* 0x00000008 function entry point - vp */
799 #define NFSTRC_LAC_INIT 0x04 /* 0x00000010 new vp & init n_mtime - vp */
800 #define NFSTRC_LAC_NP 0x05 /* 0x00000020 np size mismatch - vp... */
801 /* 0x000000c0 nfs_getattr trace points */
802 #define NFSTRC_GA_INV 0x06 /* 0x00000040 times mismatch - vp */
803 #define NFSTRC_GA_INV1 0x07 /* 0x00000080 invalidate ok - vp */
804 /* 0x00000100 vmp_invalidate trace points */
805 #define NFSTRC_VMP_INV 0x08 /* 0x00000100 function entry point - vmp */
806 /* 0x00000200 nfs_request trace points */
807 #define NFSTRC_REQ 0x09 /* 0x00000200 - alternates vp and procnum */
808 /* 0x00000c00 vmp_push_range trace points */
809 #define NFSTRC_VPR 0xa /* 0x00000400 entry point - vp... */
810 #define NFSTRC_VPR_DONE 0xb /* 0x00000800 tail exit - error # */
811 /* 0x00003000 nfs_doio trace points */
812 #define NFSTRC_DIO 0xc /* 0x00001000 entry point - vp */
813 #define NFSTRC_DIO_DONE 0xd /* 0x00002000 exit points - vp */
814 /* 0x000fc000 congestion window trace points */
815 #define NFSTRC_CWND_INIT 0xe
816 #define NFSTRC_CWND_REPLY 0xf
817 #define NFSTRC_CWND_TIMER 0x10
818 #define NFSTRC_CWND_REQ1 0x11
819 #define NFSTRC_CWND_REQ2 0x12
820 #define NFSTRC_CWND_SOFT 0x13
821 /* 0xfff00000 nfs_rcvlock & nfs_rcvunlock trace points */
822 #define NFSTRC_ECONN 0x14
823 #define NFSTRC_RCVERR 0x15
824 #define NFSTRC_REQFREE 0x16
825 #define NFSTRC_NOTMINE 0x17
826 #define NFSTRC_6 0x18
827 #define NFSTRC_7 0x19
828 #define NFSTRC_RCVLCKINTR 0x1a
829 #define NFSTRC_RCVALREADY 0x1b
830 #define NFSTRC_RCVLCKW 0x1c /* 0x10000000 seeking recieve lock (waiting) */
831 #define NFSTRC_RCVLCK 0x1d /* 0x20000000 getting recieve lock */
832 #define NFSTRC_RCVUNLW 0x1e /* 0x40000000 releasing rcv lock w/ wakeup */
833 #define NFSTRC_RCVUNL 0x1f /* 0x80000000 releasing rcv lock w/o wakeup */
834 /* trace points beyond 31 are on if any of above points are on */
835 #define NFSTRC_GA_INV2 0x20 /* nfs_getattr invalidate - error# */
836 #define NFSTRC_VBAD 0x21
837 #define NFSTRC_REQERR 0x22
838 #define NFSTRC_RPCERR 0x23
839 #define NFSTRC_DISSECTERR 0x24
840 #define NFSTRC_CONTINUE 0xff /* continuation record for previous entry */
841
842 #define NFSTRACEX(a1, a2, a3, a4) \
843 ( \
844 nfstracebuf[nfstraceindx].i1 = (uint)(a1), \
845 nfstracebuf[nfstraceindx].i2 = (uint)(a2), \
846 nfstracebuf[nfstraceindx].i3 = (uint)(a3), \
847 nfstracebuf[nfstraceindx].i4 = (uint)(a4), \
848 nfstraceindx = (nfstraceindx + 1) % NFSTBUFSIZ, \
849 1 \
850 )
851
852 #define NFSTRACE(cnst, fptr) \
853 ( \
854 (nfstracemask && ((cnst) > 31 || nfstracemask & 1<<(cnst))) ? \
855 NFSTRACEX((cnst), (fptr), current_thread(), \
856 clock_get_system_value().tv_nsec) : \
857 0 \
858 )
859
860 #define NFSTRACE4(cnst, fptr, a2, a3, a4) \
861 ( \
862 NFSTRACE(cnst,fptr) ? \
863 NFSTRACEX(NFSTRC_CONTINUE, a2, a3, a4) : \
864 0 \
865 )
866
867 #else /* NFSDIAG */
868
869 # define NFSTRACE(cnst, fptr)
870 # define NFSTRACE4(cnst, fptr, a2, a3, a4)
871
872 #endif /* NFSDIAG */
873
874 #endif /* KERNEL */
875 #endif /* __APPLE_API_PRIVATE */
876
877 #endif