Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/snapshot.c
| Show First 20 Lines • Show All 1,454 Lines • ▼ Show 20 Lines | done: | ||||
| if (kdata_fd > 0) | if (kdata_fd > 0) | ||||
| close(kdata_fd); | close(kdata_fd); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| static int | static int | ||||
| handle_message(struct vmctx *ctx, nvlist_t *nvl) | handle_message(struct vmctx *ctx, nvlist_t *nvl) | ||||
| { | { | ||||
| int err; | bool is_live_migration; | ||||
| int err, memflags; | |||||
| size_t len; | size_t len; | ||||
| const char *cmd; | const char *cmd; | ||||
| struct migrate_req req; | struct migrate_req req; | ||||
| if (!nvlist_exists_string(nvl, "cmd")) { | if (!nvlist_exists_string(nvl, "cmd")) { | ||||
| err = -1; | err = -1; | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| cmd = nvlist_get_string(nvl, "cmd"); | cmd = nvlist_get_string(nvl, "cmd"); | ||||
| is_live_migration = strcmp(cmd, "migrate_live") == 0; | |||||
| if (strcmp(cmd, "checkpoint") == 0) { | if (strcmp(cmd, "checkpoint") == 0) { | ||||
| if (!nvlist_exists_string(nvl, "filename") || | if (!nvlist_exists_string(nvl, "filename") || | ||||
| !nvlist_exists_bool(nvl, "suspend")) { | !nvlist_exists_bool(nvl, "suspend")) { | ||||
| err = -1; | err = -1; | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| err = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"), | err = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"), | ||||
| nvlist_get_bool(nvl, "suspend")); | nvlist_get_bool(nvl, "suspend")); | ||||
| } else if (strcmp(cmd, "migrate") == 0) { | } else if (strcmp(cmd, "migrate") == 0 || is_live_migration) { | ||||
| if (!nvlist_exists_string(nvl, "hostname") || | if (!nvlist_exists_string(nvl, "hostname") || | ||||
| !nvlist_exists_number(nvl, "port")) { | !nvlist_exists_number(nvl, "port")) { | ||||
| err = -1; | err = -1; | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| if (is_live_migration) { | |||||
| /* Currently, the live migration is implemented only | |||||
| * for guests that are started using -S (wired | |||||
| * memory option). | |||||
| */ | |||||
| /* Check memflags. If the VM_MEM_F_WIRED bit is not | |||||
| * set, then the live migration procedure cannot be | |||||
| * done. */ | |||||
| memflags = vm_get_memflags(ctx); | |||||
| if (!(memflags & VM_MEM_F_WIRED)) { | |||||
| EPRINTLN("Migration not supported for un-wired guests\r\n"); | |||||
| err = -1; | |||||
| goto done; | |||||
| } | |||||
| } | |||||
| memset(&req, 0, sizeof(struct migrate_req)); | memset(&req, 0, sizeof(struct migrate_req)); | ||||
| req.port = nvlist_get_number(nvl, "port"); | req.port = nvlist_get_number(nvl, "port"); | ||||
| len = strlen(nvlist_get_string(nvl, "hostname")); | len = strlen(nvlist_get_string(nvl, "hostname")); | ||||
| if (len > MAXHOSTNAMELEN - 1) { | if (len > MAXHOSTNAMELEN - 1) { | ||||
| EPRINTLN("Hostname length %lu bigger than maximum allowed %d", | EPRINTLN("Hostname length %lu bigger than maximum allowed %d", | ||||
| len, MAXHOSTNAMELEN - 1); | len, MAXHOSTNAMELEN - 1); | ||||
| err = -1; | err = -1; | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| strlcpy(req.host, nvlist_get_string(nvl, "hostname"), MAXHOSTNAMELEN); | strlcpy(req.host, nvlist_get_string(nvl, "hostname"), MAXHOSTNAMELEN); | ||||
| fprintf(stderr, "%s: IP address used for migration: %s;\r\n" | fprintf(stderr, "%s: IP address used for migration: %s;\r\n" | ||||
| "Port used for migration: %d\r\n", | "Port used for migration: %d\r\n", | ||||
| __func__, | __func__, | ||||
| req.host, | req.host, | ||||
| req.port); | req.port); | ||||
| err = vm_send_migrate_req(ctx, req); | err = vm_send_migrate_req(ctx, req, is_live_migration); | ||||
| } else { | } else { | ||||
| EPRINTLN("Unrecognized checkpoint operation\n"); | EPRINTLN("Unrecognized checkpoint operation\n"); | ||||
| err = -1; | err = -1; | ||||
| } | } | ||||
| done: | done: | ||||
| if (err != 0) | if (err != 0) | ||||
| EPRINTLN("Unable to perform the requested operation\n"); | EPRINTLN("Unable to perform the requested operation\n"); | ||||
| ▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines | |||||