diff mbox

virtio-serial-bus: Unset guest_connected at reset and driver reset

Message ID 53e1899ffbb2c90f468893a98dc0540a8f0a426d.1335552939.git.amit.shah@redhat.com
State New
Headers show

Commit Message

Amit Shah April 27, 2012, 6:56 p.m. UTC
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>
---
Fix style acc. to mst's comments (but slightly differently).  Does this
look good?

 hw/virtio-serial-bus.c |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin April 29, 2012, 8:02 a.m. UTC | #1
On Sat, Apr 28, 2012 at 12:26:50AM +0530, Amit Shah wrote:
> 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>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> Fix style acc. to mst's comments (but slightly differently).  Does this
> look good?
> 
>  hw/virtio-serial-bus.c |   36 +++++++++++++++++++++++++++++++++---
>  1 files changed, 33 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index 796224b..9e8d7bb 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -528,16 +528,37 @@ 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;
>      VirtIOSerialPort *port;
>  
>      vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
> -    port = find_port_by_id(vser, 0);
>  
> -    if (port && !use_multiport(port->vser)
> -        && (status & VIRTIO_CONFIG_S_DRIVER_OK)) {
> +    if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
> +        guest_reset(vser);
> +        return;
> +    }
> +
> +    port = find_port_by_id(vser, 0);
> +    if (port && !use_multiport(port->vser)) {
>          /*
>           * Non-multiport guests won't be able to tell us guest
>           * open/close status.  Such guests can only have a port at id
> @@ -548,6 +569,14 @@ static void set_status(VirtIODevice *vdev, uint8_t status)
>      }
>  }
>  
> +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)
>  {
>      VirtIOSerial *s = opaque;
> @@ -918,6 +947,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;
>  
> -- 
> 1.7.7.6
diff mbox

Patch

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 796224b..9e8d7bb 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -528,16 +528,37 @@  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;
     VirtIOSerialPort *port;
 
     vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
-    port = find_port_by_id(vser, 0);
 
-    if (port && !use_multiport(port->vser)
-        && (status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+    if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+        guest_reset(vser);
+        return;
+    }
+
+    port = find_port_by_id(vser, 0);
+    if (port && !use_multiport(port->vser)) {
         /*
          * Non-multiport guests won't be able to tell us guest
          * open/close status.  Such guests can only have a port at id
@@ -548,6 +569,14 @@  static void set_status(VirtIODevice *vdev, uint8_t status)
     }
 }
 
+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)
 {
     VirtIOSerial *s = opaque;
@@ -918,6 +947,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;