The branch main has been updated by rew:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4379c1da56faa43ecc925e47707a2f51b488614e

commit 4379c1da56faa43ecc925e47707a2f51b488614e
Author:     Robert Wing <[email protected]>
AuthorDate: 2022-02-15 17:12:15 +0000
Commit:     Robert Wing <[email protected]>
CommitDate: 2022-02-15 17:12:15 +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
---
 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 66f05ed68bcd..b0cc8095c3cb 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);

Reply via email to