Sat Jan 22 13:41:22 2011 UTC ()
In case sys_reboot() was called by a remote client, put the response
in the socket before we shut down.  This way the response to the
syscall travels to the caller and they know things worked correctly
instead of having to just assume.


(pooka)
diff -r1.36 -r1.37 src/lib/librumpuser/rumpuser_sp.c
diff -r1.24 -r1.25 src/lib/librumpuser/sp_common.c
diff -r1.63 -r1.64 src/sys/rump/include/rump/rumpuser.h
diff -r1.219 -r1.220 src/sys/rump/librump/rumpkern/rump.c

cvs diff -r1.36 -r1.37 src/lib/librumpuser/rumpuser_sp.c (expand / switch to unified diff)

--- src/lib/librumpuser/rumpuser_sp.c 2011/01/14 13:12:14 1.36
+++ src/lib/librumpuser/rumpuser_sp.c 2011/01/22 13:41:22 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser_sp.c,v 1.36 2011/01/14 13:12:14 pooka Exp $ */ 1/* $NetBSD: rumpuser_sp.c,v 1.37 2011/01/22 13:41:22 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUCH DAMAGE. 25 * SUCH DAMAGE.
26 */ 26 */
27 27
28/* 28/*
29 * Sysproxy routines. This provides system RPC support over host sockets. 29 * Sysproxy routines. This provides system RPC support over host sockets.
30 * The most notable limitation is that the client and server must share 30 * The most notable limitation is that the client and server must share
31 * the same ABI. This does not mean that they have to be the same 31 * the same ABI. This does not mean that they have to be the same
32 * machine or that they need to run the same version of the host OS, 32 * machine or that they need to run the same version of the host OS,
33 * just that they must agree on the data structures. This even *might* 33 * just that they must agree on the data structures. This even *might*
34 * work correctly from one hardware architecture to another. 34 * work correctly from one hardware architecture to another.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: rumpuser_sp.c,v 1.36 2011/01/14 13:12:14 pooka Exp $"); 38__RCSID("$NetBSD: rumpuser_sp.c,v 1.37 2011/01/22 13:41:22 pooka Exp $");
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/atomic.h> 41#include <sys/atomic.h>
42#include <sys/mman.h> 42#include <sys/mman.h>
43#include <sys/socket.h> 43#include <sys/socket.h>
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <netinet/in.h> 46#include <netinet/in.h>
47#include <netinet/tcp.h> 47#include <netinet/tcp.h>
48 48
49#include <assert.h> 49#include <assert.h>
50#include <errno.h> 50#include <errno.h>
51#include <fcntl.h> 51#include <fcntl.h>
@@ -574,27 +574,29 @@ serv_handleconn(int fd, connecthook_fn c @@ -574,27 +574,29 @@ serv_handleconn(int fd, connecthook_fn c
574} 574}
575 575
576static void 576static void
577serv_handlesyscall(struct spclient *spc, struct rsp_hdr *rhdr, uint8_t *data) 577serv_handlesyscall(struct spclient *spc, struct rsp_hdr *rhdr, uint8_t *data)
578{ 578{
579 register_t retval[2] = {0, 0}; 579 register_t retval[2] = {0, 0};
580 int rv, sysnum; 580 int rv, sysnum;
581 581
582 sysnum = (int)rhdr->rsp_sysnum; 582 sysnum = (int)rhdr->rsp_sysnum;
583 DPRINTF(("rump_sp: handling syscall %d from client %d\n", 583 DPRINTF(("rump_sp: handling syscall %d from client %d\n",
584 sysnum, spc->spc_pid)); 584 sysnum, spc->spc_pid));
585 585
586 lwproc_newlwp(spc->spc_pid); 586 lwproc_newlwp(spc->spc_pid);
 587 spc->spc_syscallreq = rhdr->rsp_reqno;
587 rv = rumpsyscall(sysnum, data, retval); 588 rv = rumpsyscall(sysnum, data, retval);
 589 spc->spc_syscallreq = 0;
588 lwproc_release(); 590 lwproc_release();
589 591
590 DPRINTF(("rump_sp: got return value %d & %d/%d\n", 592 DPRINTF(("rump_sp: got return value %d & %d/%d\n",
591 rv, retval[0], retval[1])); 593 rv, retval[0], retval[1]));
592 594
593 send_syscall_resp(spc, rhdr->rsp_reqno, rv, retval); 595 send_syscall_resp(spc, rhdr->rsp_reqno, rv, retval);
594} 596}
595 597
596struct sysbouncearg { 598struct sysbouncearg {
597 struct spclient *sba_spc; 599 struct spclient *sba_spc;
598 struct rsp_hdr sba_hdr; 600 struct rsp_hdr sba_hdr;
599 uint8_t *sba_data; 601 uint8_t *sba_data;
600 602
@@ -1133,22 +1135,31 @@ rumpuser_sp_init(const char *url, const  @@ -1133,22 +1135,31 @@ rumpuser_sp_init(const char *url, const
1133 return errno; 1135 return errno;
1134 } 1136 }
1135 1137
1136 if ((error = pthread_create(&pt, NULL, spserver, sarg)) != 0) { 1138 if ((error = pthread_create(&pt, NULL, spserver, sarg)) != 0) {
1137 fprintf(stderr, "rump_sp: cannot create wrkr thread\n"); 1139 fprintf(stderr, "rump_sp: cannot create wrkr thread\n");
1138 return errno; 1140 return errno;
1139 } 1141 }
1140 pthread_detach(pt); 1142 pthread_detach(pt);
1141 1143
1142 return 0; 1144 return 0;
1143} 1145}
1144 1146
1145void 1147void
1146rumpuser_sp_fini() 1148rumpuser_sp_fini(void *arg)
1147{ 1149{
 1150 struct spclient *spc = arg;
 1151 register_t retval[2] = {0, 0};
 1152
 1153 /*
 1154 * stuff response into the socket, since this process is just
 1155 * about to exit
 1156 */
 1157 if (spc && spc->spc_syscallreq)
 1158 send_syscall_resp(spc, spc->spc_syscallreq, 0, retval);
1148 1159
1149 if (spclist[0].spc_fd) { 1160 if (spclist[0].spc_fd) {
1150 parsetab[cleanupidx].cleanup(cleanupsa); 1161 parsetab[cleanupidx].cleanup(cleanupsa);
1151 shutdown(spclist[0].spc_fd, SHUT_RDWR); 1162 shutdown(spclist[0].spc_fd, SHUT_RDWR);
1152 spfini = 1; 1163 spfini = 1;
1153 } 1164 }
1154} 1165}

cvs diff -r1.24 -r1.25 src/lib/librumpuser/sp_common.c (expand / switch to unified diff)

--- src/lib/librumpuser/sp_common.c 2011/01/14 13:12:14 1.24
+++ src/lib/librumpuser/sp_common.c 2011/01/22 13:41:22 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sp_common.c,v 1.24 2011/01/14 13:12:14 pooka Exp $ */ 1/* $NetBSD: sp_common.c,v 1.25 2011/01/22 13:41:22 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -166,26 +166,27 @@ struct spclient { @@ -166,26 +166,27 @@ struct spclient {
166 pid_t spc_pid; 166 pid_t spc_pid;
167 167
168 TAILQ_HEAD(, respwait) spc_respwait; 168 TAILQ_HEAD(, respwait) spc_respwait;
169 169
170 /* rest of the fields are zeroed upon disconnect */ 170 /* rest of the fields are zeroed upon disconnect */
171#define SPC_ZEROFF offsetof(struct spclient, spc_pfd) 171#define SPC_ZEROFF offsetof(struct spclient, spc_pfd)
172 struct pollfd *spc_pfd; 172 struct pollfd *spc_pfd;
173 173
174 struct rsp_hdr spc_hdr; 174 struct rsp_hdr spc_hdr;
175 uint8_t *spc_buf; 175 uint8_t *spc_buf;
176 size_t spc_off; 176 size_t spc_off;
177 177
178 uint64_t spc_nextreq; 178 uint64_t spc_nextreq;
 179 uint64_t spc_syscallreq;
179 int spc_ostatus, spc_istatus; 180 int spc_ostatus, spc_istatus;
180 181
181 LIST_HEAD(, prefork) spc_pflist; 182 LIST_HEAD(, prefork) spc_pflist;
182}; 183};
183#define SPCSTATUS_FREE 0 184#define SPCSTATUS_FREE 0
184#define SPCSTATUS_BUSY 1 185#define SPCSTATUS_BUSY 1
185#define SPCSTATUS_WANTED 2 186#define SPCSTATUS_WANTED 2
186 187
187#define SPCSTATE_NEW 0 188#define SPCSTATE_NEW 0
188#define SPCSTATE_RUNNING 1 189#define SPCSTATE_RUNNING 1
189#define SPCSTATE_DYING 2 190#define SPCSTATE_DYING 2
190 191
191typedef int (*addrparse_fn)(const char *, struct sockaddr **, int); 192typedef int (*addrparse_fn)(const char *, struct sockaddr **, int);

cvs diff -r1.63 -r1.64 src/sys/rump/include/rump/rumpuser.h (expand / switch to unified diff)

--- src/sys/rump/include/rump/rumpuser.h 2011/01/14 13:11:08 1.63
+++ src/sys/rump/include/rump/rumpuser.h 2011/01/22 13:41:22 1.64
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser.h,v 1.63 2011/01/14 13:11:08 pooka Exp $ */ 1/* $NetBSD: rumpuser.h,v 1.64 2011/01/22 13:41:22 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by Google Summer of Code. 6 * Development of this software was supported by Google Summer of Code.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30#ifndef _RUMP_RUMPUSER_H_ 30#ifndef _RUMP_RUMPUSER_H_
31#define _RUMP_RUMPUSER_H_ 31#define _RUMP_RUMPUSER_H_
32 32
33#ifdef _KERNEL 33#ifdef _KERNEL
34#include <sys/stdint.h> 34#include <sys/stdint.h>
35#else 35#else
36#include <stdint.h> 36#include <stdint.h>
37#endif 37#endif
38 38
39#define RUMPUSER_VERSION 10 39#define RUMPUSER_VERSION 11
40int rumpuser_getversion(void); 40int rumpuser_getversion(void);
41 41
42int rumpuser_daemonize_begin(void); 42int rumpuser_daemonize_begin(void);
43int rumpuser_daemonize_done(int); 43int rumpuser_daemonize_done(int);
44 44
45struct msghdr; 45struct msghdr;
46struct pollfd; 46struct pollfd;
47struct sockaddr; 47struct sockaddr;
48 48
49typedef void (*kernel_lockfn)(int, void *); 49typedef void (*kernel_lockfn)(int, void *);
50typedef void (*kernel_unlockfn)(int, int *, void *); 50typedef void (*kernel_unlockfn)(int, int *, void *);
51 51
52int rumpuser_getfileinfo(const char *, uint64_t *, int *, int *); 52int rumpuser_getfileinfo(const char *, uint64_t *, int *, int *);
@@ -220,16 +220,16 @@ struct rumpuser_sp_ops { @@ -220,16 +220,16 @@ struct rumpuser_sp_ops {
220 int (*spop_syscall)(int, void *, register_t *); 220 int (*spop_syscall)(int, void *, register_t *);
221 void (*spop_procexit)(void); 221 void (*spop_procexit)(void);
222 pid_t (*spop_getpid)(void); 222 pid_t (*spop_getpid)(void);
223}; 223};
224 224
225int rumpuser_sp_init(const char *, const struct rumpuser_sp_ops *, 225int rumpuser_sp_init(const char *, const struct rumpuser_sp_ops *,
226 const char *, const char *, const char *); 226 const char *, const char *, const char *);
227int rumpuser_sp_copyin(void *, const void *, void *, size_t); 227int rumpuser_sp_copyin(void *, const void *, void *, size_t);
228int rumpuser_sp_copyinstr(void *, const void *, void *, size_t *); 228int rumpuser_sp_copyinstr(void *, const void *, void *, size_t *);
229int rumpuser_sp_copyout(void *, const void *, void *, size_t); 229int rumpuser_sp_copyout(void *, const void *, void *, size_t);
230int rumpuser_sp_copyoutstr(void *, const void *, void *, size_t *); 230int rumpuser_sp_copyoutstr(void *, const void *, void *, size_t *);
231int rumpuser_sp_anonmmap(void *, size_t, void **); 231int rumpuser_sp_anonmmap(void *, size_t, void **);
232int rumpuser_sp_raise(void *, int); 232int rumpuser_sp_raise(void *, int);
233void rumpuser_sp_fini(void); 233void rumpuser_sp_fini(void *);
234 234
235#endif /* _RUMP_RUMPUSER_H_ */ 235#endif /* _RUMP_RUMPUSER_H_ */

cvs diff -r1.219 -r1.220 src/sys/rump/librump/rumpkern/rump.c (expand / switch to unified diff)

--- src/sys/rump/librump/rumpkern/rump.c 2011/01/12 12:51:21 1.219
+++ src/sys/rump/librump/rumpkern/rump.c 2011/01/22 13:41:22 1.220
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rump.c,v 1.219 2011/01/12 12:51:21 pooka Exp $ */ 1/* $NetBSD: rump.c,v 1.220 2011/01/22 13:41:22 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by Google Summer of Code. 6 * Development of this software was supported by Google Summer of Code.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.219 2011/01/12 12:51:21 pooka Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.220 2011/01/22 13:41:22 pooka Exp $");
32 32
33#include <sys/systm.h> 33#include <sys/systm.h>
34#define ELFSIZE ARCH_ELFSIZE 34#define ELFSIZE ARCH_ELFSIZE
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/atomic.h> 37#include <sys/atomic.h>
38#include <sys/buf.h> 38#include <sys/buf.h>
39#include <sys/callout.h> 39#include <sys/callout.h>
40#include <sys/conf.h> 40#include <sys/conf.h>
41#include <sys/cpu.h> 41#include <sys/cpu.h>
42#include <sys/device.h> 42#include <sys/device.h>
43#include <sys/evcnt.h> 43#include <sys/evcnt.h>
44#include <sys/event.h> 44#include <sys/event.h>
@@ -488,29 +488,35 @@ rump__init(int rump_version) @@ -488,29 +488,35 @@ rump__init(int rump_version)
488} 488}
489 489
490int 490int
491rump_init_server(const char *url) 491rump_init_server(const char *url)
492{ 492{
493 493
494 return rumpuser_sp_init(url, &spops, ostype, osrelease, MACHINE); 494 return rumpuser_sp_init(url, &spops, ostype, osrelease, MACHINE);
495} 495}
496 496
497void 497void
498cpu_reboot(int howto, char *bootstr) 498cpu_reboot(int howto, char *bootstr)
499{ 499{
500 int ruhow = 0; 500 int ruhow = 0;
 501 void *finiarg;
501 502
502 printf("rump kernel halting...\n"); 503 printf("rump kernel halting...\n");
503 rumpuser_sp_fini(); 504
 505 if (!RUMP_LOCALPROC_P(curproc))
 506 finiarg = curproc->p_vmspace->vm_map.pmap;
 507 else
 508 finiarg = NULL;
 509 rumpuser_sp_fini(finiarg);
504 510
505 /* dump means we really take the dive here */ 511 /* dump means we really take the dive here */
506 if ((howto & RB_DUMP) || panicstr) { 512 if ((howto & RB_DUMP) || panicstr) {
507 ruhow = RUMPUSER_PANIC; 513 ruhow = RUMPUSER_PANIC;
508 goto out; 514 goto out;
509 } 515 }
510 516
511 /* try to sync */ 517 /* try to sync */
512 if (!((howto & RB_NOSYNC) || panicstr)) { 518 if (!((howto & RB_NOSYNC) || panicstr)) {
513 rump_vfs_fini(); 519 rump_vfs_fini();
514 } 520 }
515 521
516 /* your wish is my command */ 522 /* your wish is my command */