Module Name: src Committed By: martin Date: Tue Dec 9 19:14:27 UTC 2014
Modified Files: src/lib/librumpuser [netbsd-7]: rumpuser_sp.c src/sys/rump/librump/rumpkern [netbsd-7]: cons.c rump.c Log Message: Pull up following revision(s) (requested by gson in ticket #299): sys/rump/librump/rumpkern/cons.c: revision 1.4 sys/rump/librump/rumpkern/rump.c: revision 1.311 lib/librumpuser/rumpuser_sp.c: revision 1.67 No longer create a special process context to fork remote clients off of, simply always rfork off of proc1 closing all descriptors, and have the rump kernel open 0/1/2 if the parent process is "1". Fixes tests/rump/rumpkernel/t_sp, which was failing since the abovementioned special process change due to attempting to deliver a signal to the special process and the special process was not equipped to handle one. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.66.2.1 src/lib/librumpuser/rumpuser_sp.c cvs rdiff -u -r1.3 -r1.3.8.1 src/sys/rump/librump/rumpkern/cons.c cvs rdiff -u -r1.308.2.1 -r1.308.2.2 src/sys/rump/librump/rumpkern/rump.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librumpuser/rumpuser_sp.c diff -u src/lib/librumpuser/rumpuser_sp.c:1.66 src/lib/librumpuser/rumpuser_sp.c:1.66.2.1 --- src/lib/librumpuser/rumpuser_sp.c:1.66 Sat Jun 14 11:52:42 2014 +++ src/lib/librumpuser/rumpuser_sp.c Tue Dec 9 19:14:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser_sp.c,v 1.66 2014/06/14 11:52:42 pooka Exp $ */ +/* $NetBSD: rumpuser_sp.c,v 1.66.2.1 2014/12/09 19:14:27 martin Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -37,7 +37,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser_sp.c,v 1.66 2014/06/14 11:52:42 pooka Exp $"); +__RCSID("$NetBSD: rumpuser_sp.c,v 1.66.2.1 2014/12/09 19:14:27 martin Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -957,7 +957,6 @@ schedulework(struct spclient *spc, enum struct spservarg { int sps_sock; connecthook_fn sps_connhook; - struct lwp *sps_l; }; static void @@ -983,8 +982,11 @@ handlereq(struct spclient *spc) /* XXX make sure it contains sensible chars? */ comm[commlen] = '\0'; + /* make sure we fork off of proc1 */ + _DIAGASSERT(lwproc_curlwp() == NULL); + if ((error = lwproc_rfork(spc, - RUMP_RFFDG, comm)) != 0) { + RUMP_RFFD_CLEAR, comm)) != 0) { shutdown(spc->spc_fd, SHUT_RDWR); } @@ -1049,7 +1051,8 @@ handlereq(struct spclient *spc) * the wrong spc pointer. (yea, optimize * interfaces some day if anyone cares) */ - if ((error = lwproc_rfork(spc, 0, NULL)) != 0) { + if ((error = lwproc_rfork(spc, + RUMP_RFFD_SHARE, NULL)) != 0) { send_error_resp(spc, reqno, RUMPSP_ERR_RFORK_FAILED); shutdown(spc->spc_fd, SHUT_RDWR); @@ -1109,7 +1112,7 @@ handlereq(struct spclient *spc) * above) so we can safely use it here. */ lwproc_switch(spc->spc_mainlwp); - if ((error = lwproc_rfork(spc, RUMP_RFFDG, NULL)) != 0) { + if ((error = lwproc_rfork(spc, RUMP_RFFD_COPY, NULL)) != 0) { DPRINTF(("rump_sp: fork failed: %d (%p)\n",error, spc)); send_error_resp(spc, reqno, RUMPSP_ERR_RFORK_FAILED); lwproc_switch(NULL); @@ -1194,8 +1197,6 @@ spserver(void *arg) int rv; unsigned int nfds, maxidx; - lwproc_switch(sarg->sps_l); - for (idx = 0; idx < MAXCLI; idx++) { pfdlist[idx].fd = -1; pfdlist[idx].events = POLLIN; @@ -1320,7 +1321,6 @@ rumpuser_sp_init(const char *url, pthread_t pt; struct spservarg *sarg; struct sockaddr *sap; - struct lwp *calllwp; char *p; unsigned idx = 0; /* XXXgcc */ int error, s; @@ -1371,22 +1371,6 @@ rumpuser_sp_init(const char *url, goto out; } - /* - * Create a context that the client threads run off of. - * We fork a dedicated context so as to ensure that all - * client threads get the same set of fd's. We fork off - * of whatever context the caller is running in (most likely - * an implicit thread, i.e. proc 1) and do not - * close fd's. The assumption is that people who - * write servers (i.e. "kernels") know what they're doing. - */ - calllwp = lwproc_curlwp(); - if ((error = lwproc_rfork(NULL, RUMP_RFFDG, "spserver")) != 0) { - fprintf(stderr, "rump_sp: rfork failed"); - goto out; - } - sarg->sps_l = lwproc_curlwp(); - lwproc_switch(calllwp); if ((error = pthread_create(&pt, NULL, spserver, sarg)) != 0) { fprintf(stderr, "rump_sp: cannot create wrkr thread\n"); goto out; Index: src/sys/rump/librump/rumpkern/cons.c diff -u src/sys/rump/librump/rumpkern/cons.c:1.3 src/sys/rump/librump/rumpkern/cons.c:1.3.8.1 --- src/sys/rump/librump/rumpkern/cons.c:1.3 Sun Sep 8 04:37:17 2013 +++ src/sys/rump/librump/rumpkern/cons.c Tue Dec 9 19:14:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cons.c,v 1.3 2013/09/08 04:37:17 pooka Exp $ */ +/* $NetBSD: cons.c,v 1.3.8.1 2014/12/09 19:14:27 martin Exp $ */ /* * Copyright (c) 2013 Antti Kantee. All Rights Reserved. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.3 2013/09/08 04:37:17 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.3.8.1 2014/12/09 19:14:27 martin Exp $"); #include <sys/param.h> #include <sys/file.h> @@ -75,13 +75,10 @@ rump_consdev_init(void) struct file *fp; int fd, error; - /* - * We want to open the descriptors for the implicit proc - * so that they get inherited by default to all processes. - */ - KASSERT(curproc->p_pid == 1); KASSERT(fd_getfile(0) == NULL); - + KASSERT(fd_getfile(1) == NULL); + KASSERT(fd_getfile(2) == NULL); + /* then, map a file descriptor to the device */ if ((error = fd_allocfile(&fp, &fd)) != 0) panic("cons fd_allocfile failed: %d", error); Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.308.2.1 src/sys/rump/librump/rumpkern/rump.c:1.308.2.2 --- src/sys/rump/librump/rumpkern/rump.c:1.308.2.1 Fri Aug 15 12:58:45 2014 +++ src/sys/rump/librump/rumpkern/rump.c Tue Dec 9 19:14:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.308.2.1 2014/08/15 12:58:45 martin Exp $ */ +/* $NetBSD: rump.c,v 1.308.2.2 2014/12/09 19:14:27 martin Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.308.2.1 2014/08/15 12:58:45 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.308.2.2 2014/12/09 19:14:27 martin Exp $"); #include <sys/systm.h> #define ELFSIZE ARCH_ELFSIZE @@ -656,16 +656,34 @@ rump_hyp_rfork(void *priv, int flags, co { struct vmspace *newspace; struct proc *p; + struct lwp *l; int error; + bool initfds; + + /* + * If we are forking off of pid 1, initialize file descriptors. + */ + l = curlwp; + if (l->l_proc->p_pid == 1) { + KASSERT(flags == RUMP_RFFD_CLEAR); + initfds = true; + } else { + initfds = false; + } if ((error = rump_lwproc_rfork(flags)) != 0) return error; /* + * We forked in this routine, so cannot use curlwp (const) + */ + l = rump_lwproc_curlwp(); + p = l->l_proc; + + /* * Since it's a proxy proc, adjust the vmspace. * Refcount will eternally be 1. */ - p = curproc; newspace = kmem_zalloc(sizeof(*newspace), KM_SLEEP); newspace->vm_refcnt = 1; newspace->vm_map.pmap = priv; @@ -673,6 +691,8 @@ rump_hyp_rfork(void *priv, int flags, co p->p_vmspace = newspace; if (comm) strlcpy(p->p_comm, comm, sizeof(p->p_comm)); + if (initfds) + rump_consdev_init(); return 0; }