aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio-serial-bus.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2010-04-27 18:04:05 +0530
committerAnthony Liguori <aliguori@us.ibm.com>2010-04-28 08:58:22 -0500
commite4d5639dbb6181ebbfdb554f2594721b2d63882b (patch)
tree1ad23eabc520022e909e73bbc3affbdfca4cc25f /hw/virtio-serial-bus.c
parent3ecb45f893d09a97b8f24399b5e40808a708261f (diff)
iov: Introduce a new file for helpers around iovs, add iov_from_buf()
The virtio-net code uses iov_fill() which fills an iov from a linear buffer. The virtio-serial-bus code does something similar in an open-coded function. Create a new iov.c file that has iov_from_buf(). Convert virtio-net and virtio-serial-bus over to use this functionality. virtio-net used ints to hold sizes, the new function is going to use size_t types. Later commits will add the opposite functionality -- going from an iov to a linear buffer. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-serial-bus.c')
-rw-r--r--hw/virtio-serial-bus.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 6befd4d139..a72b6b53d3 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -15,6 +15,7 @@
* the COPYING file in the top-level directory.
*/
+#include "iov.h"
#include "monitor.h"
#include "qemu-queue.h"
#include "sysbus.h"
@@ -84,27 +85,25 @@ static size_t write_to_port(VirtIOSerialPort *port,
{
VirtQueueElement elem;
VirtQueue *vq;
- size_t offset = 0;
- size_t len = 0;
+ size_t offset;
vq = port->ivq;
if (!virtio_queue_ready(vq)) {
return 0;
}
+ offset = 0;
while (offset < size) {
- int i;
+ size_t len;
if (!virtqueue_pop(vq, &elem)) {
break;
}
- for (i = 0; offset < size && i < elem.in_num; i++) {
- len = MIN(elem.in_sg[i].iov_len, size - offset);
+ len = iov_from_buf(elem.in_sg, elem.in_num,
+ buf + offset, size - offset);
+ offset += len;
- memcpy(elem.in_sg[i].iov_base, buf + offset, len);
- offset += len;
- }
virtqueue_push(vq, &elem, len);
}