Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyvectl/bhyvectl.c
| Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | usage(bool cpu_intel) | ||||
| "Usage: %s --vm=<vmname>\n" | "Usage: %s --vm=<vmname>\n" | ||||
| " [--cpu=<vcpu_number>]\n" | " [--cpu=<vcpu_number>]\n" | ||||
| " [--create]\n" | " [--create]\n" | ||||
| " [--destroy]\n" | " [--destroy]\n" | ||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| " [--checkpoint=<filename>]\n" | " [--checkpoint=<filename>]\n" | ||||
| " [--suspend=<filename>]\n" | " [--suspend=<filename>]\n" | ||||
| " [--migrate=host[,port]]\n" | " [--migrate=host[,port]]\n" | ||||
| " [--migrate-live=host[,port]]\n" | |||||
| #endif | #endif | ||||
| " [--get-all]\n" | " [--get-all]\n" | ||||
| " [--get-stats]\n" | " [--get-stats]\n" | ||||
| " [--set-desc-ds]\n" | " [--set-desc-ds]\n" | ||||
| " [--get-desc-ds]\n" | " [--get-desc-ds]\n" | ||||
| " [--set-desc-es]\n" | " [--set-desc-es]\n" | ||||
| " [--get-desc-es]\n" | " [--get-desc-es]\n" | ||||
| " [--set-desc-gs]\n" | " [--set-desc-gs]\n" | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
| enum x2apic_state x2apic_state; | enum x2apic_state x2apic_state; | ||||
| static int unassign_pptdev, bus, slot, func; | static int unassign_pptdev, bus, slot, func; | ||||
| static int run; | static int run; | ||||
| static int get_cpu_topology; | static int get_cpu_topology; | ||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| static int vm_checkpoint_opt; | static int vm_checkpoint_opt; | ||||
| static int vm_suspend_opt; | static int vm_suspend_opt; | ||||
| static int vm_migrate; | static int vm_migrate; | ||||
| static int vm_migrate_live; | |||||
| #endif | #endif | ||||
| /* | /* | ||||
| * VMCB specific. | * VMCB specific. | ||||
| */ | */ | ||||
| static int get_vmcb_intercept, get_vmcb_exit_details, get_vmcb_tlb_ctrl; | static int get_vmcb_intercept, get_vmcb_exit_details, get_vmcb_tlb_ctrl; | ||||
| static int get_vmcb_virq, get_avic_table; | static int get_vmcb_virq, get_avic_table; | ||||
| ▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | enum { | ||||
| ASSERT_LAPIC_LVT, | ASSERT_LAPIC_LVT, | ||||
| SET_RTC_TIME, | SET_RTC_TIME, | ||||
| SET_RTC_NVRAM, | SET_RTC_NVRAM, | ||||
| RTC_NVRAM_OFFSET, | RTC_NVRAM_OFFSET, | ||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| SET_CHECKPOINT_FILE, | SET_CHECKPOINT_FILE, | ||||
| SET_SUSPEND_FILE, | SET_SUSPEND_FILE, | ||||
| MIGRATE_VM, | MIGRATE_VM, | ||||
| MIGRATE_VM_LIVE, | |||||
| #endif | #endif | ||||
| }; | }; | ||||
| static void | static void | ||||
| print_cpus(const char *banner, const cpuset_t *cpus) | print_cpus(const char *banner, const cpuset_t *cpus) | ||||
| { | { | ||||
| int i, first; | int i, first; | ||||
| ▲ Show 20 Lines • Show All 857 Lines • ▼ Show 20 Lines | const struct option common_opts[] = { | ||||
| { "get-active-cpus", NO_ARG, &get_active_cpus, 1 }, | { "get-active-cpus", NO_ARG, &get_active_cpus, 1 }, | ||||
| { "get-suspended-cpus", NO_ARG, &get_suspended_cpus, 1 }, | { "get-suspended-cpus", NO_ARG, &get_suspended_cpus, 1 }, | ||||
| { "get-intinfo", NO_ARG, &get_intinfo, 1 }, | { "get-intinfo", NO_ARG, &get_intinfo, 1 }, | ||||
| { "get-cpu-topology", NO_ARG, &get_cpu_topology, 1 }, | { "get-cpu-topology", NO_ARG, &get_cpu_topology, 1 }, | ||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| { "checkpoint", REQ_ARG, 0, SET_CHECKPOINT_FILE}, | { "checkpoint", REQ_ARG, 0, SET_CHECKPOINT_FILE}, | ||||
| { "suspend", REQ_ARG, 0, SET_SUSPEND_FILE}, | { "suspend", REQ_ARG, 0, SET_SUSPEND_FILE}, | ||||
| { "migrate", REQ_ARG, 0, MIGRATE_VM}, | { "migrate", REQ_ARG, 0, MIGRATE_VM}, | ||||
| { "migrate-live", REQ_ARG, 0, MIGRATE_VM_LIVE}, | |||||
| #endif | #endif | ||||
| }; | }; | ||||
| const struct option intel_opts[] = { | const struct option intel_opts[] = { | ||||
| { "get-vmcs-pinbased-ctls", | { "get-vmcs-pinbased-ctls", | ||||
| NO_ARG, &get_pinbased_ctls, 1 }, | NO_ARG, &get_pinbased_ctls, 1 }, | ||||
| { "get-vmcs-procbased-ctls", | { "get-vmcs-procbased-ctls", | ||||
| NO_ARG, &get_procbased_ctls, 1 }, | NO_ARG, &get_procbased_ctls, 1 }, | ||||
| ▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | snapshot_request(struct vmctx *ctx, const char *file, bool suspend) | ||||
| nvlist_add_string(nvl, "cmd", "checkpoint"); | nvlist_add_string(nvl, "cmd", "checkpoint"); | ||||
| nvlist_add_string(nvl, "filename", file); | nvlist_add_string(nvl, "filename", file); | ||||
| nvlist_add_bool(nvl, "suspend", suspend); | nvlist_add_bool(nvl, "suspend", suspend); | ||||
| return (send_message(ctx, nvl)); | return (send_message(ctx, nvl)); | ||||
| } | } | ||||
| static int | static int | ||||
| send_start_migrate(struct vmctx *ctx, const char *migrate_vm) | send_start_migrate(struct vmctx *ctx, const char *migrate_vm, bool live) | ||||
| { | { | ||||
| nvlist_t *nvl; | nvlist_t *nvl; | ||||
| char *hostname, *pos; | char *hostname, *pos; | ||||
| int rc; | int rc; | ||||
| unsigned int port; | unsigned int port; | ||||
| hostname = strdup(migrate_vm); | hostname = strdup(migrate_vm); | ||||
| Show All 9 Lines | if (rc == 0) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| } else { | } else { | ||||
| /* If only one variable could be read, it should be the host */ | /* If only one variable could be read, it should be the host */ | ||||
| port = DEFAULT_MIGRATION_PORT; | port = DEFAULT_MIGRATION_PORT; | ||||
| } | } | ||||
| nvl = nvlist_create(0); | nvl = nvlist_create(0); | ||||
| if (live) | |||||
| nvlist_add_string(nvl, "cmd", "migrate_live"); | |||||
| else | |||||
| nvlist_add_string(nvl, "cmd", "migrate"); | nvlist_add_string(nvl, "cmd", "migrate"); | ||||
| nvlist_add_string(nvl, "hostname", hostname); | nvlist_add_string(nvl, "hostname", hostname); | ||||
| nvlist_add_number(nvl, "port", port); | nvlist_add_number(nvl, "port", port); | ||||
| free(hostname); | free(hostname); | ||||
| return (send_message(ctx, nvl)); | return (send_message(ctx, nvl)); | ||||
| } | } | ||||
| #endif /* BHYVE_SNAPSHOT */ | #endif /* BHYVE_SNAPSHOT */ | ||||
| int | int | ||||
| main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
| { | { | ||||
| char *vmname; | char *vmname; | ||||
| int error, ch, vcpu, ptenum; | int error, ch, vcpu, ptenum; | ||||
| vm_paddr_t gpa_pmap; | vm_paddr_t gpa_pmap; | ||||
| struct vm_exit vmexit; | struct vm_exit vmexit; | ||||
| uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; | uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; | ||||
| ▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | #ifdef BHYVE_SNAPSHOT | ||||
| case SET_SUSPEND_FILE: | case SET_SUSPEND_FILE: | ||||
| vm_suspend_opt = 1; | vm_suspend_opt = 1; | ||||
| suspend_file = optarg; | suspend_file = optarg; | ||||
| break; | break; | ||||
| case MIGRATE_VM: | case MIGRATE_VM: | ||||
| vm_migrate = 1; | vm_migrate = 1; | ||||
| migrate_host = optarg; | migrate_host = optarg; | ||||
| break; | break; | ||||
| case MIGRATE_VM_LIVE: | |||||
| vm_migrate_live = 1; | |||||
| migrate_host = optarg; | |||||
| break; | |||||
| #endif | #endif | ||||
| default: | default: | ||||
| usage(cpu_intel); | usage(cpu_intel); | ||||
| } | } | ||||
| } | } | ||||
| argc -= optind; | argc -= optind; | ||||
| argv += optind; | argv += optind; | ||||
| ▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | |||||
| #ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
| if (!error && vm_checkpoint_opt) | if (!error && vm_checkpoint_opt) | ||||
| error = snapshot_request(ctx, checkpoint_file, false); | error = snapshot_request(ctx, checkpoint_file, false); | ||||
| if (!error && vm_suspend_opt) | if (!error && vm_suspend_opt) | ||||
| error = snapshot_request(ctx, suspend_file, true); | error = snapshot_request(ctx, suspend_file, true); | ||||
| if (!error && vm_migrate) | if (!error && vm_migrate) | ||||
| error = send_start_migrate(ctx, migrate_host); | error = send_start_migrate(ctx, migrate_host, false); | ||||
| if (!error && vm_migrate_live) | |||||
| error = send_start_migrate(ctx, migrate_host, true); | |||||
| #endif | #endif | ||||
| free (opts); | free (opts); | ||||
| exit(error); | exit(error); | ||||
| } | } | ||||