From 74be11e1ce704559b9ebf9ebade563fc3420850f Mon Sep 17 00:00:00 2001 Message-Id: <74be11e1ce704559b9ebf9ebade563fc3420850f.1335950094.git.minovotn@redhat.com> In-Reply-To: <52c3f43ff671fcf031caaf0c37dd9e736710cf15.1335950093.git.minovotn@redhat.com> References: <52c3f43ff671fcf031caaf0c37dd9e736710cf15.1335950093.git.minovotn@redhat.com> From: Alon Levy Date: Tue, 1 May 2012 06:43:22 +0200 Subject: [PATCH 2/2] virtio-serial-bus: Unset guest_connected at reset and driver reset RH-Author: Alon Levy Message-id: <1335854602-16938-3-git-send-email-alevy@redhat.com> Patchwork-id: 39532 O-Subject: [PATCH 2/2] virtio-serial-bus: Unset guest_connected at reset and driver reset Bugzilla: 787974 RH-Acked-by: Hans de Goede RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Amit Shah From: Amit Shah RHBZ: 787974 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 Signed-off-by: Amit Shah cherry picked from commit 439972253a15870be6777c9f4cdb3985797a9b7c, with the following change applied on top: VirtIOSerialPortClass replaced with VirtIOSerialPortInfo. --- hw/virtio-serial-bus.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) Signed-off-by: Michal Novotny --- hw/virtio-serial-bus.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 6a09401..bf839d7 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -553,6 +553,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; + VirtIOSerialPortInfo *info; + + QTAILQ_FOREACH(port, &vser->ports, next) { + info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info); + if (port->guest_connected) { + port->guest_connected = false; + + if (info->guest_close) + info->guest_close(port); + } + } +} + static void set_status(VirtIODevice *vdev, uint8_t status) { VirtIOSerial *vser; @@ -571,6 +587,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) @@ -972,6 +999,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