diff options
author | Kevin Wolf <kwolf@redhat.com> | 2021-06-09 08:46:52 -0700 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2021-06-30 13:15:44 +0200 |
commit | a6945f2287aa7f048b263d7187364cbf1dd5d94d (patch) | |
tree | 999b68cfc5e64af247afbc10b6fb99983583e76a /hw/virtio | |
parent | bf783261f0aee6e81af3916bff7606d71ccdc153 (diff) | |
download | qemu-a6945f2287aa7f048b263d7187364cbf1dd5d94d.zip qemu-a6945f2287aa7f048b263d7187364cbf1dd5d94d.tar.gz qemu-a6945f2287aa7f048b263d7187364cbf1dd5d94d.tar.bz2 |
vhost: Add Error parameter to vhost_dev_init()
This allows callers to return better error messages instead of making
one up while the real error ends up on stderr. Most callers can
immediately make use of this because they already have an Error
parameter themselves. The others just keep printing the error with
error_report_err().
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210609154658.350308-2-kwolf@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/virtio')
-rw-r--r-- | hw/virtio/vhost-user-fs.c | 3 | ||||
-rw-r--r-- | hw/virtio/vhost-user-vsock.c | 3 | ||||
-rw-r--r-- | hw/virtio/vhost-vsock.c | 3 | ||||
-rw-r--r-- | hw/virtio/vhost.c | 16 |
4 files changed, 13 insertions, 12 deletions
diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6f7f915..c595957 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -235,9 +235,8 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) fs->vhost_dev.nvqs = 1 + fs->conf.num_request_queues; fs->vhost_dev.vqs = g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs); ret = vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index a6f08c26..b6a4a25 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -108,9 +108,8 @@ static void vuv_device_realize(DeviceState *dev, Error **errp) vhost_dev_set_config_notifier(&vvc->vhost_dev, &vsock_ops); ret = vhost_dev_init(&vvc->vhost_dev, &vsock->vhost_user, - VHOST_BACKEND_TYPE_USER, 0); + VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost_dev_init failed"); goto err_virtio; } diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 8ddfb9a..777cafe 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -170,9 +170,8 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) vhost_vsock_common_realize(vdev, "vhost-vsock"); ret = vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd, - VHOST_BACKEND_TYPE_KERNEL, 0); + VHOST_BACKEND_TYPE_KERNEL, 0, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "vhost-vsock: vhost_dev_init failed"); goto err_virtio; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7b7bde7..991c67d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1286,7 +1286,8 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) } int vhost_dev_init(struct vhost_dev *hdev, void *opaque, - VhostBackendType backend_type, uint32_t busyloop_timeout) + VhostBackendType backend_type, uint32_t busyloop_timeout, + Error **errp) { uint64_t features; int i, r, n_initialized_vqs = 0; @@ -1300,24 +1301,26 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, r = hdev->vhost_ops->vhost_backend_init(hdev, opaque); if (r < 0) { + error_setg(errp, "vhost_backend_init failed"); goto fail; } r = hdev->vhost_ops->vhost_set_owner(hdev); if (r < 0) { - VHOST_OPS_DEBUG("vhost_set_owner failed"); + error_setg(errp, "vhost_set_owner failed"); goto fail; } r = hdev->vhost_ops->vhost_get_features(hdev, &features); if (r < 0) { - VHOST_OPS_DEBUG("vhost_get_features failed"); + error_setg(errp, "vhost_get_features failed"); goto fail; } for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); if (r < 0) { + error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); goto fail; } } @@ -1327,6 +1330,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, busyloop_timeout); if (r < 0) { + error_setg(errp, "Failed to set busyloop timeout"); goto fail_busyloop; } } @@ -1367,7 +1371,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, if (hdev->migration_blocker != NULL) { r = migrate_add_blocker(hdev->migration_blocker, &local_err); if (local_err) { - error_report_err(local_err); + error_propagate(errp, local_err); error_free(hdev->migration_blocker); goto fail_busyloop; } @@ -1384,8 +1388,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) { - error_report("vhost backend memory slots limit is less" - " than current number of present memory slots"); + error_setg(errp, "vhost backend memory slots limit is less" + " than current number of present memory slots"); r = -1; goto fail_busyloop; } |