Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Replace the various "get info from hypervisor" interfaces wi...
details: https://anonhg.NetBSD.org/src/rev/61b9b02cc12d
branches: trunk
changeset: 786483:61b9b02cc12d
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Apr 29 17:31:05 2013 +0000
description:
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)
diffstat:
lib/librumpuser/rumpuser.c | 107 +++++++++++++++++++----------------
sys/rump/include/rump/rumpuser.h | 8 +-
sys/rump/librump/rumpkern/rump.c | 29 +++++----
sys/rump/librump/rumpkern/vm.c | 7 +-
sys/rump/librump/rumpvfs/rump_vfs.c | 8 +-
sys/rump/librump/rumpvfs/rumpblk.c | 12 ++--
6 files changed, 90 insertions(+), 81 deletions(-)
diffs (truncated from 344 to 300 lines):
diff -r 80b0d385d2a5 -r 61b9b02cc12d lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c Mon Apr 29 15:40:38 2013 +0000
+++ b/lib/librumpuser/rumpuser.c Mon Apr 29 17:31:05 2013 +0000
@@ -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 @@
return rv;
}
-int
-rumpuser_getenv(const char *name, char *buf, size_t blen, int *error)
+static int
+gethostncpu(void)
{
+ int ncpu = 1;
- DOCALL(int, getenv_r(name, buf, blen));
+#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;
}
int
-rumpuser_gethostname(char *name, size_t namelen, int *error)
+rumpuser_getparam(const char *name, void *buf, size_t blen)
{
- char tmp[MAXHOSTNAMELEN];
+
+ if (strcmp(name, RUMPUSER_PARAM_NCPU) == 0) {
+ int ncpu;
- if (gethostname(tmp, sizeof(tmp)) == -1) {
- snprintf(name, namelen, "rump-%05d.rumpdomain", (int)getpid());
+ 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 @@
#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)
{
diff -r 80b0d385d2a5 -r 61b9b02cc12d sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h Mon Apr 29 15:40:38 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h Mon Apr 29 17:31:05 2013 +0000
@@ -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 @@
* 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
diff -r 80b0d385d2a5 -r 61b9b02cc12d sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c Mon Apr 29 15:40:38 2013 +0000
+++ b/sys/rump/librump/rumpkern/rump.c Mon Apr 29 17:31:05 2013 +0000
@@ -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 @@
uint64_t sec, nsec;
struct lwp *l;
int i, numcpu;
- int error;
/* not reentrant */
if (rump_inited)
@@ -255,21 +254,20 @@
}
/* 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 @@
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);
diff -r 80b0d385d2a5 -r 61b9b02cc12d sys/rump/librump/rumpkern/vm.c
--- a/sys/rump/librump/rumpkern/vm.c Mon Apr 29 15:40:38 2013 +0000
+++ b/sys/rump/librump/rumpkern/vm.c Mon Apr 29 17:31:05 2013 +0000
@@ -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 @@
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;
diff -r 80b0d385d2a5 -r 61b9b02cc12d sys/rump/librump/rumpvfs/rump_vfs.c
--- a/sys/rump/librump/rumpvfs/rump_vfs.c Mon Apr 29 15:40:38 2013 +0000
+++ b/sys/rump/librump/rumpvfs/rump_vfs.c Mon Apr 29 17:31:05 2013 +0000
@@ -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_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 @@
{
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;
Home |
Main Index |
Thread Index |
Old Index