Deleted Added
full compact
nfs.h (22975) nfs.h (24330)
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
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 * $Id$
37 * $Id: nfs.h,v 1.22 1997/02/22 09:42:34 peter Exp $
38 */
39
40#ifndef _NFS_NFS_H_
41#define _NFS_NFS_H_
42
43/*
44 * Tunable constants for nfs
45 */
46
47#ifdef KERNEL
48
49#define NFS_MAXIOVEC 34
50#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
51#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
52#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
53#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
54#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
55#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
56#define NFS_MAXREXMIT 100 /* Stop counting after this many */
57#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
58#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
59#define NFS_MAXGRPS 16 /* Max. size of groups list */
60#ifndef NFS_MINATTRTIMO
61#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */
62#endif
63#ifndef NFS_MAXATTRTIMO
64#define NFS_MAXATTRTIMO 60
65#endif
66#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
67#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
68#define NFS_READDIRSIZE 8192 /* Def. readdir size */
69#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */
70#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */
71#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
72#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */
73#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
74#ifndef NFS_GATHERDELAY
75#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
76#endif
77#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
78
79/*
80 * Oddballs
81 */
82#define NMOD(a) ((a) % nfs_asyncdaemons)
83#define NFS_CMPFH(n, f, s) \
84 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
85#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
86#define NFS_SRVMAXDATA(n) \
87 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
88 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
89
90/*
91 * XXX
92 * The B_INVAFTERWRITE flag should be set to whatever is required by the
93 * buffer cache code to say "Invalidate the block after it is written back".
94 */
95#ifdef __FreeBSD__
96#define B_INVAFTERWRITE B_NOCACHE
97#else
98#define B_INVAFTERWRITE B_INVAL
99#endif
100
101/*
102 * The IO_METASYNC flag should be implemented for local file systems.
103 * (Until then, it is nothin at all.)
104 */
105#ifndef IO_METASYNC
106#define IO_METASYNC 0
107#endif
108
109/*
110 * Set the attribute timeout based on how recently the file has been modified.
111 */
112#define NFS_ATTRTIMEO(np) \
113 ((((np)->n_flag & NMODIFIED) || \
114 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
115 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
116 (time.tv_sec - (np)->n_mtime) / 10))
117
118/*
119 * Expected allocation sizes for major data structures. If the actual size
120 * of the structure exceeds these sizes, then malloc() will be allocating
121 * almost twice the memory required. This is used in nfs_init() to warn
122 * the sysadmin that the size of a structure should be reduced.
123 * (These sizes are always a power of 2. If the kernel malloc() changes
124 * to one that does not allocate space in powers of 2 size, then this all
125 * becomes bunk!)
126 */
127#define NFS_NODEALLOC 256
128#define NFS_MNTALLOC 512
129#define NFS_SVCALLOC 256
130#define NFS_UIDALLOC 128
131
132#endif /* KERNEL */
133
134/*
135 * NFS mount option flags
136 */
137#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
138#define NFSMNT_WSIZE 0x00000002 /* set write size */
139#define NFSMNT_RSIZE 0x00000004 /* set read size */
140#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
141#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
142#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
143#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
144#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
145#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
146#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
147#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
148#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
149#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
150#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
151#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
152#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
153#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
154#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
155#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
156#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
157#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
158#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
159#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
160#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
161#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
162#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
163#define NFSMNT_WANTSND 0x02000000 /* Want above */
164#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
165#define NFSMNT_WANTRCV 0x08000000 /* Want above */
166#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
167#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
168#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
169#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
170
171/*
172 * Arguments to mount NFS
173 */
174#define NFS_ARGSVERSION 3 /* change when nfs_args changes */
175struct nfs_args {
176 int version; /* args structure version number */
177 struct sockaddr *addr; /* file server address */
178 int addrlen; /* length of address */
179 int sotype; /* Socket type */
180 int proto; /* and Protocol */
181 u_char *fh; /* File handle to be mounted */
182 int fhsize; /* Size, in bytes, of fh */
183 int flags; /* flags */
184 int wsize; /* write size in bytes */
185 int rsize; /* read size in bytes */
186 int readdirsize; /* readdir size in bytes */
187 int timeo; /* initial timeout in .1 secs */
188 int retrans; /* times to retry send */
189 int maxgrouplist; /* Max. size of group list */
190 int readahead; /* # of blocks to readahead */
191 int leaseterm; /* Term (sec) of lease */
192 int deadthresh; /* Retrans threshold */
193 char *hostname; /* server's name */
194};
195
196/*
197 * NFS mount option flags
198 */
199#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
200#define NFSMNT_WSIZE 0x00000002 /* set write size */
201#define NFSMNT_RSIZE 0x00000004 /* set read size */
202#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
203#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
204#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
205#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
206#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
207#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
208#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
209#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
210#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
211#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
212#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
213#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
214#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
215#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
216#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
217#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
218#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
219#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
220#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
221#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
222#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
223#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
224#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
225#define NFSMNT_WANTSND 0x02000000 /* Want above */
226#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
227#define NFSMNT_WANTRCV 0x08000000 /* Want above */
228#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
229#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
230#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
231#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
232
233/*
234 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
235 * should ever try and use it.
236 */
237struct nfsd_args {
238 int sock; /* Socket to serve */
239 caddr_t name; /* Client addr for connection based sockets */
240 int namelen; /* Length of name */
241};
242
243struct nfsd_srvargs {
244 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */
245 uid_t nsd_uid; /* Effective uid mapped to cred */
246 u_long nsd_haddr; /* Ip address of client */
247 struct ucred nsd_cr; /* Cred. uid maps to */
248 int nsd_authlen; /* Length of auth string (ret) */
249 u_char *nsd_authstr; /* Auth string (ret) */
250 int nsd_verflen; /* and the verfier */
251 u_char *nsd_verfstr;
252 struct timeval nsd_timestamp; /* timestamp from verifier */
253 u_long nsd_ttl; /* credential ttl (sec) */
254 NFSKERBKEY_T nsd_key; /* Session key */
255};
256
257struct nfsd_cargs {
258 char *ncd_dirp; /* Mount dir path */
259 uid_t ncd_authuid; /* Effective uid */
260 int ncd_authtype; /* Type of authenticator */
261 int ncd_authlen; /* Length of authenticator string */
262 u_char *ncd_authstr; /* Authenticator string */
263 int ncd_verflen; /* and the verifier */
264 u_char *ncd_verfstr;
265 NFSKERBKEY_T ncd_key; /* Session key */
266};
267
268/*
269 * XXX to allow amd to include nfs.h without nfsproto.h
270 */
271#ifdef NFS_NPROCS
272/*
273 * Stats structure
274 */
275struct nfsstats {
276 int attrcache_hits;
277 int attrcache_misses;
278 int lookupcache_hits;
279 int lookupcache_misses;
280 int direofcache_hits;
281 int direofcache_misses;
282 int biocache_reads;
283 int read_bios;
284 int read_physios;
285 int biocache_writes;
286 int write_bios;
287 int write_physios;
288 int biocache_readlinks;
289 int readlink_bios;
290 int biocache_readdirs;
291 int readdir_bios;
292 int rpccnt[NFS_NPROCS];
293 int rpcretries;
294 int srvrpccnt[NFS_NPROCS];
295 int srvrpc_errs;
296 int srv_errs;
297 int rpcrequests;
298 int rpctimeouts;
299 int rpcunexpected;
300 int rpcinvalid;
301 int srvcache_inproghits;
302 int srvcache_idemdonehits;
303 int srvcache_nonidemdonehits;
304 int srvcache_misses;
305 int srvnqnfs_leases;
306 int srvnqnfs_maxleases;
307 int srvnqnfs_getleases;
308 int srvvop_writes;
309};
310#endif
311
312/*
313 * Flags for nfssvc() system call.
314 */
315#define NFSSVC_BIOD 0x002
316#define NFSSVC_NFSD 0x004
317#define NFSSVC_ADDSOCK 0x008
318#define NFSSVC_AUTHIN 0x010
319#define NFSSVC_GOTAUTH 0x040
320#define NFSSVC_AUTHINFAIL 0x080
321#define NFSSVC_MNTD 0x100
322
323/*
324 * fs.nfs sysctl(3) identifiers
325 */
326#define NFS_NFSSTATS 1 /* struct: struct nfsstats */
38 */
39
40#ifndef _NFS_NFS_H_
41#define _NFS_NFS_H_
42
43/*
44 * Tunable constants for nfs
45 */
46
47#ifdef KERNEL
48
49#define NFS_MAXIOVEC 34
50#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
51#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
52#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
53#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
54#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
55#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
56#define NFS_MAXREXMIT 100 /* Stop counting after this many */
57#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
58#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
59#define NFS_MAXGRPS 16 /* Max. size of groups list */
60#ifndef NFS_MINATTRTIMO
61#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */
62#endif
63#ifndef NFS_MAXATTRTIMO
64#define NFS_MAXATTRTIMO 60
65#endif
66#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
67#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
68#define NFS_READDIRSIZE 8192 /* Def. readdir size */
69#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */
70#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */
71#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
72#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */
73#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
74#ifndef NFS_GATHERDELAY
75#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
76#endif
77#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
78
79/*
80 * Oddballs
81 */
82#define NMOD(a) ((a) % nfs_asyncdaemons)
83#define NFS_CMPFH(n, f, s) \
84 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
85#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
86#define NFS_SRVMAXDATA(n) \
87 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
88 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
89
90/*
91 * XXX
92 * The B_INVAFTERWRITE flag should be set to whatever is required by the
93 * buffer cache code to say "Invalidate the block after it is written back".
94 */
95#ifdef __FreeBSD__
96#define B_INVAFTERWRITE B_NOCACHE
97#else
98#define B_INVAFTERWRITE B_INVAL
99#endif
100
101/*
102 * The IO_METASYNC flag should be implemented for local file systems.
103 * (Until then, it is nothin at all.)
104 */
105#ifndef IO_METASYNC
106#define IO_METASYNC 0
107#endif
108
109/*
110 * Set the attribute timeout based on how recently the file has been modified.
111 */
112#define NFS_ATTRTIMEO(np) \
113 ((((np)->n_flag & NMODIFIED) || \
114 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
115 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
116 (time.tv_sec - (np)->n_mtime) / 10))
117
118/*
119 * Expected allocation sizes for major data structures. If the actual size
120 * of the structure exceeds these sizes, then malloc() will be allocating
121 * almost twice the memory required. This is used in nfs_init() to warn
122 * the sysadmin that the size of a structure should be reduced.
123 * (These sizes are always a power of 2. If the kernel malloc() changes
124 * to one that does not allocate space in powers of 2 size, then this all
125 * becomes bunk!)
126 */
127#define NFS_NODEALLOC 256
128#define NFS_MNTALLOC 512
129#define NFS_SVCALLOC 256
130#define NFS_UIDALLOC 128
131
132#endif /* KERNEL */
133
134/*
135 * NFS mount option flags
136 */
137#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
138#define NFSMNT_WSIZE 0x00000002 /* set write size */
139#define NFSMNT_RSIZE 0x00000004 /* set read size */
140#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
141#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
142#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
143#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
144#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
145#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
146#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
147#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
148#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
149#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
150#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
151#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
152#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
153#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
154#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
155#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
156#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
157#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
158#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
159#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
160#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
161#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
162#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
163#define NFSMNT_WANTSND 0x02000000 /* Want above */
164#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
165#define NFSMNT_WANTRCV 0x08000000 /* Want above */
166#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
167#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
168#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
169#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
170
171/*
172 * Arguments to mount NFS
173 */
174#define NFS_ARGSVERSION 3 /* change when nfs_args changes */
175struct nfs_args {
176 int version; /* args structure version number */
177 struct sockaddr *addr; /* file server address */
178 int addrlen; /* length of address */
179 int sotype; /* Socket type */
180 int proto; /* and Protocol */
181 u_char *fh; /* File handle to be mounted */
182 int fhsize; /* Size, in bytes, of fh */
183 int flags; /* flags */
184 int wsize; /* write size in bytes */
185 int rsize; /* read size in bytes */
186 int readdirsize; /* readdir size in bytes */
187 int timeo; /* initial timeout in .1 secs */
188 int retrans; /* times to retry send */
189 int maxgrouplist; /* Max. size of group list */
190 int readahead; /* # of blocks to readahead */
191 int leaseterm; /* Term (sec) of lease */
192 int deadthresh; /* Retrans threshold */
193 char *hostname; /* server's name */
194};
195
196/*
197 * NFS mount option flags
198 */
199#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
200#define NFSMNT_WSIZE 0x00000002 /* set write size */
201#define NFSMNT_RSIZE 0x00000004 /* set read size */
202#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
203#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
204#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
205#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
206#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
207#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
208#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
209#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
210#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
211#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
212#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
213#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
214#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
215#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
216#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
217#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
218#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
219#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
220#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
221#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
222#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
223#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
224#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
225#define NFSMNT_WANTSND 0x02000000 /* Want above */
226#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
227#define NFSMNT_WANTRCV 0x08000000 /* Want above */
228#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
229#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
230#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
231#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
232
233/*
234 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
235 * should ever try and use it.
236 */
237struct nfsd_args {
238 int sock; /* Socket to serve */
239 caddr_t name; /* Client addr for connection based sockets */
240 int namelen; /* Length of name */
241};
242
243struct nfsd_srvargs {
244 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */
245 uid_t nsd_uid; /* Effective uid mapped to cred */
246 u_long nsd_haddr; /* Ip address of client */
247 struct ucred nsd_cr; /* Cred. uid maps to */
248 int nsd_authlen; /* Length of auth string (ret) */
249 u_char *nsd_authstr; /* Auth string (ret) */
250 int nsd_verflen; /* and the verfier */
251 u_char *nsd_verfstr;
252 struct timeval nsd_timestamp; /* timestamp from verifier */
253 u_long nsd_ttl; /* credential ttl (sec) */
254 NFSKERBKEY_T nsd_key; /* Session key */
255};
256
257struct nfsd_cargs {
258 char *ncd_dirp; /* Mount dir path */
259 uid_t ncd_authuid; /* Effective uid */
260 int ncd_authtype; /* Type of authenticator */
261 int ncd_authlen; /* Length of authenticator string */
262 u_char *ncd_authstr; /* Authenticator string */
263 int ncd_verflen; /* and the verifier */
264 u_char *ncd_verfstr;
265 NFSKERBKEY_T ncd_key; /* Session key */
266};
267
268/*
269 * XXX to allow amd to include nfs.h without nfsproto.h
270 */
271#ifdef NFS_NPROCS
272/*
273 * Stats structure
274 */
275struct nfsstats {
276 int attrcache_hits;
277 int attrcache_misses;
278 int lookupcache_hits;
279 int lookupcache_misses;
280 int direofcache_hits;
281 int direofcache_misses;
282 int biocache_reads;
283 int read_bios;
284 int read_physios;
285 int biocache_writes;
286 int write_bios;
287 int write_physios;
288 int biocache_readlinks;
289 int readlink_bios;
290 int biocache_readdirs;
291 int readdir_bios;
292 int rpccnt[NFS_NPROCS];
293 int rpcretries;
294 int srvrpccnt[NFS_NPROCS];
295 int srvrpc_errs;
296 int srv_errs;
297 int rpcrequests;
298 int rpctimeouts;
299 int rpcunexpected;
300 int rpcinvalid;
301 int srvcache_inproghits;
302 int srvcache_idemdonehits;
303 int srvcache_nonidemdonehits;
304 int srvcache_misses;
305 int srvnqnfs_leases;
306 int srvnqnfs_maxleases;
307 int srvnqnfs_getleases;
308 int srvvop_writes;
309};
310#endif
311
312/*
313 * Flags for nfssvc() system call.
314 */
315#define NFSSVC_BIOD 0x002
316#define NFSSVC_NFSD 0x004
317#define NFSSVC_ADDSOCK 0x008
318#define NFSSVC_AUTHIN 0x010
319#define NFSSVC_GOTAUTH 0x040
320#define NFSSVC_AUTHINFAIL 0x080
321#define NFSSVC_MNTD 0x100
322
323/*
324 * fs.nfs sysctl(3) identifiers
325 */
326#define NFS_NFSSTATS 1 /* struct: struct nfsstats */
327#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
327
328#define FS_NFS_NAMES { \
329 { 0, 0 }, \
330 { "nfsstats", CTLTYPE_STRUCT }, \
328
329#define FS_NFS_NAMES { \
330 { 0, 0 }, \
331 { "nfsstats", CTLTYPE_STRUCT }, \
332 { "nfsprivport", CTLTYPE_INT }, \
331}
332
333/*
334 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
335 * What should be in this set is open to debate, but I believe that since
336 * I/O system calls on ufs are never interrupted by signals the set should
337 * be minimal. My reasoning is that many current programs that use signals
338 * such as SIGALRM will not expect file I/O system calls to be interrupted
339 * by them and break.
340 */
341#ifdef KERNEL
342
343struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
344
345#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
346 sigmask(SIGHUP)|sigmask(SIGQUIT))
347
348/*
349 * Socket errors ignored for connectionless sockets??
350 * For now, ignore them all
351 */
352#define NFSIGNORE_SOERROR(s, e) \
353 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
354 ((s) & PR_CONNREQUIRED) == 0)
355
356/*
357 * Nfs outstanding request list element
358 */
359struct nfsreq {
360 TAILQ_ENTRY(nfsreq) r_chain;
361 struct mbuf *r_mreq;
362 struct mbuf *r_mrep;
363 struct mbuf *r_md;
364 caddr_t r_dpos;
365 struct nfsmount *r_nmp;
366 struct vnode *r_vp;
367 u_long r_xid;
368 int r_flags; /* flags on request, see below */
369 int r_retry; /* max retransmission count */
370 int r_rexmit; /* current retrans count */
371 int r_timer; /* tick counter on reply */
372 int r_procnum; /* NFS procedure number */
373 int r_rtt; /* RTT for rpc */
374 struct proc *r_procp; /* Proc that did I/O system call */
375};
376
377/*
378 * Queue head for nfsreq's
379 */
380extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
381
382/* Flag values for r_flags */
383#define R_TIMING 0x01 /* timing request (in mntp) */
384#define R_SENT 0x02 /* request has been sent */
385#define R_SOFTTERM 0x04 /* soft mnt, too many retries */
386#define R_INTR 0x08 /* intr mnt, signal pending */
387#define R_SOCKERR 0x10 /* Fatal error on socket */
388#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
389#define R_MUSTRESEND 0x40 /* Must resend request */
390#define R_GETONEREP 0x80 /* Probe for one reply only */
391
392/*
393 * A list of nfssvc_sock structures is maintained with all the sockets
394 * that require service by the nfsd.
395 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
396 * and uid hash lists.
397 */
398#ifndef NFS_UIDHASHSIZ
399#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */
400#endif
401#define NUIDHASH(sock, uid) \
402 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
403#ifndef NFS_WDELAYHASHSIZ
404#define NFS_WDELAYHASHSIZ 16 /* and with this */
405#endif
406#define NWDELAYHASH(sock, f) \
407 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
408#ifndef NFS_MUIDHASHSIZ
409#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
410#endif
411#define NMUIDHASH(nmp, uid) \
412 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
413#define NFSNOHASH(fhsum) \
414 (&nfsnodehashtbl[(fhsum) & nfsnodehash])
415
416/*
417 * Network address hash list element
418 */
419union nethostaddr {
420 u_long had_inetaddr;
421 struct mbuf *had_nam;
422};
423
424struct nfsuid {
425 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
426 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
427 int nu_flag; /* Flags */
428 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
429 struct ucred nu_cr; /* Cred uid mapped to */
430 int nu_expire; /* Expiry time (sec) */
431 struct timeval nu_timestamp; /* Kerb. timestamp */
432 u_long nu_nickname; /* Nickname on server */
433 NFSKERBKEY_T nu_key; /* and session key */
434};
435
436#define nu_inetaddr nu_haddr.had_inetaddr
437#define nu_nam nu_haddr.had_nam
438/* Bits for nu_flag */
439#define NU_INETADDR 0x1
440#define NU_NAM 0x2
441#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
442
443struct nfssvc_sock {
444 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
445 TAILQ_HEAD(, nfsuid) ns_uidlruhead;
446 struct file *ns_fp;
447 struct socket *ns_so;
448 struct mbuf *ns_nam;
449 struct mbuf *ns_raw;
450 struct mbuf *ns_rawend;
451 struct mbuf *ns_rec;
452 struct mbuf *ns_recend;
453 struct mbuf *ns_frag;
454 int ns_flag;
455 int ns_solock;
456 int ns_cc;
457 int ns_reclen;
458 int ns_numuids;
459 u_long ns_sref;
460 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */
461 LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
462 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
463};
464
465/* Bits for "ns_flag" */
466#define SLP_VALID 0x01
467#define SLP_DOREC 0x02
468#define SLP_NEEDQ 0x04
469#define SLP_DISCONN 0x08
470#define SLP_GETSTREAM 0x10
471#define SLP_LASTFRAG 0x20
472#define SLP_ALLFLAGS 0xff
473
474extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
475extern int nfssvc_sockhead_flag;
476#define SLP_INIT 0x01
477#define SLP_WANTINIT 0x02
478
479/*
480 * One of these structures is allocated for each nfsd.
481 */
482struct nfsd {
483 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */
484 int nfsd_flag; /* NFSD_ flags */
485 struct nfssvc_sock *nfsd_slp; /* Current socket */
486 int nfsd_authlen; /* Authenticator len */
487 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
488 int nfsd_verflen; /* and the Verifier */
489 u_char nfsd_verfstr[RPCVERF_MAXSIZ];
490 struct proc *nfsd_procp; /* Proc ptr */
491 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
492};
493
494/* Bits for "nfsd_flag" */
495#define NFSD_WAITING 0x01
496#define NFSD_REQINPROG 0x02
497#define NFSD_NEEDAUTH 0x04
498#define NFSD_AUTHFAIL 0x08
499
500/*
501 * This structure is used by the server for describing each request.
502 * Some fields are used only when write request gathering is performed.
503 */
504struct nfsrv_descript {
505 u_quad_t nd_time; /* Write deadline (usec) */
506 off_t nd_off; /* Start byte offset */
507 off_t nd_eoff; /* and end byte offset */
508 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
509 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
510 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
511 struct mbuf *nd_mrep; /* Request mbuf list */
512 struct mbuf *nd_md; /* Current dissect mbuf */
513 struct mbuf *nd_mreq; /* Reply mbuf list */
514 struct mbuf *nd_nam; /* and socket addr */
515 struct mbuf *nd_nam2; /* return socket addr */
516 caddr_t nd_dpos; /* Current dissect pos */
517 int nd_procnum; /* RPC # */
518 int nd_stable; /* storage type */
519 int nd_flag; /* nd_flag */
520 int nd_len; /* Length of this write */
521 int nd_repstat; /* Reply status */
522 u_long nd_retxid; /* Reply xid */
523 u_long nd_duration; /* Lease duration */
524 struct timeval nd_starttime; /* Time RPC initiated */
525 fhandle_t nd_fh; /* File handle */
526 struct ucred nd_cr; /* Credentials */
527};
528
529/* Bits for "nd_flag" */
530#define ND_READ LEASE_READ
531#define ND_WRITE LEASE_WRITE
532#define ND_CHECK 0x04
533#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK)
534#define ND_NFSV3 0x08
535#define ND_NQNFS 0x10
536#define ND_KERBNICK 0x20
537#define ND_KERBFULL 0x40
538#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
539
540extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
541extern int nfsd_head_flag;
542#define NFSD_CHECKSLP 0x01
543
544/*
545 * These macros compare nfsrv_descript structures.
546 */
547#define NFSW_CONTIG(o, n) \
548 ((o)->nd_eoff >= (n)->nd_off && \
549 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
550
551#define NFSW_SAMECRED(o, n) \
552 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
553 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
554 sizeof (struct ucred)))
555
556
557int nfs_init __P((struct vfsconf *vfsp));
558int nfs_reply __P((struct nfsreq *));
559int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
560int nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
561int nfs_rephead __P((int,struct nfsrv_descript *,struct nfssvc_sock *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
562int nfs_sndlock __P((int *,struct nfsreq *));
563void nfs_sndunlock __P((int *flagp));
564int nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
565int nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
566int nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
567int nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int *,int *));
568int nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
569int nfs_asyncio __P((struct buf *,struct ucred *));
570int nfs_doio __P((struct buf *,struct ucred *,struct proc *));
571int nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
572int nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
573int nfs_readdirplusrpc __P((struct vnode *,register struct uio *,struct ucred *));
574int nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
575void nfsm_srvfattr __P((struct nfsrv_descript *,struct vattr *,struct nfs_fattr *));
576void nfsm_srvwcc __P((struct nfsrv_descript *,int,struct vattr *,int,struct vattr *,struct mbuf **,char **));
577void nfsm_srvpostopattr __P((struct nfsrv_descript *,int,struct vattr *,struct mbuf **,char **));
578int netaddr_match __P((int,union nethostaddr *,struct mbuf *));
579int nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
580int nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
581int nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct vnode **,struct proc *,int));
582void nfsm_adj __P((struct mbuf *,int,int));
583int nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
584void nfsrv_initcache __P((void));
585int nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,char **,int *,char *,int *,NFSKERBKEY_T));
586int nfs_getnickauth __P((struct nfsmount *,struct ucred *,char **,int *,char *,int));
587int nfs_savenickauth __P((struct nfsmount *,struct ucred *,int,NFSKERBKEY_T,struct mbuf **,char **,struct mbuf *));
588int nfs_adv __P((struct mbuf **,caddr_t *,int,int));
589void nfs_nhinit __P((void));
590void nfs_timer __P((void*));
591u_long nfs_hash __P((nfsfh_t *,int));
592int nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *,struct nfsrv_descript **));
593int nfsrv_getcache __P((struct nfsrv_descript *,struct nfssvc_sock *,struct mbuf **));
594void nfsrv_updatecache __P((struct nfsrv_descript *,int,struct mbuf *));
595void nfsrv_cleancache __P((void));
596int nfs_connect __P((struct nfsmount *,struct nfsreq *));
597void nfs_disconnect __P((struct nfsmount *));
598int nfs_getattrcache __P((struct vnode *,struct vattr *));
599int nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
600int nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
601int nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
602void nfsrv_init __P((int));
603void nfs_clearcommit __P((struct mount *));
604int nfsrv_errmap __P((struct nfsrv_descript *, int));
605void nfsrvw_sort __P((gid_t [],int));
606void nfsrv_setcred __P((struct ucred *,struct ucred *));
607int nfs_writebp __P((struct buf *,int));
608int nfsrv_object_create __P(( struct vnode * ));
609void nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
610int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
611 struct proc *, struct mbuf **));
612int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
613 struct proc *p));
614
615int nfsrv3_access __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
616 struct proc *procp, struct mbuf **mrq));
617int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
618 struct proc *procp, struct mbuf **mrq));
619int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
620 struct proc *procp, struct mbuf **mrq));
621int nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,
622 struct ucred *,struct nfssvc_sock *,struct mbuf *,
623 int *,int));
624int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
625 struct proc *procp, struct mbuf **mrq));
626int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
627 struct proc *procp, struct mbuf **mrq));
628int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
629 struct proc *procp, struct mbuf **mrq));
630int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
631 struct proc *procp, struct mbuf **mrq));
632int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
633 struct proc *procp, struct mbuf **mrq));
634int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
635 struct proc *procp, struct mbuf **mrq));
636int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
637 struct proc *procp, struct mbuf **mrq));
638int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
639 struct proc *procp, struct mbuf **mrq));
640int nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
641 struct nfssvc_sock *slp, struct proc *procp,
642 struct mbuf **mrq));
643int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
644 struct proc *procp, struct mbuf **mrq));
645int nfsrv_readdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
646 struct proc *procp, struct mbuf **mrq));
647int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
648 struct nfssvc_sock *slp, struct proc *procp,
649 struct mbuf **mrq));
650int nfsrv_readlink __P((struct nfsrv_descript *nfsd,
651 struct nfssvc_sock *slp, struct proc *procp,
652 struct mbuf **mrq));
653int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
654 struct proc *procp, struct mbuf **mrq));
655int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
656 struct proc *procp, struct mbuf **mrq));
657int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
658 struct proc *procp, struct mbuf **mrq));
659int nfsrv_setattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
660 struct proc *procp, struct mbuf **mrq));
661int nfsrv_statfs __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
662 struct proc *procp, struct mbuf **mrq));
663int nfsrv_symlink __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
664 struct proc *procp, struct mbuf **mrq));
665int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
666 struct proc *procp, struct mbuf **mrq));
667void nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
668void nfsrv_slpderef __P((struct nfssvc_sock *slp));
669#endif /* KERNEL */
670
671#endif
333}
334
335/*
336 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
337 * What should be in this set is open to debate, but I believe that since
338 * I/O system calls on ufs are never interrupted by signals the set should
339 * be minimal. My reasoning is that many current programs that use signals
340 * such as SIGALRM will not expect file I/O system calls to be interrupted
341 * by them and break.
342 */
343#ifdef KERNEL
344
345struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
346
347#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
348 sigmask(SIGHUP)|sigmask(SIGQUIT))
349
350/*
351 * Socket errors ignored for connectionless sockets??
352 * For now, ignore them all
353 */
354#define NFSIGNORE_SOERROR(s, e) \
355 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
356 ((s) & PR_CONNREQUIRED) == 0)
357
358/*
359 * Nfs outstanding request list element
360 */
361struct nfsreq {
362 TAILQ_ENTRY(nfsreq) r_chain;
363 struct mbuf *r_mreq;
364 struct mbuf *r_mrep;
365 struct mbuf *r_md;
366 caddr_t r_dpos;
367 struct nfsmount *r_nmp;
368 struct vnode *r_vp;
369 u_long r_xid;
370 int r_flags; /* flags on request, see below */
371 int r_retry; /* max retransmission count */
372 int r_rexmit; /* current retrans count */
373 int r_timer; /* tick counter on reply */
374 int r_procnum; /* NFS procedure number */
375 int r_rtt; /* RTT for rpc */
376 struct proc *r_procp; /* Proc that did I/O system call */
377};
378
379/*
380 * Queue head for nfsreq's
381 */
382extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
383
384/* Flag values for r_flags */
385#define R_TIMING 0x01 /* timing request (in mntp) */
386#define R_SENT 0x02 /* request has been sent */
387#define R_SOFTTERM 0x04 /* soft mnt, too many retries */
388#define R_INTR 0x08 /* intr mnt, signal pending */
389#define R_SOCKERR 0x10 /* Fatal error on socket */
390#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
391#define R_MUSTRESEND 0x40 /* Must resend request */
392#define R_GETONEREP 0x80 /* Probe for one reply only */
393
394/*
395 * A list of nfssvc_sock structures is maintained with all the sockets
396 * that require service by the nfsd.
397 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
398 * and uid hash lists.
399 */
400#ifndef NFS_UIDHASHSIZ
401#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */
402#endif
403#define NUIDHASH(sock, uid) \
404 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
405#ifndef NFS_WDELAYHASHSIZ
406#define NFS_WDELAYHASHSIZ 16 /* and with this */
407#endif
408#define NWDELAYHASH(sock, f) \
409 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
410#ifndef NFS_MUIDHASHSIZ
411#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
412#endif
413#define NMUIDHASH(nmp, uid) \
414 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
415#define NFSNOHASH(fhsum) \
416 (&nfsnodehashtbl[(fhsum) & nfsnodehash])
417
418/*
419 * Network address hash list element
420 */
421union nethostaddr {
422 u_long had_inetaddr;
423 struct mbuf *had_nam;
424};
425
426struct nfsuid {
427 TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
428 LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
429 int nu_flag; /* Flags */
430 union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
431 struct ucred nu_cr; /* Cred uid mapped to */
432 int nu_expire; /* Expiry time (sec) */
433 struct timeval nu_timestamp; /* Kerb. timestamp */
434 u_long nu_nickname; /* Nickname on server */
435 NFSKERBKEY_T nu_key; /* and session key */
436};
437
438#define nu_inetaddr nu_haddr.had_inetaddr
439#define nu_nam nu_haddr.had_nam
440/* Bits for nu_flag */
441#define NU_INETADDR 0x1
442#define NU_NAM 0x2
443#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
444
445struct nfssvc_sock {
446 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
447 TAILQ_HEAD(, nfsuid) ns_uidlruhead;
448 struct file *ns_fp;
449 struct socket *ns_so;
450 struct mbuf *ns_nam;
451 struct mbuf *ns_raw;
452 struct mbuf *ns_rawend;
453 struct mbuf *ns_rec;
454 struct mbuf *ns_recend;
455 struct mbuf *ns_frag;
456 int ns_flag;
457 int ns_solock;
458 int ns_cc;
459 int ns_reclen;
460 int ns_numuids;
461 u_long ns_sref;
462 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */
463 LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
464 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
465};
466
467/* Bits for "ns_flag" */
468#define SLP_VALID 0x01
469#define SLP_DOREC 0x02
470#define SLP_NEEDQ 0x04
471#define SLP_DISCONN 0x08
472#define SLP_GETSTREAM 0x10
473#define SLP_LASTFRAG 0x20
474#define SLP_ALLFLAGS 0xff
475
476extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
477extern int nfssvc_sockhead_flag;
478#define SLP_INIT 0x01
479#define SLP_WANTINIT 0x02
480
481/*
482 * One of these structures is allocated for each nfsd.
483 */
484struct nfsd {
485 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */
486 int nfsd_flag; /* NFSD_ flags */
487 struct nfssvc_sock *nfsd_slp; /* Current socket */
488 int nfsd_authlen; /* Authenticator len */
489 u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
490 int nfsd_verflen; /* and the Verifier */
491 u_char nfsd_verfstr[RPCVERF_MAXSIZ];
492 struct proc *nfsd_procp; /* Proc ptr */
493 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
494};
495
496/* Bits for "nfsd_flag" */
497#define NFSD_WAITING 0x01
498#define NFSD_REQINPROG 0x02
499#define NFSD_NEEDAUTH 0x04
500#define NFSD_AUTHFAIL 0x08
501
502/*
503 * This structure is used by the server for describing each request.
504 * Some fields are used only when write request gathering is performed.
505 */
506struct nfsrv_descript {
507 u_quad_t nd_time; /* Write deadline (usec) */
508 off_t nd_off; /* Start byte offset */
509 off_t nd_eoff; /* and end byte offset */
510 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
511 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
512 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
513 struct mbuf *nd_mrep; /* Request mbuf list */
514 struct mbuf *nd_md; /* Current dissect mbuf */
515 struct mbuf *nd_mreq; /* Reply mbuf list */
516 struct mbuf *nd_nam; /* and socket addr */
517 struct mbuf *nd_nam2; /* return socket addr */
518 caddr_t nd_dpos; /* Current dissect pos */
519 int nd_procnum; /* RPC # */
520 int nd_stable; /* storage type */
521 int nd_flag; /* nd_flag */
522 int nd_len; /* Length of this write */
523 int nd_repstat; /* Reply status */
524 u_long nd_retxid; /* Reply xid */
525 u_long nd_duration; /* Lease duration */
526 struct timeval nd_starttime; /* Time RPC initiated */
527 fhandle_t nd_fh; /* File handle */
528 struct ucred nd_cr; /* Credentials */
529};
530
531/* Bits for "nd_flag" */
532#define ND_READ LEASE_READ
533#define ND_WRITE LEASE_WRITE
534#define ND_CHECK 0x04
535#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK)
536#define ND_NFSV3 0x08
537#define ND_NQNFS 0x10
538#define ND_KERBNICK 0x20
539#define ND_KERBFULL 0x40
540#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
541
542extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
543extern int nfsd_head_flag;
544#define NFSD_CHECKSLP 0x01
545
546/*
547 * These macros compare nfsrv_descript structures.
548 */
549#define NFSW_CONTIG(o, n) \
550 ((o)->nd_eoff >= (n)->nd_off && \
551 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
552
553#define NFSW_SAMECRED(o, n) \
554 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
555 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
556 sizeof (struct ucred)))
557
558
559int nfs_init __P((struct vfsconf *vfsp));
560int nfs_reply __P((struct nfsreq *));
561int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
562int nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
563int nfs_rephead __P((int,struct nfsrv_descript *,struct nfssvc_sock *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
564int nfs_sndlock __P((int *,struct nfsreq *));
565void nfs_sndunlock __P((int *flagp));
566int nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
567int nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
568int nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
569int nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int *,int *));
570int nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
571int nfs_asyncio __P((struct buf *,struct ucred *));
572int nfs_doio __P((struct buf *,struct ucred *,struct proc *));
573int nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
574int nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
575int nfs_readdirplusrpc __P((struct vnode *,register struct uio *,struct ucred *));
576int nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
577void nfsm_srvfattr __P((struct nfsrv_descript *,struct vattr *,struct nfs_fattr *));
578void nfsm_srvwcc __P((struct nfsrv_descript *,int,struct vattr *,int,struct vattr *,struct mbuf **,char **));
579void nfsm_srvpostopattr __P((struct nfsrv_descript *,int,struct vattr *,struct mbuf **,char **));
580int netaddr_match __P((int,union nethostaddr *,struct mbuf *));
581int nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
582int nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
583int nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct vnode **,struct proc *,int));
584void nfsm_adj __P((struct mbuf *,int,int));
585int nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
586void nfsrv_initcache __P((void));
587int nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,char **,int *,char *,int *,NFSKERBKEY_T));
588int nfs_getnickauth __P((struct nfsmount *,struct ucred *,char **,int *,char *,int));
589int nfs_savenickauth __P((struct nfsmount *,struct ucred *,int,NFSKERBKEY_T,struct mbuf **,char **,struct mbuf *));
590int nfs_adv __P((struct mbuf **,caddr_t *,int,int));
591void nfs_nhinit __P((void));
592void nfs_timer __P((void*));
593u_long nfs_hash __P((nfsfh_t *,int));
594int nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *,struct nfsrv_descript **));
595int nfsrv_getcache __P((struct nfsrv_descript *,struct nfssvc_sock *,struct mbuf **));
596void nfsrv_updatecache __P((struct nfsrv_descript *,int,struct mbuf *));
597void nfsrv_cleancache __P((void));
598int nfs_connect __P((struct nfsmount *,struct nfsreq *));
599void nfs_disconnect __P((struct nfsmount *));
600int nfs_getattrcache __P((struct vnode *,struct vattr *));
601int nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
602int nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
603int nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
604void nfsrv_init __P((int));
605void nfs_clearcommit __P((struct mount *));
606int nfsrv_errmap __P((struct nfsrv_descript *, int));
607void nfsrvw_sort __P((gid_t [],int));
608void nfsrv_setcred __P((struct ucred *,struct ucred *));
609int nfs_writebp __P((struct buf *,int));
610int nfsrv_object_create __P(( struct vnode * ));
611void nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
612int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
613 struct proc *, struct mbuf **));
614int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
615 struct proc *p));
616
617int nfsrv3_access __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
618 struct proc *procp, struct mbuf **mrq));
619int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
620 struct proc *procp, struct mbuf **mrq));
621int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
622 struct proc *procp, struct mbuf **mrq));
623int nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,
624 struct ucred *,struct nfssvc_sock *,struct mbuf *,
625 int *,int));
626int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
627 struct proc *procp, struct mbuf **mrq));
628int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
629 struct proc *procp, struct mbuf **mrq));
630int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
631 struct proc *procp, struct mbuf **mrq));
632int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
633 struct proc *procp, struct mbuf **mrq));
634int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
635 struct proc *procp, struct mbuf **mrq));
636int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
637 struct proc *procp, struct mbuf **mrq));
638int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
639 struct proc *procp, struct mbuf **mrq));
640int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
641 struct proc *procp, struct mbuf **mrq));
642int nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
643 struct nfssvc_sock *slp, struct proc *procp,
644 struct mbuf **mrq));
645int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
646 struct proc *procp, struct mbuf **mrq));
647int nfsrv_readdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
648 struct proc *procp, struct mbuf **mrq));
649int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
650 struct nfssvc_sock *slp, struct proc *procp,
651 struct mbuf **mrq));
652int nfsrv_readlink __P((struct nfsrv_descript *nfsd,
653 struct nfssvc_sock *slp, struct proc *procp,
654 struct mbuf **mrq));
655int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
656 struct proc *procp, struct mbuf **mrq));
657int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
658 struct proc *procp, struct mbuf **mrq));
659int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
660 struct proc *procp, struct mbuf **mrq));
661int nfsrv_setattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
662 struct proc *procp, struct mbuf **mrq));
663int nfsrv_statfs __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
664 struct proc *procp, struct mbuf **mrq));
665int nfsrv_symlink __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
666 struct proc *procp, struct mbuf **mrq));
667int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
668 struct proc *procp, struct mbuf **mrq));
669void nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
670void nfsrv_slpderef __P((struct nfssvc_sock *slp));
671#endif /* KERNEL */
672
673#endif