We are going to split vhost_dev_init() so that the first part will do early initialization of QEMU structures, but don't communicate with backend, and the second part will do backend communication. We need this for future support for backend-transfer migration support for vhost-user-blk (backend will not be available in the early initialization point).
With this commit, let's split vhost_virtqueue_init(). The whole function is mostly about configuring the backend, so this logic will be postponed until backend become available. The only thing to keep in early initialization is attaching vhost_dev structure. Let's simply move it to vhost_dev_init(). Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> --- hw/virtio/vhost.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 551d1687fc..1998663461 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1500,9 +1500,9 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n) } } -static int vhost_virtqueue_init(struct vhost_dev *dev, - struct vhost_virtqueue *vq, int n) +static int vhost_virtqueue_connect(struct vhost_virtqueue *vq, int n) { + struct vhost_dev *dev = vq->dev; int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n); struct vhost_vring_file file = { .index = vhost_vq_index, @@ -1519,8 +1519,6 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, goto fail_call; } - vq->dev = dev; - if (dev->vhost_ops->vhost_set_vring_err) { r = event_notifier_init(&vq->error_notifier, 0); if (r < 0) { @@ -1629,6 +1627,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, hdev->migration_blocker = NULL; hdev->busyloop_timeout = busyloop_timeout; + for (i = 0; i < hdev->nvqs; ++i) { + hdev->vqs[i].dev = hdev; + } + r = vhost_set_backend_type(hdev, backend_type); assert(r >= 0); @@ -1680,7 +1682,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, } for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { - r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); + r = vhost_virtqueue_connect(hdev->vqs + i, hdev->vq_index + i); if (r < 0) { error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); goto fail; -- 2.48.1
