diff options
author | 2022-11-25 13:39:49 +0100 | |
---|---|---|
committer | 2023-10-03 15:18:54 +0300 | |
commit | e6d6621bced8b62dc9f98a09870b527535cbb158 (patch) | |
tree | a0779840e12602ad199e4ee45a7976e89e39b129 /vhost_loopback.c | |
parent | a3fcee5911bf760f9f4522e94cb9e6ab22a7eb95 (diff) |
Virtio-loopback-adapter Beta version:
- Build a single virtio-loopback-adapter binary
- Mmap the vrings with dynamic defined size
- Add set_mem_table mechanism (Not used into this release)
Signed-off-by: Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
Diffstat (limited to 'vhost_loopback.c')
-rw-r--r-- | vhost_loopback.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/vhost_loopback.c b/vhost_loopback.c index aed1cc5..a8b78b6 100644 --- a/vhost_loopback.c +++ b/vhost_loopback.c @@ -70,8 +70,6 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) { int i, r, e; - DBG("vhost_dev_enable_notifiers(...)\n"); - /* * We will pass the notifiers to the kernel, make sure that QEMU * doesn't interfere. @@ -84,6 +82,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail; } + for (i = 0; i < hdev->nvqs; ++i) { r = virtio_bus_set_host_notifier(vdev->vbus, hdev->vq_index + i, true); @@ -180,8 +179,6 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, } file.index = vhost_user_get_vq_index(hdev, n); - DBG("vhost_virtqueue_mask -> index: %d, n: %d, file.fd: %d\n", - index, n, file.fd); r = vhost_user_set_vring_call(&file); if (r < 0) { @@ -198,8 +195,6 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, uint64_t s, l, a; int r; - DBG("vhost_virtqueue_start()\n"); - int vhost_vq_index = vhost_user_get_vq_index(dev, idx); struct vhost_vring_file file = { .index = vhost_vq_index @@ -250,7 +245,6 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx); vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx); - DBG("vdev->vq[n].vring.used: 0x%lx\n", a); vq->used = (void *)a; if (!vq->used || l != s) { DBG("Error : vq->used = a\n"); @@ -264,6 +258,10 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, return r; } + /* The next line has to be disable for rng */ + /* Clear and discard previous events if any. */ + //event_notifier_test_and_clear(virtio_queue_get_host_notifier(vvq)); + file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); r = vhost_user_set_vring_kick(&file); if (r) { @@ -288,6 +286,14 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, return 0; } +void update_mem_table(VirtIODevice *vdev) +{ + print_mem_table(vdev->vhdev); + vhost_commit_vqs(vdev->vhdev); + print_mem_table(vdev->vhdev); + (void)vhost_user_set_mem_table(vdev->vhdev); +} + /* Host notifiers must be enabled at this point. */ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) { @@ -296,8 +302,6 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) hdev->started = true; hdev->vdev = vdev; - DBG("vhost_dev_start()\n"); - r = vhost_dev_set_features(hdev, hdev->log_enabled); if (r < 0) { return r; @@ -308,20 +312,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) DBG("memory_listener_register?\n"); } - /* TODO: We might need this function in the next release */ - /* - * r = vhost_user_set_mem_table(hdev); - * if (r < 0) { - * DBG("vhost_set_mem_table failed\n"); - * return r; - * } - */ - /* This is used to exhange the loopback_fd to the vhost-user-device */ vhost_user_share_fd(); - DBG("hdev->nvqs: %d\n", hdev->nvqs); - for (i = 0; i < hdev->nvqs; ++i) { r = vhost_virtqueue_start(hdev, vdev, @@ -333,8 +326,6 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } - DBG("vhost_dev_start return successfully\n"); - return 0; } @@ -342,23 +333,18 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, uint32_t config_len) { - DBG("vhost_dev_get_config(...)\n"); - return vhost_user_get_config(hdev, config, config_len); } int vhost_dev_set_config(struct vhost_dev *hdev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) { - DBG("vhost_dev_set_config(...)\n"); return vhost_user_set_config(hdev, data, offset, size, flags); - } void vhost_dev_set_config_notifier(struct vhost_dev *hdev, const VhostDevConfigOps *ops) { - DBG("vhost_dev_set_config_notifier(...)\n"); hdev->config_ops = ops; } |