Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib Support fork() for rumpclient users.
details: https://anonhg.NetBSD.org/src/rev/ca2156764814
branches: trunk
changeset: 760464:ca2156764814
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Jan 05 17:14:50 2011 +0000
description:
Support fork() for rumpclient users.
diffstat:
lib/librumpclient/rumpclient.c | 168 +++++++++++++++++++++++++++------
lib/librumpclient/rumpclient.h | 6 +-
lib/librumpuser/rumpuser_sp.c | 198 ++++++++++++++++++++++++++++++++++++----
lib/librumpuser/sp_common.c | 24 +++-
4 files changed, 332 insertions(+), 64 deletions(-)
diffs (truncated from 627 to 300 lines):
diff -r b86d1e887209 -r ca2156764814 lib/librumpclient/rumpclient.c
--- a/lib/librumpclient/rumpclient.c Wed Jan 05 17:02:03 2011 +0000
+++ b/lib/librumpclient/rumpclient.c Wed Jan 05 17:14:50 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: rumpclient.c,v 1.10 2010/12/16 17:05:44 pooka Exp $ */
+/* $NetBSD: rumpclient.c,v 1.11 2011/01/05 17:14:50 pooka Exp $ */
/*
- * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
+ * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -45,6 +45,7 @@
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -55,7 +56,9 @@
#include "sp_common.c"
-static struct spclient clispc;
+static struct spclient clispc = {
+ .spc_fd = -1,
+};
static int
syscall_req(struct spclient *spc, int sysnum,
@@ -87,21 +90,30 @@
}
static int
-handshake_req(struct spclient *spc)
+handshake_req(struct spclient *spc, uint32_t *auth, int cancel)
{
+ struct handshake_fork rf;
struct rsp_hdr rhdr;
struct respwait rw;
int rv;
/* performs server handshake */
- rhdr.rsp_len = sizeof(rhdr);
+ rhdr.rsp_len = sizeof(rhdr) + (auth ? sizeof(rf) : 0);
rhdr.rsp_class = RUMPSP_REQ;
rhdr.rsp_type = RUMPSP_HANDSHAKE;
- rhdr.rsp_handshake = HANDSHAKE_GUEST;
+ if (auth)
+ rhdr.rsp_handshake = HANDSHAKE_FORK;
+ else
+ rhdr.rsp_handshake = HANDSHAKE_GUEST;
putwait(spc, &rw, &rhdr);
rv = dosend(spc, &rhdr, sizeof(rhdr));
- if (rv != 0) {
+ if (auth) {
+ memcpy(rf.rf_auth, auth, AUTHLEN*sizeof(*auth));
+ rf.rf_cancel = cancel;
+ rv = dosend(spc, &rf, sizeof(rf));
+ }
+ if (rv != 0 || cancel) {
unputwait(spc, &rw);
return rv;
}
@@ -117,6 +129,31 @@
}
static int
+prefork_req(struct spclient *spc, void **resp)
+{
+ struct rsp_hdr rhdr;
+ struct respwait rw;
+ int rv;
+
+ rhdr.rsp_len = sizeof(rhdr);
+ rhdr.rsp_class = RUMPSP_REQ;
+ rhdr.rsp_type = RUMPSP_PREFORK;
+ rhdr.rsp_error = 0;
+
+
+ putwait(spc, &rw, &rhdr);
+ rv = dosend(spc, &rhdr, sizeof(rhdr));
+ if (rv != 0) {
+ unputwait(spc, &rw);
+ return rv;
+ }
+
+ rv = waitresp(spc, &rw);
+ *resp = rw.rw_data;
+ return rv;
+}
+
+static int
send_copyin_resp(struct spclient *spc, uint64_t reqno, void *data, size_t dlen,
int wantstr)
{
@@ -234,33 +271,30 @@
spcfreebuf(spc);
}
-int
-rumpclient_init()
+static unsigned ptab_idx;
+static struct sockaddr *serv_sa;
+
+static int
+doconnect(void)
{
char banner[MAXBANNER];
- struct sockaddr *sap;
- char *p;
- unsigned idx;
+ int s, error;
ssize_t n;
- int error, s;
- if ((p = getenv("RUMP_SERVER")) == NULL) {
- errno = ENOENT;
+ s = socket(parsetab[ptab_idx].domain, SOCK_STREAM, 0);
+ if (s == -1)
return -1;
- }
- if ((error = parseurl(p, &sap, &idx, 0)) != 0) {
+ if (connect(s, serv_sa, (socklen_t)serv_sa->sa_len) == -1) {
+ error = errno;
+ fprintf(stderr, "rump_sp: client connect failed\n");
errno = error;
return -1;
}
- s = socket(parsetab[idx].domain, SOCK_STREAM, 0);
- if (s == -1)
- return -1;
-
- if (connect(s, sap, (socklen_t)sap->sa_len) == -1) {
+ if ((error = parsetab[ptab_idx].connhook(s)) != 0) {
error = errno;
- fprintf(stderr, "rump_sp: client connect failed\n");
+ fprintf(stderr, "rump_sp: connect hook failed\n");
errno = error;
return -1;
}
@@ -281,23 +315,91 @@
/* parse the banner some day */
- if ((error = parsetab[idx].connhook(s)) != 0) {
- error = errno;
- fprintf(stderr, "rump_sp: connect hook failed\n");
+ clispc.spc_fd = s;
+ TAILQ_INIT(&clispc.spc_respwait);
+ pthread_mutex_init(&clispc.spc_mtx, NULL);
+ pthread_cond_init(&clispc.spc_cv, NULL);
+
+ return 0;
+}
+
+int
+rumpclient_init()
+{
+ char *p;
+ int error;
+
+ if ((p = getenv("RUMP_SERVER")) == NULL) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ if ((error = parseurl(p, &serv_sa, &ptab_idx, 0)) != 0) {
+ errno = error;
+ return -1;
+ }
+
+ if (doconnect() == -1)
+ return -1;
+
+ error = handshake_req(&clispc, NULL, 0);
+ if (error) {
+ pthread_mutex_destroy(&clispc.spc_mtx);
+ pthread_cond_destroy(&clispc.spc_cv);
+ close(clispc.spc_fd);
errno = error;
return -1;
}
- pthread_mutex_init(&clispc.spc_mtx, NULL);
- pthread_cond_init(&clispc.spc_cv, NULL);
- clispc.spc_fd = s;
- TAILQ_INIT(&clispc.spc_respwait);
+ return 0;
+}
+
+struct rumpclient_fork {
+ uint32_t fork_auth[AUTHLEN];
+};
+
+struct rumpclient_fork *
+rumpclient_prefork(void)
+{
+ struct rumpclient_fork *rpf;
+ void *resp;
+ int rv;
+
+ rpf = malloc(sizeof(*rpf));
+ if (rpf == NULL)
+ return NULL;
- error = handshake_req(&clispc);
+ if ((rv = prefork_req(&clispc, &resp)) != 0) {
+ free(rpf);
+ errno = rv;
+ return NULL;
+ }
+
+ memcpy(rpf->fork_auth, resp, sizeof(rpf->fork_auth));
+ free(resp);
+
+ return rpf;
+}
+
+int
+rumpclient_fork_init(struct rumpclient_fork *rpf)
+{
+ int error;
+
+ close(clispc.spc_fd);
+ memset(&clispc, 0, sizeof(clispc));
+ clispc.spc_fd = -1;
+
+ if (doconnect() == -1)
+ return -1;
+
+ error = handshake_req(&clispc, rpf->fork_auth, 0);
if (error) {
pthread_mutex_destroy(&clispc.spc_mtx);
pthread_cond_destroy(&clispc.spc_cv);
- close(s);
+ errno = error;
+ return -1;
}
- return error;
+
+ return 0;
}
diff -r b86d1e887209 -r ca2156764814 lib/librumpclient/rumpclient.h
--- a/lib/librumpclient/rumpclient.h Wed Jan 05 17:02:03 2011 +0000
+++ b/lib/librumpclient/rumpclient.h Wed Jan 05 17:14:50 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpclient.h,v 1.1 2010/11/04 21:01:29 pooka Exp $ */
+/* $NetBSD: rumpclient.h,v 1.2 2011/01/05 17:14:50 pooka Exp $ */
/*-
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@@ -33,6 +33,10 @@
int rumpclient_syscall(int, const void *, size_t, register_t *);
int rumpclient_init(void);
+struct rumpclient_fork;
+struct rumpclient_fork *rumpclient_prefork(void);
+int rumpclient_fork_init(struct rumpclient_fork *);
+
__END_DECLS
#endif /* _RUMP_RUMPCLIENT_H_ */
diff -r b86d1e887209 -r ca2156764814 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c Wed Jan 05 17:02:03 2011 +0000
+++ b/lib/librumpuser/rumpuser_sp.c Wed Jan 05 17:14:50 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: rumpuser_sp.c,v 1.28 2011/01/02 13:01:45 pooka Exp $ */
+/* $NetBSD: rumpuser_sp.c,v 1.29 2011/01/05 17:14:50 pooka Exp $ */
/*
- * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
+ * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.28 2011/01/02 13:01:45 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.29 2011/01/05 17:14:50 pooka Exp $");
#include <sys/types.h>
#include <sys/atomic.h>
@@ -85,7 +85,17 @@
static char banner[MAXBANNER];
#define PROTOMAJOR 0
-#define PROTOMINOR 0
+#define PROTOMINOR 1
+
+struct prefork {
+ uint32_t pf_auth[AUTHLEN];
+ struct lwp *pf_lwp;
Home |
Main Index |
Thread Index |
Old Index