Module Name: src Committed By: pooka Date: Mon Apr 29 17:31:05 UTC 2013
Modified Files: src/lib/librumpuser: rumpuser.c src/sys/rump/include/rump: rumpuser.h src/sys/rump/librump/rumpkern: rump.c vm.c src/sys/rump/librump/rumpvfs: rump_vfs.c rumpblk.c Log Message: Replace the various "get info from hypervisor" interfaces with one unified rumpuser_getparam(), and make it return a plist. The contents can come e.g. from the env or a config file. Make identifiers starting with an underscore denote system identifiers which must be implemented by hypervisor. (yea, j/k about the plist bit) To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/lib/librumpuser/rumpuser.c cvs rdiff -u -r1.94 -r1.95 src/sys/rump/include/rump/rumpuser.h cvs rdiff -u -r1.263 -r1.264 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.140 -r1.141 src/sys/rump/librump/rumpkern/vm.c cvs rdiff -u -r1.74 -r1.75 src/sys/rump/librump/rumpvfs/rump_vfs.c cvs rdiff -u -r1.51 -r1.52 src/sys/rump/librump/rumpvfs/rumpblk.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.c diff -u src/lib/librumpuser/rumpuser.c:1.42 src/lib/librumpuser/rumpuser.c:1.43 --- src/lib/librumpuser/rumpuser.c:1.42 Mon Apr 29 15:40:38 2013 +++ src/lib/librumpuser/rumpuser.c Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.c,v 1.42 2013/04/29 15:40:38 pooka Exp $ */ +/* $NetBSD: rumpuser.c,v 1.43 2013/04/29 17:31:05 pooka Exp $ */ /* * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: rumpuser.c,v 1.42 2013/04/29 15:40:38 pooka Exp $"); +__RCSID("$NetBSD: rumpuser.c,v 1.43 2013/04/29 17:31:05 pooka Exp $"); #endif /* !lint */ #include <sys/ioctl.h> @@ -512,27 +512,71 @@ rumpuser_clock_sleep(uint64_t sec, uint6 return rv; } -int -rumpuser_getenv(const char *name, char *buf, size_t blen, int *error) +static int +gethostncpu(void) { + int ncpu = 1; + +#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) + size_t sz = sizeof(ncpu); + + sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0); +#elif defined(__linux__) || defined(__CYGWIN__) + FILE *fp; + char *line = NULL; + size_t n = 0; - DOCALL(int, getenv_r(name, buf, blen)); + /* If anyone knows a better way, I'm all ears */ + if ((fp = fopen("/proc/cpuinfo", "r")) != NULL) { + ncpu = 0; + while (getline(&line, &n, fp) != -1) { + if (strncmp(line, + "processor", sizeof("processor")-1) == 0) + ncpu++; + } + if (ncpu == 0) + ncpu = 1; + free(line); + fclose(fp); + } +#elif __sun__ + /* XXX: this is just a rough estimate ... */ + ncpu = sysconf(_SC_NPROCESSORS_ONLN); +#endif + + return ncpu; } int -rumpuser_gethostname(char *name, size_t namelen, int *error) +rumpuser_getparam(const char *name, void *buf, size_t blen) { - char tmp[MAXHOSTNAMELEN]; - if (gethostname(tmp, sizeof(tmp)) == -1) { - snprintf(name, namelen, "rump-%05d.rumpdomain", (int)getpid()); + if (strcmp(name, RUMPUSER_PARAM_NCPU) == 0) { + int ncpu; + + if (getenv_r("RUMP_NCPU", buf, blen) == -1) { + ncpu = gethostncpu(); + snprintf(buf, blen, "%d", ncpu); + } + return 0; + } else if (strcmp(name, RUMPUSER_PARAM_HOSTNAME) == 0) { + char tmp[MAXHOSTNAMELEN]; + + if (gethostname(tmp, sizeof(tmp)) == -1) { + snprintf(buf, blen, "rump-%05d", (int)getpid()); + } else { + snprintf(buf, blen, "rump-%05d.%s", + (int)getpid(), tmp); + } + return 0; + } else if (*name == '_') { + return EINVAL; } else { - snprintf(name, namelen, "rump-%05d.%s.rumpdomain", - (int)getpid(), tmp); + if (getenv_r(name, buf, blen) == -1) + return errno; + else + return 0; } - - *error = 0; - return 0; } int @@ -592,41 +636,6 @@ rumpuser_kill(int64_t pid, int sig, int #endif } -int -rumpuser_getnhostcpu(void) -{ - int ncpu = 1; - -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) - size_t sz = sizeof(ncpu); - - sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0); -#elif defined(__linux__) || defined(__CYGWIN__) - FILE *fp; - char *line = NULL; - size_t n = 0; - - /* If anyone knows a better way, I'm all ears */ - if ((fp = fopen("/proc/cpuinfo", "r")) != NULL) { - ncpu = 0; - while (getline(&line, &n, fp) != -1) { - if (strncmp(line, - "processor", sizeof("processor")-1) == 0) - ncpu++; - } - if (ncpu == 0) - ncpu = 1; - free(line); - fclose(fp); - } -#elif __sun__ - /* XXX: this is just a rough estimate ... */ - ncpu = sysconf(_SC_NPROCESSORS_ONLN); -#endif - - return ncpu; -} - size_t rumpuser_getrandom(void *buf, size_t buflen, int flags) { Index: src/sys/rump/include/rump/rumpuser.h diff -u src/sys/rump/include/rump/rumpuser.h:1.94 src/sys/rump/include/rump/rumpuser.h:1.95 --- src/sys/rump/include/rump/rumpuser.h:1.94 Mon Apr 29 15:40:38 2013 +++ src/sys/rump/include/rump/rumpuser.h Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.h,v 1.94 2013/04/29 15:40:38 pooka Exp $ */ +/* $NetBSD: rumpuser.h,v 1.95 2013/04/29 17:31:05 pooka Exp $ */ /* * Copyright (c) 2007-2013 Antti Kantee. All Rights Reserved. @@ -124,9 +124,9 @@ int rumpuser_clock_sleep(uint64_t, uint6 * host information retrieval */ -int rumpuser_getenv(const char *, char *, size_t, int *); -int rumpuser_getnhostcpu(void); -int rumpuser_gethostname(char *, size_t, int *); +#define RUMPUSER_PARAM_NCPU "_RUMPUSER_NCPU" +#define RUMPUSER_PARAM_HOSTNAME "_RUMPUSER_HOSTNAME" +int rumpuser_getparam(const char *, void *, size_t); /* * system call emulation, set errno is TLS Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.263 src/sys/rump/librump/rumpkern/rump.c:1.264 --- src/sys/rump/librump/rumpkern/rump.c:1.263 Mon Apr 29 14:51:41 2013 +++ src/sys/rump/librump/rumpkern/rump.c Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.263 2013/04/29 14:51:41 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.264 2013/04/29 17:31:05 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.263 2013/04/29 14:51:41 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.264 2013/04/29 17:31:05 pooka Exp $"); #include <sys/systm.h> #define ELFSIZE ARCH_ELFSIZE @@ -238,7 +238,6 @@ rump_init(void) uint64_t sec, nsec; struct lwp *l; int i, numcpu; - int error; /* not reentrant */ if (rump_inited) @@ -255,21 +254,20 @@ rump_init(void) } /* retrieve env vars which affect the early stage of bootstrap */ - if (rumpuser_getenv("RUMP_THREADS", buf, sizeof(buf), &error) == 0) { + if (rumpuser_getparam("RUMP_THREADS", buf, sizeof(buf)) == 0) { rump_threads = *buf != '0'; } - if (rumpuser_getenv("RUMP_VERBOSE", buf, sizeof(buf), &error) == 0) { + if (rumpuser_getparam("RUMP_VERBOSE", buf, sizeof(buf)) == 0) { if (*buf != '0') boothowto = AB_VERBOSE; } - if (rumpuser_getenv("RUMP_NCPU", buf, sizeof(buf), &error) == 0) - error = 0; - if (error == 0) { - numcpu = strtoll(buf, NULL, 10); - if (numcpu < 1) - numcpu = 1; - } else { - numcpu = rumpuser_getnhostcpu(); + + if (rumpuser_getparam(RUMPUSER_PARAM_NCPU, buf, sizeof(buf)) != 0) + panic("mandatory hypervisor configuration (NCPU) missing"); + numcpu = strtoll(buf, NULL, 10); + if (numcpu < 1) { + panic("rump kernels are not lightweight enough for \"%d\" CPUs", + numcpu); } rump_thread_init(); @@ -441,7 +439,10 @@ rump_init(void) module_init_class(MODULE_CLASS_ANY); - rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error); + if (rumpuser_getparam(RUMPUSER_PARAM_HOSTNAME, + hostname, MAXHOSTNAMELEN) != 0) { + panic("mandatory hypervisor configuration (HOSTNAME) missing"); + } hostnamelen = strlen(hostname); sigemptyset(&sigcantmask); Index: src/sys/rump/librump/rumpkern/vm.c diff -u src/sys/rump/librump/rumpkern/vm.c:1.140 src/sys/rump/librump/rumpkern/vm.c:1.141 --- src/sys/rump/librump/rumpkern/vm.c:1.140 Sun Apr 28 23:21:00 2013 +++ src/sys/rump/librump/rumpkern/vm.c Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vm.c,v 1.140 2013/04/28 23:21:00 pooka Exp $ */ +/* $NetBSD: vm.c,v 1.141 2013/04/29 17:31:05 pooka Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.140 2013/04/28 23:21:00 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.141 2013/04/29 17:31:05 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -273,9 +273,8 @@ void uvm_init(void) { char buf[64]; - int error; - if (rumpuser_getenv("RUMP_MEMLIMIT", buf, sizeof(buf), &error) == 0) { + if (rumpuser_getparam("RUMP_MEMLIMIT", buf, sizeof(buf)) == 0) { unsigned long tmp; char *ep; int mult; Index: src/sys/rump/librump/rumpvfs/rump_vfs.c diff -u src/sys/rump/librump/rumpvfs/rump_vfs.c:1.74 src/sys/rump/librump/rumpvfs/rump_vfs.c:1.75 --- src/sys/rump/librump/rumpvfs/rump_vfs.c:1.74 Mon Apr 29 12:56:03 2013 +++ src/sys/rump/librump/rumpvfs/rump_vfs.c Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_vfs.c,v 1.74 2013/04/29 12:56:03 pooka Exp $ */ +/* $NetBSD: rump_vfs.c,v 1.75 2013/04/29 17:31:05 pooka Exp $ */ /* * Copyright (c) 2008 Antti Kantee. All Rights Reserved. @@ -29,7 +29,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.74 2013/04/29 12:56:03 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.75 2013/04/29 17:31:05 pooka Exp $"); #include <sys/param.h> #include <sys/buf.h> @@ -100,7 +100,7 @@ RUMP_COMPONENT(RUMP__FACTION_VFS) rump_vfs_fini = fini; rump_vfs_drainbufs = drainbufs; - if (rumpuser_getenv("RUMP_NVNODES", buf, sizeof(buf), &error) == 0) { + if (rumpuser_getparam("RUMP_NVNODES", buf, sizeof(buf)) == 0) { desiredvnodes = strtoul(buf, NULL, 10); } else { desiredvnodes = 1<<10; @@ -158,7 +158,7 @@ RUMP_COMPONENT(RUMP__FACTION_VFS) { char *mbase; - if (rumpuser_getenv("RUMP_MODULEBASE", buf, sizeof(buf), &error) == 0) + if (rumpuser_getparam("RUMP_MODULEBASE", buf, sizeof(buf)) == 0) mbase = buf; else mbase = module_base; Index: src/sys/rump/librump/rumpvfs/rumpblk.c diff -u src/sys/rump/librump/rumpvfs/rumpblk.c:1.51 src/sys/rump/librump/rumpvfs/rumpblk.c:1.52 --- src/sys/rump/librump/rumpvfs/rumpblk.c:1.51 Mon Apr 29 15:40:39 2013 +++ src/sys/rump/librump/rumpvfs/rumpblk.c Mon Apr 29 17:31:05 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpblk.c,v 1.51 2013/04/29 15:40:39 pooka Exp $ */ +/* $NetBSD: rumpblk.c,v 1.52 2013/04/29 17:31:05 pooka Exp $ */ /* * Copyright (c) 2009 Antti Kantee. All Rights Reserved. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.51 2013/04/29 15:40:39 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.52 2013/04/29 17:31:05 pooka Exp $"); #include <sys/param.h> #include <sys/buf.h> @@ -165,13 +165,13 @@ rumpblk_init(void) mutex_init(&rumpblk_lock, MUTEX_DEFAULT, IPL_NONE); - if (rumpuser_getenv("RUMP_BLKFAIL", buf, sizeof(buf), &error) == 0) { + if (rumpuser_getparam("RUMP_BLKFAIL", buf, sizeof(buf)) == 0) { blkfail = strtoul(buf, NULL, 10); /* fail everything */ if (blkfail > BLKFAIL_MAX) blkfail = BLKFAIL_MAX; - if (rumpuser_getenv("RUMP_BLKFAIL_SEED", buf, sizeof(buf), - &error) == 0) { + if (rumpuser_getparam("RUMP_BLKFAIL_SEED", + buf, sizeof(buf)) == 0) { randstate = strtoul(buf, NULL, 10); } else { randstate = cprng_fast32(); @@ -182,7 +182,7 @@ rumpblk_init(void) blkfail = 0; } - if (rumpuser_getenv("RUMP_BLKSECTSHIFT", buf, sizeof(buf), &error)==0){ + if (rumpuser_getparam("RUMP_BLKSECTSHIFT", buf, sizeof(buf)) == 0) { printf("rumpblk: "); tmp = strtoul(buf, NULL, 10); if (tmp >= DEV_BSHIFT)