Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Support physio for remote processes.



details:   https://anonhg.NetBSD.org/src/rev/83dcc96cc4fd
branches:  trunk
changeset: 758970:83dcc96cc4fd
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Nov 22 20:42:19 2010 +0000

description:
Support physio for remote processes.
==> add support for remote vmspace vmapbuf/vunmapbuf
  ==> add proper support for copyin/out_vmspace
    ==> add support for remote vmspace uvm_io
      ==> add support for non-curproc rumpuser_sp_copyin/out
        ==> store remote context in vm_map->pmap instead of
            pthread_specificdata

In short, makes read/write of most (all?) block devices work from
a remote rump client via rump syscalls.

diffstat:

 lib/librumpuser/rumpuser_sp.c        |  53 +++++++------------------
 sys/rump/include/rump/rumpuser.h     |  12 ++--
 sys/rump/librump/rumpkern/lwproc.c   |  10 +++-
 sys/rump/librump/rumpkern/rump.c     |  37 ++++++++++++-----
 sys/rump/librump/rumpkern/rumpcopy.c |  76 ++++++++++++++++++++++++++++++-----
 sys/rump/librump/rumpkern/vm.c       |  46 +++++++++++++--------
 6 files changed, 147 insertions(+), 87 deletions(-)

diffs (truncated from 557 to 300 lines):

diff -r a5dfc8ffbb19 -r 83dcc96cc4fd lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Mon Nov 22 20:29:15 2010 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Mon Nov 22 20:42:19 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_sp.c,v 1.9 2010/11/19 17:47:44 pooka Exp $   */
+/*      $NetBSD: rumpuser_sp.c,v 1.10 2010/11/22 20:42:19 pooka Exp $  */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.9 2010/11/19 17:47:44 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.10 2010/11/22 20:42:19 pooka Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -68,7 +68,6 @@
 static struct pollfd pfdlist[MAXCLI];
 static struct spclient spclist[MAXCLI];
 static unsigned int nfds, maxidx;
-static pthread_key_t spclient_tls;
 
 static struct rumpuser_sp_ops spops;
 
@@ -96,12 +95,12 @@
 }
 
 static int
-lwproc_newproc(void)
+lwproc_newproc(struct spclient *spc)
 {
        int rv;
 
        spops.spop_schedule();
-       rv = spops.spop_lwproc_newproc();
+       rv = spops.spop_lwproc_newproc(spc);
        spops.spop_unschedule();
 
        return rv;
@@ -350,17 +349,17 @@
                return error;
        }
 
-       if ((error = lwproc_newproc()) != 0) {
-               close(newfd);
-               return error;
-       }
-
        /* find empty slot the simple way */
        for (i = 0; i < MAXCLI; i++) {
                if (pfdlist[i].fd == -1)
                        break;
        }
 
+       if ((error = lwproc_newproc(&spclist[i])) != 0) {
+               close(newfd);
+               return error;
+       }
+
        assert(i < MAXCLI);
        nfds++;
 
@@ -395,11 +394,9 @@
        DPRINTF(("rump_sp: handling syscall %d from client %d\n",
            sysnum, 0));
 
-       pthread_setspecific(spclient_tls, spc);
        lwproc_newlwp(spc->spc_pid);
        rv = rumpsyscall(sysnum, data, retval);
        lwproc_switch(NULL);
-       pthread_setspecific(spclient_tls, NULL);
        free(data);
 
        DPRINTF(("rump_sp: got return value %d & %d/%d\n",
@@ -424,15 +421,11 @@
 }
 
 int
-rumpuser_sp_copyin(const void *uaddr, void *kaddr, size_t len)
+rumpuser_sp_copyin(void *arg, const void *uaddr, void *kaddr, size_t len)
 {
-       struct spclient *spc;
+       struct spclient *spc = arg;
        void *rdata = NULL; /* XXXuninit */
 
-       spc = pthread_getspecific(spclient_tls);
-       if (!spc)
-               return EFAULT;
-
        copyin_req(spc, uaddr, len, &rdata);
 
        memcpy(kaddr, rdata, len);
@@ -442,15 +435,9 @@
 }
 
 int
-rumpuser_sp_copyout(const void *kaddr, void *uaddr, size_t dlen)
+rumpuser_sp_copyout(void *arg, const void *kaddr, void *uaddr, size_t dlen)
 {
-       struct spclient *spc;
-
-       spc = pthread_getspecific(spclient_tls);
-       if (!spc) {
-               DPRINTF(("rump_sp: copyout curlwp not found\n"));
-               return EFAULT;
-       }
+       struct spclient *spc = arg;
 
        if (send_copyout_req(spc, uaddr, kaddr, dlen) != 0)
                return EFAULT;
@@ -458,16 +445,12 @@
 }
 
 int
-rumpuser_sp_anonmmap(size_t howmuch, void **addr)
+rumpuser_sp_anonmmap(void *arg, size_t howmuch, void **addr)
 {
-       struct spclient *spc;
+       struct spclient *spc = arg;
        void *resp, *rdata;
        int rv;
 
-       spc = pthread_getspecific(spclient_tls);
-       if (!spc)
-               return EFAULT;
-
        rv = anonmmap_req(spc, howmuch, &rdata);
        if (rv)
                return rv;
@@ -638,12 +621,6 @@
 
        /* sloppy error recovery */
 
-       error = pthread_key_create(&spclient_tls, NULL);
-       if (error) {
-               fprintf(stderr, "rump_sp: tls create failed\n");
-               return error;
-       }
-
        /*LINTED*/
        if (bind(s, sap, sap->sa_len) == -1) {
                fprintf(stderr, "rump_sp: server bind failed\n");
diff -r a5dfc8ffbb19 -r 83dcc96cc4fd sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Mon Nov 22 20:29:15 2010 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Mon Nov 22 20:42:19 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.h,v 1.51 2010/11/19 17:06:57 pooka Exp $      */
+/*     $NetBSD: rumpuser.h,v 1.52 2010/11/22 20:42:19 pooka Exp $      */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -36,7 +36,7 @@
 #include <stdint.h>
 #endif
 
-#define RUMPUSER_VERSION 4
+#define RUMPUSER_VERSION 5
 int rumpuser_getversion(void);
 
 struct msghdr;
@@ -210,7 +210,7 @@
 
        void (*spop_lwproc_switch)(struct lwp *);
        void (*spop_lwproc_release)(void);
-       int (*spop_lwproc_newproc)(void);
+       int (*spop_lwproc_newproc)(void *);
        int (*spop_lwproc_newlwp)(pid_t);
        struct lwp * (*spop_lwproc_curlwp)(void);
        int (*spop_syscall)(int, void *, register_t *);
@@ -218,8 +218,8 @@
 };
 
 int    rumpuser_sp_init(const struct rumpuser_sp_ops *, const char *);
-int    rumpuser_sp_copyin(const void *, void *, size_t);
-int    rumpuser_sp_copyout(const void *, void *, size_t);
-int    rumpuser_sp_anonmmap(size_t, void **);
+int    rumpuser_sp_copyin(void *, const void *, void *, size_t);
+int    rumpuser_sp_copyout(void *, const void *, void *, size_t);
+int    rumpuser_sp_anonmmap(void *, size_t, void **);
 
 #endif /* _RUMP_RUMPUSER_H_ */
diff -r a5dfc8ffbb19 -r 83dcc96cc4fd sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c        Mon Nov 22 20:29:15 2010 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c        Mon Nov 22 20:42:19 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.5 2010/11/17 19:54:09 pooka Exp $        */
+/*      $NetBSD: lwproc.c,v 1.6 2010/11/22 20:42:19 pooka Exp $        */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.5 2010/11/17 19:54:09 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.6 2010/11/22 20:42:19 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -77,6 +77,12 @@
        cv_destroy(&p->p_waitcv);
        cv_destroy(&p->p_lwpcv);
 
+       /* non-kernel vmspaces are not shared */
+       if (p->p_vmspace != vmspace_kernel()) {
+               KASSERT(p->p_vmspace->vm_refcnt == 1);
+               kmem_free(p->p_vmspace, sizeof(*p->p_vmspace));
+       }
+
        proc_free_mem(p);
 }
 
diff -r a5dfc8ffbb19 -r 83dcc96cc4fd sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Mon Nov 22 20:29:15 2010 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Mon Nov 22 20:42:19 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.205 2010/11/21 22:17:24 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.206 2010/11/22 20:42:19 pooka Exp $ */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.205 2010/11/21 22:17:24 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.206 2010/11/22 20:42:19 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -100,13 +100,8 @@
 int rump_threads = 1;
 #endif
 
-/*
- * System call proxying support.  These deserve another look later,
- * but good enough for now.
- */
-static struct vmspace sp_vmspace;
-
 static int rump_proxy_syscall(int, void *, register_t *);
+static int rump_proxy_newproc(void *);
 
 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
 
@@ -202,7 +197,7 @@
        .spop_unschedule        = rump_unschedule,
        .spop_lwproc_switch     = rump_lwproc_switch,
        .spop_lwproc_release    = rump_lwproc_releaselwp,
-       .spop_lwproc_newproc    = rump_lwproc_newproc,
+       .spop_lwproc_newproc    = rump_proxy_newproc,
        .spop_lwproc_newlwp     = rump_lwproc_newlwp,
        .spop_lwproc_curlwp     = rump_lwproc_curlwp,
        .spop_syscall           = rump_proxy_syscall,
@@ -649,13 +644,33 @@
 
        callp = rump_sysent + num;
        l = curlwp;
-       curproc->p_vmspace = &sp_vmspace;
        rv = sy_call(callp, l, (void *)arg, retval);
-       curproc->p_vmspace = vmspace_kernel();
 
        return rv;
 }
 
+static int
+rump_proxy_newproc(void *priv)
+{
+       struct vmspace *newspace;
+       int error;
+
+       if ((error = rump_lwproc_newproc()) != 0)
+               return error;
+
+       /*
+        * Since it's a proxy proc, adjust the vmspace.
+        * Refcount will eternally be 1.
+        */
+       newspace = kmem_alloc(sizeof(*newspace), KM_SLEEP);
+       newspace->vm_refcnt = 1;
+       newspace->vm_map.pmap = priv;
+       KASSERT(curproc->p_vmspace == vmspace_kernel());
+       curproc->p_vmspace = newspace;
+
+       return 0;
+}
+
 int
 rump_boot_gethowto()
 {
diff -r a5dfc8ffbb19 -r 83dcc96cc4fd sys/rump/librump/rumpkern/rumpcopy.c
--- a/sys/rump/librump/rumpkern/rumpcopy.c      Mon Nov 22 20:29:15 2010 +0000
+++ b/sys/rump/librump/rumpkern/rumpcopy.c      Mon Nov 22 20:42:19 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpcopy.c,v 1.10 2010/11/17 19:54:09 pooka Exp $      */
+/*     $NetBSD: rumpcopy.c,v 1.11 2010/11/22 20:42:19 pooka Exp $      */
 
 /*



Home | Main Index | Thread Index | Old Index