network - Tokenize NFS, fix MP races
[dragonfly.git] / sys / vfs / nfs / nfs.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1989, 1993, 1995
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 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs.h 8.4 (Berkeley) 5/1/95
37 * $FreeBSD: src/sys/nfs/nfs.h,v 1.53.2.5 2002/02/20 01:35:34 iedowse Exp $
67863d04 38 * $DragonFly: src/sys/vfs/nfs/nfs.h,v 1.21 2008/09/17 21:44:24 dillon Exp $
984263bc
MD
39 */
40
41#ifndef _NFS_NFS_H_
42#define _NFS_NFS_H_
43
44#ifdef _KERNEL
45#include "opt_nfs.h"
46#endif
47
e97453f3 48#include <sys/vnode.h>
8684e6f9 49#include <sys/mutex.h>
c6b43e93 50#include <sys/thread.h>
8684e6f9 51
984263bc
MD
52/*
53 * Tunable constants for nfs
54 */
55
56#define NFS_MAXIOVEC 34
13ddc895 57#define NFS_TICKINTVL 200 /* Desired time for a tick (msec) */
984263bc
MD
58#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
59#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
60#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
61#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
62#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
63#define NFS_MAXREXMIT 100 /* Stop counting after this many */
64#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
65#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
66#define NFS_MAXGRPS 16 /* Max. size of groups list */
67#ifndef NFS_MINATTRTIMO
68#define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */
97100839
MD
69#endif
70#ifndef NFS_DEFATTRTIMO
71#define NFS_DEFATTRTIMO 10 /* VREG attrib cache timeout in sec */
984263bc
MD
72#endif
73#ifndef NFS_MAXATTRTIMO
74#define NFS_MAXATTRTIMO 60
75#endif
76#ifndef NFS_MINDIRATTRTIMO
77#define NFS_MINDIRATTRTIMO 30 /* VDIR attrib cache timeout in sec */
78#endif
79#ifndef NFS_MAXDIRATTRTIMO
80#define NFS_MAXDIRATTRTIMO 60
81#endif
e07fef60
MD
82#ifndef NFS_DEADTHRESH
83#define NFS_DEADTHRESH NFS_NEVERDEAD
84#endif
85#define NFS_NEVERDEAD 9
984263bc
MD
86#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
87#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
88#define NFS_READDIRSIZE 8192 /* Def. readdir size */
4c6b389e 89#define NFS_DEFRAHEAD 6 /* Def. read ahead # blocks */
f88ac120 90#define NFS_MAXRAHEAD 32 /* Max. read ahead # blocks */
f8565b0f 91#define NFS_MAXASYNCBIO 64 /* Max. asynchronous BIOs */
984263bc 92#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
984263bc
MD
93#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
94#ifndef NFS_GATHERDELAY
2cb16efc 95#define NFS_GATHERDELAY 20 /* Default write gather delay (msec) */
984263bc
MD
96#endif
97#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
98#ifdef _KERNEL
99#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
100#endif
101
f8565b0f
MD
102#define NFS_ASYSCALE 256
103#define NFS_MINASYNC_SCALED (4 * NFS_ASYSCALE)
104#define NFS_MAXASYNC_SCALED (NFS_MAXASYNCBIO * NFS_ASYSCALE)
105
984263bc
MD
106/*
107 * Oddballs
108 */
109#define NMOD(a) ((a) % nfs_asyncdaemons)
110#define NFS_CMPFH(n, f, s) \
111 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
112#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
113#define NFS_SRVMAXDATA(n) \
114 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
115 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
116
117/*
984263bc
MD
118 * The IO_METASYNC flag should be implemented for local file systems.
119 * (Until then, it is nothin at all.)
120 */
121#ifndef IO_METASYNC
122#define IO_METASYNC 0
123#endif
124
125/*
126 * Arguments to mount NFS
127 */
128#define NFS_ARGSVERSION 3 /* change when nfs_args changes */
129struct nfs_args {
130 int version; /* args structure version number */
131 struct sockaddr *addr; /* file server address */
132 int addrlen; /* length of address */
133 int sotype; /* Socket type */
134 int proto; /* and Protocol */
135 u_char *fh; /* File handle to be mounted */
136 int fhsize; /* Size, in bytes, of fh */
137 int flags; /* flags */
138 int wsize; /* write size in bytes */
139 int rsize; /* read size in bytes */
140 int readdirsize; /* readdir size in bytes */
141 int timeo; /* initial timeout in .1 secs */
142 int retrans; /* times to retry send */
143 int maxgrouplist; /* Max. size of group list */
144 int readahead; /* # of blocks to readahead */
e07fef60 145 int unused01; /* Term (sec) of lease */
984263bc
MD
146 int deadthresh; /* Retrans threshold */
147 char *hostname; /* server's name */
148 int acregmin; /* cache attrs for reg files min time */
149 int acregmax; /* cache attrs for reg files max time */
150 int acdirmin; /* cache attrs for dirs min time */
151 int acdirmax; /* cache attrs for dirs max time */
152};
153
154/*
155 * NFS mount option flags
156 */
157#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
158#define NFSMNT_WSIZE 0x00000002 /* set write size */
159#define NFSMNT_RSIZE 0x00000004 /* set read size */
160#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
161#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
162#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
163#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
164#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
d9adbeaf 165#define NFSMNT_FORCE 0x00000100 /* Forced unmount */
984263bc
MD
166#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
167#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
168#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
6a9301d9 169#define NFSMNT_CACHE 0x00001000 /* enable swapcache */
984263bc
MD
170#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
171#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
172#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
173#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
174#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
175#define NFSMNT_ACREGMIN 0x00040000
176#define NFSMNT_ACREGMAX 0x00080000
177#define NFSMNT_ACDIRMIN 0x00100000
178#define NFSMNT_ACDIRMAX 0x00200000
179
180#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
181#define NFSSTA_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
182#define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
183#define NFSSTA_MNTD 0x00200000 /* Mnt server for mnt point */
184#define NFSSTA_DISMINPROG 0x00400000 /* Dismount in progress */
185#define NFSSTA_DISMNT 0x00800000 /* Dismounted */
cc7d050e 186#define NFSSTA_SENDSPACE 0x01000000 /* Printed sendspace warning */
8684e6f9
MD
187#define NFSSTA_UNUSED25 0x02000000
188#define NFSSTA_UNUSED26 0x04000000
189#define NFSSTA_UNUSED27 0x08000000
984263bc
MD
190#define NFSSTA_WAITAUTH 0x10000000 /* Wait for authentication */
191#define NFSSTA_HASAUTH 0x20000000 /* Has authenticator */
192#define NFSSTA_WANTAUTH 0x40000000 /* Wants an authenticator */
193#define NFSSTA_AUTHERR 0x80000000 /* Authentication error */
194
195/*
196 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
197 * should ever try and use it.
198 */
199struct nfsd_args {
200 int sock; /* Socket to serve */
201 caddr_t name; /* Client addr for connection based sockets */
202 int namelen; /* Length of name */
203};
204
205struct nfsd_srvargs {
206 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */
207 uid_t nsd_uid; /* Effective uid mapped to cred */
208 u_int32_t nsd_haddr; /* Ip address of client */
209 struct ucred nsd_cr; /* Cred. uid maps to */
210 u_int nsd_authlen; /* Length of auth string (ret) */
211 u_char *nsd_authstr; /* Auth string (ret) */
212 u_int nsd_verflen; /* and the verfier */
213 u_char *nsd_verfstr;
214 struct timeval nsd_timestamp; /* timestamp from verifier */
215 u_int32_t nsd_ttl; /* credential ttl (sec) */
216 NFSKERBKEY_T nsd_key; /* Session key */
217};
218
219struct nfsd_cargs {
220 char *ncd_dirp; /* Mount dir path */
221 uid_t ncd_authuid; /* Effective uid */
222 int ncd_authtype; /* Type of authenticator */
223 u_int ncd_authlen; /* Length of authenticator string */
224 u_char *ncd_authstr; /* Authenticator string */
225 u_int ncd_verflen; /* and the verifier */
226 u_char *ncd_verfstr;
227 NFSKERBKEY_T ncd_key; /* Session key */
228};
229
230/*
231 * XXX to allow amd to include nfs.h without nfsproto.h
232 */
233#ifdef NFS_NPROCS
234/*
235 * Stats structure
236 */
237struct nfsstats {
238 int attrcache_hits;
239 int attrcache_misses;
240 int lookupcache_hits;
241 int lookupcache_misses;
242 int direofcache_hits;
243 int direofcache_misses;
244 int biocache_reads;
245 int read_bios;
246 int read_physios;
247 int biocache_writes;
248 int write_bios;
249 int write_physios;
250 int biocache_readlinks;
251 int readlink_bios;
252 int biocache_readdirs;
253 int readdir_bios;
254 int rpccnt[NFS_NPROCS];
255 int rpcretries;
256 int srvrpccnt[NFS_NPROCS];
257 int srvrpc_errs;
258 int srv_errs;
259 int rpcrequests;
260 int rpctimeouts;
261 int rpcunexpected;
262 int rpcinvalid;
263 int srvcache_inproghits;
264 int srvcache_idemdonehits;
265 int srvcache_nonidemdonehits;
266 int srvcache_misses;
267 int srvnqnfs_leases;
268 int srvnqnfs_maxleases;
269 int srvnqnfs_getleases;
270 int srvvop_writes;
271 int accesscache_hits;
272 int accesscache_misses;
273};
274#endif
275
276/*
277 * Flags for nfssvc() system call.
278 */
279#define NFSSVC_BIOD 0x002
280#define NFSSVC_NFSD 0x004
281#define NFSSVC_ADDSOCK 0x008
282#define NFSSVC_AUTHIN 0x010
283#define NFSSVC_GOTAUTH 0x040
284#define NFSSVC_AUTHINFAIL 0x080
285#define NFSSVC_MNTD 0x100
286
287/*
288 * fs.nfs sysctl(3) identifiers
289 */
290#define NFS_NFSSTATS 1 /* struct: struct nfsstats */
291#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
292
293#define FS_NFS_NAMES { \
294 { 0, 0 }, \
295 { "nfsstats", CTLTYPE_STRUCT }, \
296 { "nfsprivport", CTLTYPE_INT }, \
297}
298
299#ifdef _KERNEL
300
301#ifdef MALLOC_DECLARE
302MALLOC_DECLARE(M_NFSREQ);
303MALLOC_DECLARE(M_NFSDIROFF);
304MALLOC_DECLARE(M_NFSRVDESC);
305MALLOC_DECLARE(M_NFSUID);
984263bc
MD
306MALLOC_DECLARE(M_NFSD);
307MALLOC_DECLARE(M_NFSBIGFH);
308MALLOC_DECLARE(M_NFSHASH);
309#endif
310
311#ifdef ZONE_INTERRUPT
312extern vm_zone_t nfsmount_zone;
313#endif
314
f786cc86 315extern struct callout nfs_timer_handle;
a482a28a 316extern int nfs_async;
cc7d050e
MD
317extern int nfs_maxasyncbio;
318extern int nfs_soreserve;
984263bc 319
fad57d0e
MD
320struct uio;
321struct buf;
81b5c339 322struct bio;
fad57d0e
MD
323struct vattr;
324struct nlookupdata;
984263bc
MD
325
326/*
327 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
328 * What should be in this set is open to debate, but I believe that since
329 * I/O system calls on ufs are never interrupted by signals the set should
330 * be minimal. My reasoning is that many current programs that use signals
331 * such as SIGALRM will not expect file I/O system calls to be interrupted
332 * by them and break.
333 */
334#define NFSINT_SIGMASK(set) \
335 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
336 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
337 SIGISMEMBER(set, SIGQUIT))
338
339/*
340 * Socket errors ignored for connectionless sockets??
341 * For now, ignore them all
342 */
343#define NFSIGNORE_SOERROR(s, e) \
344 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
345 ((s) & PR_CONNREQUIRED) == 0)
346
edb90c22
MD
347struct nfsm_info;
348
984263bc
MD
349/*
350 * Nfs outstanding request list element
351 */
352struct nfsreq {
353 TAILQ_ENTRY(nfsreq) r_chain;
edb90c22 354 struct nfsm_info *r_info;
8684e6f9 355 struct mtx_link r_link;
984263bc
MD
356 struct mbuf *r_mreq;
357 struct mbuf *r_mrep;
358 struct mbuf *r_md;
359 caddr_t r_dpos;
360 struct nfsmount *r_nmp;
361 struct vnode *r_vp;
362 u_int32_t r_xid;
363 int r_flags; /* flags on request, see below */
364 int r_retry; /* max retransmission count */
365 int r_rexmit; /* current retrans count */
366 int r_timer; /* tick counter on reply */
367 u_int32_t r_procnum; /* NFS procedure number */
368 int r_rtt; /* RTT for rpc */
dadab5e9 369 struct thread *r_td; /* Thread that did I/O system call */
8684e6f9
MD
370 struct mbuf *r_mrest;
371 struct mbuf *r_mheadend;
372 struct mbuf **r_mrp;
373 struct mbuf **r_mdp;
374 caddr_t *r_dposp;
375 int r_mrest_len;
376 int r_failed_auth;
377 NFSKERBKEY_T r_key;
378 struct ucred *r_cred;
984263bc
MD
379};
380
381/*
e21aec5b 382 * Flag values for r_flags
f8565b0f
MD
383 *
384 * R_TIMING - Timer is active on request. If timer goes off the
385 * request's retransmit counter will bump and it will
386 * be flagged NEEDSXMIT to retransmit.
387 *
388 * R_SENT - Indicates that the request was sent the first time.
389 * This stays set unless we want to repeat a first-time
390 * styled transmit sequence.
391 *
392 * R_NEEDSXMIT - The request needs a [re]transmission. It will still
393 * be sitting on nm_reqq if synchronous, otherwise it
394 * will be moved to nm_reqtxq.
395 *
396 * R_ASYNC - Indicates an asynchronous request, which modifies the
397 * behavior of how it is dealt with.
398 *
399 * R_LOCKED - Prevents the request from being moved between queues
400 * e.g. by the timer or by the async thread.
984263bc 401 */
54938b92
MD
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. */
f8565b0f
MD
408#define R_NEEDSXMIT 0x0040 /* Needs [re]transmission */
409#define R_ASYNC 0x0080 /* Asynchronous mechanics */
410#define R_ONREQQ 0x0100 /* On primary request queue */
411#define R_LOCKED 0x0200 /* Locked by the someone */
412#define R_WANTED 0x0400 /* Someone wants access */
984263bc
MD
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#ifndef NFS_WDELAYHASHSIZ
426#define NFS_WDELAYHASHSIZ 16 /* and with this */
427#endif
428#define NWDELAYHASH(sock, f) \
429 (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
430#ifndef NFS_MUIDHASHSIZ
431#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
432#endif
433#define NMUIDHASH(nmp, uid) \
434 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
984263bc
MD
435
436/*
437 * Network address hash list element
438 */
439union nethostaddr {
440 u_int32_t had_inetaddr;
441 struct sockaddr *had_nam;
442};
443
444struct nfsuid {
445 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
446 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
447 int nu_flag; /* Flags */
448 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
449 struct ucred nu_cr; /* Cred uid mapped to */
450 int nu_expire; /* Expiry time (sec) */
451 struct timeval nu_timestamp; /* Kerb. timestamp */
452 u_int32_t nu_nickname; /* Nickname on server */
453 NFSKERBKEY_T nu_key; /* and session key */
454};
455
456#define nu_inetaddr nu_haddr.had_inetaddr
457#define nu_nam nu_haddr.had_nam
458/* Bits for nu_flag */
459#define NU_INETADDR 0x1
460#define NU_NAM 0x2
461#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
462
463struct nfsrv_rec {
464 STAILQ_ENTRY(nfsrv_rec) nr_link;
465 struct sockaddr *nr_address;
466 struct mbuf *nr_packet;
467};
468
469struct nfssvc_sock {
470 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
471 TAILQ_HEAD(, nfsuid) ns_uidlruhead;
472 struct file *ns_fp;
473 struct socket *ns_so;
474 struct sockaddr *ns_nam;
475 struct mbuf *ns_raw;
476 struct mbuf *ns_rawend;
477 STAILQ_HEAD(, nfsrv_rec) ns_rec;
478 struct mbuf *ns_frag;
52553028 479 int ns_numrec;
984263bc 480 int ns_flag;
8684e6f9 481 struct mtx ns_solock;
984263bc
MD
482 int ns_cc;
483 int ns_reclen;
484 int ns_numuids;
485 u_int32_t 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];
c6b43e93 489 struct lwkt_token ns_token;
984263bc
MD
490};
491
492/* Bits for "ns_flag" */
493#define SLP_VALID 0x01
494#define SLP_DOREC 0x02
495#define SLP_NEEDQ 0x04
496#define SLP_DISCONN 0x08
497#define SLP_GETSTREAM 0x10
498#define SLP_LASTFRAG 0x20
499#define SLP_ALLFLAGS 0xff
500
501extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
502extern int nfssvc_sockhead_flag;
49433307 503extern TAILQ_HEAD(nfsmount_head, nfsmount) nfs_mountq;
e21aec5b 504
984263bc
MD
505#define SLP_INIT 0x01
506#define SLP_WANTINIT 0x02
507
508/*
509 * One of these structures is allocated for each nfsd.
510 */
511struct nfsd {
512 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */
513 int nfsd_flag; /* NFSD_ flags */
514 struct nfssvc_sock *nfsd_slp; /* Current socket */
515 int nfsd_authlen; /* Authenticator len */
516 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
517 int nfsd_verflen; /* and the Verifier */
518 u_char nfsd_verfstr[RPCVERF_MAXSIZ];
dadab5e9 519 struct thread *nfsd_td; /* thread ptr */
984263bc
MD
520 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
521};
522
523/* Bits for "nfsd_flag" */
524#define NFSD_WAITING 0x01
525#define NFSD_REQINPROG 0x02
526#define NFSD_NEEDAUTH 0x04
527#define NFSD_AUTHFAIL 0x08
528
5a9187cb
MD
529/* Bits for loadattrcache */
530#define NFS_LATTR_NOSHRINK 0x01
531#define NFS_LATTR_NOMTIMECHECK 0x02
532
984263bc
MD
533/*
534 * This structure is used by the server for describing each request.
535 * Some fields are used only when write request gathering is performed.
536 */
537struct nfsrv_descript {
538 u_quad_t nd_time; /* Write deadline (usec) */
539 off_t nd_off; /* Start byte offset */
540 off_t nd_eoff; /* and end byte offset */
541 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
542 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
543 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
544 struct mbuf *nd_mrep; /* Request mbuf list */
545 struct mbuf *nd_md; /* Current dissect mbuf */
546 struct mbuf *nd_mreq; /* Reply mbuf list */
547 struct sockaddr *nd_nam; /* and socket addr */
548 struct sockaddr *nd_nam2; /* return socket addr */
549 caddr_t nd_dpos; /* Current dissect pos */
550 u_int32_t nd_procnum; /* RPC # */
551 int nd_stable; /* storage type */
552 int nd_flag; /* nd_flag */
553 int nd_len; /* Length of this write */
554 int nd_repstat; /* Reply status */
555 u_int32_t nd_retxid; /* Reply xid */
984263bc
MD
556 struct timeval nd_starttime; /* Time RPC initiated */
557 fhandle_t nd_fh; /* File handle */
558 struct ucred nd_cr; /* Credentials */
559};
560
561/* Bits for "nd_flag" */
e07fef60
MD
562#define ND_READ 0x01
563#define ND_WRITE 0x02
984263bc 564#define ND_CHECK 0x04
984263bc 565#define ND_NFSV3 0x08
e07fef60 566#define ND_UNUSED010 0x10
984263bc
MD
567#define ND_KERBNICK 0x20
568#define ND_KERBFULL 0x40
569#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
570
571extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
572extern int nfsd_head_flag;
52553028 573extern int nfsd_waiting;
984263bc
MD
574#define NFSD_CHECKSLP 0x01
575
576/*
577 * These macros compare nfsrv_descript structures.
578 */
579#define NFSW_CONTIG(o, n) \
580 ((o)->nd_eoff >= (n)->nd_off && \
581 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
582
583#define NFSW_SAMECRED(o, n) \
584 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
585 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
586 sizeof (struct ucred)))
587
588/*
589 * Defines for WebNFS
590 */
591
592#define WEBNFS_ESC_CHAR '%'
593#define WEBNFS_SPECCHAR_START 0x80
594
595#define WEBNFS_NATIVE_CHAR 0x80
596/*
597 * ..
598 * Possibly more here in the future.
599 */
600
601/*
602 * Macro for converting escape characters in WebNFS pathnames.
603 * Should really be in libkern.
604 */
605
606#define HEXTOC(c) \
607 ((c) >= 'a' ? ((c) - ('a' - 10)) : \
608 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
609#define HEXSTRTOI(p) \
610 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
611
612#ifdef NFS_DEBUG
613
614extern int nfs_debug;
615#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */
616#define NFS_DEBUG_WG 2 /* server write gathering */
617#define NFS_DEBUG_RC 4 /* server request caching */
618
619#define NFS_DPF(cat, args) \
620 do { \
086c1d7e 621 if (nfs_debug & NFS_DEBUG_##cat) kprintf args; \
984263bc
MD
622 } while (0)
623
624#else
625
626#define NFS_DPF(cat, args)
627
628#endif
629
e97453f3
MD
630extern u_int32_t nfs_xdrneg1;
631extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
632extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
633extern u_int32_t rpc_auth_kerb;
634extern u_int32_t nfs_prog, nfs_true, nfs_false;
635extern struct nfsstats nfsstats;
636extern nfstype nfsv2_type[9];
637extern nfstype nfsv3_type[9];
638extern int nfsv2_procid[NFS_NPROCS];
639extern enum vtype nv3tov_type[8];
640extern int nfsv3_procid[NFS_NPROCS];
641extern int nfs_ticks;
642extern struct nfsrtt nfsrtt;
643extern int nfsrtton;
644extern int nfsrvw_procrastinate;
645extern int nfsrvw_procrastinate_v3;
646extern int32_t (*nfsrv3_procs[NFS_NPROCS]) (struct nfsrv_descript *nd,
647 struct nfssvc_sock *slp,
648 struct thread *td,
649 struct mbuf **mreqp);
650
651extern struct nfsv3_diskless nfsv3_diskless;
c6b43e93 652extern struct lwkt_token nfs_token;
e97453f3 653
a6ee311a
RG
654u_quad_t nfs_curusec (void);
655int nfs_init (struct vfsconf *vfsp);
656int nfs_uninit (struct vfsconf *vfsp);
edb90c22 657int nfs_reply (struct nfsmount *nmp, struct nfsreq *);
a6ee311a
RG
658int nfs_getreq (struct nfsrv_descript *,struct nfsd *,int);
659int nfs_send (struct socket *, struct sockaddr *, struct mbuf *,
660 struct nfsreq *);
661int nfs_rephead (int, struct nfsrv_descript *, struct nfssvc_sock *,
e07fef60 662 int, struct mbuf **, struct mbuf **, caddr_t *);
edb90c22
MD
663int nfs_sndlock (struct nfsmount *, struct nfsreq *);
664void nfs_sndunlock (struct nfsmount *);
a6ee311a
RG
665int nfs_slplock (struct nfssvc_sock *, int);
666void nfs_slpunlock (struct nfssvc_sock *);
667int nfs_disct (struct mbuf **, caddr_t *, int, int, caddr_t *);
87de5057 668int nfs_vinvalbuf (struct vnode *, int, int);
edb90c22
MD
669int nfs_readrpc_uio (struct vnode *, struct uio *);
670void nfs_readrpc_bio (struct vnode *, struct bio *);
cc7d050e
MD
671int nfs_writerpc_uio (struct vnode *, struct uio *, int *, int *);
672void nfs_writerpc_bio (struct vnode *, struct bio *);
673int nfs_commitrpc_uio (struct vnode *vp, u_quad_t offset, int cnt,
a6ee311a 674 struct thread *td);
cc7d050e
MD
675void nfs_commitrpc_bio (struct vnode *vp, struct bio *);
676int nfs_readdirrpc_uio (struct vnode *, struct uio *);
677void nfs_startio(struct vnode *vp, struct bio *, struct thread *);
678int nfs_doio(struct vnode *vp, struct bio *, struct thread *);
edb90c22
MD
679void nfs_asyncio(struct vnode *vp, struct bio *bio);
680int nfs_asyncok(struct nfsmount *nmp);
edb90c22 681
cc7d050e 682int nfs_readlinkrpc_uio (struct vnode *, struct uio *);
a6ee311a 683int nfs_sigintr (struct nfsmount *, struct nfsreq *, struct thread *);
cc7d050e 684int nfs_readdirplusrpc_uio (struct vnode *, struct uio *);
a6ee311a 685int netaddr_match (int, union nethostaddr *, struct sockaddr *);
8684e6f9 686
42edf14f
MD
687int nfs_loadattrcache (struct vnode *, struct mbuf **, caddr_t *,
688 struct vattr *, int);
fad57d0e
MD
689int nfs_namei (struct nlookupdata *, struct ucred *, int,
690 struct vnode **, struct vnode **, fhandle_t *, int,
691 struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
692 caddr_t *, struct vnode **, struct thread *, int, int);
a6ee311a
RG
693void nfsrv_initcache (void);
694int nfs_getauth (struct nfsmount *, struct nfsreq *, struct ucred *,
695 char **, int *, char *, int *, NFSKERBKEY_T);
696int nfs_getnickauth (struct nfsmount *, struct ucred *, char **,
697 int *, char *, int);
698int nfs_savenickauth (struct nfsmount *, struct ucred *, int,
984263bc 699 NFSKERBKEY_T, struct mbuf **, char **,
a6ee311a
RG
700 struct mbuf *);
701int nfs_adv (struct mbuf **, caddr_t *, int, int);
702void nfs_nhinit (void);
703int nfs_nmcancelreqs (struct nfsmount *);
c6b43e93 704void nfs_timer_callout (void*);
a6ee311a
RG
705int nfsrv_dorec (struct nfssvc_sock *, struct nfsd *,
706 struct nfsrv_descript **);
707int nfsrv_getcache (struct nfsrv_descript *, struct nfssvc_sock *,
708 struct mbuf **);
709void nfsrv_updatecache (struct nfsrv_descript *, int, struct mbuf *);
710void nfsrv_cleancache (void);
711int nfs_connect (struct nfsmount *, struct nfsreq *);
712void nfs_disconnect (struct nfsmount *);
713void nfs_safedisconnect (struct nfsmount *);
714int nfs_getattrcache (struct vnode *, struct vattr *);
a6ee311a 715int nfs_bioread (struct vnode *, struct uio *, int);
a6ee311a
RG
716void nfsrv_init (int);
717void nfs_clearcommit (struct mount *);
718int nfsrv_errmap (struct nfsrv_descript *, int);
719void nfsrvw_sort (gid_t *, int);
720void nfsrv_setcred (struct ucred *, struct ucred *);
a6ee311a 721int nfsrv_object_create (struct vnode *);
52553028 722void nfsrv_wakenfsd (struct nfssvc_sock *slp, int nparallel);
a6ee311a
RG
723int nfsrv_writegather (struct nfsrv_descript **, struct nfssvc_sock *,
724 struct thread *, struct mbuf **);
725int nfs_fsinfo (struct nfsmount *, struct vnode *, struct thread *p);
726
727int nfsrv3_access (struct nfsrv_descript *nfsd,
984263bc 728 struct nfssvc_sock *slp,
a6ee311a
RG
729 struct thread *td, struct mbuf **mrq);
730int nfsrv_commit (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
731 struct thread *td, struct mbuf **mrq);
732int nfsrv_create (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
733 struct thread *td, struct mbuf **mrq);
67863d04
MD
734int nfsrv_fhtovp (fhandle_t *, int, struct mount **, struct vnode **,
735 struct ucred *, struct nfssvc_sock *,
736 struct sockaddr *, int *, int, int);
a6ee311a
RG
737int nfsrv_setpublicfs (struct mount *, struct netexport *,
738 struct export_args *);
739int nfs_ispublicfh (fhandle_t *);
740int nfsrv_fsinfo (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
741 struct thread *td, struct mbuf **mrq);
742int nfsrv_getattr (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
743 struct thread *td, struct mbuf **mrq);
744int nfsrv_link (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
745 struct thread *td, struct mbuf **mrq);
746int nfsrv_lookup (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
747 struct thread *td, struct mbuf **mrq);
748int nfsrv_mkdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
749 struct thread *td, struct mbuf **mrq);
750int nfsrv_mknod (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
751 struct thread *td, struct mbuf **mrq);
752int nfsrv_noop (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
753 struct thread *td, struct mbuf **mrq);
754int nfsrv_null (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
755 struct thread *td, struct mbuf **mrq);
756int nfsrv_pathconf (struct nfsrv_descript *nfsd,
dadab5e9 757 struct nfssvc_sock *slp, struct thread *td,
a6ee311a
RG
758 struct mbuf **mrq);
759int nfsrv_read (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
760 struct thread *td, struct mbuf **mrq);
761int nfsrv_readdir (struct nfsrv_descript *nfsd,
984263bc 762 struct nfssvc_sock *slp,
a6ee311a
RG
763 struct thread *td, struct mbuf **mrq);
764int nfsrv_readdirplus (struct nfsrv_descript *nfsd,
dadab5e9 765 struct nfssvc_sock *slp, struct thread *td,
a6ee311a
RG
766 struct mbuf **mrq);
767int nfsrv_readlink (struct nfsrv_descript *nfsd,
dadab5e9 768 struct nfssvc_sock *slp, struct thread *td,
a6ee311a
RG
769 struct mbuf **mrq);
770int nfsrv_remove (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
771 struct thread *td, struct mbuf **mrq);
772int nfsrv_rename (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
773 struct thread *td, struct mbuf **mrq);
774int nfsrv_rmdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
775 struct thread *td, struct mbuf **mrq);
776int nfsrv_setattr (struct nfsrv_descript *nfsd,
984263bc 777 struct nfssvc_sock *slp,
a6ee311a
RG
778 struct thread *td, struct mbuf **mrq);
779int nfsrv_statfs (struct nfsrv_descript *nfsd,
984263bc 780 struct nfssvc_sock *slp,
a6ee311a
RG
781 struct thread *td, struct mbuf **mrq);
782int nfsrv_symlink (struct nfsrv_descript *nfsd,
984263bc 783 struct nfssvc_sock *slp,
a6ee311a
RG
784 struct thread *td, struct mbuf **mrq);
785int nfsrv_write (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
786 struct thread *td, struct mbuf **mrq);
787void nfsrv_rcv (struct socket *so, void *arg, int waitflag);
c6b43e93 788void nfsrv_rcv_upcall (struct socket *so, void *arg, int waitflag);
a6ee311a 789void nfsrv_slpderef (struct nfssvc_sock *slp);
c6b43e93 790void nfsrv_slpref (struct nfssvc_sock *slp);
8452310f
MD
791int nfs_meta_setsize (struct vnode *vp, struct thread *td,
792 off_t nbase, int trivial);
e07fef60
MD
793int nfs_clientd(struct nfsmount *nmp, struct ucred *cred,
794 struct nfsd_cargs *ncd, int flag, caddr_t argp,
795 struct thread *td);
52e1cf57
MD
796void nfssvc_iod_reader(void *arg);
797void nfssvc_iod_writer(void *arg);
13ddc895
MD
798void nfssvc_iod_stop1(struct nfsmount *nmp);
799void nfssvc_iod_stop2(struct nfsmount *nmp);
52e1cf57 800void nfssvc_iod_writer_wakeup(struct nfsmount *nmp);
edb90c22 801void nfssvc_iod_reader_wakeup(struct nfsmount *nmp);
984263bc
MD
802
803#endif /* _KERNEL */
804
805#endif