render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0413-hw-virtio-serial-bus-post_load-send_event-when-vm-is.patch

Alon Levy cc85c4
From 9903053345528aa8eebb16365b2ece77c58c0cf6 Mon Sep 17 00:00:00 2001
Alon Levy cc85c4
From: Alon Levy <alevy@redhat.com>
Alon Levy cc85c4
Date: Wed, 14 Nov 2012 15:06:35 +0200
Alon Levy cc85c4
Subject: [PATCH 1/2] hw/virtio-serial-bus: post_load send_event when vm is
Alon Levy cc85c4
 running
Alon Levy cc85c4
Alon Levy cc85c4
Add a new timer based on vm_clock for 1 ns in the future from post_load
Alon Levy cc85c4
to do the event send in case host_connected differs between migration
Alon Levy cc85c4
source and target.
Alon Levy cc85c4
Alon Levy cc85c4
RHBZ: 867366
Alon Levy cc85c4
Alon Levy cc85c4
Signed-off-by: Alon Levy <alevy@redhat.com>
Alon Levy cc85c4
---
Alon Levy cc85c4
 hw/virtio-serial-bus.c | 54 ++++++++++++++++++++++++++++++++++++++++----------
Alon Levy cc85c4
 1 file changed, 44 insertions(+), 10 deletions(-)
Alon Levy cc85c4
Alon Levy cc85c4
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
Alon Levy cc85c4
index d20bd8b..a028877 100644
Alon Levy cc85c4
--- a/hw/virtio-serial-bus.c
Alon Levy cc85c4
+++ b/hw/virtio-serial-bus.c
Alon Levy cc85c4
@@ -53,6 +53,15 @@ struct VirtIOSerial {
Alon Levy cc85c4
     uint32_t *ports_map;
Alon Levy cc85c4
 
Alon Levy cc85c4
     struct virtio_console_config config;
Alon Levy cc85c4
+
Alon Levy cc85c4
+    struct VirtIOSerialPostLoad {
Alon Levy cc85c4
+        QEMUTimer *timer;
Alon Levy cc85c4
+        int nr_active_ports;
Alon Levy cc85c4
+        struct VirtIOSerialPostLoadPort {
Alon Levy cc85c4
+            VirtIOSerialPort *port;
Alon Levy cc85c4
+            uint8_t host_connected;
Alon Levy cc85c4
+        } *connected;
Alon Levy cc85c4
+    } post_load;
Alon Levy cc85c4
 };
Alon Levy cc85c4
 
Alon Levy cc85c4
 static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
Alon Levy cc85c4
@@ -626,6 +635,29 @@ static void virtio_serial_save(QEMUFile *f, void *opaque)
Alon Levy cc85c4
     }
Alon Levy cc85c4
 }
Alon Levy cc85c4
 
Alon Levy cc85c4
+static void virtio_serial_post_load_timer_cb(void *opaque)
Alon Levy cc85c4
+{
Alon Levy cc85c4
+    int i;
Alon Levy cc85c4
+    VirtIOSerial *s = opaque;
Alon Levy cc85c4
+    VirtIOSerialPort *port;
Alon Levy cc85c4
+    uint8_t host_connected;
Alon Levy cc85c4
+
Alon Levy cc85c4
+    for (i = 0 ; i < s->post_load.nr_active_ports; ++i) {
Alon Levy cc85c4
+        port = s->post_load.connected[i].port;
Alon Levy cc85c4
+        host_connected = s->post_load.connected[i].host_connected;
Alon Levy cc85c4
+        if (host_connected != port->host_connected) {
Alon Levy cc85c4
+            /*
Alon Levy cc85c4
+             * We have to let the guest know of the host connection
Alon Levy cc85c4
+             * status change
Alon Levy cc85c4
+             */
Alon Levy cc85c4
+            send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
Alon Levy cc85c4
+                               port->host_connected);
Alon Levy cc85c4
+        }
Alon Levy cc85c4
+    }
Alon Levy cc85c4
+    g_free(s->post_load.connected);
Alon Levy cc85c4
+    s->post_load.connected = NULL;
Alon Levy cc85c4
+}
Alon Levy cc85c4
+
Alon Levy cc85c4
 static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
Alon Levy cc85c4
 {
Alon Levy cc85c4
     VirtIOSerial *s = opaque;
Alon Levy cc85c4
@@ -673,10 +705,13 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
Alon Levy cc85c4
 
Alon Levy cc85c4
     qemu_get_be32s(f, &nr_active_ports);
Alon Levy cc85c4
 
Alon Levy cc85c4
+    s->post_load.nr_active_ports = nr_active_ports;
Alon Levy cc85c4
+    s->post_load.connected =
Alon Levy cc85c4
+        g_malloc0(sizeof(*s->post_load.connected) * nr_active_ports);
Alon Levy cc85c4
+
Alon Levy cc85c4
     /* Items in struct VirtIOSerialPort */
Alon Levy cc85c4
     for (i = 0; i < nr_active_ports; i++) {
Alon Levy cc85c4
         uint32_t id;
Alon Levy cc85c4
-        bool host_connected;
Alon Levy cc85c4
 
Alon Levy cc85c4
         id = qemu_get_be32(f);
Alon Levy cc85c4
         port = find_port_by_id(s, id);
Alon Levy cc85c4
@@ -685,15 +720,8 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
Alon Levy cc85c4
         }
Alon Levy cc85c4
 
Alon Levy cc85c4
         port->guest_connected = qemu_get_byte(f);
Alon Levy cc85c4
-        host_connected = qemu_get_byte(f);
Alon Levy cc85c4
-        if (host_connected != port->host_connected) {
Alon Levy cc85c4
-            /*
Alon Levy cc85c4
-             * We have to let the guest know of the host connection
Alon Levy cc85c4
-             * status change
Alon Levy cc85c4
-             */
Alon Levy cc85c4
-            send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
Alon Levy cc85c4
-                               port->host_connected);
Alon Levy cc85c4
-        }
Alon Levy cc85c4
+        s->post_load.connected[i].port = port;
Alon Levy cc85c4
+        s->post_load.connected[i].host_connected = qemu_get_byte(f);
Alon Levy cc85c4
 
Alon Levy cc85c4
         if (version_id > 2) {
Alon Levy cc85c4
             uint32_t elem_popped;
Alon Levy cc85c4
@@ -718,6 +746,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
Alon Levy cc85c4
             }
Alon Levy cc85c4
         }
Alon Levy cc85c4
     }
Alon Levy cc85c4
+    qemu_mod_timer(s->post_load.timer, 1);
Alon Levy cc85c4
     return 0;
Alon Levy cc85c4
 }
Alon Levy cc85c4
 
Alon Levy cc85c4
@@ -967,6 +996,9 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
Alon Levy cc85c4
     register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save,
Alon Levy cc85c4
                     virtio_serial_load, vser);
Alon Levy cc85c4
 
Alon Levy cc85c4
+    vser->post_load.timer = qemu_new_timer_ns(vm_clock,
Alon Levy cc85c4
+            virtio_serial_post_load_timer_cb, vser);
Alon Levy cc85c4
+
Alon Levy cc85c4
     return vdev;
Alon Levy cc85c4
 }
Alon Levy cc85c4
 
Alon Levy cc85c4
@@ -979,6 +1011,8 @@ void virtio_serial_exit(VirtIODevice *vdev)
Alon Levy cc85c4
     g_free(vser->ivqs);
Alon Levy cc85c4
     g_free(vser->ovqs);
Alon Levy cc85c4
     g_free(vser->ports_map);
Alon Levy cc85c4
+    g_free(vser->post_load.connected);
Alon Levy cc85c4
+    qemu_free_timer(vser->post_load.timer);
Alon Levy cc85c4
 
Alon Levy cc85c4
     virtio_cleanup(vdev);
Alon Levy cc85c4
 }
Alon Levy cc85c4
-- 
Alon Levy cc85c4
1.8.0
Alon Levy cc85c4