mirror of https://github.com/proxmox/mirror_qemu
virtio: Introduce virtqueue_get_avail_bytes()
The current virtqueue_avail_bytes() is oddly named, and checks if a particular number of bytes are available in a vq. A better API is to fetch the number of bytes available in the vq, and let the caller do what's interesting with the numbers. Introduce virtqueue_get_avail_bytes(), which returns the number of bytes for buffers marked for both, in as well as out. virtqueue_avail_bytes() is made a wrapper over this new function. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>master
parent
385ce95d9d
commit
0d8d769085
28
hw/virtio.c
28
hw/virtio.c
|
@ -335,7 +335,8 @@ static unsigned virtqueue_next_desc(target_phys_addr_t desc_pa,
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes)
|
void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
|
||||||
|
unsigned int *out_bytes)
|
||||||
{
|
{
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
unsigned int total_bufs, in_total, out_total;
|
unsigned int total_bufs, in_total, out_total;
|
||||||
|
@ -380,13 +381,9 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) {
|
if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) {
|
||||||
if (in_bytes > 0 &&
|
in_total += vring_desc_len(desc_pa, i);
|
||||||
(in_total += vring_desc_len(desc_pa, i)) >= in_bytes)
|
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
if (out_bytes > 0 &&
|
out_total += vring_desc_len(desc_pa, i);
|
||||||
(out_total += vring_desc_len(desc_pa, i)) >= out_bytes)
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
} while ((i = virtqueue_next_desc(desc_pa, i, max)) != max);
|
} while ((i = virtqueue_next_desc(desc_pa, i, max)) != max);
|
||||||
|
|
||||||
|
@ -395,7 +392,24 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes)
|
||||||
else
|
else
|
||||||
total_bufs++;
|
total_bufs++;
|
||||||
}
|
}
|
||||||
|
if (in_bytes) {
|
||||||
|
*in_bytes = in_total;
|
||||||
|
}
|
||||||
|
if (out_bytes) {
|
||||||
|
*out_bytes = out_total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
|
||||||
|
unsigned int out_bytes)
|
||||||
|
{
|
||||||
|
unsigned int in_total, out_total;
|
||||||
|
|
||||||
|
virtqueue_get_avail_bytes(vq, &in_total, &out_total);
|
||||||
|
if ((in_bytes && in_bytes < in_total)
|
||||||
|
|| (out_bytes && out_bytes < out_total)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,10 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
|
||||||
void virtqueue_map_sg(struct iovec *sg, target_phys_addr_t *addr,
|
void virtqueue_map_sg(struct iovec *sg, target_phys_addr_t *addr,
|
||||||
size_t num_sg, int is_write);
|
size_t num_sg, int is_write);
|
||||||
int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
|
int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
|
||||||
int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes);
|
int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
|
||||||
|
unsigned int out_bytes);
|
||||||
|
void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
|
||||||
|
unsigned int *out_bytes);
|
||||||
|
|
||||||
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
|
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue