Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/bhyverun.c
Show First 20 Lines • Show All 1,120 Lines • ▼ Show 20 Lines | #ifndef WITHOUT_CAPSICUM | ||||
if (caph_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1) | if (caph_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
free((cap_ioctl_t *)cmds); | free((cap_ioctl_t *)cmds); | ||||
#endif | #endif | ||||
if (reinit) { | if (reinit) { | ||||
error = vm_reinit(ctx); | error = vm_reinit(ctx); | ||||
if (error) { | if (error) { | ||||
fprintf(stderr, "%s: error code is %d\r\n", __func__, error); | |||||
perror("vm_reinit"); | perror("vm_reinit"); | ||||
exit(4); | exit(4); | ||||
} | } | ||||
} | } | ||||
error = vm_set_topology(ctx, sockets, cores, threads, maxcpus); | error = vm_set_topology(ctx, sockets, cores, threads, maxcpus); | ||||
if (error) | if (error) | ||||
errx(EX_OSERR, "vm_set_topology"); | errx(EX_OSERR, "vm_set_topology"); | ||||
return (ctx); | return (ctx); | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
set_defaults(void) | set_defaults(void) | ||||
{ | { | ||||
set_config_bool("acpi_tables", false); | set_config_bool("acpi_tables", false); | ||||
set_config_value("memory.size", "256M"); | set_config_value("memory.size", "256M"); | ||||
set_config_bool("x86.strictmsr", true); | set_config_bool("x86.strictmsr", true); | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
char *get_ckp_path(char *str) | |||||
{ | |||||
char *strcopy; | |||||
char *aux1, *aux2, *aux3, *aux4, *aux5; | |||||
char *path = NULL; | |||||
const char delim[2] = ","; | |||||
strcopy = strdup(str); | |||||
assert(strcopy != NULL); | |||||
aux1 = strtok(strcopy, delim); | |||||
aux2 = strtok(NULL, delim); | |||||
aux3 = strtok(NULL, delim); | |||||
if (aux3 != NULL) { | |||||
if (strcmp(aux3, "virtio-blk") || | |||||
strcmp(aux3, "ahci-hd") || | |||||
strcmp(aux3, "ahci")) { | |||||
aux4 = realpath(aux3, NULL); | |||||
if (aux4 != NULL) { | |||||
aux5 = strrchr(aux4, '/'); | |||||
if (aux5 != NULL) { | |||||
*aux5 = '\0'; | |||||
path = strdup(aux4); | |||||
} | |||||
free(aux4); | |||||
} | |||||
} | |||||
} | |||||
free(strcopy); | |||||
return path; | |||||
} | |||||
#endif | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int c, error, err; | int c, error, err; | ||||
int max_vcpus, memflags; | int max_vcpus, memflags; | ||||
struct vmctx *ctx; | struct vmctx *ctx; | ||||
uint64_t rip; | uint64_t rip; | ||||
size_t memsize; | size_t memsize; | ||||
const char *value, *vmname; | const char *value, *vmname; | ||||
char *optstr; | char *optstr; | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
char *restore_file; | char *restore_file; | ||||
struct restore_state rstate; | struct restore_state rstate; | ||||
int vcpu; | int vcpu; | ||||
restore_file = NULL; | restore_file = NULL; | ||||
#endif | #endif | ||||
cap_channel_t *capcas; | cap_channel_t *capcas = NULL; | ||||
char *ckp_path = NULL; | |||||
init_config(); | init_config(); | ||||
set_defaults(); | set_defaults(); | ||||
progname = basename(argv[0]); | progname = basename(argv[0]); | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
optstr = "aehuwxACDHIPSWYk:o:p:G:c:s:m:l:K:U:r:"; | optstr = "aehuwxACDHIPSWYk:o:p:G:c:s:m:l:K:U:r:"; | ||||
#else | #else | ||||
optstr = "aehuwxACDHIPSWYk:o:p:G:c:s:m:l:K:U:"; | optstr = "aehuwxACDHIPSWYk:o:p:G:c:s:m:l:K:U:"; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | case 'r': | ||||
break; | break; | ||||
#endif | #endif | ||||
case 's': | case 's': | ||||
if (strncmp(optarg, "help", strlen(optarg)) == 0) { | if (strncmp(optarg, "help", strlen(optarg)) == 0) { | ||||
pci_print_supported_devices(); | pci_print_supported_devices(); | ||||
exit(0); | exit(0); | ||||
} else if (pci_parse_slot(optarg) != 0) | } else if (pci_parse_slot(optarg) != 0) | ||||
exit(4); | exit(4); | ||||
else | else { | ||||
#ifndef WITHOUT_CAPSISCUM | |||||
if (ckp_path == NULL) | |||||
ckp_path = get_ckp_path(optarg); | |||||
#endif | |||||
break; | break; | ||||
} | |||||
case 'S': | case 'S': | ||||
set_config_bool("memory.wired", true); | set_config_bool("memory.wired", true); | ||||
break; | break; | ||||
case 'm': | case 'm': | ||||
set_config_value("memory.size", optarg); | set_config_value("memory.size", optarg); | ||||
break; | break; | ||||
case 'o': | case 'o': | ||||
if (!parse_config_option(optarg)) | if (!parse_config_option(optarg)) | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | #endif | ||||
if (lpc_bootrom()) | if (lpc_bootrom()) | ||||
fwctl_init(); | fwctl_init(); | ||||
/* | /* | ||||
* Change the proc title to include the VM name. | * Change the proc title to include the VM name. | ||||
*/ | */ | ||||
setproctitle("%s", vmname); | setproctitle("%s", vmname); | ||||
#ifndef WITHOUT_CAPSICUM | |||||
/* Open capability to Casper. */ | /* Open capability to Casper. */ | ||||
capcas = cap_init(); | capcas = cap_init(); | ||||
if (capcas == NULL) | if (capcas == NULL) | ||||
errx(EX_OSERR, "cap_init() failed"); | errx(EX_OSERR, "cap_init() failed"); | ||||
#endif | |||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
if (restore_file != NULL) | if (restore_file != NULL) | ||||
destroy_restore_state(&rstate); | destroy_restore_state(&rstate); | ||||
/* initialize mutex/cond variables */ | /* initialize mutex/cond variables */ | ||||
init_snapshot(); | init_snapshot(); | ||||
/* | /* | ||||
* checkpointing thread for communication with bhyvectl | * checkpointing thread for communication with bhyvectl | ||||
*/ | */ | ||||
if (init_checkpoint_thread(ctx, capcas) < 0) | if (init_checkpoint_thread(ctx, ckp_path, capcas) < 0) | ||||
printf("Failed to start checkpoint thread!\r\n"); | printf("Failed to start checkpoint thread!\r\n"); | ||||
if (restore_file != NULL) | if (restore_file != NULL) | ||||
vm_restore_time(ctx); | vm_restore_time(ctx); | ||||
#endif | #endif | ||||
#ifndef WITHOUT_CAPSICUM | #ifndef WITHOUT_CAPSICUM | ||||
free(ckp_path); | |||||
caph_cache_catpages(); | caph_cache_catpages(); | ||||
if (caph_limit_stdout() == -1 || caph_limit_stderr() == -1) | if (caph_limit_stdout() == -1 || caph_limit_stderr() == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
if (caph_enter() == -1) | if (caph_enter() == -1) | ||||
errx(EX_OSERR, "cap_enter() failed"); | errx(EX_OSERR, "cap_enter() failed"); | ||||
#endif | #endif | ||||
Show All 29 Lines |