Module Name:    src
Committed By:   pooka
Date:           Sun Jan  2 12:52:25 UTC 2011

Modified Files:
        src/sys/rump/include/rump: rump.h rumpuser.h
        src/sys/rump/librump/rumpkern: lwproc.c rump.c rumpkern.ifspec

Log Message:
There is a use case where preserving the parent's fd table is
relevant, so to accommodate that change rump_lwproc_newproc() to
rump_lwproc_rfork().  The new interface has the rfork() fd table
semantics.  The equivalent of rump_lwproc_newproc() is
rump_lwproc_rfork(RUMP_RFCFDG).


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/rump/include/rump/rump.h
cvs rdiff -u -r1.60 -r1.61 src/sys/rump/include/rump/rumpuser.h
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.213 -r1.214 src/sys/rump/librump/rumpkern/rump.c
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/librump/rumpkern/rumpkern.ifspec

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/include/rump/rump.h
diff -u src/sys/rump/include/rump/rump.h:1.49 src/sys/rump/include/rump/rump.h:1.50
--- src/sys/rump/include/rump/rump.h:1.49	Tue Nov 30 14:23:24 2010
+++ src/sys/rump/include/rump/rump.h	Sun Jan  2 12:52:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.h,v 1.49 2010/11/30 14:23:24 pooka Exp $	*/
+/*	$NetBSD: rump.h,v 1.50 2011/01/02 12:52:25 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -73,6 +73,10 @@
 	RUMP_SIGMODEL_RECORD
 };
 
+/* flags to rump_lwproc_rfork */
+#define RUMP_RFFDG	0x01
+#define RUMP_RFCFDG	0x02
+
 /* rumpvfs */
 #define RUMPCN_FREECRED  0x02
 #define RUMP_ETFS_SIZE_ENDOFF ((uint64_t)-1)

Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.60 src/sys/rump/include/rump/rumpuser.h:1.61
--- src/sys/rump/include/rump/rumpuser.h:1.60	Thu Dec 30 15:47:30 2010
+++ src/sys/rump/include/rump/rumpuser.h	Sun Jan  2 12:52:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.h,v 1.60 2010/12/30 15:47:30 pooka Exp $	*/
+/*	$NetBSD: rumpuser.h,v 1.61 2011/01/02 12:52:25 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -214,7 +214,7 @@
 
 	void (*spop_lwproc_switch)(struct lwp *);
 	void (*spop_lwproc_release)(void);
-	int (*spop_lwproc_newproc)(void *);
+	int (*spop_lwproc_rfork)(void *, int);
 	int (*spop_lwproc_newlwp)(pid_t);
 	struct lwp * (*spop_lwproc_curlwp)(void);
 	int (*spop_syscall)(int, void *, register_t *);

Index: src/sys/rump/librump/rumpkern/lwproc.c
diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.6 src/sys/rump/librump/rumpkern/lwproc.c:1.7
--- src/sys/rump/librump/rumpkern/lwproc.c:1.6	Mon Nov 22 20:42:19 2010
+++ src/sys/rump/librump/rumpkern/lwproc.c	Sun Jan  2 12:52:25 2011
@@ -1,7 +1,7 @@
-/*      $NetBSD: lwproc.c,v 1.6 2010/11/22 20:42:19 pooka Exp $	*/
+/*      $NetBSD: lwproc.c,v 1.7 2011/01/02 12:52:25 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
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.6 2010/11/22 20:42:19 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.7 2011/01/02 12:52:25 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -94,7 +94,7 @@
  * Switch to the new lwp and return a pointer to it.
  */
 static struct proc *
-lwproc_newproc(struct proc *parent)
+lwproc_newproc(struct proc *parent, int flags)
 {
 	uid_t uid = kauth_cred_getuid(parent->p_cred);
 	struct proc *p;
@@ -113,10 +113,18 @@
 
 	p->p_stats = pstatscopy(parent->p_stats);
 
-	/* not based on parent */
 	p->p_vmspace = vmspace_kernel();
 	p->p_emul = &emul_netbsd;
-	p->p_fd = fd_init(NULL);
+
+	if ((flags & RUMP_RFCFDG) == 0)
+		KASSERT(parent == curproc);
+	if (flags & RUMP_RFFDG)
+		p->p_fd = fd_copy();
+	else if (flags & RUMP_RFCFDG)
+		p->p_fd = fd_init(NULL);
+	else
+		fd_share(p);
+
 	lim_addref(parent->p_limit);
 	p->p_limit = parent->p_limit;
 
@@ -234,7 +242,7 @@
 	bool newproc = false;
 
 	if (p == NULL) {
-		p = lwproc_newproc(&proc0);
+		p = lwproc_newproc(&proc0, 0);
 		newproc = true;
 	}
 
@@ -268,12 +276,16 @@
 }
 
 int
-rump_lwproc_newproc(void)
+rump_lwproc_rfork(int flags)
 {
 	struct proc *p;
 	struct lwp *l;
 
-	p = lwproc_newproc(curproc);
+	if (flags & ~(RUMP_RFFDG|RUMP_RFCFDG) ||
+	    (~flags & (RUMP_RFFDG|RUMP_RFCFDG)) == 0)
+		return EINVAL;
+
+	p = lwproc_newproc(curproc, flags);
 	l = kmem_zalloc(sizeof(*l), KM_SLEEP);
 	mutex_enter(p->p_lock);
 	lwproc_makelwp(p, l, true, true);

Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.213 src/sys/rump/librump/rumpkern/rump.c:1.214
--- src/sys/rump/librump/rumpkern/rump.c:1.213	Thu Dec 30 16:46:32 2010
+++ src/sys/rump/librump/rumpkern/rump.c	Sun Jan  2 12:52:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.c,v 1.213 2010/12/30 16:46:32 pooka Exp $	*/
+/*	$NetBSD: rump.c,v 1.214 2011/01/02 12:52:25 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.213 2010/12/30 16:46:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.214 2011/01/02 12:52:25 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -99,7 +99,7 @@
 #endif
 
 static int rump_proxy_syscall(int, void *, register_t *);
-static int rump_proxy_newproc(void *);
+static int rump_proxy_rfork(void *, int);
 
 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
 
@@ -199,7 +199,7 @@
 	.spop_unschedule	= rump_unschedule,
 	.spop_lwproc_switch	= rump_lwproc_switch,
 	.spop_lwproc_release	= rump_lwproc_releaselwp,
-	.spop_lwproc_newproc	= rump_proxy_newproc,
+	.spop_lwproc_rfork	= rump_proxy_rfork,
 	.spop_lwproc_newlwp	= rump_lwproc_newlwp,
 	.spop_lwproc_curlwp	= rump_lwproc_curlwp,
 	.spop_syscall		= rump_proxy_syscall,
@@ -704,12 +704,12 @@
 }
 
 static int
-rump_proxy_newproc(void *priv)
+rump_proxy_rfork(void *priv, int flags)
 {
 	struct vmspace *newspace;
 	int error;
 
-	if ((error = rump_lwproc_newproc()) != 0)
+	if ((error = rump_lwproc_rfork(flags)) != 0)
 		return error;
 
 	/*

Index: src/sys/rump/librump/rumpkern/rumpkern.ifspec
diff -u src/sys/rump/librump/rumpkern/rumpkern.ifspec:1.9 src/sys/rump/librump/rumpkern/rumpkern.ifspec:1.10
--- src/sys/rump/librump/rumpkern/rumpkern.ifspec:1.9	Sun Nov 21 17:34:11 2010
+++ src/sys/rump/librump/rumpkern/rumpkern.ifspec	Sun Jan  2 12:52:25 2011
@@ -1,4 +1,4 @@
-;	$NetBSD: rumpkern.ifspec,v 1.9 2010/11/21 17:34:11 pooka Exp $
+;	$NetBSD: rumpkern.ifspec,v 1.10 2011/01/02 12:52:25 pooka Exp $
 
 NAME|kern
 PUBHDR|include/rump/rumpkern_if_pub.h
@@ -23,7 +23,7 @@
 void		  |cred_put	|struct kauth_cred *
 
 ; lwp and proc creation / switching interfaces
-int		|lwproc_newproc		|void
+int		|lwproc_rfork		|int
 int		|lwproc_newlwp		|pid_t
 void		|lwproc_switch		|struct lwp *
 void		|lwproc_releaselwp	|void

Reply via email to