[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/17] iov: Introduce a new file for helpers around
From: |
Amit Shah |
Subject: |
[Qemu-devel] [PATCH 11/17] iov: Introduce a new file for helpers around iovs, add iov_from_buf() |
Date: |
Wed, 31 Mar 2010 13:04:02 +0530 |
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 <address@hidden>
---
Makefile.objs | 1 +
hw/iov.c | 33 +++++++++++++++++++++++++++++++++
hw/iov.h | 16 ++++++++++++++++
hw/virtio-net.c | 20 +++-----------------
hw/virtio-serial-bus.c | 15 +++++++--------
5 files changed, 60 insertions(+), 25 deletions(-)
create mode 100644 hw/iov.c
create mode 100644 hw/iov.h
diff --git a/Makefile.objs b/Makefile.objs
index 233fbba..2ab09d7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -129,6 +129,7 @@ user-obj-y += cutils.o cache-utils.o
hw-obj-y =
hw-obj-y += vl.o loader.o
+hw-obj-y += iov.o
hw-obj-y += virtio.o virtio-console.o
hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
diff --git a/hw/iov.c b/hw/iov.c
new file mode 100644
index 0000000..07bd499
--- /dev/null
+++ b/hw/iov.c
@@ -0,0 +1,33 @@
+/*
+ * Helpers for getting linearized buffers from iov / filling buffers into iovs
+ *
+ * Copyright IBM, Corp. 2007, 2008
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * Author(s):
+ * Anthony Liguori <address@hidden>
+ * Amit Shah <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "iov.h"
+
+size_t iov_from_buf(struct iovec *iov, unsigned int iovcnt,
+ const void *buf, size_t size)
+{
+ size_t offset;
+ unsigned int i;
+
+ offset = 0;
+ for (i = 0; offset < size && i < iovcnt; i++) {
+ size_t len;
+
+ len = MIN(iov[i].iov_len, size - offset);
+
+ memcpy(iov[i].iov_base, buf + offset, len);
+ offset += len;
+ }
+ return offset;
+}
diff --git a/hw/iov.h b/hw/iov.h
new file mode 100644
index 0000000..5e3e541
--- /dev/null
+++ b/hw/iov.h
@@ -0,0 +1,16 @@
+/*
+ * Helpers for getting linearized buffers from iov / filling buffers into iovs
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * Author(s):
+ * Amit Shah <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu-common.h"
+
+size_t iov_from_buf(struct iovec *iov, unsigned int iovcnt,
+ const void *buf, size_t size);
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index be33c68..273e7f9 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -11,6 +11,7 @@
*
*/
+#include "iov.h"
#include "virtio.h"
#include "net.h"
#include "net/checksum.h"
@@ -423,21 +424,6 @@ static void work_around_broken_dhclient(struct
virtio_net_hdr *hdr,
}
}
-static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
-{
- int offset, i;
-
- offset = i = 0;
- while (offset < count && i < iovcnt) {
- int len = MIN(iov[i].iov_len, count - offset);
- memcpy(iov[i].iov_base, buf + offset, len);
- offset += len;
- i++;
- }
-
- return offset;
-}
-
static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
const void *buf, size_t size, size_t hdr_len)
{
@@ -573,8 +559,8 @@ static ssize_t virtio_net_receive(VLANClientState *nc,
const uint8_t *buf, size_
}
/* copy in packet. ugh */
- len = iov_fill(sg, elem.in_num,
- buf + offset, size - offset);
+ len = iov_from_buf(sg, elem.in_num,
+ buf + offset, size - offset);
total += len;
/* signal other side */
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 236e300..ee45146 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);
}
--
1.6.2.5
- [Qemu-devel] [PATCH 01/17] virtio-serial: save/load: Ensure target has enough ports, (continued)
- [Qemu-devel] [PATCH 01/17] virtio-serial: save/load: Ensure target has enough ports, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 02/17] virtio-serial: save/load: Ensure nr_ports on src and dest are same., Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 03/17] virtio-serial: save/load: Ensure we have hot-plugged ports instantiated, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 04/17] virtio-serial: save/load: Send target host connection status if different, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 05/17] virtio-serial: Use control messages to notify guest of new ports, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 06/17] virtio-serial: whitespace: match surrounding code, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 07/17] virtio-serial: Remove redundant check for 0-sized write request, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 08/17] virtio-serial: Update copyright year to 2010, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 09/17] virtio-serial: Propagate errors in initialising ports / devices in guest, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 10/17] virtio-serial: Send out guest data to ports only if port is opened, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 11/17] iov: Introduce a new file for helpers around iovs, add iov_from_buf(),
Amit Shah <=
- [Qemu-devel] [PATCH 12/17] iov: Add iov_to_buf and iov_size helpers, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 13/17] virtio-serial: Handle scatter-gather buffers for control messages, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 14/17] virtio-serial: Handle scatter/gather input from the guest, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 16/17] virtio-serial: Discard data that guest sends us when ports aren't connected, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 17/17] virtio-serial: Implement flow control for individual ports, Amit Shah, 2010/03/31
- [Qemu-devel] Re: [PATCH 16/17] virtio-serial: Discard data that guest sends us when ports aren't connected, Juan Quintela, 2010/03/31
- Re: [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Gerd Hoffmann, 2010/03/31
- Re: [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Amit Shah, 2010/03/31
[Qemu-devel] Re: [PATCH 00/17] v4: virtio-serial fixes, new abi for port discovery, Juan Quintela, 2010/03/31