Patchwork [2/3] vhost: don't exit on memory errors

login
register
mail settings
Submitter Michael S. Tsirkin
Date March 28, 2011, 9:14 p.m.
Message ID <bf6d533cf690a6ba3b3512207260084f28ae6e88.1301346785.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/88687/
State New
Headers show

Comments

Michael S. Tsirkin - March 28, 2011, 9:14 p.m.
When memory including one of the VQs
goes away, handle that as a guest error
instead of exiting qemu.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/vhost.c |    8 +++++---
 hw/vhost.h |    1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/vhost.c b/hw/vhost.c
index 97a1299..c17a831 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -287,11 +287,11 @@  static int vhost_verify_ring_mappings(struct vhost_dev *dev,
         l = vq->ring_size;
         p = cpu_physical_memory_map(vq->ring_phys, &l, 1);
         if (!p || l != vq->ring_size) {
-            fprintf(stderr, "Unable to map ring buffer for ring %d\n", i);
+            virtio_error(dev->vdev, "Unable to map ring buffer for ring %d\n", i);
             return -ENOMEM;
         }
         if (p != vq->ring) {
-            fprintf(stderr, "Ring buffer relocated for ring %d\n", i);
+            virtio_error(dev->vdev, "Ring buffer relocated for ring %d\n", i);
             return -EBUSY;
         }
         cpu_physical_memory_unmap(p, l, 0, 0);
@@ -330,7 +330,9 @@  static void vhost_client_set_memory(CPUPhysMemoryClient *client,
 
     if (dev->started) {
         r = vhost_verify_ring_mappings(dev, start_addr, size);
-        assert(r >= 0);
+        if (r < 0) {
+            return;
+        }
     }
 
     if (!dev->log_enabled) {
diff --git a/hw/vhost.h b/hw/vhost.h
index c8c595a..90b5bc8 100644
--- a/hw/vhost.h
+++ b/hw/vhost.h
@@ -39,6 +39,7 @@  struct vhost_dev {
     vhost_log_chunk_t *log;
     unsigned long long log_size;
     bool force;
+    VirtIODevice *vdev;
 };
 
 int vhost_dev_init(struct vhost_dev *hdev, int devfd, bool force);