summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2015-10-06 10:37:29 +0200
committerMichael S. Tsirkin <mst@redhat.com>2015-10-22 14:34:48 +0300
commitaebf81680bf49c5953d7ae9ebb7b98c0f4dad8f3 (patch)
treedf7c202f4f0791b499a640b09eb0c9f85b619262
parent3fad87881e55aaff659408dcf25fa204f89a7896 (diff)
downloadfocaccia-qemu-aebf81680bf49c5953d7ae9ebb7b98c0f4dad8f3.tar.gz
focaccia-qemu-aebf81680bf49c5953d7ae9ebb7b98c0f4dad8f3.zip
vhost: fail backend intialization early
Don't initialize vhost backend if memslots number exceeds the supported
limit. This prevents failures down the road when backend
is actually started.

[MST: rewrite commit log]

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--hw/virtio/vhost.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index a3b4f9e8ea..f14a5c5133 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -933,6 +933,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
         return -errno;
     }
 
+    if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {
+        fprintf(stderr, "vhost backend memory slots limit is less"
+                " than current number of present memory slots\n");
+        close((uintptr_t)opaque);
+        return -1;
+    }
     QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);
 
     r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_OWNER, NULL);