summary refs log tree commit diff stats
path: root/hw/virtio-serial-bus.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2012-04-24 19:33:59 +0530
committerAmit Shah <amit.shah@redhat.com>2012-04-25 16:44:07 +0530
commit439972253a15870be6777c9f4cdb3985797a9b7c (patch)
tree835928452ceeeaca5756b07a4cde48edb1c8f00b /hw/virtio-serial-bus.c
parent62a9fbf7fd022103c6b271abd7b7834b84ba7071 (diff)
downloadfocaccia-qemu-439972253a15870be6777c9f4cdb3985797a9b7c.tar.gz
focaccia-qemu-439972253a15870be6777c9f4cdb3985797a9b7c.zip
virtio-serial-bus: Unset guest_connected at reset and driver reset
When a guest driver resets the virtio status to not ready, or when qemu
is reset, reset all ports' guest_connected bit and let port users know
of this event if they have the guest_close() callback registered.

Reviewed-by: Alon Levy <alevy@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Diffstat (limited to 'hw/virtio-serial-bus.c')
-rw-r--r--hw/virtio-serial-bus.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 796224b204..ffbdfc2de1 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -528,6 +528,22 @@ static void set_config(VirtIODevice *vdev, const uint8_t *config_data)
     memcpy(&config, config_data, sizeof(config));
 }
 
+static void guest_reset(VirtIOSerial *vser)
+{
+    VirtIOSerialPort *port;
+    VirtIOSerialPortClass *vsc;
+
+    QTAILQ_FOREACH(port, &vser->ports, next) {
+        vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
+        if (port->guest_connected) {
+            port->guest_connected = false;
+
+            if (vsc->guest_close)
+                vsc->guest_close(port);
+        }
+    }
+}
+
 static void set_status(VirtIODevice *vdev, uint8_t status)
 {
     VirtIOSerial *vser;
@@ -546,6 +562,17 @@ static void set_status(VirtIODevice *vdev, uint8_t status)
          */
         port->guest_connected = true;
     }
+    if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+        guest_reset(vser);
+    }
+}
+
+static void vser_reset(VirtIODevice *vdev)
+{
+    VirtIOSerial *vser;
+
+    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    guest_reset(vser);
 }
 
 static void virtio_serial_save(QEMUFile *f, void *opaque)
@@ -918,6 +945,7 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
     vser->vdev.get_config = get_config;
     vser->vdev.set_config = set_config;
     vser->vdev.set_status = set_status;
+    vser->vdev.reset = vser_reset;
 
     vser->qdev = dev;