From patchwork Mon Apr 23 15:23:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 154470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EBE75B6F62 for ; Tue, 24 Apr 2012 01:23:33 +1000 (EST) Received: from localhost ([::1]:33726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SML6x-0003rx-QS for incoming@patchwork.ozlabs.org; Mon, 23 Apr 2012 11:23:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SML6q-0003r3-HR for qemu-devel@nongnu.org; Mon, 23 Apr 2012 11:23:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SML6g-0006Be-CQ for qemu-devel@nongnu.org; Mon, 23 Apr 2012 11:23:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SML6g-0006BE-5A for qemu-devel@nongnu.org; Mon, 23 Apr 2012 11:23:14 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3NFNCph009115 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Apr 2012 11:23:12 -0400 Received: from garlic.tlv.redhat.com (spice-ovirt.tlv.redhat.com [10.35.4.71]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3NFNAAb018726; Mon, 23 Apr 2012 11:23:11 -0400 From: Alon Levy To: qemu-devel@nongnu.org, amit.shah@redhat.com, mst@redhat.com Date: Mon, 23 Apr 2012 18:23:10 +0300 Message-Id: <1335194590-15080-1-git-send-email-alevy@redhat.com> In-Reply-To: <20120423124019.GA1349@redhat.com> References: <20120423124019.GA1349@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] virtio-serial-bus: fix guest_connected pre-driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org guest_connected should be false before guest driver initialization, and true after, both for multiport aware and non multiport aware drivers. Don't set it before the guest_features are available, instead use set_status which is called by io to VIRTIO_PCI_STATUS with VIRTIO_CONFIG_S_DRIVER_OK by even older non multiport drivers. Signed-off-by: Alon Levy Acked-by: Michael S. Tsirkin --- hw/virtio-serial-bus.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index e22940e..8788da2 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -528,6 +528,18 @@ static void set_config(VirtIODevice *vdev, const uint8_t *config_data) memcpy(&config, config_data, sizeof(config)); } +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)) { + port->guest_connected = status & VIRTIO_CONFIG_S_DRIVER_OK; + } +} + static void virtio_serial_save(QEMUFile *f, void *opaque) { VirtIOSerial *s = opaque; @@ -798,14 +810,6 @@ static int virtser_port_qdev_init(DeviceState *qdev) return ret; } - if (!use_multiport(port->vser)) { - /* - * Allow writes to guest in this case; we have no way of - * knowing if a guest port is connected. - */ - port->guest_connected = true; - } - port->elem.out_num = 0; QTAILQ_INSERT_TAIL(&port->vser->ports, port, next); @@ -905,6 +909,7 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) vser->vdev.get_features = get_features; vser->vdev.get_config = get_config; vser->vdev.set_config = set_config; + vser->vdev.set_status = set_status; vser->qdev = dev;