Skip to content

Commit

Permalink
Revert "bhyve: add command line parameter and parsing for migration"
Browse files Browse the repository at this point in the history
Unfortunately, this feature didn't receive much feedback in the past.
However, after committing this, some people came up and complain that
this feature requires some more discussion before upstreaming it.
Additionally, it wasn't a good idea to start this new feature by adding
a new command line parameter as it fixes the user interface.

This reverts commit c9fdd4f.
  • Loading branch information
ckoehne committed Jun 21, 2023
1 parent 5bd5470 commit 1e8d0c6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 294 deletions.
1 change: 0 additions & 1 deletion usr.sbin/bhyve/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ SRCS= \

.if ${MK_BHYVE_SNAPSHOT} != "no"
SRCS+= snapshot.c
SRCS+= migration.c
.endif

CFLAGS.kernemu_dev.c+= -I${SRCTOP}/sys/amd64
Expand Down
12 changes: 0 additions & 12 deletions usr.sbin/bhyve/bhyve.8
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@
.Op Fl o Ar var Ns Cm = Ns Ar value
.Op Fl p Ar vcpu Ns Cm \&: Ns Ar hostcpu
.Op Fl r Ar file
.Oo Fl R
.Sm off
.Ar host Op Cm \&: Ar port
.Sm on
.Oc
.Sm off
.Oo Fl s\~
.Ar slot Cm \&, Ar emulation Op Cm \&, Ar conf
Expand Down Expand Up @@ -281,13 +276,6 @@ and
.Fl l
options.
The count of vCPUs and memory configuration are read from the snapshot.
.It Fl R Ar host Ns Op Cm \&: Ns Ar port
Receive migration from a source guest.
Await for a connection from
.Ar host
on the specified
.Ar port
and resume execution. The default migration port is 24983.
.It Fl S
Wire guest memory.
.It Fl s Cm help
Expand Down
66 changes: 19 additions & 47 deletions usr.sbin/bhyve/bhyverun.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ __FBSDID("$FreeBSD$");
#include "kernemu_dev.h"
#include "mem.h"
#include "mevent.h"
#ifdef BHYVE_SNAPSHOT
#include "migration.h"
#endif
#include "mptbl.h"
#include "pci_emul.h"
#include "pci_irq.h"
Expand Down Expand Up @@ -234,7 +231,6 @@ usage(int code)
" -p: pin 'vcpu' to 'hostcpu'\n"
#ifdef BHYVE_SNAPSHOT
" -r: path to checkpoint file\n"
" -R: <host[:port]> the source vm host and port for migration\n"
#endif
" -S: guest memory cannot be swapped\n"
" -s: <slot,driver,configinfo> PCI slot config\n"
Expand Down Expand Up @@ -1082,11 +1078,7 @@ do_open(const char *vmname)
exit(4);
}
} else {
#ifndef BHYVE_SNAPSHOT
if (!romboot) {
#else
if (!romboot && !get_config_bool_default("is_migrated", false)) {
#endif
/*
* If the virtual machine was just created then a
* bootrom must be configured to boot it.
Expand Down Expand Up @@ -1231,19 +1223,17 @@ main(int argc, char *argv[])
const char *optstr, *value, *vmname;
#ifdef BHYVE_SNAPSHOT
char *restore_file;
char *migration_host;
struct restore_state rstate;

restore_file = NULL;
migration_host = NULL;
#endif

init_config();
set_defaults();
progname = basename(argv[0]);

#ifdef BHYVE_SNAPSHOT
optstr = "aehuwxACDHIPSWYk:f:o:p:G:c:s:m:l:K:U:r:R:";
optstr = "aehuwxACDHIPSWYk:f:o:p:G:c:s:m:l:K:U:r:";
#else
optstr = "aehuwxACDHIPSWYk:f:o:p:G:c:s:m:l:K:U:";
#endif
Expand Down Expand Up @@ -1300,10 +1290,6 @@ main(int argc, char *argv[])
case 'r':
restore_file = optarg;
break;
case 'R':
migration_host = optarg;
set_config_bool("is_migrated", true);
break;
#endif
case 's':
if (strncmp(optarg, "help", strlen(optarg)) == 0) {
Expand Down Expand Up @@ -1520,51 +1506,38 @@ main(int argc, char *argv[])
spinup_vcpu(&vcpu_info[vcpuid], vcpuid == BSP);

#ifdef BHYVE_SNAPSHOT
if (restore_file != NULL || migration_host != NULL) {
fprintf(stdout, "Pausing pci devs...\n");
if (restore_file != NULL) {
fprintf(stdout, "Pausing pci devs...\r\n");
if (vm_pause_devices() != 0) {
fprintf(stderr, "Failed to pause PCI device state.\n");
exit(1);
}

if (restore_file != NULL) {
fprintf(stdout, "Restoring vm mem...\n");
if (restore_vm_mem(ctx, &rstate) != 0) {
fprintf(stderr,
"Failed to restore VM memory.\n");
exit(1);
}

fprintf(stdout, "Restoring pci devs...\n");
if (vm_restore_devices(&rstate) != 0) {
fprintf(stderr,
"Failed to restore PCI device state.\n");
exit(1);
}
fprintf(stdout, "Restoring vm mem...\r\n");
if (restore_vm_mem(ctx, &rstate) != 0) {
fprintf(stderr, "Failed to restore VM memory.\n");
exit(1);
}

fprintf(stdout, "Restoring kernel structs...\n");
if (vm_restore_kern_structs(ctx, &rstate) != 0) {
fprintf(stderr,
"Failed to restore kernel structs.\n");
exit(1);
}
fprintf(stdout, "Restoring pci devs...\r\n");
if (vm_restore_devices(&rstate) != 0) {
fprintf(stderr, "Failed to restore PCI device state.\n");
exit(1);
}

if (migration_host != NULL) {
fprintf(stdout, "Starting the migration process...\n");
if (receive_vm_migration(ctx, migration_host) != 0) {
fprintf(stderr, "Failed to migrate the vm.\n");
exit(1);
}
fprintf(stdout, "Restoring kernel structs...\r\n");
if (vm_restore_kern_structs(ctx, &rstate) != 0) {
fprintf(stderr, "Failed to restore kernel structs.\n");
exit(1);
}

fprintf(stdout, "Resuming pci devs...\n");
fprintf(stdout, "Resuming pci devs...\r\n");
if (vm_resume_devices() != 0) {
fprintf(stderr, "Failed to resume PCI device state.\n");
exit(1);
}
}
#endif /* BHYVE_SNAPSHOT */
#endif

error = vm_get_register(bsp, VM_REG_GUEST_RIP, &rip);
assert(error == 0);
Expand Down Expand Up @@ -1632,9 +1605,8 @@ main(int argc, char *argv[])
#endif

#ifdef BHYVE_SNAPSHOT
if (restore_file != NULL)
if (restore_file != NULL) {
destroy_restore_state(&rstate);
if (restore_file != NULL || migration_host != NULL) {
if (vm_restore_time(ctx) < 0)
err(EX_OSERR, "Unable to restore time");

Expand Down
98 changes: 0 additions & 98 deletions usr.sbin/bhyve/migration.c

This file was deleted.

27 changes: 0 additions & 27 deletions usr.sbin/bhyve/migration.h

This file was deleted.

35 changes: 0 additions & 35 deletions usr.sbin/bhyve/snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ __FBSDID("$FreeBSD$");
#include "ioapic.h"
#include "mem.h"
#include "mevent.h"
#include "migration.h"
#include "mptbl.h"
#include "pci_emul.h"
#include "pci_irq.h"
Expand Down Expand Up @@ -1400,40 +1399,6 @@ vm_do_checkpoint(struct vmctx *ctx, const nvlist_t *nvl)
}
IPC_COMMAND(ipc_cmd_set, checkpoint, vm_do_checkpoint);

static int
vm_do_migrate(struct vmctx __unused *ctx, const nvlist_t *nvl)
{
size_t len;
struct migrate_req req;

if (!nvlist_exists_string(nvl, "hostname") ||
!nvlist_exists_number(nvl, "port"))
return (EINVAL);

memset(&req, 0, sizeof(struct migrate_req));
req.port = nvlist_get_number(nvl, "port");

len = strlen(nvlist_get_string(nvl, "hostname"));
if (len > MAXHOSTNAMELEN - 1) {
EPRINTLN("Hostname length %lu bigger than maximum allowed %d",
len, MAXHOSTNAMELEN - 1);
return (EINVAL);
}

strlcpy(req.host, nvlist_get_string(nvl, "hostname"), MAXHOSTNAMELEN);

printf("%s: IP address used for migration: %s;\n"
"Port used for migration: %d\n",
__func__,
req.host,
req.port);

// return (vm_send_migrate_req(ctx, req, nvlist_get_bool(nvl, "live")));
EPRINTLN("Migration operation not implemented yet\n");
return (EOPNOTSUPP);
}
IPC_COMMAND(ipc_cmd_set, migrate, vm_do_migrate);

void
init_snapshot(void)
{
Expand Down
19 changes: 0 additions & 19 deletions usr.sbin/bhyvectl/bhyvectl.8
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
.Op Fl -force-poweroff
.Op Fl -checkpoint= Ns Ar <filename>
.Op Fl -suspend= Ns Ar <filename>
.Oo
.Fl -migrate= Ns Ar host Ns Op Cm \&: Ns Ar port
|
.Fl -migrate-live= Ns Ar host Ns Op Cm \&: Ns Ar port
.Oc
.Sh DESCRIPTION
The
.Nm
Expand Down Expand Up @@ -90,20 +85,6 @@ Save a snapshot of a virtual machine similar to
.Fl -checkpoint .
The virtual machine will terminate after the snapshot has been
saved.
.It Fl -migrate= Ns Ar host Ns Op Cm \&: Ns Ar port
Warm migrate the virtual machine to a
.Ar host
on the specified
.Ar port .
The default migration port is 24983.
The virtual machine will be destroyed after the migration finishes.
.It Fl -migrate-live= Ns Ar host Ns Op Cm \&: Ns Ar port
Live migrate the virtual machine to a
.Ar host
on the specified
.Ar port .
The default migration port is 24983.
The virtual machine will be destroyed after the migration finishes.
.El
.Sh EXIT STATUS
.Ex -std
Expand Down
Loading

0 comments on commit 1e8d0c6

Please sign in to comment.