Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/virtio: Extract virtqueue initialization in vq_reset

So we can reset after that in the main loop.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Link: https://lore.kernel.org/r/20200418102217.32327-7-eperezma@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Eugenio Pérez and committed by
Michael S. Tsirkin
67412392 4cfb9393

+14 -7
+14 -7
tools/virtio/virtio_test.c
··· 94 94 assert(r >= 0); 95 95 } 96 96 97 + static void vq_reset(struct vq_info *info, int num, struct virtio_device *vdev) 98 + { 99 + if (info->vq) 100 + vring_del_virtqueue(info->vq); 101 + 102 + memset(info->ring, 0, vring_size(num, 4096)); 103 + vring_init(&info->vring, num, info->ring, 4096); 104 + info->vq = __vring_new_virtqueue(info->idx, info->vring, vdev, true, 105 + false, vq_notify, vq_callback, "test"); 106 + assert(info->vq); 107 + info->vq->priv = info; 108 + } 109 + 97 110 static void vq_info_add(struct vdev_info *dev, int num) 98 111 { 99 112 struct vq_info *info = &dev->vqs[dev->nvqs]; ··· 116 103 info->call = eventfd(0, EFD_NONBLOCK); 117 104 r = posix_memalign(&info->ring, 4096, vring_size(num, 4096)); 118 105 assert(r >= 0); 119 - memset(info->ring, 0, vring_size(num, 4096)); 120 - vring_init(&info->vring, num, info->ring, 4096); 121 - info->vq = 122 - __vring_new_virtqueue(info->idx, info->vring, &dev->vdev, true, 123 - false, vq_notify, vq_callback, "test"); 124 - assert(info->vq); 125 - info->vq->priv = info; 106 + vq_reset(info, num, &dev->vdev); 126 107 vhost_vq_setup(dev, info); 127 108 dev->fds[info->idx].fd = info->call; 128 109 dev->fds[info->idx].events = POLLIN;