git: 395c0adb2ab5 - stable/13 - bhyve/snapshot: use a string for cmd element in the nvlist
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Jan 2023 18:54:26 UTC
The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=395c0adb2ab59cf90c05b48749f5a5de9ae9426e commit 395c0adb2ab59cf90c05b48749f5a5de9ae9426e Author: Robert Wing <rew@FreeBSD.org> AuthorDate: 2022-02-15 17:12:15 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2023-01-26 18:47:33 +0000 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 (cherry picked from commit 4379c1da56faa43ecc925e47707a2f51b488614e) --- usr.sbin/bhyve/snapshot.c | 27 +++++++++++++-------------- usr.sbin/bhyve/snapshot.h | 6 ------ usr.sbin/bhyvectl/bhyvectl.c | 9 +++++---- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c index 62ef0acd8f95..aae8353b89db 100644 --- a/usr.sbin/bhyve/snapshot.c +++ b/usr.sbin/bhyve/snapshot.c @@ -1443,24 +1443,23 @@ done: 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) diff --git a/usr.sbin/bhyve/snapshot.h b/usr.sbin/bhyve/snapshot.h index ddf23b8c0619..718e48467f56 100644 --- a/usr.sbin/bhyve/snapshot.h +++ b/usr.sbin/bhyve/snapshot.h @@ -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; diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c index 560a3a3eb443..0480e1623621 100644 --- a/usr.sbin/bhyvectl/bhyvectl.c +++ b/usr.sbin/bhyvectl/bhyvectl.c @@ -1725,13 +1725,14 @@ done: } 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);