Patchwork [RESEND,4/6] virtio: Allow virtio_save() errors

login
register
mail settings
Submitter Alex Williamson
Date Nov. 5, 2010, 9:16 p.m.
Message ID <20101105211637.19958.3484.stgit@s20.home>
Download mbox | patch
Permalink /patch/70297/
State New
Headers show

Comments

Alex Williamson - Nov. 5, 2010, 9:16 p.m.
Carry pci_device_save() error through to virtio_save().

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/virtio-balloon.c    |    6 +++++-
 hw/virtio-blk.c        |    6 +++++-
 hw/virtio-net.c        |    6 +++++-
 hw/virtio-pci.c        |   10 ++++++++--
 hw/virtio-serial-bus.c |    6 +++++-
 hw/virtio.c            |   14 ++++++++++----
 hw/virtio.h            |    4 ++--
 7 files changed, 40 insertions(+), 12 deletions(-)

Patch

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index ed652f3..d9fa535 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -236,8 +236,12 @@  static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
 static int virtio_balloon_save(QEMUFile *f, void *opaque)
 {
     VirtIOBalloon *s = opaque;
+    int ret;
 
-    virtio_save(&s->vdev, f);
+    ret = virtio_save(&s->vdev, f);
+    if (ret < 0) {
+        return ret;
+    }
 
     qemu_put_be32(f, s->num_pages);
     qemu_put_be32(f, s->actual);
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 84fb93e..cb27086 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -470,8 +470,12 @@  static int virtio_blk_save(QEMUFile *f, void *opaque)
 {
     VirtIOBlock *s = opaque;
     VirtIOBlockReq *req = s->rq;
+    int ret;
 
-    virtio_save(&s->vdev, f);
+    ret = virtio_save(&s->vdev, f);
+    if (ret < 0) {
+        return ret;
+    }
     
     while (req) {
         qemu_put_sbyte(f, 1);
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index a2308fa..9254fdf 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -813,11 +813,15 @@  static void virtio_net_tx_bh(void *opaque)
 static int virtio_net_save(QEMUFile *f, void *opaque)
 {
     VirtIONet *n = opaque;
+    int ret;
 
     /* At this point, backend must be stopped, otherwise
      * it might keep writing to memory. */
     assert(!n->vhost_started);
-    virtio_save(&n->vdev, f);
+    ret = virtio_save(&n->vdev, f);
+    if (ret < 0) {
+        return ret;
+    }
 
     qemu_put_buffer(f, n->mac, ETH_ALEN);
     qemu_put_be32(f, n->tx_waiting);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 729917d..afb8f5b 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -121,13 +121,19 @@  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 int virtio_pci_save_config(void * opaque, QEMUFile *f)
 {
     VirtIOPCIProxy *proxy = opaque;
-    pci_device_save(&proxy->pci_dev, f);
+    int ret;
+
+    ret = pci_device_save(&proxy->pci_dev, f);
+    if (ret < 0) {
+        return ret;
+    }
     msix_save(&proxy->pci_dev, f);
     if (msix_present(&proxy->pci_dev))
         qemu_put_be16(f, proxy->vdev->config_vector);
+    return 0;
 }
 
 static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 7f00fcf..ca57dda 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -459,9 +459,13 @@  static int virtio_serial_save(QEMUFile *f, void *opaque)
     VirtIOSerialPort *port;
     uint32_t nr_active_ports;
     unsigned int i;
+    int ret;
 
     /* The virtio device */
-    virtio_save(&s->vdev, f);
+    ret = virtio_save(&s->vdev, f);
+    if (ret < 0) {
+        return ret;
+    }
 
     /* The config space */
     qemu_put_be16s(f, &s->config.cols);
diff --git a/hw/virtio.c b/hw/virtio.c
index a2a657e..cb1b248 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -642,12 +642,16 @@  void virtio_notify_config(VirtIODevice *vdev)
     virtio_notify_vector(vdev, vdev->config_vector);
 }
 
-void virtio_save(VirtIODevice *vdev, QEMUFile *f)
+int virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
-    int i;
+    int i, ret;
 
-    if (vdev->binding->save_config)
-        vdev->binding->save_config(vdev->binding_opaque, f);
+    if (vdev->binding->save_config) {
+        ret = vdev->binding->save_config(vdev->binding_opaque, f);
+        if (ret < 0) {
+            return ret;
+        }
+    }
 
     qemu_put_8s(f, &vdev->status);
     qemu_put_8s(f, &vdev->isr);
@@ -673,6 +677,8 @@  void virtio_save(VirtIODevice *vdev, QEMUFile *f)
         if (vdev->binding->save_queue)
             vdev->binding->save_queue(vdev->binding_opaque, i, f);
     }
+
+    return 0;
 }
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
diff --git a/hw/virtio.h b/hw/virtio.h
index 02fa312..a7e412c 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -88,7 +88,7 @@  typedef struct VirtQueueElement
 
 typedef struct {
     void (*notify)(void * opaque, uint16_t vector);
-    void (*save_config)(void * opaque, QEMUFile *f);
+    int (*save_config)(void * opaque, QEMUFile *f);
     void (*save_queue)(void * opaque, int n, QEMUFile *f);
     int (*load_config)(void * opaque, QEMUFile *f);
     int (*load_queue)(void * opaque, int n, QEMUFile *f);
@@ -150,7 +150,7 @@  int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes);
 
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
 
-void virtio_save(VirtIODevice *vdev, QEMUFile *f);
+int virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f);