qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [6396] I/O vector helpers (Avi Kivity)
@ 2009-01-22 16:59 Anthony Liguori
  2009-01-23 11:18 ` Gerd Hoffmann
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony Liguori @ 2009-01-22 16:59 UTC (permalink / raw)
  To: qemu-devel

Revision: 6396
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6396
Author:   aliguori
Date:     2009-01-22 16:59:20 +0000 (Thu, 22 Jan 2009)

Log Message:
-----------
I/O vector helpers (Avi Kivity)

In general, it is not possible to predict the size of of an I/O vector since
a contiguous guest region may map to a disconiguous host region.  Add some
helpers to manage I/O vector growth.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Modified Paths:
--------------
    trunk/cutils.c
    trunk/qemu-common.h

Modified: trunk/cutils.c
===================================================================
--- trunk/cutils.c	2009-01-22 16:59:16 UTC (rev 6395)
+++ trunk/cutils.c	2009-01-22 16:59:20 UTC (rev 6396)
@@ -101,3 +101,50 @@
 {
     return 32 - clz32(i);
 }
+
+/* io vectors */
+
+void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
+{
+    qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
+    qiov->niov = 0;
+    qiov->nalloc = alloc_hint;
+}
+
+void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
+{
+    if (qiov->niov == qiov->nalloc) {
+        qiov->nalloc = 2 * qiov->nalloc + 1;
+        qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
+    }
+    qiov->iov[qiov->niov].iov_base = base;
+    qiov->iov[qiov->niov].iov_len = len;
+    ++qiov->niov;
+}
+
+void qemu_iovec_destroy(QEMUIOVector *qiov)
+{
+    qemu_free(qiov->iov);
+}
+
+void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
+{
+    uint8_t *p = (uint8_t *)buf;
+    int i;
+
+    for (i = 0; i < qiov->niov; ++i) {
+        memcpy(p, qiov->iov[i].iov_base, qiov->iov[i].iov_len);
+        p += qiov->iov[i].iov_len;
+    }
+}
+
+void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf)
+{
+    const uint8_t *p = (const uint8_t *)buf;
+    int i;
+
+    for (i = 0; i < qiov->niov; ++i) {
+        memcpy(qiov->iov[i].iov_base, p, qiov->iov[i].iov_len);
+        p += qiov->iov[i].iov_len;
+    }
+}

Modified: trunk/qemu-common.h
===================================================================
--- trunk/qemu-common.h	2009-01-22 16:59:16 UTC (rev 6395)
+++ trunk/qemu-common.h	2009-01-22 16:59:20 UTC (rev 6396)
@@ -191,6 +191,18 @@
 /* Force QEMU to stop what it's doing and service IO */
 void qemu_service_io(void);
 
+typedef struct QEMUIOVector {
+    struct iovec *iov;
+    int niov;
+    int nalloc;
+} QEMUIOVector;
+
+void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
+void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
+void qemu_iovec_destroy(QEMUIOVector *qiov);
+void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
+void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf);
+
 #endif /* dyngen-exec.h hack */
 
 #endif

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [6396] I/O vector helpers (Avi Kivity)
  2009-01-22 16:59 [Qemu-devel] [6396] I/O vector helpers (Avi Kivity) Anthony Liguori
@ 2009-01-23 11:18 ` Gerd Hoffmann
  0 siblings, 0 replies; 2+ messages in thread
From: Gerd Hoffmann @ 2009-01-23 11:18 UTC (permalink / raw)
  To: qemu-devel

Anthony Liguori wrote:
> +void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
> +{
> +    if (qiov->niov == qiov->nalloc) {
> +        qiov->nalloc = 2 * qiov->nalloc + 1;
> +        qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
> +    }
> +    qiov->iov[qiov->niov].iov_base = base;
> +    qiov->iov[qiov->niov].iov_len = len;
> +    ++qiov->niov;
> +}

Breaks the build:

AR libqemu.a
LINK qemu-x86_64
../libqemu_user.a(cutils.o): In function `qemu_iovec_add':
/home/kraxel/projects/qemu/cutils.c:118: undefined reference to
`qemu_realloc'
collect2: ld returned 1 exit status
make[1]: *** [qemu-x86_64] Error 1
make[1]: Leaving directory `/home/kraxel/projects/qemu/x86_64-linux-user'
make: *** [subdir-x86_64-linux-user] Error 2

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-23 11:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-22 16:59 [Qemu-devel] [6396] I/O vector helpers (Avi Kivity) Anthony Liguori
2009-01-23 11:18 ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).