Source-Changes-HG archive

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

[src/trunk]: src No longer create a special process context to fork remote cl...



details:   https://anonhg.NetBSD.org/src/rev/707b83908f28
branches:  trunk
changeset: 331818:707b83908f28
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Aug 25 14:58:48 2014 +0000

description:
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.

diffstat:

 lib/librumpuser/rumpuser_sp.c    |  34 +++++++++-------------------------
 sys/rump/librump/rumpkern/cons.c |  13 +++++--------
 sys/rump/librump/rumpkern/rump.c |  26 +++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 36 deletions(-)

diffs (196 lines):

diff -r cfb6cbb0eccc -r 707b83908f28 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Mon Aug 25 14:11:51 2014 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Mon Aug 25 14:58:48 2014 +0000
@@ -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.67 2014/08/25 14:58:48 pooka 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.67 2014/08/25 14:58:48 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -957,7 +957,6 @@
 struct spservarg {
        int sps_sock;
        connecthook_fn sps_connhook;
-       struct lwp *sps_l;
 };
 
 static void
@@ -983,8 +982,11 @@
                        /* 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 @@
                         * 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 @@
                 * 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 @@
        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 @@
        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 @@
                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;
diff -r cfb6cbb0eccc -r 707b83908f28 sys/rump/librump/rumpkern/cons.c
--- a/sys/rump/librump/rumpkern/cons.c  Mon Aug 25 14:11:51 2014 +0000
+++ b/sys/rump/librump/rumpkern/cons.c  Mon Aug 25 14:58:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cons.c,v 1.3 2013/09/08 04:37:17 pooka Exp $   */
+/*     $NetBSD: cons.c,v 1.4 2014/08/25 14:58:48 pooka 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.4 2014/08/25 14:58:48 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/file.h>
@@ -75,13 +75,10 @@
        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);
diff -r cfb6cbb0eccc -r 707b83908f28 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Mon Aug 25 14:11:51 2014 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Mon Aug 25 14:58:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.310 2014/08/14 16:28:49 riastradh Exp $     */
+/*     $NetBSD: rump.c,v 1.311 2014/08/25 14:58:48 pooka 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.310 2014/08/14 16:28:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.311 2014/08/25 14:58:48 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -656,16 +656,34 @@
 {
        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 @@
        p->p_vmspace = newspace;
        if (comm)
                strlcpy(p->p_comm, comm, sizeof(p->p_comm));
+       if (initfds)
+               rump_consdev_init();
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index