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