From a4526da67938f48522cb0f0abee63d4b2182b359 Mon Sep 17 00:00:00 2001 From: Michael S. Tsirkin Date: Mon, 19 Jul 2010 11:25:04 -0300 Subject: [PATCH 9/9] vhost: fix miration during device start RH-Author: Michael S. Tsirkin Message-id: <20100719112504.GA1140@redhat.com> Patchwork-id: 10813 O-Subject: [RHEL6.0 PATCHv2] vhost: fix miration during device start Bugzilla: 615228 RH-Acked-by: Jes Sorensen RH-Acked-by: Amit Shah RH-Acked-by: Juan Quintela We need to know ring layout to allocate log buffer. So init rings first. Also fixes a theoretical memory-leak-on-error. Signed-off-by: Michael S. Tsirkin Tested-by: Gerd Hoffmann Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=2604248 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=615228 Upstream: posted --- Changes from v1: fix error handling issue noted by Juan Quintela Signed-off-by: Eduardo Habkost --- hw/vhost.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/hw/vhost.c b/hw/vhost.c index ad2f98a..3c1c702 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -659,6 +659,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) r = -errno; goto fail; } + for (i = 0; i < hdev->nvqs; ++i) { + r = vhost_virtqueue_init(hdev, + vdev, + hdev->vqs + i, + i); + if (r < 0) { + goto fail_vq; + } + } + if (hdev->log_enabled) { hdev->log_size = vhost_get_log_size(hdev); hdev->log = hdev->log_size ? @@ -667,19 +677,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) (uint64_t)(unsigned long)hdev->log); if (r < 0) { r = -errno; - goto fail; - } - } - - for (i = 0; i < hdev->nvqs; ++i) { - r = vhost_virtqueue_init(hdev, - vdev, - hdev->vqs + i, - i); - if (r < 0) { goto fail_vq; } } + hdev->started = true; return 0; -- 1.7.0.3