rump_vfs.c revision 1.11.2.2 1 1.11.2.2 mjf /* $NetBSD: rump_vfs.c,v 1.11.2.2 2009/01/17 13:29:38 mjf Exp $ */
2 1.11.2.2 mjf
3 1.11.2.2 mjf /*
4 1.11.2.2 mjf * Copyright (c) 2008 Antti Kantee. All Rights Reserved.
5 1.11.2.2 mjf *
6 1.11.2.2 mjf * Development of this software was supported by the
7 1.11.2.2 mjf * Finnish Cultural Foundation.
8 1.11.2.2 mjf *
9 1.11.2.2 mjf * Redistribution and use in source and binary forms, with or without
10 1.11.2.2 mjf * modification, are permitted provided that the following conditions
11 1.11.2.2 mjf * are met:
12 1.11.2.2 mjf * 1. Redistributions of source code must retain the above copyright
13 1.11.2.2 mjf * notice, this list of conditions and the following disclaimer.
14 1.11.2.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
15 1.11.2.2 mjf * notice, this list of conditions and the following disclaimer in the
16 1.11.2.2 mjf * documentation and/or other materials provided with the distribution.
17 1.11.2.2 mjf *
18 1.11.2.2 mjf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 1.11.2.2 mjf * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 1.11.2.2 mjf * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 1.11.2.2 mjf * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 1.11.2.2 mjf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.11.2.2 mjf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.11.2.2 mjf * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.11.2.2 mjf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.11.2.2 mjf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.11.2.2 mjf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.11.2.2 mjf * SUCH DAMAGE.
29 1.11.2.2 mjf */
30 1.11.2.2 mjf
31 1.11.2.2 mjf #include <sys/cdefs.h>
32 1.11.2.2 mjf __KERNEL_RCSID(0, "$NetBSD");
33 1.11.2.2 mjf
34 1.11.2.2 mjf #include <sys/param.h>
35 1.11.2.2 mjf #include <sys/buf.h>
36 1.11.2.2 mjf #include <sys/conf.h>
37 1.11.2.2 mjf #include <sys/filedesc.h>
38 1.11.2.2 mjf #include <sys/lockf.h>
39 1.11.2.2 mjf #include <sys/module.h>
40 1.11.2.2 mjf #include <sys/namei.h>
41 1.11.2.2 mjf #include <sys/queue.h>
42 1.11.2.2 mjf #include <sys/vfs_syscalls.h>
43 1.11.2.2 mjf #include <sys/vnode.h>
44 1.11.2.2 mjf #include <sys/wapbl.h>
45 1.11.2.2 mjf
46 1.11.2.2 mjf #include <miscfs/specfs/specdev.h>
47 1.11.2.2 mjf
48 1.11.2.2 mjf #include <rump/rump.h>
49 1.11.2.2 mjf #include <rump/rumpuser.h>
50 1.11.2.2 mjf
51 1.11.2.2 mjf #include "rump_private.h"
52 1.11.2.2 mjf #include "rump_vfs_private.h"
53 1.11.2.2 mjf
54 1.11.2.2 mjf struct fakeblk {
55 1.11.2.2 mjf char path[MAXPATHLEN];
56 1.11.2.2 mjf LIST_ENTRY(fakeblk) entries;
57 1.11.2.2 mjf };
58 1.11.2.2 mjf static LIST_HEAD(, fakeblk) fakeblks = LIST_HEAD_INITIALIZER(fakeblks);
59 1.11.2.2 mjf
60 1.11.2.2 mjf static struct cwdinfo rump_cwdi;
61 1.11.2.2 mjf
62 1.11.2.2 mjf static void rump_rcvp_lwpset(struct vnode *, struct vnode *, struct lwp *);
63 1.11.2.2 mjf
64 1.11.2.2 mjf static void
65 1.11.2.2 mjf pvfs_init(struct proc *p)
66 1.11.2.2 mjf {
67 1.11.2.2 mjf
68 1.11.2.2 mjf p->p_cwdi = cwdinit();
69 1.11.2.2 mjf }
70 1.11.2.2 mjf
71 1.11.2.2 mjf static void
72 1.11.2.2 mjf pvfs_rele(struct proc *p)
73 1.11.2.2 mjf {
74 1.11.2.2 mjf
75 1.11.2.2 mjf cwdfree(p->p_cwdi);
76 1.11.2.2 mjf }
77 1.11.2.2 mjf
78 1.11.2.2 mjf void
79 1.11.2.2 mjf rump_vfs_init()
80 1.11.2.2 mjf {
81 1.11.2.2 mjf char buf[64];
82 1.11.2.2 mjf int error;
83 1.11.2.2 mjf
84 1.11.2.2 mjf syncdelay = 0;
85 1.11.2.2 mjf dovfsusermount = 1;
86 1.11.2.2 mjf
87 1.11.2.2 mjf rumpblk_init();
88 1.11.2.2 mjf
89 1.11.2.2 mjf if (rumpuser_getenv("RUMP_NVNODES", buf, sizeof(buf), &error) == 0) {
90 1.11.2.2 mjf desiredvnodes = strtoul(buf, NULL, 10);
91 1.11.2.2 mjf } else {
92 1.11.2.2 mjf desiredvnodes = 1<<16;
93 1.11.2.2 mjf }
94 1.11.2.2 mjf
95 1.11.2.2 mjf cache_cpu_init(&rump_cpu);
96 1.11.2.2 mjf vfsinit();
97 1.11.2.2 mjf bufinit();
98 1.11.2.2 mjf wapbl_init();
99 1.11.2.2 mjf cwd_sys_init();
100 1.11.2.2 mjf lf_init();
101 1.11.2.2 mjf
102 1.11.2.2 mjf rumpuser_bioinit(rump_biodone);
103 1.11.2.2 mjf rumpfs_init();
104 1.11.2.2 mjf
105 1.11.2.2 mjf rump_proc_vfs_init = pvfs_init;
106 1.11.2.2 mjf rump_proc_vfs_release = pvfs_rele;
107 1.11.2.2 mjf
108 1.11.2.2 mjf rw_init(&rump_cwdi.cwdi_lock);
109 1.11.2.2 mjf rump_cwdi.cwdi_cdir = rootvnode;
110 1.11.2.2 mjf vref(rump_cwdi.cwdi_cdir);
111 1.11.2.2 mjf proc0.p_cwdi = &rump_cwdi;
112 1.11.2.2 mjf }
113 1.11.2.2 mjf
114 1.11.2.2 mjf struct mount *
115 1.11.2.2 mjf rump_mnt_init(struct vfsops *vfsops, int mntflags)
116 1.11.2.2 mjf {
117 1.11.2.2 mjf struct mount *mp;
118 1.11.2.2 mjf
119 1.11.2.2 mjf mp = kmem_zalloc(sizeof(struct mount), KM_SLEEP);
120 1.11.2.2 mjf
121 1.11.2.2 mjf mp->mnt_op = vfsops;
122 1.11.2.2 mjf mp->mnt_flag = mntflags;
123 1.11.2.2 mjf TAILQ_INIT(&mp->mnt_vnodelist);
124 1.11.2.2 mjf rw_init(&mp->mnt_unmounting);
125 1.11.2.2 mjf mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE);
126 1.11.2.2 mjf mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE);
127 1.11.2.2 mjf mp->mnt_refcnt = 1;
128 1.11.2.2 mjf mp->mnt_vnodecovered = rootvnode;
129 1.11.2.2 mjf
130 1.11.2.2 mjf mount_initspecific(mp);
131 1.11.2.2 mjf
132 1.11.2.2 mjf return mp;
133 1.11.2.2 mjf }
134 1.11.2.2 mjf
135 1.11.2.2 mjf int
136 1.11.2.2 mjf rump_mnt_mount(struct mount *mp, const char *path, void *data, size_t *dlen)
137 1.11.2.2 mjf {
138 1.11.2.2 mjf struct vnode *rvp;
139 1.11.2.2 mjf int rv;
140 1.11.2.2 mjf
141 1.11.2.2 mjf rv = VFS_MOUNT(mp, path, data, dlen);
142 1.11.2.2 mjf if (rv)
143 1.11.2.2 mjf return rv;
144 1.11.2.2 mjf
145 1.11.2.2 mjf (void) VFS_STATVFS(mp, &mp->mnt_stat);
146 1.11.2.2 mjf rv = VFS_START(mp, 0);
147 1.11.2.2 mjf if (rv)
148 1.11.2.2 mjf VFS_UNMOUNT(mp, MNT_FORCE);
149 1.11.2.2 mjf
150 1.11.2.2 mjf /*
151 1.11.2.2 mjf * XXX: set a root for lwp0. This is strictly not correct,
152 1.11.2.2 mjf * but makes things work for single fs case without having
153 1.11.2.2 mjf * to manually call rump_rcvp_set().
154 1.11.2.2 mjf */
155 1.11.2.2 mjf VFS_ROOT(mp, &rvp);
156 1.11.2.2 mjf rump_rcvp_lwpset(rvp, rvp, &lwp0);
157 1.11.2.2 mjf vput(rvp);
158 1.11.2.2 mjf
159 1.11.2.2 mjf return rv;
160 1.11.2.2 mjf }
161 1.11.2.2 mjf
162 1.11.2.2 mjf void
163 1.11.2.2 mjf rump_mnt_destroy(struct mount *mp)
164 1.11.2.2 mjf {
165 1.11.2.2 mjf
166 1.11.2.2 mjf /* See rcvp XXX above */
167 1.11.2.2 mjf rump_cwdi.cwdi_rdir = NULL;
168 1.11.2.2 mjf vref(rootvnode);
169 1.11.2.2 mjf rump_cwdi.cwdi_cdir = rootvnode;
170 1.11.2.2 mjf
171 1.11.2.2 mjf mount_finispecific(mp);
172 1.11.2.2 mjf kmem_free(mp, sizeof(*mp));
173 1.11.2.2 mjf }
174 1.11.2.2 mjf
175 1.11.2.2 mjf struct componentname *
176 1.11.2.2 mjf rump_makecn(u_long nameiop, u_long flags, const char *name, size_t namelen,
177 1.11.2.2 mjf kauth_cred_t creds, struct lwp *l)
178 1.11.2.2 mjf {
179 1.11.2.2 mjf struct componentname *cnp;
180 1.11.2.2 mjf const char *cp = NULL;
181 1.11.2.2 mjf
182 1.11.2.2 mjf cnp = kmem_zalloc(sizeof(struct componentname), KM_SLEEP);
183 1.11.2.2 mjf
184 1.11.2.2 mjf cnp->cn_nameiop = nameiop;
185 1.11.2.2 mjf cnp->cn_flags = flags | HASBUF;
186 1.11.2.2 mjf
187 1.11.2.2 mjf cnp->cn_pnbuf = PNBUF_GET();
188 1.11.2.2 mjf strcpy(cnp->cn_pnbuf, name);
189 1.11.2.2 mjf cnp->cn_nameptr = cnp->cn_pnbuf;
190 1.11.2.2 mjf cnp->cn_namelen = namelen;
191 1.11.2.2 mjf cnp->cn_hash = namei_hash(name, &cp);
192 1.11.2.2 mjf
193 1.11.2.2 mjf cnp->cn_cred = creds;
194 1.11.2.2 mjf
195 1.11.2.2 mjf return cnp;
196 1.11.2.2 mjf }
197 1.11.2.2 mjf
198 1.11.2.2 mjf void
199 1.11.2.2 mjf rump_freecn(struct componentname *cnp, int flags)
200 1.11.2.2 mjf {
201 1.11.2.2 mjf
202 1.11.2.2 mjf if (flags & RUMPCN_FREECRED)
203 1.11.2.2 mjf rump_cred_destroy(cnp->cn_cred);
204 1.11.2.2 mjf
205 1.11.2.2 mjf if ((flags & RUMPCN_HASNTBUF) == 0) {
206 1.11.2.2 mjf if (cnp->cn_flags & SAVENAME) {
207 1.11.2.2 mjf if (flags & RUMPCN_ISLOOKUP ||cnp->cn_flags & SAVESTART)
208 1.11.2.2 mjf PNBUF_PUT(cnp->cn_pnbuf);
209 1.11.2.2 mjf } else {
210 1.11.2.2 mjf PNBUF_PUT(cnp->cn_pnbuf);
211 1.11.2.2 mjf }
212 1.11.2.2 mjf }
213 1.11.2.2 mjf kmem_free(cnp, sizeof(*cnp));
214 1.11.2.2 mjf }
215 1.11.2.2 mjf
216 1.11.2.2 mjf /* hey baby, what's your namei? */
217 1.11.2.2 mjf int
218 1.11.2.2 mjf rump_namei(uint32_t op, uint32_t flags, const char *namep,
219 1.11.2.2 mjf struct vnode **dvpp, struct vnode **vpp, struct componentname **cnpp)
220 1.11.2.2 mjf {
221 1.11.2.2 mjf struct nameidata nd;
222 1.11.2.2 mjf int rv;
223 1.11.2.2 mjf
224 1.11.2.2 mjf NDINIT(&nd, op, flags, UIO_SYSSPACE, namep);
225 1.11.2.2 mjf rv = namei(&nd);
226 1.11.2.2 mjf if (rv)
227 1.11.2.2 mjf return rv;
228 1.11.2.2 mjf
229 1.11.2.2 mjf if (dvpp) {
230 1.11.2.2 mjf KASSERT(flags & LOCKPARENT);
231 1.11.2.2 mjf *dvpp = nd.ni_dvp;
232 1.11.2.2 mjf } else {
233 1.11.2.2 mjf KASSERT((flags & LOCKPARENT) == 0);
234 1.11.2.2 mjf }
235 1.11.2.2 mjf
236 1.11.2.2 mjf if (vpp) {
237 1.11.2.2 mjf *vpp = nd.ni_vp;
238 1.11.2.2 mjf } else {
239 1.11.2.2 mjf if (nd.ni_vp) {
240 1.11.2.2 mjf if (flags & LOCKLEAF)
241 1.11.2.2 mjf vput(nd.ni_vp);
242 1.11.2.2 mjf else
243 1.11.2.2 mjf vrele(nd.ni_vp);
244 1.11.2.2 mjf }
245 1.11.2.2 mjf }
246 1.11.2.2 mjf
247 1.11.2.2 mjf if (cnpp) {
248 1.11.2.2 mjf struct componentname *cnp;
249 1.11.2.2 mjf
250 1.11.2.2 mjf cnp = kmem_alloc(sizeof(*cnp), KM_SLEEP);
251 1.11.2.2 mjf memcpy(cnp, &nd.ni_cnd, sizeof(*cnp));
252 1.11.2.2 mjf *cnpp = cnp;
253 1.11.2.2 mjf } else if (nd.ni_cnd.cn_flags & HASBUF) {
254 1.11.2.2 mjf panic("%s: pathbuf mismatch", __func__);
255 1.11.2.2 mjf }
256 1.11.2.2 mjf
257 1.11.2.2 mjf return rv;
258 1.11.2.2 mjf }
259 1.11.2.2 mjf
260 1.11.2.2 mjf static struct fakeblk *
261 1.11.2.2 mjf _rump_fakeblk_find(const char *path)
262 1.11.2.2 mjf {
263 1.11.2.2 mjf char buf[MAXPATHLEN];
264 1.11.2.2 mjf struct fakeblk *fblk;
265 1.11.2.2 mjf int error;
266 1.11.2.2 mjf
267 1.11.2.2 mjf if (rumpuser_realpath(path, buf, &error) == NULL)
268 1.11.2.2 mjf return NULL;
269 1.11.2.2 mjf
270 1.11.2.2 mjf LIST_FOREACH(fblk, &fakeblks, entries)
271 1.11.2.2 mjf if (strcmp(fblk->path, buf) == 0)
272 1.11.2.2 mjf return fblk;
273 1.11.2.2 mjf
274 1.11.2.2 mjf return NULL;
275 1.11.2.2 mjf }
276 1.11.2.2 mjf
277 1.11.2.2 mjf int
278 1.11.2.2 mjf rump_fakeblk_register(const char *path)
279 1.11.2.2 mjf {
280 1.11.2.2 mjf char buf[MAXPATHLEN];
281 1.11.2.2 mjf struct fakeblk *fblk;
282 1.11.2.2 mjf int error;
283 1.11.2.2 mjf
284 1.11.2.2 mjf if (_rump_fakeblk_find(path))
285 1.11.2.2 mjf return EEXIST;
286 1.11.2.2 mjf
287 1.11.2.2 mjf if (rumpuser_realpath(path, buf, &error) == NULL)
288 1.11.2.2 mjf return error;
289 1.11.2.2 mjf
290 1.11.2.2 mjf fblk = kmem_alloc(sizeof(struct fakeblk), KM_NOSLEEP);
291 1.11.2.2 mjf if (fblk == NULL)
292 1.11.2.2 mjf return ENOMEM;
293 1.11.2.2 mjf
294 1.11.2.2 mjf strlcpy(fblk->path, buf, MAXPATHLEN);
295 1.11.2.2 mjf LIST_INSERT_HEAD(&fakeblks, fblk, entries);
296 1.11.2.2 mjf
297 1.11.2.2 mjf return 0;
298 1.11.2.2 mjf }
299 1.11.2.2 mjf
300 1.11.2.2 mjf int
301 1.11.2.2 mjf rump_fakeblk_find(const char *path)
302 1.11.2.2 mjf {
303 1.11.2.2 mjf
304 1.11.2.2 mjf return _rump_fakeblk_find(path) != NULL;
305 1.11.2.2 mjf }
306 1.11.2.2 mjf
307 1.11.2.2 mjf void
308 1.11.2.2 mjf rump_fakeblk_deregister(const char *path)
309 1.11.2.2 mjf {
310 1.11.2.2 mjf struct fakeblk *fblk;
311 1.11.2.2 mjf
312 1.11.2.2 mjf fblk = _rump_fakeblk_find(path);
313 1.11.2.2 mjf if (fblk == NULL)
314 1.11.2.2 mjf return;
315 1.11.2.2 mjf
316 1.11.2.2 mjf LIST_REMOVE(fblk, entries);
317 1.11.2.2 mjf kmem_free(fblk, sizeof(*fblk));
318 1.11.2.2 mjf }
319 1.11.2.2 mjf
320 1.11.2.2 mjf void
321 1.11.2.2 mjf rump_getvninfo(struct vnode *vp, enum vtype *vtype, voff_t *vsize, dev_t *vdev)
322 1.11.2.2 mjf {
323 1.11.2.2 mjf
324 1.11.2.2 mjf *vtype = vp->v_type;
325 1.11.2.2 mjf *vsize = vp->v_size;
326 1.11.2.2 mjf if (vp->v_specnode)
327 1.11.2.2 mjf *vdev = vp->v_rdev;
328 1.11.2.2 mjf else
329 1.11.2.2 mjf *vdev = 0;
330 1.11.2.2 mjf }
331 1.11.2.2 mjf
332 1.11.2.2 mjf struct vfsops *
333 1.11.2.2 mjf rump_vfslist_iterate(struct vfsops *ops)
334 1.11.2.2 mjf {
335 1.11.2.2 mjf
336 1.11.2.2 mjf if (ops == NULL)
337 1.11.2.2 mjf return LIST_FIRST(&vfs_list);
338 1.11.2.2 mjf else
339 1.11.2.2 mjf return LIST_NEXT(ops, vfs_list);
340 1.11.2.2 mjf }
341 1.11.2.2 mjf
342 1.11.2.2 mjf struct vfsops *
343 1.11.2.2 mjf rump_vfs_getopsbyname(const char *name)
344 1.11.2.2 mjf {
345 1.11.2.2 mjf
346 1.11.2.2 mjf return vfs_getopsbyname(name);
347 1.11.2.2 mjf }
348 1.11.2.2 mjf
349 1.11.2.2 mjf struct vattr*
350 1.11.2.2 mjf rump_vattr_init()
351 1.11.2.2 mjf {
352 1.11.2.2 mjf struct vattr *vap;
353 1.11.2.2 mjf
354 1.11.2.2 mjf vap = kmem_alloc(sizeof(struct vattr), KM_SLEEP);
355 1.11.2.2 mjf vattr_null(vap);
356 1.11.2.2 mjf
357 1.11.2.2 mjf return vap;
358 1.11.2.2 mjf }
359 1.11.2.2 mjf
360 1.11.2.2 mjf void
361 1.11.2.2 mjf rump_vattr_settype(struct vattr *vap, enum vtype vt)
362 1.11.2.2 mjf {
363 1.11.2.2 mjf
364 1.11.2.2 mjf vap->va_type = vt;
365 1.11.2.2 mjf }
366 1.11.2.2 mjf
367 1.11.2.2 mjf void
368 1.11.2.2 mjf rump_vattr_setmode(struct vattr *vap, mode_t mode)
369 1.11.2.2 mjf {
370 1.11.2.2 mjf
371 1.11.2.2 mjf vap->va_mode = mode;
372 1.11.2.2 mjf }
373 1.11.2.2 mjf
374 1.11.2.2 mjf void
375 1.11.2.2 mjf rump_vattr_setrdev(struct vattr *vap, dev_t dev)
376 1.11.2.2 mjf {
377 1.11.2.2 mjf
378 1.11.2.2 mjf vap->va_rdev = dev;
379 1.11.2.2 mjf }
380 1.11.2.2 mjf
381 1.11.2.2 mjf void
382 1.11.2.2 mjf rump_vattr_free(struct vattr *vap)
383 1.11.2.2 mjf {
384 1.11.2.2 mjf
385 1.11.2.2 mjf kmem_free(vap, sizeof(*vap));
386 1.11.2.2 mjf }
387 1.11.2.2 mjf
388 1.11.2.2 mjf void
389 1.11.2.2 mjf rump_vp_incref(struct vnode *vp)
390 1.11.2.2 mjf {
391 1.11.2.2 mjf
392 1.11.2.2 mjf mutex_enter(&vp->v_interlock);
393 1.11.2.2 mjf ++vp->v_usecount;
394 1.11.2.2 mjf mutex_exit(&vp->v_interlock);
395 1.11.2.2 mjf }
396 1.11.2.2 mjf
397 1.11.2.2 mjf int
398 1.11.2.2 mjf rump_vp_getref(struct vnode *vp)
399 1.11.2.2 mjf {
400 1.11.2.2 mjf
401 1.11.2.2 mjf return vp->v_usecount;
402 1.11.2.2 mjf }
403 1.11.2.2 mjf
404 1.11.2.2 mjf void
405 1.11.2.2 mjf rump_vp_decref(struct vnode *vp)
406 1.11.2.2 mjf {
407 1.11.2.2 mjf
408 1.11.2.2 mjf mutex_enter(&vp->v_interlock);
409 1.11.2.2 mjf --vp->v_usecount;
410 1.11.2.2 mjf mutex_exit(&vp->v_interlock);
411 1.11.2.2 mjf }
412 1.11.2.2 mjf
413 1.11.2.2 mjf /*
414 1.11.2.2 mjf * Really really recycle with a cherry on top. We should be
415 1.11.2.2 mjf * extra-sure we can do this. For example with p2k there is
416 1.11.2.2 mjf * no problem, since puffs in the kernel takes care of refcounting
417 1.11.2.2 mjf * for us.
418 1.11.2.2 mjf */
419 1.11.2.2 mjf void
420 1.11.2.2 mjf rump_vp_recycle_nokidding(struct vnode *vp)
421 1.11.2.2 mjf {
422 1.11.2.2 mjf
423 1.11.2.2 mjf mutex_enter(&vp->v_interlock);
424 1.11.2.2 mjf vp->v_usecount = 1;
425 1.11.2.2 mjf /*
426 1.11.2.2 mjf * XXX: NFS holds a reference to the root vnode, so don't clean
427 1.11.2.2 mjf * it out. This is very wrong, but fixing it properly would
428 1.11.2.2 mjf * take too much effort for now
429 1.11.2.2 mjf */
430 1.11.2.2 mjf if (vp->v_tag == VT_NFS && vp->v_vflag & VV_ROOT) {
431 1.11.2.2 mjf mutex_exit(&vp->v_interlock);
432 1.11.2.2 mjf return;
433 1.11.2.2 mjf }
434 1.11.2.2 mjf vclean(vp, DOCLOSE);
435 1.11.2.2 mjf vrelel(vp, 0);
436 1.11.2.2 mjf }
437 1.11.2.2 mjf
438 1.11.2.2 mjf void
439 1.11.2.2 mjf rump_vp_rele(struct vnode *vp)
440 1.11.2.2 mjf {
441 1.11.2.2 mjf
442 1.11.2.2 mjf vrele(vp);
443 1.11.2.2 mjf }
444 1.11.2.2 mjf
445 1.11.2.2 mjf void
446 1.11.2.2 mjf rump_vp_interlock(struct vnode *vp)
447 1.11.2.2 mjf {
448 1.11.2.2 mjf
449 1.11.2.2 mjf mutex_enter(&vp->v_interlock);
450 1.11.2.2 mjf }
451 1.11.2.2 mjf
452 1.11.2.2 mjf int
453 1.11.2.2 mjf rump_vfs_unmount(struct mount *mp, int mntflags)
454 1.11.2.2 mjf {
455 1.11.2.2 mjf
456 1.11.2.2 mjf return VFS_UNMOUNT(mp, mntflags);
457 1.11.2.2 mjf }
458 1.11.2.2 mjf
459 1.11.2.2 mjf int
460 1.11.2.2 mjf rump_vfs_root(struct mount *mp, struct vnode **vpp, int lock)
461 1.11.2.2 mjf {
462 1.11.2.2 mjf int rv;
463 1.11.2.2 mjf
464 1.11.2.2 mjf rv = VFS_ROOT(mp, vpp);
465 1.11.2.2 mjf if (rv)
466 1.11.2.2 mjf return rv;
467 1.11.2.2 mjf
468 1.11.2.2 mjf if (!lock)
469 1.11.2.2 mjf VOP_UNLOCK(*vpp, 0);
470 1.11.2.2 mjf
471 1.11.2.2 mjf return 0;
472 1.11.2.2 mjf }
473 1.11.2.2 mjf
474 1.11.2.2 mjf int
475 1.11.2.2 mjf rump_vfs_statvfs(struct mount *mp, struct statvfs *sbp)
476 1.11.2.2 mjf {
477 1.11.2.2 mjf
478 1.11.2.2 mjf return VFS_STATVFS(mp, sbp);
479 1.11.2.2 mjf }
480 1.11.2.2 mjf
481 1.11.2.2 mjf int
482 1.11.2.2 mjf rump_vfs_sync(struct mount *mp, int wait, kauth_cred_t cred)
483 1.11.2.2 mjf {
484 1.11.2.2 mjf
485 1.11.2.2 mjf return VFS_SYNC(mp, wait ? MNT_WAIT : MNT_NOWAIT, cred);
486 1.11.2.2 mjf }
487 1.11.2.2 mjf
488 1.11.2.2 mjf int
489 1.11.2.2 mjf rump_vfs_fhtovp(struct mount *mp, struct fid *fid, struct vnode **vpp)
490 1.11.2.2 mjf {
491 1.11.2.2 mjf
492 1.11.2.2 mjf return VFS_FHTOVP(mp, fid, vpp);
493 1.11.2.2 mjf }
494 1.11.2.2 mjf
495 1.11.2.2 mjf int
496 1.11.2.2 mjf rump_vfs_vptofh(struct vnode *vp, struct fid *fid, size_t *fidsize)
497 1.11.2.2 mjf {
498 1.11.2.2 mjf
499 1.11.2.2 mjf return VFS_VPTOFH(vp, fid, fidsize);
500 1.11.2.2 mjf }
501 1.11.2.2 mjf
502 1.11.2.2 mjf /*ARGSUSED*/
503 1.11.2.2 mjf void
504 1.11.2.2 mjf rump_vfs_syncwait(struct mount *mp)
505 1.11.2.2 mjf {
506 1.11.2.2 mjf int n;
507 1.11.2.2 mjf
508 1.11.2.2 mjf n = buf_syncwait();
509 1.11.2.2 mjf if (n)
510 1.11.2.2 mjf printf("syncwait: unsynced buffers: %d\n", n);
511 1.11.2.2 mjf }
512 1.11.2.2 mjf
513 1.11.2.2 mjf void
514 1.11.2.2 mjf rump_bioops_sync()
515 1.11.2.2 mjf {
516 1.11.2.2 mjf
517 1.11.2.2 mjf if (bioopsp)
518 1.11.2.2 mjf bioopsp->io_sync(NULL);
519 1.11.2.2 mjf }
520 1.11.2.2 mjf
521 1.11.2.2 mjf void
522 1.11.2.2 mjf rump_biodone(void *arg, size_t count, int error)
523 1.11.2.2 mjf {
524 1.11.2.2 mjf struct buf *bp = arg;
525 1.11.2.2 mjf
526 1.11.2.2 mjf bp->b_resid = bp->b_bcount - count;
527 1.11.2.2 mjf KASSERT(bp->b_resid >= 0);
528 1.11.2.2 mjf bp->b_error = error;
529 1.11.2.2 mjf
530 1.11.2.2 mjf rump_intr_enter();
531 1.11.2.2 mjf biodone(bp);
532 1.11.2.2 mjf rump_intr_exit();
533 1.11.2.2 mjf }
534 1.11.2.2 mjf
535 1.11.2.2 mjf static void
536 1.11.2.2 mjf rump_rcvp_lwpset(struct vnode *rvp, struct vnode *cvp, struct lwp *l)
537 1.11.2.2 mjf {
538 1.11.2.2 mjf struct cwdinfo *cwdi = l->l_proc->p_cwdi;
539 1.11.2.2 mjf
540 1.11.2.2 mjf KASSERT(cvp);
541 1.11.2.2 mjf
542 1.11.2.2 mjf rw_enter(&cwdi->cwdi_lock, RW_WRITER);
543 1.11.2.2 mjf if (cwdi->cwdi_rdir)
544 1.11.2.2 mjf vrele(cwdi->cwdi_rdir);
545 1.11.2.2 mjf if (rvp)
546 1.11.2.2 mjf vref(rvp);
547 1.11.2.2 mjf cwdi->cwdi_rdir = rvp;
548 1.11.2.2 mjf
549 1.11.2.2 mjf vrele(cwdi->cwdi_cdir);
550 1.11.2.2 mjf vref(cvp);
551 1.11.2.2 mjf cwdi->cwdi_cdir = cvp;
552 1.11.2.2 mjf rw_exit(&cwdi->cwdi_lock);
553 1.11.2.2 mjf }
554 1.11.2.2 mjf
555 1.11.2.2 mjf void
556 1.11.2.2 mjf rump_rcvp_set(struct vnode *rvp, struct vnode *cvp)
557 1.11.2.2 mjf {
558 1.11.2.2 mjf
559 1.11.2.2 mjf rump_rcvp_lwpset(rvp, cvp, curlwp);
560 1.11.2.2 mjf }
561 1.11.2.2 mjf
562 1.11.2.2 mjf struct vnode *
563 1.11.2.2 mjf rump_cdir_get()
564 1.11.2.2 mjf {
565 1.11.2.2 mjf struct vnode *vp;
566 1.11.2.2 mjf struct cwdinfo *cwdi = curlwp->l_proc->p_cwdi;
567 1.11.2.2 mjf
568 1.11.2.2 mjf rw_enter(&cwdi->cwdi_lock, RW_READER);
569 1.11.2.2 mjf vp = cwdi->cwdi_cdir;
570 1.11.2.2 mjf rw_exit(&cwdi->cwdi_lock);
571 1.11.2.2 mjf vref(vp);
572 1.11.2.2 mjf
573 1.11.2.2 mjf return vp;
574 1.11.2.2 mjf }
575