Patchwork [12/41] virtio-pci: port pci config to vmstate

login
register
mail settings
Submitter Juan Quintela
Date Dec. 2, 2009, 12:04 p.m.
Message ID <1d7703a5ad842eb7f60547e08b41d15f966303e2.1259754427.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/40018/
State New
Headers show

Comments

Juan Quintela - Dec. 2, 2009, 12:04 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/virtio-pci.c |   72 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 50 insertions(+), 22 deletions(-)
Michael S. Tsirkin - Dec. 2, 2009, 2:39 p.m.
On Wed, Dec 02, 2009 at 01:04:10PM +0100, Juan Quintela wrote:
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  hw/virtio-pci.c |   72 ++++++++++++++++++++++++++++++++++++++----------------
>  1 files changed, 50 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index a2179de..4fe55aa 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -105,35 +105,28 @@ static void virtio_pci_notify(void *opaque, uint16_t vector)
>          qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
>  }
> 
> -static void virtio_pci_save_config(void * opaque, QEMUFile *f)
> +static bool is_msix(void *opaque, int version_id)
>  {
>      VirtIOPCIProxy *proxy = opaque;
> -    pci_device_save(&proxy->pci_dev, f);
> -    if (msix_present(&proxy->pci_dev)) {
> -        msix_save(&proxy->pci_dev, f);
> -        qemu_put_be16(f, proxy->vdev->config_vector);
> -    }
> +    return msix_present(&proxy->pci_dev);
>  }
> 
> -static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
> -{
> -    VirtIOPCIProxy *proxy = opaque;
> -    if (msix_present(&proxy->pci_dev))
> -        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
> -}
> +static const VMStateDescription vmstate_msix_vector = {
> +    .name = "msix_vector",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .minimum_version_id_old = 1,
> +    .fields      = (VMStateField []) {
> +        VMSTATE_UINT16(config_vector, VirtIODevice),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> 
> -static int virtio_pci_load_config(void * opaque, QEMUFile *f)
> +static int virtio_pci_post_load(void * opaque, int version_id)
>  {
>      VirtIOPCIProxy *proxy = opaque;
> -    int ret;
> -    ret = pci_device_load(&proxy->pci_dev, f);
> -    if (ret) {
> -        return ret;
> -    }
> -    if (msix_present(&proxy->pci_dev)) {
> -        msix_load(&proxy->pci_dev, f);
> -        qemu_get_be16s(f, &proxy->vdev->config_vector);
> -    } else {
> +
> +    if (!msix_present(&proxy->pci_dev)) {
>          proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
>      }
>      if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
> @@ -142,6 +135,41 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f)
>      return 0;
>  }
> 
> +const VMStateDescription vmstate_virtio_pci_config = {
> +    .name = "pci_config",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .minimum_version_id_old = 1,
> +    .post_load = virtio_pci_post_load,
> +    .fields      = (VMStateField []) {
> +        VMSTATE_PCI_DEVICE(pci_dev, VirtIOPCIProxy),
> +        VMSTATE_STRUCT_TEST(pci_dev, VirtIOPCIProxy, is_msix, 0,
> +                            vmstate_msix, PCIDevice),
> +        VMSTATE_STRUCT_POINTER_TEST(vdev, VirtIOPCIProxy, is_msix,
> +                                    vmstate_msix_vector, VirtIODevice *),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +static void virtio_pci_save_config(void * opaque, QEMUFile *f)
> +{
> +    vmstate_save_state(f, &vmstate_virtio_pci_config, opaque);
> +}
> +
> +static int virtio_pci_load_config(void * opaque, QEMUFile *f)
> +{
> +    return vmstate_load_state(f, &vmstate_virtio_pci_config, opaque,
> +                              vmstate_virtio_pci_config.version_id);
> +}
> +
> +static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
> +{
> +    VirtIOPCIProxy *proxy = opaque;
> +    if (msix_present(&proxy->pci_dev))
> +        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
> +}
> +
> +

extra empty line here

>  static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
>  {
>      VirtIOPCIProxy *proxy = opaque;
> -- 
> 1.6.5.2

Patch

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index a2179de..4fe55aa 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -105,35 +105,28 @@  static void virtio_pci_notify(void *opaque, uint16_t vector)
         qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
 }

-static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+static bool is_msix(void *opaque, int version_id)
 {
     VirtIOPCIProxy *proxy = opaque;
-    pci_device_save(&proxy->pci_dev, f);
-    if (msix_present(&proxy->pci_dev)) {
-        msix_save(&proxy->pci_dev, f);
-        qemu_put_be16(f, proxy->vdev->config_vector);
-    }
+    return msix_present(&proxy->pci_dev);
 }

-static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
-{
-    VirtIOPCIProxy *proxy = opaque;
-    if (msix_present(&proxy->pci_dev))
-        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
-}
+static const VMStateDescription vmstate_msix_vector = {
+    .name = "msix_vector",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT16(config_vector, VirtIODevice),
+        VMSTATE_END_OF_LIST()
+    }
+};

-static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+static int virtio_pci_post_load(void * opaque, int version_id)
 {
     VirtIOPCIProxy *proxy = opaque;
-    int ret;
-    ret = pci_device_load(&proxy->pci_dev, f);
-    if (ret) {
-        return ret;
-    }
-    if (msix_present(&proxy->pci_dev)) {
-        msix_load(&proxy->pci_dev, f);
-        qemu_get_be16s(f, &proxy->vdev->config_vector);
-    } else {
+
+    if (!msix_present(&proxy->pci_dev)) {
         proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
     }
     if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
@@ -142,6 +135,41 @@  static int virtio_pci_load_config(void * opaque, QEMUFile *f)
     return 0;
 }

+const VMStateDescription vmstate_virtio_pci_config = {
+    .name = "pci_config",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .post_load = virtio_pci_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_PCI_DEVICE(pci_dev, VirtIOPCIProxy),
+        VMSTATE_STRUCT_TEST(pci_dev, VirtIOPCIProxy, is_msix, 0,
+                            vmstate_msix, PCIDevice),
+        VMSTATE_STRUCT_POINTER_TEST(vdev, VirtIOPCIProxy, is_msix,
+                                    vmstate_msix_vector, VirtIODevice *),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+{
+    vmstate_save_state(f, &vmstate_virtio_pci_config, opaque);
+}
+
+static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+{
+    return vmstate_load_state(f, &vmstate_virtio_pci_config, opaque,
+                              vmstate_virtio_pci_config.version_id);
+}
+
+static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
+{
+    VirtIOPCIProxy *proxy = opaque;
+    if (msix_present(&proxy->pci_dev))
+        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
+}
+
+
 static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
 {
     VirtIOPCIProxy *proxy = opaque;