qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] add qemu_iovec_init_external
@ 2009-03-18  7:52 Christoph Hellwig
  2009-03-28 17:46 ` Anthony Liguori
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2009-03-18  7:52 UTC (permalink / raw)
  To: qemu-devel


Allow to initialize a QEMUIOVector from an externally allocated iovec.
qiov->nalloc is initialized to -1 to indicate external storage for qiov->iov
and all functions dealing with memory management assert on the iovec beeing
an internally managed first.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: qemu/cutils.c
===================================================================
--- qemu.orig/cutils.c	2009-03-18 08:23:25.412987454 +0100
+++ qemu/cutils.c	2009-03-18 08:43:25.521856132 +0100
@@ -23,6 +23,7 @@
  */
 #include "qemu-common.h"
 #include "host-utils.h"
+#include <assert.h>
 
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
@@ -112,8 +113,22 @@ void qemu_iovec_init(QEMUIOVector *qiov,
     qiov->size = 0;
 }
 
+void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov)
+{
+    int i;
+
+    qiov->iov = iov;
+    qiov->niov = niov;
+    qiov->nalloc = -1;
+    qiov->size = 0;
+    for (i = 0; i < niov; i++)
+        qiov->size += iov[i].iov_len;
+}
+
 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
 {
+    assert(qiov->nalloc != -1);
+
     if (qiov->niov == qiov->nalloc) {
         qiov->nalloc = 2 * qiov->nalloc + 1;
         qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
@@ -126,11 +141,15 @@ void qemu_iovec_add(QEMUIOVector *qiov, 
 
 void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
+    assert(qiov->nalloc != -1);
+
     qemu_free(qiov->iov);
 }
 
 void qemu_iovec_reset(QEMUIOVector *qiov)
 {
+    assert(qiov->nalloc != -1);
+
     qiov->niov = 0;
     qiov->size = 0;
 }
Index: qemu/qemu-common.h
===================================================================
--- qemu.orig/qemu-common.h	2009-03-18 08:25:11.505853329 +0100
+++ qemu/qemu-common.h	2009-03-18 08:34:34.075854099 +0100
@@ -194,6 +194,7 @@ typedef struct QEMUIOVector {
 } QEMUIOVector;
 
 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
+void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
 void qemu_iovec_destroy(QEMUIOVector *qiov);
 void qemu_iovec_reset(QEMUIOVector *qiov);

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

* Re: [Qemu-devel] [PATCH 1/2] add qemu_iovec_init_external
  2009-03-18  7:52 [Qemu-devel] [PATCH 1/2] add qemu_iovec_init_external Christoph Hellwig
@ 2009-03-28 17:46 ` Anthony Liguori
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2009-03-28 17:46 UTC (permalink / raw)
  To: qemu-devel

Christoph Hellwig wrote:
> Allow to initialize a QEMUIOVector from an externally allocated iovec.
> qiov->nalloc is initialized to -1 to indicate external storage for qiov->iov
> and all functions dealing with memory management assert on the iovec beeing
> an internally managed first.
>   

Applied whole series.  Thanks.

I also committed a patch I had lying around that switches virtio to the 
new DMA API.

Regards,

Anthony Liguori

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

end of thread, other threads:[~2009-03-28 17:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-18  7:52 [Qemu-devel] [PATCH 1/2] add qemu_iovec_init_external Christoph Hellwig
2009-03-28 17:46 ` Anthony Liguori

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).