xref: /netbsd-src/sys/nfs/nfs_var.h (revision cac8e449158efc7261bebc8657cbb0125a2cfdde)
1 /*	$NetBSD: nfs_var.h,v 1.79 2008/04/28 20:24:10 martin 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 
40 MALLOC_DECLARE(M_NFSD);
41 MALLOC_DECLARE(M_NFSDIROFF);
42 
43 struct vnode;
44 struct uio;
45 struct proc;
46 struct buf;
47 struct nfs_diskless;
48 struct sockaddr_in;
49 struct nfs_dlmount;
50 struct vnode;
51 struct nfsd;
52 struct mbuf;
53 struct file;
54 struct nfssvc_sock;
55 struct nfsmount;
56 struct socket;
57 struct nfsreq;
58 struct vattr;
59 struct nameidata;
60 struct nfsnode;
61 struct sillyrename;
62 struct componentname;
63 struct nfsd_srvargs;
64 struct nfsrv_descript;
65 struct nfs_fattr;
66 struct nfsdircache;
67 union nethostaddr;
68 
69 /* nfs_bio.c */
70 int nfs_bioread(struct vnode *, struct uio *, int, kauth_cred_t, int);
71 struct buf *nfs_getcacheblk(struct vnode *, daddr_t, int, struct lwp *);
72 int nfs_vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, int);
73 int nfs_flushstalebuf(struct vnode *, kauth_cred_t, struct lwp *, int);
74 #define	NFS_FLUSHSTALEBUF_MYWRITE	1	/* assume writes are ours */
75 int nfs_asyncio(struct buf *);
76 int nfs_doio(struct buf *);
77 
78 /* nfs_boot.c */
79 /* see nfsdiskless.h */
80 
81 /* nfs_kq.c */
82 void nfs_kqinit(void);
83 
84 /* nfs_node.c */
85 void nfs_nhinit(void);
86 void nfs_nhreinit(void);
87 void nfs_nhdone(void);
88 int nfs_nget1(struct mount *, nfsfh_t *, int, struct nfsnode **, int);
89 #define	nfs_nget(mp, fhp, fhsize, npp) \
90 	nfs_nget1((mp), (fhp), (fhsize), (npp), 0)
91 
92 /* nfs_vnops.c */
93 int nfs_null(struct vnode *, kauth_cred_t, struct lwp *);
94 int nfs_setattrrpc(struct vnode *, struct vattr *, kauth_cred_t, struct lwp *);
95 int nfs_readlinkrpc(struct vnode *, struct uio *, kauth_cred_t);
96 int nfs_readrpc(struct vnode *, struct uio *);
97 int nfs_writerpc(struct vnode *, struct uio *, int *, bool, bool *);
98 int nfs_mknodrpc(struct vnode *, struct vnode **, struct componentname *,
99 	struct vattr *);
100 int nfs_removeit(struct sillyrename *);
101 int nfs_removerpc(struct vnode *, const char *, int, kauth_cred_t,
102 	struct lwp *);
103 int nfs_renameit(struct vnode *, struct componentname *, struct sillyrename *);
104 int nfs_renamerpc(struct vnode *, const char *, int, struct vnode *,
105 	const char *, int, kauth_cred_t, struct lwp *);
106 int nfs_readdirrpc(struct vnode *, struct uio *, kauth_cred_t);
107 int nfs_readdirplusrpc(struct vnode *, struct uio *, kauth_cred_t);
108 int nfs_sillyrename(struct vnode *, struct vnode *, struct componentname *,
109 	bool);
110 int nfs_lookitup(struct vnode *, const char *, int, kauth_cred_t,
111 	struct lwp *, struct nfsnode **);
112 int nfs_commit(struct vnode *, off_t, uint32_t, struct lwp *);
113 int nfs_flush(struct vnode *, kauth_cred_t, int, struct lwp *, int);
114 
115 /* nfs_serv.c */
116 int nfsrv3_access(struct nfsrv_descript *, struct nfssvc_sock *,
117 	struct lwp *, struct mbuf **);
118 int nfsrv_getattr(struct nfsrv_descript *, struct nfssvc_sock *,
119 	struct lwp *, struct mbuf **);
120 int nfsrv_setattr(struct nfsrv_descript *, struct nfssvc_sock *,
121 	struct lwp *, struct mbuf **);
122 int nfsrv_lookup(struct nfsrv_descript *, struct nfssvc_sock *,
123 	struct lwp *, struct mbuf **);
124 int nfsrv_readlink(struct nfsrv_descript *, struct nfssvc_sock *,
125 	struct lwp *, struct mbuf **);
126 int nfsrv_read(struct nfsrv_descript *, struct nfssvc_sock *,
127 	struct lwp *, struct mbuf **);
128 int nfsrv_write(struct nfsrv_descript *, struct nfssvc_sock *,
129 	struct lwp *, struct mbuf **);
130 int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
131 	struct lwp *, struct mbuf **);
132 void nfsrvw_coalesce(struct nfsrv_descript *, struct nfsrv_descript *);
133 int nfsrv_create(struct nfsrv_descript *, struct nfssvc_sock *,
134 	struct lwp *, struct mbuf **);
135 int nfsrv_mknod(struct nfsrv_descript *, struct nfssvc_sock *,
136 	struct lwp *, struct mbuf **);
137 int nfsrv_remove(struct nfsrv_descript *, struct nfssvc_sock *,
138 	struct lwp *, struct mbuf **);
139 int nfsrv_rename(struct nfsrv_descript *, struct nfssvc_sock *,
140 	struct lwp *, struct mbuf **);
141 int nfsrv_link(struct nfsrv_descript *, struct nfssvc_sock *,
142 	struct lwp *, struct mbuf **);
143 int nfsrv_symlink(struct nfsrv_descript *, struct nfssvc_sock *,
144 	struct lwp *, struct mbuf **);
145 int nfsrv_mkdir(struct nfsrv_descript *, struct nfssvc_sock *,
146 	struct lwp *, struct mbuf **);
147 int nfsrv_rmdir(struct nfsrv_descript *, struct nfssvc_sock *,
148 	struct lwp *, struct mbuf **);
149 int nfsrv_readdir(struct nfsrv_descript *, struct nfssvc_sock *,
150 	struct lwp *, struct mbuf **);
151 int nfsrv_readdirplus(struct nfsrv_descript *, struct nfssvc_sock *,
152 	struct lwp *, struct mbuf **);
153 int nfsrv_commit(struct nfsrv_descript *, struct nfssvc_sock *,
154 	struct lwp *, struct mbuf **);
155 int nfsrv_statfs(struct nfsrv_descript *, struct nfssvc_sock *,
156 	struct lwp *, struct mbuf **);
157 int nfsrv_fsinfo(struct nfsrv_descript *, struct nfssvc_sock *,
158 	struct lwp *, struct mbuf **);
159 int nfsrv_pathconf(struct nfsrv_descript *, struct nfssvc_sock *,
160 	struct lwp *, struct mbuf **);
161 int nfsrv_null(struct nfsrv_descript *, struct nfssvc_sock *,
162 	struct lwp *, struct mbuf **);
163 int nfsrv_noop(struct nfsrv_descript *, struct nfssvc_sock *,
164 	struct lwp *, struct mbuf **);
165 int nfsrv_access(struct vnode *, int, kauth_cred_t, int, struct lwp *, int);
166 
167 /* nfs_socket.c */
168 int nfs_connect(struct nfsmount *, struct nfsreq *, struct lwp *);
169 int nfs_reconnect(struct nfsreq *);
170 void nfs_disconnect(struct nfsmount *);
171 void nfs_safedisconnect(struct nfsmount *);
172 int nfs_send(struct socket *, struct mbuf *, struct mbuf *, struct nfsreq *,
173 	struct lwp *);
174 int nfs_request(struct nfsnode *, struct mbuf *, int, struct lwp *,
175 	kauth_cred_t, struct mbuf **, struct mbuf **, char **, int *);
176 int nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
177 	int, int, u_quad_t *, struct mbuf **, struct mbuf **, char **);
178 void nfs_timer(void *);
179 void nfs_timer_init(void);
180 void nfs_timer_start(void);
181 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct lwp *);
182 int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
183 int nfs_msg(struct lwp *, const char *, const char *);
184 void nfsrv_soupcall(struct socket *, void *, int);
185 void nfsrv_rcv(struct nfssvc_sock *);
186 int nfsrv_getstream(struct nfssvc_sock *, int);
187 int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **,
188     bool *);
189 void nfsrv_wakenfsd(struct nfssvc_sock *);
190 int nfsdsock_lock(struct nfssvc_sock *, bool);
191 void nfsdsock_unlock(struct nfssvc_sock *);
192 int nfsdsock_drain(struct nfssvc_sock *);
193 int nfsdsock_sendreply(struct nfssvc_sock *, struct nfsrv_descript *);
194 void nfsdreq_init(void);
195 struct nfsrv_descript *nfsdreq_alloc(void);
196 void nfsdreq_free(struct nfsrv_descript *);
197 
198 void nfsdsock_setbits(struct nfssvc_sock *, int);
199 void nfsdsock_clearbits(struct nfssvc_sock *, int);
200 bool nfsdsock_testbits(struct nfssvc_sock *, int);
201 
202 /* nfs_srvcache.c */
203 void nfsrv_initcache(void);
204 int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
205 	struct mbuf **);
206 void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
207 void nfsrv_cleancache(void);
208 
209 /* nfs_subs.c */
210 struct mbuf *nfsm_reqh(struct nfsnode *, u_long, int, char **);
211 struct mbuf *nfsm_rpchead(kauth_cred_t, int, int, int, int, char *, int,
212 	char *, struct mbuf *, int, struct mbuf **, u_int32_t *);
213 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, char **);
214 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, char **);
215 int nfsm_disct(struct mbuf **, char **, int, int, char **);
216 int nfs_adv(struct mbuf **, char **, int, int);
217 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
218 u_long nfs_dirhash(off_t);
219 void nfs_initdircache(struct vnode *);
220 void nfs_initdirxlatecookie(struct vnode *);
221 struct nfsdircache *nfs_searchdircache(struct vnode *, off_t, int, int *);
222 struct nfsdircache *nfs_enterdircache(struct vnode *, off_t, off_t, int,
223 	daddr_t);
224 void nfs_putdircache(struct nfsnode *, struct nfsdircache *);
225 void nfs_invaldircache(struct vnode *, int);
226 #define	NFS_INVALDIRCACHE_FORCE		1
227 #define	NFS_INVALDIRCACHE_KEEPEOF	2
228 void nfs_init __P((void));
229 int nfsm_loadattrcache(struct vnode **, struct mbuf **, char **,
230 	struct vattr *, int flags);
231 int nfs_loadattrcache(struct vnode **, struct nfs_fattr *, struct vattr *,
232 	int flags);
233 int nfs_getattrcache(struct vnode *, struct vattr *);
234 void nfs_delayedtruncate(struct vnode *);
235 int nfs_check_wccdata(struct nfsnode *, const struct timespec *,
236 	struct timespec *, bool);
237 int nfs_namei(struct nameidata *, nfsrvfh_t *, uint32_t, struct nfssvc_sock *,
238 	struct mbuf *, struct mbuf **, char **, struct vnode **, struct lwp *,
239 	int, int);
240 void nfs_zeropad(struct mbuf *, int, int);
241 void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
242 	struct vattr *, struct mbuf **, char **);
243 void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
244 	struct mbuf **, char **);
245 void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, struct nfs_fattr *);
246 int nfsrv_fhtovp(nfsrvfh_t *, int, struct vnode **, kauth_cred_t,
247 	struct nfssvc_sock *, struct mbuf *, int *, int, int);
248 int nfs_ispublicfh __P((const nfsrvfh_t *));
249 int netaddr_match(int, union nethostaddr *, struct mbuf *);
250 time_t nfs_attrtimeo(struct nfsmount *, struct nfsnode *);
251 
252 /* flags for nfs_loadattrcache and friends */
253 #define	NAC_NOTRUNC	1	/* don't truncate file size */
254 
255 void nfs_clearcommit(struct mount *);
256 void nfs_merge_commit_ranges(struct vnode *);
257 int nfs_in_committed_range(struct vnode *, off_t, off_t);
258 int nfs_in_tobecommitted_range(struct vnode *, off_t, off_t);
259 void nfs_add_committed_range(struct vnode *, off_t, off_t);
260 void nfs_del_committed_range(struct vnode *, off_t, off_t);
261 void nfs_add_tobecommitted_range(struct vnode *, off_t, off_t);
262 void nfs_del_tobecommitted_range(struct vnode *, off_t, off_t);
263 
264 int nfsrv_errmap(struct nfsrv_descript *, int);
265 void nfs_cookieheuristic(struct vnode *, int *, struct lwp *, kauth_cred_t);
266 
267 u_int32_t nfs_getxid(void);
268 void nfs_renewxid(struct nfsreq *);
269 
270 int nfsrv_composefh(struct vnode *, nfsrvfh_t *, bool);
271 int nfsrv_comparefh(const nfsrvfh_t *, const nfsrvfh_t *);
272 void nfsrv_copyfh(nfsrvfh_t *, const nfsrvfh_t *);
273 
274 /* nfs_syscalls.c */
275 struct sys_getfh_args;
276 struct sys_nfssvc_args;
277 int sys_getfh(struct lwp *, const struct sys_getfh_args *, register_t *);
278 int sys_nfssvc(struct lwp *, const struct sys_nfssvc_args *, register_t *);
279 int nfssvc_addsock(struct file *, struct mbuf *);
280 int nfssvc_nfsd(struct nfsd_srvargs *, void *, struct lwp *);
281 void nfsrv_zapsock(struct nfssvc_sock *);
282 void nfsrv_slpderef(struct nfssvc_sock *);
283 void nfsrv_init(int);
284 void nfs_iodinit(void);
285 int nfs_set_niothreads(int);
286 int nfs_getauth(struct nfsmount *, struct nfsreq *, kauth_cred_t, char **,
287 	int *, char *, int *, NFSKERBKEY_T);
288 int nfs_getnickauth(struct nfsmount *, kauth_cred_t, char **, int *, char *,
289 	int);
290 int nfs_savenickauth(struct nfsmount *, kauth_cred_t, int, NFSKERBKEY_T,
291 	struct mbuf **, char **, struct mbuf *);
292 
293 /* nfs_export.c */
294 extern struct nfs_public nfs_pub;
295 int mountd_set_exports_list(const struct mountd_exports_list *, struct lwp *);
296 int netexport_check(const fsid_t *, struct mbuf *, struct mount **, int *,
297     kauth_cred_t *);
298 void netexport_rdlock(void);
299 void netexport_rdunlock(void);
300 #ifdef COMPAT_30
301 int nfs_update_exports_30(struct mount *, const char *,
302     struct mnt_export_args30 *, struct lwp *);
303 #endif
304 #endif /* _KERNEL */
305