1/* $NetBSD: nfs_var.h,v 1.94 2015/07/15 03:28:55 manu Exp $ */
2
3/*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * XXX needs <nfs/rpcv2.h> and <nfs/nfs.h> because of typedefs
34 */
35
36#ifdef _KERNEL
37#include <sys/mallocvar.h>
38#include <sys/pool.h>
39
40struct vnode;
41struct uio;
42struct proc;
43struct buf;
44struct nfs_diskless;
45struct sockaddr_in;
46struct nfs_dlmount;
47struct vnode;
48struct nfsd;
49struct mbuf;
50struct file;
51struct nfssvc_sock;
52struct nfsmount;
53struct socket;
54struct nfsreq;
55struct vattr;
56struct nameidata;
57struct nfsnode;
58struct sillyrename;
59struct componentname;
60struct nfsd_srvargs;
61struct nfsrv_descript;
62struct nfs_fattr;
63struct nfsdircache;
64union nethostaddr;
65
66/* nfs_bio.c */
67int nfs_bioread(struct vnode *, struct uio *, int, kauth_cred_t, int);
68struct buf *nfs_getcacheblk(struct vnode *, daddr_t, int, struct lwp *);
69int nfs_vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, int);
70int nfs_flushstalebuf(struct vnode *, kauth_cred_t, struct lwp *, int);
71#define NFS_FLUSHSTALEBUF_MYWRITE 1 /* assume writes are ours */
72int nfs_asyncio(struct buf *);
73int nfs_doio(struct buf *);
74
75/* nfs_boot.c */
76/* see nfsdiskless.h */
77
78/* nfs_kq.c */
79void nfs_kqinit(void);
80void nfs_kqfini(void);
81
82/* nfs_node.c */
83void nfs_node_init(void);
84void nfs_node_done(void);
85
86int nfs_nget1(struct mount *, nfsfh_t *, int, struct nfsnode **, int);
87#define nfs_nget(mp, fhp, fhsize, npp) \
88 nfs_nget1((mp), (fhp), (fhsize), (npp), 0)
89
90/* nfs_vnops.c */
91int nfs_null(struct vnode *, kauth_cred_t, struct lwp *);
92int nfs_setattrrpc(struct vnode *, struct vattr *, kauth_cred_t, struct lwp *);
93int nfs_readlinkrpc(struct vnode *, struct uio *, kauth_cred_t);
94int nfs_readrpc(struct vnode *, struct uio *);
95int nfs_writerpc(struct vnode *, struct uio *, int *, bool, bool *);
96int nfs_mknodrpc(struct vnode *, struct vnode **, struct componentname *,
97 struct vattr *);
98int nfs_removeit(struct sillyrename *);
99int nfs_removerpc(struct vnode *, const char *, int, kauth_cred_t,
100 struct lwp *);
101int nfs_renameit(struct vnode *, struct componentname *, struct sillyrename *);
102int nfs_renamerpc(struct vnode *, const char *, int, struct vnode *,
103 const char *, int, kauth_cred_t, struct lwp *);
104int nfs_readdirrpc(struct vnode *, struct uio *, kauth_cred_t);
105int nfs_readdirplusrpc(struct vnode *, struct uio *, kauth_cred_t);
106int nfs_sillyrename(struct vnode *, struct vnode *, struct componentname *,
107 bool);
108int nfs_lookitup(struct vnode *, const char *, int, kauth_cred_t,
109 struct lwp *, struct nfsnode **);
110int nfs_commit(struct vnode *, off_t, uint32_t, struct lwp *);
111int nfs_flush(struct vnode *, kauth_cred_t, int, struct lwp *, int);
112
113/* nfs_serv.c */
114int nfsrv3_access(struct nfsrv_descript *, struct nfssvc_sock *,
115 struct lwp *, struct mbuf **);
116int nfsrv_getattr(struct nfsrv_descript *, struct nfssvc_sock *,
117 struct lwp *, struct mbuf **);
118int nfsrv_setattr(struct nfsrv_descript *, struct nfssvc_sock *,
119 struct lwp *, struct mbuf **);
120int nfsrv_lookup(struct nfsrv_descript *, struct nfssvc_sock *,
121 struct lwp *, struct mbuf **);
122int nfsrv_readlink(struct nfsrv_descript *, struct nfssvc_sock *,
123 struct lwp *, struct mbuf **);
124int nfsrv_read(struct nfsrv_descript *, struct nfssvc_sock *,
125 struct lwp *, struct mbuf **);
126int nfsrv_write(struct nfsrv_descript *, struct nfssvc_sock *,
127 struct lwp *, struct mbuf **);
128int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
129 struct lwp *, struct mbuf **);
130void nfsrvw_coalesce(struct nfsrv_descript *, struct nfsrv_descript *);
131int nfsrv_create(struct nfsrv_descript *, struct nfssvc_sock *,
132 struct lwp *, struct mbuf **);
133int nfsrv_mknod(struct nfsrv_descript *, struct nfssvc_sock *,
134 struct lwp *, struct mbuf **);
135int nfsrv_remove(struct nfsrv_descript *, struct nfssvc_sock *,
136 struct lwp *, struct mbuf **);
137int nfsrv_rename(struct nfsrv_descript *, struct nfssvc_sock *,
138 struct lwp *, struct mbuf **);
139int nfsrv_link(struct nfsrv_descript *, struct nfssvc_sock *,
140 struct lwp *, struct mbuf **);
141int nfsrv_symlink(struct nfsrv_descript *, struct nfssvc_sock *,
142 struct lwp *, struct mbuf **);
143int nfsrv_mkdir(struct nfsrv_descript *, struct nfssvc_sock *,
144 struct lwp *, struct mbuf **);
145int nfsrv_rmdir(struct nfsrv_descript *, struct nfssvc_sock *,
146 struct lwp *, struct mbuf **);
147int nfsrv_readdir(struct nfsrv_descript *, struct nfssvc_sock *,
148 struct lwp *, struct mbuf **);
149int nfsrv_readdirplus(struct nfsrv_descript *, struct nfssvc_sock *,
150 struct lwp *, struct mbuf **);
151int nfsrv_commit(struct nfsrv_descript *, struct nfssvc_sock *,
152 struct lwp *, struct mbuf **);
153int nfsrv_statfs(struct nfsrv_descript *, struct nfssvc_sock *,
154 struct lwp *, struct mbuf **);
155int nfsrv_fsinfo(struct nfsrv_descript *, struct nfssvc_sock *,
156 struct lwp *, struct mbuf **);
157int nfsrv_pathconf(struct nfsrv_descript *, struct nfssvc_sock *,
158 struct lwp *, struct mbuf **);
159int nfsrv_null(struct nfsrv_descript *, struct nfssvc_sock *,
160 struct lwp *, struct mbuf **);
161int nfsrv_noop(struct nfsrv_descript *, struct nfssvc_sock *,
162 struct lwp *, struct mbuf **);
163int nfsrv_access(struct vnode *, int, kauth_cred_t, int, struct lwp *, int);
164
165/* nfs_socket.c */
166int nfs_connect(struct nfsmount *, struct nfsreq *, struct lwp *);
167int nfs_reconnect(struct nfsreq *);
168void nfs_disconnect(struct nfsmount *);
169void nfs_safedisconnect(struct nfsmount *);
170int nfs_send(struct socket *, struct mbuf *, struct mbuf *, struct nfsreq *,
171 struct lwp *);
172int nfs_request(struct nfsnode *, struct mbuf *, int, struct lwp *,
173 kauth_cred_t, struct mbuf **, struct mbuf **, char **, int *);
174int nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
175 int, int, u_quad_t *, struct mbuf **, struct mbuf **, char **);
176void nfs_timer(void *);
177void nfs_timer_init(void);
178void nfs_timer_fini(void);
179void nfs_timer_start(void);
180void nfs_timer_srvinit(bool (*)(void));
181void nfs_timer_srvfini(void);
182int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct lwp *);
183int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
184int nfs_msg(struct lwp *, const char *, const char *);
185void nfsrv_soupcall(struct socket *, void *, int, int);
186void nfsrv_rcv(struct nfssvc_sock *);
187int nfsrv_getstream(struct nfssvc_sock *, int);
188int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **,
189 bool *);
190void nfsrv_wakenfsd(struct nfssvc_sock *);
191int nfsdsock_lock(struct nfssvc_sock *, bool);
192void nfsdsock_unlock(struct nfssvc_sock *);
193int nfsdsock_drain(struct nfssvc_sock *);
194int nfsdsock_sendreply(struct nfssvc_sock *, struct nfsrv_descript *);
195void nfsdreq_init(void);
196void nfsdreq_fini(void);
197struct nfsrv_descript *nfsdreq_alloc(void);
198void nfsdreq_free(struct nfsrv_descript *);
199bool nfsrv_timer(void);
200int nfs_rcvlock(struct nfsmount *, struct nfsreq *);
201void nfs_rcvunlock(struct nfsmount *);
202
203void nfsdsock_setbits(struct nfssvc_sock *, int);
204void nfsdsock_clearbits(struct nfssvc_sock *, int);
205bool nfsdsock_testbits(struct nfssvc_sock *, int);
206
207/*
208 * Estimate rto for an nfs rpc sent via. an unreliable datagram.
209 * Use the mean and mean deviation of rtt for the appropriate type of rpc
210 * for the frequent rpcs and a default for the others.
211 * The justification for doing "other" this way is that these rpcs
212 * happen so infrequently that timer est. would probably be stale.
213 * Also, since many of these rpcs are
214 * non-idempotent, a conservative timeout is desired.
215 * getattr, lookup - A+2D
216 * read, write - A+4D
217 * other - nm_timeo
218 */
219#define NFS_RTO(n, t) \
220 ((t) == 0 ? (n)->nm_timeo : \
221 ((t) < 3 ? \
222 (((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
223 ((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
224#define NFS_SRTT(r) (r)->r_nmp->nm_srtt[nfs_proct[(r)->r_procnum] - 1]
225#define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[nfs_proct[(r)->r_procnum] - 1]
226
227extern int nfsrtton;
228extern struct nfsrtt nfsrtt;
229extern const int nfs_proct[];
230
231extern const struct timeval nfs_err_interval;
232extern struct timeval nfs_reply_last_err_time;
233extern struct timeval nfs_timer_last_err_time;
234
235
236/* nfs_srvcache.c */
237void nfsrv_initcache(void);
238void nfsrv_finicache(void);
239int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
240 struct mbuf **);
241void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
242void nfsrv_cleancache(void);
243
244/* nfs_subs.c */
245struct mbuf *nfsm_reqh(struct nfsnode *, u_long, int, char **);
246struct mbuf *nfsm_rpchead(kauth_cred_t, int, int, int, int, char *, int,
247 char *, struct mbuf *, int, struct mbuf **, u_int32_t *);
248int nfsm_mbuftouio(struct mbuf **, struct uio *, int, char **);
249int nfsm_uiotombuf(struct uio *, struct mbuf **, int, char **);
250int nfsm_disct(struct mbuf **, char **, int, int, char **);
251int nfs_adv(struct mbuf **, char **, int, int);
252int nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
253u_long nfs_dirhash(off_t);
254void nfs_initdircache(struct vnode *);
255void nfs_initdirxlatecookie(struct vnode *);
256struct nfsdircache *nfs_searchdircache(struct vnode *, off_t, int, int *);
257struct nfsdircache *nfs_enterdircache(struct vnode *, off_t, off_t, int,
258 daddr_t);
259void nfs_putdircache(struct nfsnode *, struct nfsdircache *);
260void nfs_invaldircache(struct vnode *, int);
261#define NFS_INVALDIRCACHE_FORCE 1
262#define NFS_INVALDIRCACHE_KEEPEOF 2
263void nfs_init(void);
264void nfs_fini(void);
265int nfsm_loadattrcache(struct vnode **, struct mbuf **, char **,
266 struct vattr *, int flags);
267int nfs_loadattrcache(struct vnode **, struct nfs_fattr *, struct vattr *,
268 int flags);
269int nfs_getattrcache(struct vnode *, struct vattr *);
270void nfs_delayedtruncate(struct vnode *);
271int nfs_check_wccdata(struct nfsnode *, const struct timespec *,
272 struct timespec *, bool);
273int nfs_namei(struct nameidata *, nfsrvfh_t *, uint32_t, struct nfssvc_sock *,
274 struct mbuf *, struct mbuf **, char **, struct vnode **, struct lwp *,
275 int, int);
276void nfs_zeropad(struct mbuf *, int, int);
277void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
278 struct vattr *, struct mbuf **, char **);
279void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
280 struct mbuf **, char **);
281void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, struct nfs_fattr *);
282int nfsrv_fhtovp(nfsrvfh_t *, int, struct vnode **, kauth_cred_t,
283 struct nfssvc_sock *, struct mbuf *, int *, int, int);
284int nfs_ispublicfh(const nfsrvfh_t *);
285int netaddr_match(int, union nethostaddr *, struct mbuf *);
286time_t nfs_attrtimeo(struct nfsmount *, struct nfsnode *);
287
288/* flags for nfs_loadattrcache and friends */
289#define NAC_NOTRUNC 1 /* don't truncate file size */
290
291void nfs_clearcommit(struct mount *);
292void nfs_merge_commit_ranges(struct vnode *);
293int nfs_in_committed_range(struct vnode *, off_t, off_t);
294int nfs_in_tobecommitted_range(struct vnode *, off_t, off_t);
295void nfs_add_committed_range(struct vnode *, off_t, off_t);
296void nfs_del_committed_range(struct vnode *, off_t, off_t);
297void nfs_add_tobecommitted_range(struct vnode *, off_t, off_t);
298void nfs_del_tobecommitted_range(struct vnode *, off_t, off_t);
299
300int nfsrv_errmap(struct nfsrv_descript *, int);
301void nfs_cookieheuristic(struct vnode *, int *, struct lwp *, kauth_cred_t);
302
303u_int32_t nfs_getxid(void);
304void nfs_renewxid(struct nfsreq *);
305
306int nfsrv_composefh(struct vnode *, nfsrvfh_t *, bool);
307int nfsrv_comparefh(const nfsrvfh_t *, const nfsrvfh_t *);
308void nfsrv_copyfh(nfsrvfh_t *, const nfsrvfh_t *);
309
310extern const enum vtype nv2tov_type[8];
311extern const enum vtype nv3tov_type[8];
312
313extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers,
314 rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr,
315 rpc_auth_kerb;
316extern u_int32_t nfs_prog;
317extern const int nfsv3_procid[NFS_NPROCS];
318extern int nfs_ticks;
319
320/* nfs_syscalls.c */
321struct sys_getfh_args;
322struct sys_nfssvc_args;
323int sys_getfh(struct lwp *, const struct sys_getfh_args *, register_t *);
324int sys_nfssvc(struct lwp *, const struct sys_nfssvc_args *, register_t *);
325int nfssvc_addsock(struct file *, struct mbuf *);
326void nfsrv_zapsock(struct nfssvc_sock *);
327void nfsrv_slpderef(struct nfssvc_sock *);
328void nfsrv_init(int);
329void nfsrv_fini(void);
330void nfs_iodinit(void);
331void nfs_iodfini(void);
332int nfs_iodbusy(struct nfsmount *);
333int nfs_set_niothreads(int);
334int nfs_getauth(struct nfsmount *, struct nfsreq *, kauth_cred_t, char **,
335 int *, char *, int *, NFSKERBKEY_T);
336int nfs_getnickauth(struct nfsmount *, kauth_cred_t, char **, int *, char *,
337 int);
338int nfs_savenickauth(struct nfsmount *, kauth_cred_t, int, NFSKERBKEY_T,
339 struct mbuf **, char **, struct mbuf *);
340/*
341 * Backend copyin/out functions for nfssvc(2), so that netbsd32 can
342 * easily access NFS. Each operation either must perform a copyin or
343 * copyout of the right data for the emulation. exp_in() takes a count
344 * of the number of export_args to copyin, and order arguments for
345 * func(dst, src).
346 */
347struct nfssvc_copy_ops {
348 int (*addsock_in)(struct nfsd_args *, const void *);
349 int (*setexports_in)(struct mountd_exports_list *, const void *);
350 int (*nsd_in)(struct nfsd_srvargs *, const void *);
351 int (*nsd_out)(void *, const struct nfsd_srvargs *);
352 int (*exp_in)(struct export_args *, const void *, size_t);
353};
354int do_nfssvc(struct nfssvc_copy_ops *, struct lwp *, int, void *, register_t *);
355
356/* nfs_export.c */
357extern struct nfs_public nfs_pub;
358int mountd_set_exports_list(const struct mountd_exports_list *, struct lwp *,
359 struct mount *);
360int netexport_check(const fsid_t *, struct mbuf *, struct mount **, int *,
361 kauth_cred_t *);
362void netexport_rdlock(void);
363void netexport_rdunlock(void);
364void netexport_init(void);
365void netexport_fini(void);
366bool netexport_hasexports(void);
367#endif /* _KERNEL */
368