Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Refactor the sysproxy code so that rumpuser contains only th...
details: https://anonhg.NetBSD.org/src/rev/f7574cdb7738
branches: trunk
changeset: 758436:f7574cdb7738
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Nov 04 20:54:07 2010 +0000
description:
Refactor the sysproxy code so that rumpuser contains only the server side.
diffstat:
lib/librumpuser/rumpuser_sp.c | 582 ++----------------------------
lib/librumpuser/sp_common.c | 405 +++++++++++++++++++++
sys/rump/include/rump/rump_syscalls.h | 2 +-
sys/rump/include/rump/rumpuser.h | 9 +-
sys/rump/librump/rumpkern/rump.c | 42 +-
sys/rump/librump/rumpkern/rump_private.h | 5 +-
6 files changed, 467 insertions(+), 578 deletions(-)
diffs (truncated from 1231 to 300 lines):
diff -r a8dd81440f0f -r f7574cdb7738 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c Thu Nov 04 20:51:18 2010 +0000
+++ b/lib/librumpuser/rumpuser_sp.c Thu Nov 04 20:54:07 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_sp.c,v 1.4 2010/11/01 13:55:19 pooka Exp $ */
+/* $NetBSD: rumpuser_sp.c,v 1.5 2010/11/04 20:54:07 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.4 2010/11/01 13:55:19 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.5 2010/11/04 20:54:07 pooka Exp $");
#include <sys/types.h>
#include <sys/mman.h>
@@ -61,84 +61,7 @@
#include <rump/rumpuser.h>
-//#define DEBUG
-#ifdef DEBUG
-#include <rump/rump.h>
-#include <rump/rump_syscalls.h>
-#define DPRINTF(x) mydprintf x
-static void
-mydprintf(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- va_end(ap);
-}
-#else
-#define DPRINTF(x)
-#endif
-
-/*
- * Bah, I hate writing on-off-wire conversions in C
- */
-
-enum {
- RUMPSP_SYSCALL_REQ, RUMPSP_SYSCALL_RESP,
- RUMPSP_COPYIN_REQ, RUMPSP_COPYIN_RESP,
- RUMPSP_COPYOUT_REQ, /* no copyout resp */
- RUMPSP_ANONMMAP_REQ, RUMPSP_ANONMMAP_RESP
-};
-
-struct rsp_hdr {
- uint64_t rsp_len;
- uint64_t rsp_reqno;
- uint32_t rsp_type;
- /*
- * We want this structure 64bit-aligned for typecast fun,
- * so might as well use the following for something.
- */
- uint32_t rsp_sysnum;
-};
-#define HDRSZ sizeof(struct rsp_hdr)
-
-/*
- * Data follows the header. We have two types of structured data.
- */
-
-/* copyin/copyout */
-struct rsp_copydata {
- size_t rcp_len;
- void *rcp_addr;
- uint8_t rcp_data[0];
-};
-
-/* syscall response */
-struct rsp_sysresp {
- int rsys_error;
- register_t rsys_retval[2];
-};
-
-
-struct spclient {
- int spc_fd;
- struct lwp *spc_lwp;
-
- /* incoming */
- struct rsp_hdr spc_hdr;
- uint8_t *spc_buf;
- size_t spc_off;
-
-#if 0
- /* outgoing */
- int spc_obusy;
- pthread_mutex_t spc_omtx;
- pthread_cond_t spc_cv;
-#endif
-};
-
-typedef int (*addrparse_fn)(const char *, int, struct sockaddr **);
-typedef int (*connecthook_fn)(int);
+#include "sp_common.c"
#define MAXCLI 4
@@ -148,8 +71,6 @@
static uint64_t nextreq;
static pthread_key_t spclient_tls;
-static struct spclient clispc;
-
static struct rumpuser_sp_ops spops;
/*
@@ -212,57 +133,6 @@
}
static int
-dosend(struct spclient *spc, const void *data, size_t dlen)
-{
- struct pollfd pfd;
- const uint8_t *sdata = data;
- ssize_t n;
- size_t sent;
- int fd = spc->spc_fd;
-
- pfd.fd = fd;
- pfd.events = POLLOUT;
-
- for (sent = 0, n = 0; sent < dlen; ) {
- if (n) {
- if (poll(&pfd, 1, INFTIM) == -1) {
- if (errno == EINTR)
- continue;
- return errno;
- }
- }
-
- n = write(fd, sdata + sent, dlen - sent);
- if (n == 0) {
- return EFAULT;
- }
- if (n == -1 && errno != EAGAIN) {
- return EFAULT;
- }
- sent += n;
- }
-
- return 0;
-}
-
-static int
-send_syscall_req(struct spclient *spc, int sysnum,
- const void *data, size_t dlen)
-{
- struct rsp_hdr rhdr;
-
- rhdr.rsp_len = sizeof(rhdr) + dlen;
- rhdr.rsp_reqno = nextreq++;
- rhdr.rsp_type = RUMPSP_SYSCALL_REQ;
- rhdr.rsp_sysnum = sysnum;
-
- dosend(spc, &rhdr, sizeof(rhdr));
- dosend(spc, data, dlen);
-
- return 0;
-}
-
-static int
send_syscall_resp(struct spclient *spc, uint64_t reqno, int error,
register_t retval[2])
{
@@ -304,22 +174,6 @@
}
static int
-send_copyin_resp(struct spclient *spc, uint64_t reqno, void *data, size_t dlen)
-{
- struct rsp_hdr rhdr;
-
- rhdr.rsp_len = sizeof(rhdr) + dlen;
- rhdr.rsp_reqno = reqno;
- rhdr.rsp_type = RUMPSP_COPYIN_RESP;
- rhdr.rsp_sysnum = 0;
-
- dosend(spc, &rhdr, sizeof(rhdr));
- dosend(spc, data, dlen);
-
- return 0;
-}
-
-static int
send_copyout_req(struct spclient *spc, const void *remaddr,
const void *data, size_t dlen)
{
@@ -357,22 +211,6 @@
return 0;
}
-static int
-send_anonmmap_resp(struct spclient *spc, uint64_t reqno, void *addr)
-{
- struct rsp_hdr rhdr;
-
- rhdr.rsp_len = sizeof(rhdr) + sizeof(addr);
- rhdr.rsp_reqno = reqno;
- rhdr.rsp_type = RUMPSP_ANONMMAP_RESP;
- rhdr.rsp_sysnum = 0;
-
- dosend(spc, &rhdr, sizeof(rhdr));
- dosend(spc, &addr, sizeof(addr));
-
- return 0;
-}
-
static void
serv_handledisco(unsigned int idx)
{
@@ -455,7 +293,7 @@
maxidx = i;
DPRINTF(("rump_sp: added new connection at idx %u, pid %d\n",
- i, rump_sys_getpid())); /* XXX: getpid not spop */
+ i, 9)); /* XXX: getpid not spop */
lwproc_switch(NULL);
@@ -478,83 +316,9 @@
lwproc_switch(NULL);
pthread_setspecific(spclient_tls, NULL);
- send_syscall_resp(spc, rhdr->rsp_reqno, rv, retval);
-}
-
-static int
-readframe(struct spclient *spc)
-{
- int fd = spc->spc_fd;
- size_t left;
- size_t framelen;
- ssize_t n;
-
- /* still reading header? */
- if (spc->spc_off < HDRSZ) {
- DPRINTF(("rump_sp: readframe getting header at offset %zu\n",
- spc->spc_off));
-
- left = HDRSZ - spc->spc_off;
- /*LINTED: cast ok */
- n = read(fd, (uint8_t *)&spc->spc_hdr + spc->spc_off, left);
- if (n == 0) {
- return -1;
- }
- if (n == -1) {
- if (errno == EAGAIN)
- return 0;
- return -1;
- }
-
- spc->spc_off += n;
- if (spc->spc_off < HDRSZ)
- return -1;
-
- /*LINTED*/
- framelen = spc->spc_hdr.rsp_len;
+ DPRINTF(("rump_sp: got return value %d\n", rv));
- if (framelen < HDRSZ) {
- return -1;
- } else if (framelen == HDRSZ) {
- return 1;
- }
-
- spc->spc_buf = malloc(framelen - HDRSZ);
- if (spc->spc_buf == NULL) {
- return -1;
- }
- memset(spc->spc_buf, 0, framelen - HDRSZ);
-
- /* "fallthrough" */
- } else {
- /*LINTED*/
- framelen = spc->spc_hdr.rsp_len;
- }
-
- left = framelen - spc->spc_off;
-
- DPRINTF(("rump_sp: readframe getting body at offset %zu, left %zu\n",
- spc->spc_off, left));
-
- if (left == 0)
- return 1;
- n = read(fd, spc->spc_buf + (spc->spc_off - HDRSZ), left);
- if (n == 0) {
- return -1;
- }
- if (n == -1) {
- if (errno == EAGAIN)
- return 0;
- return -1;
- }
Home |
Main Index |
Thread Index |
Old Index