xref: /netbsd-src/sys/nfs/nfs_var.h (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: nfs_var.h,v 1.58 2006/01/05 11:22:56 yamt 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * XXX needs <nfs/rpcv2.h> and <nfs/nfs.h> because of typedefs
41  */
42 
43 #ifdef _KERNEL
44 #include <sys/mallocvar.h>
45 #include <sys/pool.h>
46 
47 MALLOC_DECLARE(M_NFSREQ);
48 MALLOC_DECLARE(M_NFSMNT);
49 MALLOC_DECLARE(M_NFSUID);
50 MALLOC_DECLARE(M_NFSD);
51 MALLOC_DECLARE(M_NFSDIROFF);
52 MALLOC_DECLARE(M_NFSBIGFH);
53 MALLOC_DECLARE(M_NQLEASE);
54 extern struct pool nfs_srvdesc_pool;
55 
56 struct vnode;
57 struct uio;
58 struct ucred;
59 struct proc;
60 struct buf;
61 struct nfs_diskless;
62 struct sockaddr_in;
63 struct nfs_dlmount;
64 struct vnode;
65 struct nfsd;
66 struct mbuf;
67 struct file;
68 struct nqlease;
69 struct nqhost;
70 struct nfssvc_sock;
71 struct nfsmount;
72 struct socket;
73 struct nfsreq;
74 struct vattr;
75 struct nameidata;
76 struct nfsnode;
77 struct sillyrename;
78 struct componentname;
79 struct nfsd_srvargs;
80 struct nfsrv_descript;
81 struct nfs_fattr;
82 struct nfsdircache;
83 union nethostaddr;
84 
85 /* nfs_bio.c */
86 int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *, int);
87 struct buf *nfs_getcacheblk(struct vnode *, daddr_t, int, struct lwp *);
88 int nfs_vinvalbuf(struct vnode *, int, struct ucred *, struct lwp *, int);
89 int nfs_flushstalebuf(struct vnode *, struct ucred *, struct lwp *, int);
90 #define	NFS_FLUSHSTALEBUF_MYWRITE	1	/* assume writes are ours */
91 int nfs_asyncio(struct buf *);
92 int nfs_doio(struct buf *);
93 
94 /* nfs_boot.c */
95 /* see nfsdiskless.h */
96 
97 /* nfs_kq.c */
98 void nfs_kqinit(void);
99 
100 /* nfs_node.c */
101 void nfs_nhinit(void);
102 void nfs_nhreinit(void);
103 void nfs_nhdone(void);
104 int nfs_nget1(struct mount *, nfsfh_t *, int, struct nfsnode **, int);
105 #define	nfs_nget(mp, fhp, fhsize, npp) \
106 	nfs_nget1((mp), (fhp), (fhsize), (npp), 0)
107 
108 /* nfs_vnops.c */
109 int nfs_null(struct vnode *, struct ucred *, struct lwp *);
110 int nfs_setattrrpc(struct vnode *, struct vattr *, struct ucred *,
111 	struct lwp *);
112 int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
113 int nfs_readrpc(struct vnode *, struct uio *);
114 int nfs_writerpc(struct vnode *, struct uio *, int *, boolean_t, boolean_t *);
115 int nfs_mknodrpc(struct vnode *, struct vnode **, struct componentname *,
116 	struct vattr *);
117 int nfs_removeit(struct sillyrename *);
118 int nfs_removerpc(struct vnode *, const char *, int, struct ucred *,
119 	struct lwp *);
120 int nfs_renameit(struct vnode *, struct componentname *, struct sillyrename *);
121 int nfs_renamerpc(struct vnode *, const char *, int, struct vnode *,
122 	const char *, int, struct ucred *, struct lwp *);
123 int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
124 int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
125 int nfs_sillyrename(struct vnode *, struct vnode *, struct componentname *);
126 int nfs_lookitup(struct vnode *, const char *, int, struct ucred *,
127 	struct lwp *, struct nfsnode **);
128 int nfs_commit(struct vnode *, off_t, uint32_t, struct lwp *);
129 int nfs_flush(struct vnode *, struct ucred *, int, struct lwp *, int);
130 
131 /* nfs_nqlease.c */
132 void nqnfs_lease_updatetime(int);
133 void nqnfs_clientlease(struct nfsmount *, struct nfsnode *, int, int, time_t,
134 	u_quad_t);
135 void nqsrv_locklease(struct nqlease *);
136 void nqsrv_unlocklease(struct nqlease *);
137 int nqsrv_getlease(struct vnode *, u_int32_t *, int, struct nfssvc_sock *,
138 	struct lwp *, struct mbuf *, int *, u_quad_t *, struct ucred *);
139 void nqsrv_addhost(struct nqhost *, struct nfssvc_sock *, struct mbuf *);
140 void nqsrv_instimeq(struct nqlease *, u_int32_t);
141 int nqsrv_cmpnam(struct nfssvc_sock *, struct mbuf *, struct nqhost *);
142 void nqsrv_send_eviction(struct vnode *, struct nqlease *,
143 	struct nfssvc_sock *, struct mbuf *, struct ucred *, struct lwp *);
144 void nqsrv_waitfor_expiry(struct nqlease *);
145 void nqnfs_serverd(void);
146 int nqnfsrv_getlease(struct nfsrv_descript *, struct nfssvc_sock *,
147 	struct lwp *, struct mbuf **);
148 int nqnfsrv_vacated(struct nfsrv_descript *, struct nfssvc_sock *,
149 	struct lwp *, struct mbuf **);
150 int nqnfs_getlease(struct vnode *, int, struct ucred *, struct lwp *);
151 int nqnfs_vacated(struct vnode *, struct ucred *, struct lwp *);
152 int nqnfs_callback(struct nfsmount *, struct mbuf *, struct mbuf *,
153 	caddr_t, struct lwp *);
154 
155 /* nfs_serv.c */
156 int nfsrv3_access(struct nfsrv_descript *, struct nfssvc_sock *,
157 	struct lwp *, struct mbuf **);
158 int nfsrv_getattr(struct nfsrv_descript *, struct nfssvc_sock *,
159 	struct lwp *, struct mbuf **);
160 int nfsrv_setattr(struct nfsrv_descript *, struct nfssvc_sock *,
161 	struct lwp *, struct mbuf **);
162 int nfsrv_lookup(struct nfsrv_descript *, struct nfssvc_sock *,
163 	struct lwp *, struct mbuf **);
164 int nfsrv_readlink(struct nfsrv_descript *, struct nfssvc_sock *,
165 	struct lwp *, struct mbuf **);
166 int nfsrv_read(struct nfsrv_descript *, struct nfssvc_sock *,
167 	struct lwp *, struct mbuf **);
168 int nfsrv_write(struct nfsrv_descript *, struct nfssvc_sock *,
169 	struct lwp *, struct mbuf **);
170 int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
171 	struct lwp *, struct mbuf **);
172 void nfsrvw_coalesce(struct nfsrv_descript *, struct nfsrv_descript *);
173 int nfsrv_create(struct nfsrv_descript *, struct nfssvc_sock *,
174 	struct lwp *, struct mbuf **);
175 int nfsrv_mknod(struct nfsrv_descript *, struct nfssvc_sock *,
176 	struct lwp *, struct mbuf **);
177 int nfsrv_remove(struct nfsrv_descript *, struct nfssvc_sock *,
178 	struct lwp *, struct mbuf **);
179 int nfsrv_rename(struct nfsrv_descript *, struct nfssvc_sock *,
180 	struct lwp *, struct mbuf **);
181 int nfsrv_link(struct nfsrv_descript *, struct nfssvc_sock *,
182 	struct lwp *, struct mbuf **);
183 int nfsrv_symlink(struct nfsrv_descript *, struct nfssvc_sock *,
184 	struct lwp *, struct mbuf **);
185 int nfsrv_mkdir(struct nfsrv_descript *, struct nfssvc_sock *,
186 	struct lwp *, struct mbuf **);
187 int nfsrv_rmdir(struct nfsrv_descript *, struct nfssvc_sock *,
188 	struct lwp *, struct mbuf **);
189 int nfsrv_readdir(struct nfsrv_descript *, struct nfssvc_sock *,
190 	struct lwp *, struct mbuf **);
191 int nfsrv_readdirplus(struct nfsrv_descript *, struct nfssvc_sock *,
192 	struct lwp *, struct mbuf **);
193 int nfsrv_commit(struct nfsrv_descript *, struct nfssvc_sock *,
194 	struct lwp *, struct mbuf **);
195 int nfsrv_statfs(struct nfsrv_descript *, struct nfssvc_sock *,
196 	struct lwp *, struct mbuf **);
197 int nfsrv_fsinfo(struct nfsrv_descript *, struct nfssvc_sock *,
198 	struct lwp *, struct mbuf **);
199 int nfsrv_pathconf(struct nfsrv_descript *, struct nfssvc_sock *,
200 	struct lwp *, struct mbuf **);
201 int nfsrv_null(struct nfsrv_descript *, struct nfssvc_sock *,
202 	struct lwp *, struct mbuf **);
203 int nfsrv_noop(struct nfsrv_descript *, struct nfssvc_sock *,
204 	struct lwp *, struct mbuf **);
205 int nfsrv_access(struct vnode *, int, struct ucred *, int, struct lwp *, int);
206 
207 /* nfs_socket.c */
208 int nfs_connect(struct nfsmount *, struct nfsreq *, struct lwp *);
209 int nfs_reconnect(struct nfsreq *, struct lwp *);
210 void nfs_disconnect(struct nfsmount *);
211 void nfs_safedisconnect(struct nfsmount *);
212 int nfs_send(struct socket *, struct mbuf *, struct mbuf *, struct nfsreq *,
213 	struct lwp *);
214 int nfs_receive(struct nfsreq *, struct mbuf **, struct mbuf **, struct lwp *);
215 int nfs_reply(struct nfsreq *, struct lwp *);
216 int nfs_request(struct nfsnode *, struct mbuf *, int, struct lwp *,
217 	struct ucred *, struct mbuf **, struct mbuf **, caddr_t *, int *);
218 int nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
219 	int, int, u_quad_t *, struct mbuf **, struct mbuf **, caddr_t *);
220 void nfs_timer(void *);
221 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct lwp *);
222 int nfs_sndlock(int *, struct nfsreq *);
223 void nfs_exit(struct proc *, void *);
224 void nfs_sndunlock(int *);
225 int nfs_rcvlock(struct nfsreq *);
226 void nfs_rcvunlock(struct nfsmount *);
227 int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
228 int nfs_msg(struct lwp *, const char *, const char *);
229 void nfsrv_rcv(struct socket *, caddr_t, int);
230 int nfsrv_getstream(struct nfssvc_sock *, int);
231 int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **);
232 void nfsrv_wakenfsd(struct nfssvc_sock *);
233 int nfsdsock_lock(struct nfssvc_sock *, boolean_t);
234 void nfsdsock_unlock(struct nfssvc_sock *);
235 int nfsdsock_drain(struct nfssvc_sock *);
236 int nfsdsock_sendreply(struct nfssvc_sock *, struct nfsrv_descript *);
237 
238 /* nfs_srvcache.c */
239 void nfsrv_initcache(void);
240 int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
241 	struct mbuf **);
242 void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
243 void nfsrv_cleancache(void);
244 
245 /* nfs_subs.c */
246 struct mbuf *nfsm_reqh(struct nfsnode *, u_long, int, caddr_t *);
247 struct mbuf *nfsm_rpchead(struct ucred *, int, int, int, int, char *, int,
248 	char *, struct mbuf *, int, struct mbuf **, u_int32_t *);
249 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
250 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
251 int nfsm_disct(struct mbuf **, caddr_t *, int, int, caddr_t *);
252 int nfs_adv(struct mbuf **, caddr_t *, int, int);
253 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
254 u_long nfs_dirhash(off_t);
255 void nfs_initdircache(struct vnode *);
256 void nfs_initdirxlatecookie(struct vnode *);
257 struct nfsdircache *nfs_searchdircache(struct vnode *, off_t, int, int *);
258 struct nfsdircache *nfs_enterdircache(struct vnode *, off_t, off_t, int,
259 	daddr_t);
260 void nfs_putdircache(struct nfsnode *, struct nfsdircache *);
261 void nfs_invaldircache(struct vnode *, int);
262 #define	NFS_INVALDIRCACHE_FORCE		1
263 #define	NFS_INVALDIRCACHE_KEEPEOF	2
264 void nfs_init __P((void));
265 int nfsm_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
266 	struct vattr *, int flags);
267 int nfs_loadattrcache(struct vnode **, struct nfs_fattr *, struct vattr *,
268 	int flags);
269 int nfs_getattrcache(struct vnode *, struct vattr *);
270 void nfs_delayedtruncate(struct vnode *);
271 int nfs_check_wccdata(struct nfsnode *, const struct timespec *,
272 	struct timespec *, boolean_t);
273 int nfs_namei(struct nameidata *, fhandle_t *, uint32_t, struct nfssvc_sock *,
274 	struct mbuf *, struct mbuf **, caddr_t *, struct vnode **, struct lwp *,
275 	int, int);
276 void nfs_zeropad(struct mbuf *, int, int);
277 void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
278 	struct vattr *, struct mbuf **, char **);
279 void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
280 	struct mbuf **, char **);
281 void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, struct nfs_fattr *);
282 int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, struct ucred *,
283 	struct nfssvc_sock *, struct mbuf *, int *, int, int);
284 int nfs_ispublicfh __P((fhandle_t *));
285 int netaddr_match(int, union nethostaddr *, struct mbuf *);
286 
287 /* flags for nfs_loadattrcache and friends */
288 #define	NAC_NOTRUNC	1	/* don't truncate file size */
289 
290 void nfs_clearcommit(struct mount *);
291 void nfs_merge_commit_ranges(struct vnode *);
292 int nfs_in_committed_range(struct vnode *, off_t, off_t);
293 int nfs_in_tobecommitted_range(struct vnode *, off_t, off_t);
294 void nfs_add_committed_range(struct vnode *, off_t, off_t);
295 void nfs_del_committed_range(struct vnode *, off_t, off_t);
296 void nfs_add_tobecommitted_range(struct vnode *, off_t, off_t);
297 void nfs_del_tobecommitted_range(struct vnode *, off_t, off_t);
298 
299 int nfsrv_errmap(struct nfsrv_descript *, int);
300 void nfsrvw_sort(gid_t *, int);
301 void nfsrv_setcred(struct ucred *, struct ucred *);
302 void nfs_cookieheuristic(struct vnode *, int *, struct lwp *, struct ucred *);
303 
304 u_int32_t nfs_getxid(void);
305 void nfs_renewxid(struct nfsreq *);
306 
307 /* nfs_syscalls.c */
308 int sys_getfh(struct lwp *, void *, register_t *);
309 int sys_nfssvc(struct lwp *, void *, register_t *);
310 int nfssvc_addsock(struct file *, struct mbuf *);
311 int nfssvc_nfsd(struct nfsd_srvargs *, caddr_t, struct lwp *);
312 void nfsrv_zapsock(struct nfssvc_sock *);
313 void nfsrv_slpderef(struct nfssvc_sock *);
314 void nfsrv_init(int);
315 int nfssvc_iod(struct lwp *);
316 void nfs_iodinit(void);
317 void start_nfsio(void *);
318 void nfs_getset_niothreads(int);
319 int nfs_getauth(struct nfsmount *, struct nfsreq *, struct ucred *, char **,
320 	int *, char *, int *, NFSKERBKEY_T);
321 int nfs_getnickauth(struct nfsmount *, struct ucred *, char **, int *, char *,
322 	int);
323 int nfs_savenickauth(struct nfsmount *, struct ucred *, int, NFSKERBKEY_T,
324 	struct mbuf **, char **, struct mbuf *);
325 
326 /* nfs_export.c */
327 extern struct nfs_public nfs_pub;
328 int mountd_set_exports_list(const struct mountd_exports_list *, struct lwp *);
329 int netexport_check(const fsid_t *, struct mbuf *, struct mount **, int *,
330     struct ucred **);
331 void netexport_rdlock(void);
332 void netexport_rdunlock(void);
333 #ifdef COMPAT_30
334 int nfs_update_exports_30(struct mount *, const char *, void *, struct lwp *);
335 #endif
336 #endif /* _KERNEL */
337