diff mbox series

[RFC,3/4] vdagent: add live migration support

Message ID 20221230092758.281805-4-dengpc12@chinatelecom.cn (mailing list archive)
State New, archived
Headers show
Series vdagent: support live migration | expand

Commit Message

dengpc12@chinatelecom.cn Dec. 30, 2022, 9:27 a.m. UTC
From: "dengpc12@chinatelecom.cn" <dengpc12@chinatelecom.cn>

To support live migration, we made the following 2 modifications:
1. save the caps field of VDAgentChardev.
2. register vdagent to qemu-clipboard after
   vm device state being reloaded during live migration.

Signed-off-by: dengpc12@chinatelecom.cn <dengpc12@chinatelecom.cn>
Signed-off-by: liuym16@chinatelecom.cn <liuym16@chinatelecom.cn>
---
 ui/trace-events |  1 +
 ui/vdagent.c    | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Marc-André Lureau Jan. 2, 2023, 11:42 a.m. UTC | #1
Hi


On Fri, Dec 30, 2022 at 6:49 PM <dengpc12@chinatelecom.cn> wrote:
>
> From: "dengpc12@chinatelecom.cn" <dengpc12@chinatelecom.cn>
>
> To support live migration, we made the following 2 modifications:
> 1. save the caps field of VDAgentChardev.
> 2. register vdagent to qemu-clipboard after
>    vm device state being reloaded during live migration.
>
> Signed-off-by: dengpc12@chinatelecom.cn <dengpc12@chinatelecom.cn>
> Signed-off-by: liuym16@chinatelecom.cn <liuym16@chinatelecom.cn>
> ---
>  ui/trace-events |  1 +
>  ui/vdagent.c    | 28 ++++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>
> diff --git a/ui/trace-events b/ui/trace-events
> index 5e50b60da5..ccacd867d1 100644
> --- a/ui/trace-events
> +++ b/ui/trace-events
> @@ -144,6 +144,7 @@ vdagent_cb_grab_discard(const char *name, int cur, int recv) "selection %s, cur:
>  vdagent_cb_grab_type(const char *name) "type %s"
>  vdagent_cb_serial_discard(uint32_t current, uint32_t received) "current=%u, received=%u"
>  vdagent_recv_caps(uint32_t caps) "received caps %u"
> +vdagent_migration_caps(uint32_t caps) "migrated caps %u"
>
>  # dbus.c
>  dbus_registered_listener(const char *bus_name) "peer %s"
> diff --git a/ui/vdagent.c b/ui/vdagent.c
> index 38061d5b38..1193abe348 100644
> --- a/ui/vdagent.c
> +++ b/ui/vdagent.c
> @@ -6,6 +6,7 @@
>  #include "qemu/units.h"
>  #include "hw/qdev-core.h"
>  #include "migration/blocker.h"
> +#include "migration/vmstate.h"
>  #include "ui/clipboard.h"
>  #include "ui/console.h"
>  #include "ui/input.h"
> @@ -906,6 +907,31 @@ static void vdagent_chr_parse(QemuOpts *opts, ChardevBackend *backend,
>
>  /* ------------------------------------------------------------------ */
>
> +static int vdagent_post_load(void *opaque, int version_id)
> +{
> +    VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(opaque);
> +
> +    trace_vdagent_migration_caps(vd->caps);
> +
> +    if (vd->caps) {
> +        vdagent_register_to_qemu_clipboard(vd);
> +        qemu_input_handler_activate(vd->mouse_hs);
> +    }
> +
> +    return 0;
> +}
> +
> +static const VMStateDescription vmstate_vdagent = {
> +    .name = "vdagent",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .post_load = vdagent_post_load,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_UINT32(caps, VDAgentChardev),

You are missing a lot of states from VDAgentChardev. Most of the
fields must be saved/restored.

> +        VMSTATE_END_OF_LIST()
> +    },
> +};
> +
>  static void vdagent_chr_class_init(ObjectClass *oc, void *data)
>  {
>      ChardevClass *cc = CHARDEV_CLASS(oc);
> @@ -922,6 +948,8 @@ static void vdagent_chr_init(Object *obj)
>      VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(obj);
>
>      buffer_init(&vd->outbuf, "vdagent-outbuf");
> +
> +    vmstate_register(NULL, 0, &vmstate_vdagent, vd);
>      error_setg(&vd->migration_blocker,
>                 "The vdagent chardev doesn't yet support migration");
>  }
> --
> 2.27.0
>
>


--
Marc-André Lureau
diff mbox series

Patch

diff --git a/ui/trace-events b/ui/trace-events
index 5e50b60da5..ccacd867d1 100644
--- a/ui/trace-events
+++ b/ui/trace-events
@@ -144,6 +144,7 @@  vdagent_cb_grab_discard(const char *name, int cur, int recv) "selection %s, cur:
 vdagent_cb_grab_type(const char *name) "type %s"
 vdagent_cb_serial_discard(uint32_t current, uint32_t received) "current=%u, received=%u"
 vdagent_recv_caps(uint32_t caps) "received caps %u"
+vdagent_migration_caps(uint32_t caps) "migrated caps %u"
 
 # dbus.c
 dbus_registered_listener(const char *bus_name) "peer %s"
diff --git a/ui/vdagent.c b/ui/vdagent.c
index 38061d5b38..1193abe348 100644
--- a/ui/vdagent.c
+++ b/ui/vdagent.c
@@ -6,6 +6,7 @@ 
 #include "qemu/units.h"
 #include "hw/qdev-core.h"
 #include "migration/blocker.h"
+#include "migration/vmstate.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
 #include "ui/input.h"
@@ -906,6 +907,31 @@  static void vdagent_chr_parse(QemuOpts *opts, ChardevBackend *backend,
 
 /* ------------------------------------------------------------------ */
 
+static int vdagent_post_load(void *opaque, int version_id)
+{
+    VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(opaque);
+
+    trace_vdagent_migration_caps(vd->caps);
+
+    if (vd->caps) {
+        vdagent_register_to_qemu_clipboard(vd);
+        qemu_input_handler_activate(vd->mouse_hs);
+    }
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_vdagent = {
+    .name = "vdagent",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .post_load = vdagent_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(caps, VDAgentChardev),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
 static void vdagent_chr_class_init(ObjectClass *oc, void *data)
 {
     ChardevClass *cc = CHARDEV_CLASS(oc);
@@ -922,6 +948,8 @@  static void vdagent_chr_init(Object *obj)
     VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(obj);
 
     buffer_init(&vd->outbuf, "vdagent-outbuf");
+
+    vmstate_register(NULL, 0, &vmstate_vdagent, vd);
     error_setg(&vd->migration_blocker,
                "The vdagent chardev doesn't yet support migration");
 }