From patchwork Wed Dec 2 12:04:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 40026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9DA99B7BDE for ; Thu, 3 Dec 2009 00:51:50 +1100 (EST) Received: from localhost ([127.0.0.1]:43536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFpcR-0000Ym-9x for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 08:51:47 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFnxy-0004Tg-Ef for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:05:54 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFnxv-0004RB-6y for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:05:53 -0500 Received: from [199.232.76.173] (port=42929 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnxu-0004R1-Hb for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:05:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45776) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFnxt-0004DX-On for qemu-devel@nongnu.org; Wed, 02 Dec 2009 07:05:50 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2C5mML020930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 07:05:49 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2C5ILI029769; Wed, 2 Dec 2009 07:05:47 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 13:04:18 +0100 Message-Id: <98f690df10290c28da9f981a4d4ac1446675265f.1259754427.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH 20/41] virtio: abstract test for save/load values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- hw/virtio.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index 2b36cad..5497716 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -615,6 +615,20 @@ void virtio_notify_config(VirtIODevice *vdev) virtio_notify_vector(vdev, vdev->config_vector); } +static bool is_virtio_pci(void *opaque, int version_id) +{ + VirtIODevice *vdev = opaque; + + return vdev->type == VIRTIO_PCI; +} + +static bool is_virtio_msix(void *opaque, int version_id) +{ + VirtIODevice *vdev = opaque; + return (vdev->type == VIRTIO_PCI) && + virtio_pci_msix_present(vdev->binding_opaque); +} + static void virtio_pre_save(void *opaque) { VirtIODevice *vdev = opaque; @@ -633,7 +647,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) virtio_pre_save(vdev); - if (vdev->type == VIRTIO_PCI) + if (is_virtio_pci(vdev, 1)) vmstate_save_state(f, &vmstate_virtio_pci_config, vdev->binding_opaque); qemu_put_8s(f, &vdev->status); @@ -649,8 +663,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) qemu_put_be32s(f, &vdev->vq[i].vring.num); qemu_put_be64s(f, &vdev->vq[i].pa); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); - if (vdev->type == VIRTIO_PCI && - virtio_pci_msix_present(vdev->binding_opaque)) { + if (is_virtio_msix(vdev, 1)) { qemu_put_be16s(f, &vdev->vq[i].vector); } } @@ -682,11 +695,12 @@ static int virtio_post_load(void *opaque, int version_id) return 0; } + int virtio_load(VirtIODevice *vdev, QEMUFile *f) { int i, ret; - if (vdev->type == VIRTIO_PCI) { + if (is_virtio_pci(vdev, 1)) { ret = vmstate_load_state(f, &vmstate_virtio_pci_config, vdev->binding_opaque, vmstate_virtio_pci_config.version_id); if (ret) @@ -707,9 +721,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) qemu_get_be64s(f, &vdev->vq[i].pa); qemu_get_be16s(f, &vdev->vq[i].last_avail_idx); - if (vdev->type == VIRTIO_PCI && - virtio_pci_msix_present(vdev->binding_opaque)) { - qemu_get_be16s(f, &vdev->vq[i].vector); + if (is_virtio_msix(vdev, 1)) { + qemu_get_be16s(f, &vdev->vq[i].vector); } } virtio_post_load(vdev, 1);