Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyveload/bhyveload.c
/*- | /*- | ||||
* Copyright (c) 2011 NetApp, Inc. | * Copyright (c) 2011 NetApp, Inc. | ||||
* Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
#include <termios.h> | #include <termios.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <vmmapi.h> | #include <vmmapi.h> | ||||
#include <config.h> | |||||
#include "userboot.h" | #include "userboot.h" | ||||
#define MB (1024 * 1024UL) | #define MB (1024 * 1024UL) | ||||
#define GB (1024 * 1024 * 1024UL) | #define GB (1024 * 1024 * 1024UL) | ||||
#define BSP 0 | #define BSP 0 | ||||
#define NDISKS 32 | #define NDISKS 32 | ||||
▲ Show 20 Lines • Show All 532 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"usage: %s [-c <console-device>] [-d <disk-path>] [-e <name=value>]\n" | "usage: %s [-c <console-device>] [-d <disk-path>] [-e <name=value>]\n" | ||||
" %*s [-h <host-path>] [-m mem-size] <vmname>\n", | " %*s [-f <config-file> [-h <host-path>] [-m mem-size]\n" | ||||
" %*s <vmname>\n", | |||||
progname, | progname, | ||||
(int)strlen(progname), ""); | (int)strlen(progname), (int)strlen(progname), ""); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
int | int | ||||
main(int argc, char** argv) | main(int argc, char** argv) | ||||
{ | { | ||||
void *h; | void *h; | ||||
void (*func)(struct loader_callbacks *, void *, int, int); | void (*func)(struct loader_callbacks *, void *, int, int); | ||||
uint64_t mem_size; | uint64_t mem_size; | ||||
int opt, error, need_reinit; | int opt, error, need_reinit; | ||||
struct config_entry config; | |||||
progname = basename(argv[0]); | progname = basename(argv[0]); | ||||
mem_size = 256 * MB; | mem_size = 256 * MB; | ||||
consin_fd = STDIN_FILENO; | consin_fd = STDIN_FILENO; | ||||
consout_fd = STDOUT_FILENO; | consout_fd = STDOUT_FILENO; | ||||
while ((opt = getopt(argc, argv, "c:d:e:h:m:")) != -1) { | while ((opt = getopt(argc, argv, "c:d:e:f:h:m:")) != -1) { | ||||
switch (opt) { | switch (opt) { | ||||
case 'c': | case 'c': | ||||
error = altcons_open(optarg); | error = altcons_open(optarg); | ||||
if (error != 0) | if (error != 0) | ||||
errx(EX_USAGE, "Could not open '%s'", optarg); | errx(EX_USAGE, "Could not open '%s'", optarg); | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
error = disk_open(optarg); | error = disk_open(optarg); | ||||
if (error != 0) | if (error != 0) | ||||
errx(EX_USAGE, "Could not open '%s'", optarg); | errx(EX_USAGE, "Could not open '%s'", optarg); | ||||
break; | break; | ||||
case 'e': | case 'e': | ||||
addenv(optarg); | addenv(optarg); | ||||
break; | break; | ||||
case 'f': | |||||
if (load_config(optarg) == 0) { | |||||
config = parse_conf(optarg); | |||||
error = altcons_open(config.console); | |||||
if (error != 0) | |||||
errx(EX_USAGE, "Could not open console"); | |||||
if (config.isofile) | |||||
error = disk_open(config.isofile); | |||||
else | |||||
error = disk_open(config.bootdisk); | |||||
if (error != 0 ) | |||||
errx(EX_USAGE, "Could not open disk"); | |||||
error = vm_parse_memsize(config.memsize, &mem_size); | |||||
if (error != 0) | |||||
errx(EX_USAGE, "Invalid memsize"); | |||||
vmname = config.vmname; | |||||
} else { | |||||
errx(EX_USAGE, "Error to parse config file: %s", optarg); | |||||
exit (1); | |||||
} | |||||
break; | |||||
case 'h': | case 'h': | ||||
host_base = optarg; | host_base = optarg; | ||||
break; | break; | ||||
case 'm': | case 'm': | ||||
error = vm_parse_memsize(optarg, &mem_size); | error = vm_parse_memsize(optarg, &mem_size); | ||||
if (error != 0) | if (error != 0) | ||||
errx(EX_USAGE, "Invalid memsize '%s'", optarg); | errx(EX_USAGE, "Invalid memsize '%s'", optarg); | ||||
break; | break; | ||||
case '?': | case '?': | ||||
usage(); | usage(); | ||||
} | } | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (argc != 1) | if (!vmname && argc > 0) | ||||
usage(); | |||||
vmname = argv[0]; | vmname = argv[0]; | ||||
if (!vmname) | |||||
usage(); | |||||
need_reinit = 0; | need_reinit = 0; | ||||
error = vm_create(vmname); | error = vm_create(vmname); | ||||
if (error) { | if (error) { | ||||
if (errno != EEXIST) { | if (errno != EEXIST) { | ||||
perror("vm_create"); | perror("vm_create"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |