Received: from eggs.gnu.org ([2001:4830:134:3::10]:34642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoqbh-0004H3-5B for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zoqbb-00064x-JA for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:26:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoqbb-00064q-Do for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:26:51 -0400 Date: Wed, 21 Oct 2015 13:26:48 +0300 From: "Michael S. Tsirkin" Message-ID: <1445423133-5119-8-git-send-email-mst@redhat.com> References: <1445423133-5119-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1445423133-5119-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 07/38] vhost: fail backend intialization early List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Igor Mammedov From: Igor Mammedov 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 Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a3b4f9e..f14a5c5 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); -- MST