diff options
author | grehan <grehan@FreeBSD.org> | 2013-12-13 06:59:18 +0000 |
---|---|---|
committer | grehan <grehan@FreeBSD.org> | 2013-12-13 06:59:18 +0000 |
commit | 3f29e37aefa08dee5a3ddfff64daea1158b01a53 (patch) | |
tree | 06ecf2aef97101260263472fc8529085c536703d /usr.sbin/bhyveload | |
parent | 37e02e5c7aa4bc01fa32f20080173c76f6e53012 (diff) | |
download | FreeBSD-src-3f29e37aefa08dee5a3ddfff64daea1158b01a53.zip FreeBSD-src-3f29e37aefa08dee5a3ddfff64daea1158b01a53.tar.gz |
MFC r256657,r257018,r257347,r257423,r257729,r257767,
r257933,r258609,r258614,r258668,r258673,r258855
Pull in some minor bugfixes and functionality enhancements
from CURRENT. These are candidates to be moved to 10.0-release.
r258855
mdoc: quote string properly.
r258673
Don't create an initial value for the host filesystem of "/".
r258668
Allow bhyve and bhyveload to attach to tty devices.
r258614
The 22-bit Data Byte Count (DBC) field of a Physical Region Descriptor was
being read as a 32-bit quantity by the bhyve AHCI driver.
r258609
Fix discrepancy between the IOAPIC ID advertised by firmware tables and the
actual value read by the guest.
r257933
Route the legacy timer interrupt (IRQ0) to pin 2 of the IOAPIC.
r257767
Fix an off-by-one error when iterating over the emulated PCI BARs.
r257729
Add the VM name to the process name with setproctitle().
r257423
Make the virtual ioapic available unconditionally in a bhyve virtual machine.
r257347
Update copyright to include the author of the LPC bridge emulation code.
hand-merge r257018
Tidy usage messages for bhyve and bhyveload.
r256657
Add an option to bhyveload(8) that allows setting a loader environment variable
from the command line.
Discussed with: neel
Diffstat (limited to 'usr.sbin/bhyveload')
-rw-r--r-- | usr.sbin/bhyveload/bhyveload.8 | 33 | ||||
-rw-r--r-- | usr.sbin/bhyveload/bhyveload.c | 120 |
2 files changed, 127 insertions, 26 deletions
diff --git a/usr.sbin/bhyveload/bhyveload.8 b/usr.sbin/bhyveload/bhyveload.8 index 2efcad0..eed1f1a 100644 --- a/usr.sbin/bhyveload/bhyveload.8 +++ b/usr.sbin/bhyveload/bhyveload.8 @@ -38,6 +38,8 @@ guest inside a bhyve virtual machine .Op Fl m Ar mem-size .Op Fl d Ar disk-path .Op Fl h Ar host-path +.Op Fl e Ar name=value +.Op Fl c Ar cons-dev .Ar vmname .Sh DESCRIPTION .Nm @@ -91,6 +93,24 @@ is the pathname of the guest's boot disk image. The .Ar host-path is the directory at the top of the guest's boot filesystem. +.It Fl e Ar name=value +Set the FreeBSD loader environment variable +.Ar name +to +.Ar value . +.Pp +The option may be used more than once to set more than one environment +variable. +.It Fl c Ar cons-dev +.Ar cons-dev +is a +.Xr tty 4 +device to use for +.Nm +terminal I/O. +.Pp +The text string "stdio" is also accepted and selects the use of +unbuffered standard I/O. This is the default value. .El .Sh EXAMPLES To create a virtual machine named @@ -100,10 +120,23 @@ that boots off the ISO image and has 1GB memory allocated to it: .Pp .Dl "bhyveload -m 1G -d /freebsd/release.iso freebsd-vm" +.Pp +To create a virtual machine named +.Ar test-vm +with 256MB of memory allocated, the guest root filesystem under the host +directory +.Pa /user/images/test +and terminal I/O sent to the +.Xr nmdm 4 +device +.Pa /dev/nmdm1B +.Pp +.Dl "bhyveload -m 256MB -h /usr/images/test -c /dev/nmdm1B test-vm" .Sh SEE ALSO .Xr bhyve 4 , .Xr bhyve 8 , .Xr loader 8 , +.Xr nmdm 4, .Xr vmm 4 .Sh HISTORY .Nm diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c index 6e541e8..94cb1b1 100644 --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/disk.h> +#include <sys/queue.h> #include <machine/specialreg.h> #include <machine/vmm.h> @@ -70,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <fcntl.h> #include <getopt.h> +#include <libgen.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -86,9 +88,10 @@ __FBSDID("$FreeBSD$"); #define GB (1024 * 1024 * 1024UL) #define BSP 0 -static char *host_base = "/"; +static char *host_base; static struct termios term, oldterm; static int disk_fd = -1; +static int consin_fd, consout_fd; static char *vmname, *progname; static struct vmctx *ctx; @@ -106,7 +109,7 @@ cb_putc(void *arg, int ch) { char c = ch; - write(1, &c, 1); + (void) write(consout_fd, &c, 1); } static int @@ -114,7 +117,7 @@ cb_getc(void *arg) { char c; - if (read(0, &c, 1) == 1) + if (read(consin_fd, &c, 1) == 1) return (c); return (-1); } @@ -124,7 +127,7 @@ cb_poll(void *arg) { int n; - if (ioctl(0, FIONREAD, &n) >= 0) + if (ioctl(consin_fd, FIONREAD, &n) >= 0) return (n > 0); return (0); } @@ -486,7 +489,7 @@ static void cb_exit(void *arg, int v) { - tcsetattr(0, TCSAFLUSH, &oldterm); + tcsetattr(consout_fd, TCSAFLUSH, &oldterm); exit(v); } @@ -498,23 +501,37 @@ cb_getmem(void *arg, uint64_t *ret_lowmem, uint64_t *ret_highmem) vm_get_memory_seg(ctx, 4 * GB, ret_highmem, NULL); } -static const char * -cb_getenv(void *arg, int num) +struct env { + const char *str; /* name=value */ + SLIST_ENTRY(env) next; +}; + +static SLIST_HEAD(envhead, env) envhead; + +static void +addenv(const char *str) { - int max; + struct env *env; - static const char * var[] = { - "smbios.bios.vendor=BHYVE", - "boot_serial=1", - NULL - }; + env = malloc(sizeof(struct env)); + env->str = str; + SLIST_INSERT_HEAD(&envhead, env, next); +} - max = sizeof(var) / sizeof(var[0]); +static const char * +cb_getenv(void *arg, int num) +{ + int i; + struct env *env; + + i = 0; + SLIST_FOREACH(env, &envhead, next) { + if (i == num) + return (env->str); + i++; + } - if (num < max) - return (var[num]); - else - return (NULL); + return (NULL); } static struct loader_callbacks cb = { @@ -548,13 +565,46 @@ static struct loader_callbacks cb = { .getenv = cb_getenv, }; +static int +altcons_open(char *path) +{ + struct stat sb; + int err; + int fd; + + /* + * Allow stdio to be passed in so that the same string + * can be used for the bhyveload console and bhyve com-port + * parameters + */ + if (!strcmp(path, "stdio")) + return (0); + + err = stat(path, &sb); + if (err == 0) { + if (!S_ISCHR(sb.st_mode)) + err = ENOTSUP; + else { + fd = open(path, O_RDWR | O_NONBLOCK); + if (fd < 0) + err = errno; + else + consin_fd = consout_fd = fd; + } + } + + return (err); +} + static void usage(void) { fprintf(stderr, - "usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] " - "<vmname>\n", progname); + "usage: %s [-m mem-size] [-d <disk-path>] [-h <host-path>]\n" + " %*s [-e <name=value>] [-c <console-device>] <vmname>\n", + progname, + (int)strlen(progname), ""); exit(1); } @@ -567,17 +617,29 @@ main(int argc, char** argv) int opt, error; char *disk_image; - progname = argv[0]; + progname = basename(argv[0]); mem_size = 256 * MB; disk_image = NULL; - while ((opt = getopt(argc, argv, "d:h:m:")) != -1) { + consin_fd = STDIN_FILENO; + consout_fd = STDOUT_FILENO; + + while ((opt = getopt(argc, argv, "c:d:e:h:m:")) != -1) { switch (opt) { + case 'c': + error = altcons_open(optarg); + if (error != 0) + errx(EX_USAGE, "Could not open '%s'", optarg); + break; case 'd': disk_image = optarg; break; + case 'e': + addenv(optarg); + break; + case 'h': host_base = optarg; break; @@ -619,11 +681,13 @@ main(int argc, char** argv) exit(1); } - tcgetattr(0, &term); + tcgetattr(consout_fd, &term); oldterm = term; - term.c_lflag &= ~(ICANON|ECHO); - term.c_iflag &= ~ICRNL; - tcsetattr(0, TCSAFLUSH, &term); + cfmakeraw(&term); + term.c_cflag |= CLOCAL; + + tcsetattr(consout_fd, TCSAFLUSH, &term); + h = dlopen("/boot/userboot.so", RTLD_LOCAL); if (!h) { printf("%s\n", dlerror()); @@ -638,5 +702,9 @@ main(int argc, char** argv) if (disk_image) { disk_fd = open(disk_image, O_RDONLY); } + + addenv("smbios.bios.vendor=BHYVE"); + addenv("boot_serial=1"); + func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0); } |