Add the ability to run puffs in userspace. This means that puffs

can now be developed in userspace using puffs for development
(I hate emulators, they are annoyingly clumsy).

To e.g. mount psshfs using puffs-on-puffs, run fs/bin/syspuffs/syspuffs
with the regular mount_psshfs command line as an argument:

    golem> ./syspuffs /usr/sbin/mount_psshfs ftp.netbsd.org:/pub /puffs

This will make the mount appear as usual, with the exception that the
requests will be passed through puffs both in the kernel and userspace:

    ftp.netbsd.org:/pub on /puffs type puffs|p2k|puffs|psshfs
This commit is contained in:
pooka 2008-01-02 18:15:12 +00:00
parent cf16702d95
commit 4f69d01d2f
18 changed files with 629 additions and 59 deletions

View File

@ -1,9 +1,9 @@
# $NetBSD: Makefile.rumpfs,v 1.7 2007/08/14 15:56:15 pooka Exp $
# $NetBSD: Makefile.rumpfs,v 1.8 2008/01/02 18:15:12 pooka Exp $
#
.include <bsd.own.mk>
RUMPFSLIST= cd9660fs efs ext2fs ffs hfs lfs msdosfs ntfs tmpfs udf
RUMPFSLIST= cd9660fs efs ext2fs ffs hfs lfs msdosfs ntfs syspuffs tmpfs udf
RUMPFSALL= ${RUMPFSLIST} p2k ukfs ufs
RUMPFSLIBDIR?= ${NETBSDSRCDIR}/sys/rump/fs/lib

View File

@ -0,0 +1,11 @@
# $NetBSD: Makefile,v 1.1 2008/01/02 18:15:12 pooka Exp $
#
PROG= syspuffs
LDADD+= ${RUMPFSLD_SYSPUFFS}
DPADD+= ${RUMPFSDP_SYSPUFFS}
CPPFLAGS+= -I${RUMPFSLIBDIR}/libsyspuffs
.include <bsd.prog.mk>

View File

@ -0,0 +1,131 @@
/* $NetBSD: syspuffs.c,v 1.1 2008/01/02 18:15:12 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
*
* Development of this software was supported by the
* Research Foundation of Helsinki University of Technology
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <assert.h>
#include <err.h>
#include <paths.h>
#include <puffs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "p2k.h"
#include "puffs_rumpglue.h"
static void
usage(void)
{
errx(1, "usage: %s file_server [fs opts] dev mountpath", getprogname());
}
int
main(int argc, char *argv[])
{
struct puffs_kargs kargs;
extern char **environ;
char *mntpath, *fromname;
size_t len;
char comfd[16];
int sv[2];
int mntflags, pflags, rv;
#if 1
extern int puffsdebug;
extern int putterdebug;
puffsdebug = putterdebug = 1;
#endif
setprogname(argv[0]);
if (argc < 2)
usage();
/* Create sucketpair for communication with the real file server */
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
err(1, "socketpair");
snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
if (setenv("PUFFS_COMFD", comfd, 1) == -1)
err(1, "setenv");
switch (fork()) {
case 0:
argv++;
if (execve(argv[0], argv, environ) == -1)
err(1, "execvp");
/*NOTREACHED*/
case -1:
err(1, "fork");
/*NOTREACHED*/
default:
unsetenv("PUFFS_COMFD");
break;
}
/* read args */
if (read(sv[1], &len, sizeof(len)) != sizeof(len))
err(1, "mp 1");
mntpath = malloc(len);
if (mntpath == NULL)
err(1, "malloc %zu", len);
if (read(sv[1], mntpath, len) != len)
err(1, "mp 2");
if (read(sv[1], &len, sizeof(len)) != sizeof(len))
err(1, "fn 1");
fromname = malloc(len);
if (fromname == NULL)
err(1, "malloc %zu", len);
if (read(sv[1], fromname, len) != len)
err(1, "fn 2");
if (read(sv[1], &mntflags, sizeof(mntflags)) != sizeof(mntflags))
err(1, "mntflags");
if (read(sv[1], &kargs, sizeof(kargs)) != sizeof(kargs))
err(1, "puffs_args");
if (read(sv[1], &pflags, sizeof(kargs)) != sizeof(pflags))
err(1, "pflags");
/* XXX: some adjustments */
pflags |= PUFFS_KFLAG_NOCACHE;
pflags &= ~PUFFS_FLAG_BUILDPATH;
rv = puffs_rumpglue_init(sv[1], &kargs.pa_fd);
assert(rv == 0);
rv = p2k_run_fs(MOUNT_PUFFS, fromname, mntpath, mntflags,
&kargs, sizeof(kargs), pflags);
if (rv)
err(1, "mount");
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: p2k.c,v 1.34 2008/01/02 15:44:03 pooka Exp $ */
/* $NetBSD: p2k.c,v 1.35 2008/01/02 18:15:13 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -160,7 +160,12 @@ p2k_run_fs(const char *vfsname, const char *devpath, const char *mountpath,
PUFFSOP_SET(pops, p2k, node, reclaim);
strcpy(typebuf, "p2k|");
strlcat(typebuf, vfsname, sizeof(typebuf));
if (strcmp(vfsname, "puffs") == 0) { /* XXX */
struct puffs_kargs *args = arg;
strlcat(typebuf, args->pa_typename, sizeof(typebuf));
} else {
strlcat(typebuf, vfsname, sizeof(typebuf));
}
pu = puffs_init(pops, devpath, typebuf, ukfs_getmp(ukfs), puffs_flags);
if (pu == NULL)

View File

@ -0,0 +1,21 @@
# $NetBSD: Makefile,v 1.1 2008/01/02 18:15:13 pooka Exp $
#
.include <bsd.own.mk>
LIB= syspuffs
.PATH: ${NETBSDSRCDIR}/sys/fs/puffs
.PATH: ${NETBSDSRCDIR}/sys/dev/putter
SRCS= puffs_msgif.c puffs_node.c puffs_subr.c puffs_vfsops.c puffs_vnops.c
SRCS+= putter.c
SRCS+= puffs_rumpglue.c
CPPFLAGS+= -I${NETBSDSRCDIR}/sys/rump/librump/rumpkern
CPPFLAGS+= -I${NETBSDSRCDIR}/sys/rump/librump/rumpuser
CPPFLAGS+= -DPUFFSDEBUG -DPUTTERDEBUG
.include <bsd.lib.mk>
.include <bsd.klinks.mk>

View File

@ -0,0 +1,171 @@
/* $NetBSD: puffs_rumpglue.c,v 1.1 2008/01/02 18:15:13 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
*
* Development of this software was supported by the
* Research Foundation of Helsinki University of Technology
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_rumpglue.c,v 1.1 2008/01/02 18:15:13 pooka Exp $");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/kthread.h>
#include <sys/mount.h>
#include <dev/putter/putter_sys.h>
#include "rump.h"
#include "rumpuser.h"
#include "puffs_rumpglue.h"
int
dounmount(struct mount *mp, int flags, struct lwp *l)
{
VFS_UNMOUNT(mp, MNT_FORCE);
panic("control fd is dead");
}
void putterattach(void); /* XXX: from autoconf */
dev_type_open(puttercdopen);
struct ptargs {
int comfd;
int fpfd;
struct filedesc *fdp;
};
#define BUFSIZE (64*1024)
extern int hz;
/*
* Read requests from /dev/puffs and forward them to comfd
*
* XXX: the init detection is really sucky, but let's not
* waste too much energy for a better one here
*/
static void
readthread(void *arg)
{
struct ptargs *pap = arg;
struct file *fp;
register_t rv;
char *buf;
off_t off;
int error, inited;
buf = kmem_alloc(BUFSIZE, KM_SLEEP);
inited = 0;
retry:
kpause(NULL, 0, hz/4, NULL);
for (;;) {
ssize_t n;
off = 0;
fp = fd_getfile(pap->fdp, pap->fpfd);
FILE_USE(fp);
error = dofileread(pap->fpfd, fp, buf, BUFSIZE,
&off, 0, &rv);
if (error) {
if (error == ENOENT && inited == 0)
goto retry;
if (error == ENXIO)
kthread_exit(0);
panic("fileread failed: %d", error);
}
inited = 1;
while (rv) {
n = rumpuser_write(pap->comfd, buf, rv, &error);
if (n == -1)
panic("fileread failed: %d", error);
if (n == 0)
panic("fileread failed: closed");
rv -= n;
}
}
}
/* Read requests from comfd and proxy them to /dev/puffs */
static void
writethread(void *arg)
{
struct ptargs *pap = arg;
struct file *fp;
register_t rv;
char *buf;
off_t off;
int error;
buf = kmem_alloc(BUFSIZE, KM_SLEEP);
for (;;) {
ssize_t n;
n = rumpuser_read(pap->comfd, buf, BUFSIZE, &error);
if (n <= 0)
panic("rumpuser_read %zd %d", n, error);
off = 0;
fp = fd_getfile(pap->fdp, pap->fpfd);
FILE_USE(fp);
error = dofilewrite(pap->fpfd, fp, buf, n,
&off, 0, &rv);
if (error == ENXIO)
kthread_exit(0);
KASSERT(rv == n);
}
}
int
puffs_rumpglue_init(int fd, int *newfd)
{
struct ptargs *pap;
int rv;
rump_init();
putterattach();
rv = puttercdopen(makedev(178, 0), 0, 0, curlwp);
if (rv && rv != EMOVEFD)
return rv;
pap = kmem_alloc(sizeof(struct ptargs), KM_SLEEP);
pap->comfd = fd;
pap->fpfd = curlwp->l_dupfd;
pap->fdp = curlwp->l_proc->p_fd;
kthread_create(PRI_NONE, 0, NULL, readthread, pap, NULL, "rputter");
kthread_create(PRI_NONE, 0, NULL, writethread, pap, NULL, "wputter");
*newfd = curlwp->l_dupfd;
return 0;
}

View File

@ -0,0 +1,31 @@
/* $NetBSD: puffs_rumpglue.h,v 1.1 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
*
* Development of this software was supported by the
* Research Foundation of Helsinki University of Technology
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
int puffs_rumpglue_init(int, int *);

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.24 2008/01/02 12:49:53 ad Exp $
# $NetBSD: Makefile,v 1.25 2008/01/02 18:15:14 pooka Exp $
#
.include <bsd.own.mk>
@ -12,17 +12,17 @@ LIB= rump
${NETBSDSRCDIR}/sys/miscfs/syncfs
# implement something
SRCS= rump.c atomic.c auth.c emul.c genfs_io.c locks.c ltsleep.c pool.c \
intr.c specfs.c vfs.c vm.c
SRCS= rump.c atomic.c auth.c emul.c intr.c genfs_io.c locks.c \
ltsleep.c pool.c specfs.c vfs.c vm.c
# just stubs
SRCS+= fstrans_stub.c misc_stub.c pmap_stub.c vfsops_stub.c
# sys/kern
SRCS+= clock_subr.c kern_lock.c kern_stub.c param.c subr_bufq.c \
subr_hash.c subr_prf2.c subr_specificdata.c subr_time.c \
vfs_bio.c vfs_cache.c vfs_vnops.c vfs_init.c vfs_subr2.c \
vnode_if.c subr_workqueue.c
SRCS+= clock_subr.c kern_descrip.c kern_lock.c kern_stub.c param.c \
subr_bufq.c subr_hash.c subr_prf2.c subr_specificdata.c \
subr_time.c subr_workqueue.c sys_generic.c vfs_bio.c \
vfs_cache.c vfs_vnops.c vfs_init.c vfs_subr2.c vnode_if.c
# sys/miscfs
SRCS+= genfs_vnops.c sync_subr.c
@ -43,6 +43,8 @@ CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/common/include \
-I${NETBSDSRCDIR}/sys/rump/librump/rumpuser \
-I${.CURDIR}/opt -DMAXUSERS=32
CFLAGS+= -Wno-pointer-sign
# Create a few files. We can't include them directly, because that
# would create hideous namespace lossage. So just do some clever
# (or less clever) renaming.

View File

@ -1,4 +1,4 @@
/* $NetBSD: auth.c,v 1.3 2007/12/08 19:29:52 pooka Exp $ */
/* $NetBSD: auth.c,v 1.4 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -49,6 +49,8 @@ rump_cred_create(uid_t uid, gid_t gid, size_t ngroups, gid_t *groups)
kauth_cred_t cred;
size_t credsize;
KASSERT(ngroups <= NGROUPS);
credsize = sizeof(struct kauth_cred) + ngroups * sizeof(gid_t);
cred = rumpuser_malloc(credsize, 0);
@ -150,6 +152,36 @@ kauth_cred_group(kauth_cred_t cred, u_int idx)
return cred->cr_groups[idx];
}
void
kauth_cred_to_uucred(struct uucred *uucred, const kauth_cred_t cred)
{
if (cred == RUMPCRED_SUSER) {
memset(uucred, 0, sizeof(struct uucred));
return;
}
uucred->cr_uid = cred->cr_uid;
uucred->cr_gid = cred->cr_gid;
uucred->cr_ngroups = cred->cr_ngroups;
memcpy(uucred->cr_groups, cred->cr_groups,
cred->cr_ngroups * sizeof(gid_t));
}
void
kauth_cred_hold(kauth_cred_t cred)
{
/* nada: creds are always destroyed upon exit from VOP */
}
void
kauth_cred_free(kauth_cred_t cred)
{
/* nada: see above */
}
kauth_cred_t
kauth_cred_get()
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: emul.c,v 1.19 2007/11/11 17:18:47 pooka Exp $ */
/* $NetBSD: emul.c,v 1.20 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -40,10 +40,12 @@
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/queue.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/kthread.h>
#include <sys/cpu.h>
#include <sys/kmem.h>
#include <sys/poll.h>
#include <machine/stdarg.h>
@ -75,6 +77,7 @@ MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure");
MALLOC_DEFINE(M_TEMP, "temp", "misc. temporary data buffers");
MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory");
MALLOC_DEFINE(M_VNODE, "vnodes", "Dynamically allocated vnodes");
MALLOC_DEFINE(M_KEVENT, "kevent", "kevents/knotes");
char hostname[MAXHOSTNAMELEN];
size_t hostnamelen;
@ -87,6 +90,8 @@ u_int nbuf;
const char *panicstr;
const struct filterops seltrue_filtops;
void
panic(const char *fmt, ...)
{
@ -389,3 +394,77 @@ callout_stop(callout_t *c)
panic("%s: not implemented", __func__);
}
struct proc *
p_find(pid_t pid, uint flags)
{
panic("%s: not implemented", __func__);
}
struct pgrp *
pg_find(pid_t pid, uint flags)
{
panic("%s: not implemented", __func__);
}
void
kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
{
panic("%s: not implemented", __func__);
}
void
kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
{
panic("%s: not implemented", __func__);
}
int
pgid_in_session(struct proc *p, pid_t pg_id)
{
panic("%s: not implemented", __func__);
}
int
sigispending(struct lwp *l, int signo)
{
return 0;
}
void
knote_fdclose(struct lwp *l, int fd)
{
/* since we don't add knotes, we don't have to remove them */
}
int
seltrue_kqfilter(dev_t dev, struct knote *kn)
{
panic("%s: not implemented", __func__);
}
int
kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
{
extern int hz;
int rv, error;
if (mtx)
mutex_exit(mtx);
rv = rumpuser_usleep(timeo * (1000000 / hz), &error);
if (mtx)
mutex_enter(mtx);
if (rv)
return error;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fstrans_stub.c,v 1.4 2008/01/02 11:49:05 ad Exp $ */
/* $NetBSD: fstrans_stub.c,v 1.5 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -88,6 +88,20 @@ fscow_run(struct buf *bp, bool data_valid)
return 0;
}
int
vfs_suspend(struct mount *mp, int nowait)
{
return ENOSYS;
}
void
vfs_resume(struct mount *mp)
{
panic("%s: impossible", __func__);
}
int
fstrans_mount(struct mount *mp)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: pool.c,v 1.4 2007/11/07 16:22:22 pooka Exp $ */
/* $NetBSD: pool.c,v 1.5 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -61,7 +61,7 @@ pool_cache_init(size_t size, u_int align, u_int align_offset, u_int flags,
pool_cache_t pc;
char *ptr;
ptr = rumpuser_malloc(sizeof(*pc) + CACHE_LINE_SIZE, 0);
ptr = kmem_zalloc(sizeof(*pc) + CACHE_LINE_SIZE, KM_SLEEP);
pc = (pool_cache_t)(((uintptr_t)ptr + CACHE_LINE_SIZE - 1) &
~(CACHE_LINE_SIZE - 1));
@ -74,6 +74,14 @@ pool_cache_init(size_t size, u_int align, u_int align_offset, u_int flags,
return pc;
}
void
pool_cache_destroy(pool_cache_t pc)
{
pool_destroy(&pc->pc_pool);
kmem_free(pc, sizeof(*pc) + CACHE_LINE_SIZE);
}
void *
pool_cache_get_paddr(pool_cache_t pc, int flags, paddr_t *pap)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump.c,v 1.26 2008/01/02 15:44:03 pooka Exp $ */
/* $NetBSD: rump.c,v 1.27 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -28,6 +28,7 @@
*/
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/filedesc.h>
#include <sys/kauth.h>
#include <sys/kmem.h>
@ -35,8 +36,8 @@
#include <sys/namei.h>
#include <sys/queue.h>
#include <sys/resourcevar.h>
#include <sys/select.h>
#include <sys/vnode.h>
#include <sys/cpu.h>
#include <miscfs/specfs/specdev.h>
@ -49,6 +50,7 @@ struct pstats rump_stats;
struct plimit rump_limits;
kauth_cred_t rump_cred;
struct cpu_info rump_cpu;
struct filedesc0 rump_filedesc0;
kmutex_t rump_giantlock;
@ -70,6 +72,8 @@ rump_aiodone_worker(struct work *wk, void *dummy)
bp->b_iodone(bp);
}
int rump_inited;
void
rump_init()
{
@ -80,12 +84,19 @@ rump_init()
struct lwp *l;
int error;
/* XXX */
if (rump_inited)
return;
rump_inited = 1;
l = &lwp0;
p = &rump_proc;
p->p_stats = &rump_stats;
p->p_cwdi = &rump_cwdi;
p->p_limit = &rump_limits;
p->p_pid = 0;
p->p_fd = &rump_filedesc0.fd_fd;
p->p_vmspace = &rump_vmspace;
l->l_cred = rump_cred;
l->l_proc = p;
l->l_lid = 1;
@ -94,12 +105,15 @@ rump_init()
rumpvm_init();
rump_limits.pl_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
rump_limits.pl_rlimit[RLIMIT_NOFILE].rlim_cur = RLIM_INFINITY;
/* should be "enough" */
syncdelay = 0;
vfsinit();
bufinit();
filedesc_init();
selsysinit();
rump_sleepers_init();
rumpuser_thrinit();
@ -115,6 +129,8 @@ rump_init()
hostnamelen = strlen(hostname);
sigemptyset(&sigcantmask);
fdinit1(&rump_filedesc0);
}
struct mount *
@ -143,13 +159,8 @@ rump_mnt_mount(struct mount *mp, const char *path, void *data, size_t *dlen)
if (rv)
return rv;
rv = VFS_STATVFS(mp, &mp->mnt_stat);
if (rv) {
VFS_UNMOUNT(mp, MNT_FORCE);
return rv;
}
rv = VFS_START(mp, 0);
(void) VFS_STATVFS(mp, &mp->mnt_stat);
rv = VFS_START(mp, 0);
if (rv)
VFS_UNMOUNT(mp, MNT_FORCE);
@ -536,6 +547,7 @@ rump_setup_curlwp(pid_t pid, lwpid_t lid, int set)
p->p_cwdi = &rump_cwdi;
p->p_limit = &rump_limits;
p->p_pid = pid;
p->p_vmspace = &rump_vmspace;
l->l_cred = rump_cred;
l->l_proc = p;
l->l_lid = lid;

View File

@ -1,4 +1,4 @@
/* $NetBSD: specfs.c,v 1.14 2008/01/02 15:44:04 pooka Exp $ */
/* $NetBSD: specfs.c,v 1.15 2008/01/02 18:15:14 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -252,11 +252,10 @@ rump_specstrategy(void *v)
} else {
syncfallback:
if (bp->b_flags & B_READ) {
printf("scheduling read\n");
rumpuser_read(sp->rsp_fd, bp->b_data,
rumpuser_read_bio(sp->rsp_fd, bp->b_data,
bp->b_bcount, off, bp);
} else {
rumpuser_write(sp->rsp_fd, bp->b_data,
rumpuser_write_bio(sp->rsp_fd, bp->b_data,
bp->b_bcount, off, bp);
}
biowait(bp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs.c,v 1.24 2008/01/02 15:44:04 pooka Exp $ */
/* $NetBSD: vfs.c,v 1.25 2008/01/02 18:15:15 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -93,9 +93,12 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
vp->v_vnlock = &vp->v_lock;
vp->v_usecount = 1;
mutex_init(&vp->v_interlock, MUTEX_DEFAULT, IPL_NONE);
TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes);
lockinit(&vp->v_lock, PVFS, "vnlock", 0, 0);
cv_init(&vp->v_cv, "vnode");
lockinit(&vp->v_lock, PVFS, "vnlock", 0, 0);
if (mp) {
TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes);
}
uobj = &vp->v_uobj;
uobj->pgops = &uvm_vnodeops;
@ -184,7 +187,6 @@ valloc(struct mount *mp)
uobj = &vp->v_uobj;
uobj->pgops = &uvm_vnodeops;
mutex_init(&vp->v_interlock, MUTEX_DEFAULT, IPL_NONE);
lockinit(&vp->v_lock, PVFS, "vnlock", 0, 0);
cv_init(&vp->v_cv, "vnode");
TAILQ_INIT(&uobj->memq);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.c,v 1.9 2007/11/04 18:43:55 pooka Exp $ */
/* $NetBSD: rumpuser.c,v 1.10 2008/01/02 18:15:15 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -87,6 +87,13 @@ rumpuser_lstat(const char *path, struct stat *sb, int *error)
DOCALL(int, (lstat(path, sb)));
}
int
rumpuser_usleep(unsigned long sec, int *error)
{
DOCALL(int, (usleep(sec)));
}
void *
_rumpuser_malloc(size_t howmuch, int canfail, const char *func, int line)
{
@ -154,40 +161,80 @@ rumpuser_fsync(int fd, int *error)
DOCALL(int, fsync(fd));
}
void
rumpuser_read(int fd, void *data, size_t size, off_t offset,
void *biodonecookie)
ssize_t
rumpuser_read(int fd, void *data, size_t size, int *error)
{
ssize_t rv;
rv = read(fd, data, size);
if (rv == -1)
*error = errno;
return rv;
}
ssize_t
rumpuser_pread(int fd, void *data, size_t size, off_t offset, int *error)
{
ssize_t rv;
int error;
error = 0;
rv = pread(fd, data, size, offset);
if (rv == -1)
*error = errno;
/* check against <0 instead of ==-1 to get typing below right */
if (rv < 0) {
error = errno;
rv = 0;
}
rump_biodone(biodonecookie, rv, error);
return rv;
}
void
rumpuser_write(int fd, const void *data, size_t size, off_t offset,
rumpuser_read_bio(int fd, void *data, size_t size, off_t offset,
void *biodonecookie)
{
ssize_t rv;
int error;
error = 0;
rv = pwrite(fd, data, size, offset);
rv = rumpuser_pread(fd, data, size, offset, &error);
/* check against <0 instead of ==-1 to get typing below right */
if (rv < 0) {
error = errno;
if (rv < 0)
rv = 0;
rump_biodone(biodonecookie, rv, error);
}
ssize_t
rumpuser_write(int fd, const void *data, size_t size, int *error)
{
ssize_t rv;
rv = write(fd, data, size);
if (rv == -1)
*error = errno;
return rv;
}
ssize_t
rumpuser_pwrite(int fd, const void *data, size_t size, off_t offset, int *error)
{
ssize_t rv;
rv = pwrite(fd, data, size, offset);
if (rv == -1)
*error = errno;
return rv;
}
void
rumpuser_write_bio(int fd, const void *data, size_t size, off_t offset,
void *biodonecookie)
{
ssize_t rv;
int error;
rv = rumpuser_pwrite(fd, data, size, offset, &error);
/* check against <0 instead of ==-1 to get typing below right */
if (rv < 0)
rv = 0;
}
rump_biodone(biodonecookie, rv, error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.h,v 1.12 2007/11/19 14:17:22 pooka Exp $ */
/* $NetBSD: rumpuser.h,v 1.13 2008/01/02 18:15:15 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -36,6 +36,7 @@
int rumpuser_stat(const char *, struct stat *, int *);
int rumpuser_lstat(const char *, struct stat *, int *);
int rumpuser_usleep(unsigned long, int *);
#define rumpuser_malloc(a,b) _rumpuser_malloc(a,b,__func__,__LINE__);
#define rumpuser_realloc(a,b,c) _rumpuser_realloc(a,b,c,__func__,__LINE__);
@ -49,8 +50,12 @@ int rumpuser_ioctl(int, u_long, void *, int *);
int rumpuser_close(int, int *);
int rumpuser_fsync(int, int *);
void rumpuser_read(int, void *, size_t, off_t, void *);
void rumpuser_write(int, const void *, size_t, off_t, void *);
ssize_t rumpuser_read(int, void *, size_t, int *);
ssize_t rumpuser_pread(int, void *, size_t, off_t, int *);
ssize_t rumpuser_write(int, const void *, size_t, int *);
ssize_t rumpuser_pwrite(int, const void *, size_t, off_t, int *);
void rumpuser_read_bio(int, void *, size_t, off_t, void *);
void rumpuser_write_bio(int, const void *, size_t, off_t, void *);
int rumpuser_gettimeofday(struct timeval *, int *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser_pth.c,v 1.6 2007/11/19 14:17:22 pooka Exp $ */
/* $NetBSD: rumpuser_pth.c,v 1.7 2008/01/02 18:15:15 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -80,10 +80,10 @@ iothread(void *arg)
pthread_mutex_unlock(&rua_mtx.pthmtx);
if (rua->rua_op)
rumpuser_read(rua->rua_fd, rua->rua_data,
rumpuser_read_bio(rua->rua_fd, rua->rua_data,
rua->rua_dlen, rua->rua_off, rua->rua_bp);
else
rumpuser_write(rua->rua_fd, rua->rua_data,
rumpuser_write_bio(rua->rua_fd, rua->rua_data,
rua->rua_dlen, rua->rua_off, rua->rua_bp);
free(rua);