bhyve/snapshot: use a string for cmd element in the nvlist
The nvlist for a checkpoint request will now look like: { cmd="checkpoint", suspend="true/false", filename="afilename" } Reviewed by: jhb Suggested by: jhb Differential Revision: https://reviews.freebsd.org/D34237
This commit is contained in:
parent
9f22e0959b
commit
4379c1da56
@ -1443,24 +1443,23 @@ vm_checkpoint(struct vmctx *ctx, const char *checkpoint_file, bool stop_vm)
|
||||
static int
|
||||
handle_message(struct vmctx *ctx, nvlist_t *nvl)
|
||||
{
|
||||
int err, cmd;
|
||||
int err;
|
||||
const char *cmd;
|
||||
|
||||
if (!nvlist_exists_number(nvl, "cmd"))
|
||||
if (!nvlist_exists_string(nvl, "cmd"))
|
||||
return (-1);
|
||||
|
||||
cmd = nvlist_get_number(nvl, "cmd");
|
||||
switch (cmd) {
|
||||
case START_SUSPEND:
|
||||
case START_CHECKPOINT:
|
||||
if (!nvlist_exists_string(nvl, "filename"))
|
||||
err = -1;
|
||||
else
|
||||
err = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"),
|
||||
cmd == START_SUSPEND ? true : false);
|
||||
break;
|
||||
default:
|
||||
EPRINTLN("Unrecognized checkpoint operation\n");
|
||||
cmd = nvlist_get_string(nvl, "cmd");
|
||||
if (strcmp(cmd, "checkpoint") == 0) {
|
||||
if (!nvlist_exists_string(nvl, "filename") ||
|
||||
!nvlist_exists_bool(nvl, "suspend"))
|
||||
err = -1;
|
||||
else
|
||||
err = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"),
|
||||
nvlist_get_bool(nvl, "suspend"));
|
||||
} else {
|
||||
EPRINTLN("Unrecognized checkpoint operation\n");
|
||||
err = -1;
|
||||
}
|
||||
|
||||
if (err != 0)
|
||||
|
@ -60,12 +60,6 @@ struct restore_state {
|
||||
ucl_object_t *meta_root_obj;
|
||||
};
|
||||
|
||||
/* Messages that a bhyve process understands. */
|
||||
enum ipc_opcode {
|
||||
START_CHECKPOINT,
|
||||
START_SUSPEND,
|
||||
};
|
||||
|
||||
struct checkpoint_thread_info {
|
||||
struct vmctx *ctx;
|
||||
int socket_fd;
|
||||
|
@ -1725,13 +1725,14 @@ send_message(struct vmctx *ctx, nvlist_t *nvl)
|
||||
}
|
||||
|
||||
static int
|
||||
snapshot_request(struct vmctx *ctx, const char *file, enum ipc_opcode code)
|
||||
snapshot_request(struct vmctx *ctx, const char *file, bool suspend)
|
||||
{
|
||||
nvlist_t *nvl;
|
||||
|
||||
nvl = nvlist_create(0);
|
||||
nvlist_add_number(nvl, "cmd", code);
|
||||
nvlist_add_string(nvl, "cmd", "checkpoint");
|
||||
nvlist_add_string(nvl, "filename", file);
|
||||
nvlist_add_bool(nvl, "suspend", suspend);
|
||||
|
||||
return (send_message(ctx, nvl));
|
||||
}
|
||||
@ -2397,10 +2398,10 @@ main(int argc, char *argv[])
|
||||
|
||||
#ifdef BHYVE_SNAPSHOT
|
||||
if (!error && vm_checkpoint_opt)
|
||||
error = snapshot_request(ctx, checkpoint_file, START_CHECKPOINT);
|
||||
error = snapshot_request(ctx, checkpoint_file, false);
|
||||
|
||||
if (!error && vm_suspend_opt)
|
||||
error = snapshot_request(ctx, suspend_file, START_SUSPEND);
|
||||
error = snapshot_request(ctx, suspend_file, true);
|
||||
#endif
|
||||
|
||||
free (opts);
|
||||
|
Loading…
Reference in New Issue
Block a user