qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6448] qemu iovec: keep track of total size, allow partial copies ( Gerd Hoffman)
Date: Mon, 26 Jan 2009 17:17:53 +0000	[thread overview]
Message-ID: <E1LRV5t-0008OA-RA@cvs.savannah.gnu.org> (raw)

Revision: 6448
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6448
Author:   aliguori
Date:     2009-01-26 17:17:52 +0000 (Mon, 26 Jan 2009)

Log Message:
-----------
qemu iovec: keep track of total size, allow partial copies (Gerd Hoffman)

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

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

Modified: trunk/block.c
===================================================================
--- trunk/block.c	2009-01-26 17:07:46 UTC (rev 6447)
+++ trunk/block.c	2009-01-26 17:17:52 UTC (rev 6448)
@@ -1265,7 +1265,7 @@
     VectorTranslationState *s = opaque;
 
     if (!s->is_write) {
-        qemu_iovec_from_buffer(s->iov, s->bounce);
+        qemu_iovec_from_buffer(s->iov, s->bounce, s->iov->size);
     }
     qemu_free(s->bounce);
     s->this_aiocb->cb(s->this_aiocb->opaque, ret);

Modified: trunk/cutils.c
===================================================================
--- trunk/cutils.c	2009-01-26 17:07:46 UTC (rev 6447)
+++ trunk/cutils.c	2009-01-26 17:17:52 UTC (rev 6448)
@@ -109,6 +109,7 @@
     qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
     qiov->niov = 0;
     qiov->nalloc = alloc_hint;
+    qiov->size = 0;
 }
 
 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
@@ -119,6 +120,7 @@
     }
     qiov->iov[qiov->niov].iov_base = base;
     qiov->iov[qiov->niov].iov_len = len;
+    qiov->size += len;
     ++qiov->niov;
 }
 
@@ -138,13 +140,18 @@
     }
 }
 
-void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf)
+void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
 {
     const uint8_t *p = (const uint8_t *)buf;
+    size_t copy;
     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;
+    for (i = 0; i < qiov->niov && count; ++i) {
+        copy = count;
+        if (copy > qiov->iov[i].iov_len)
+            copy = qiov->iov[i].iov_len;
+        memcpy(qiov->iov[i].iov_base, p, copy);
+        p     += copy;
+        count -= copy;
     }
 }

Modified: trunk/qemu-common.h
===================================================================
--- trunk/qemu-common.h	2009-01-26 17:07:46 UTC (rev 6447)
+++ trunk/qemu-common.h	2009-01-26 17:17:52 UTC (rev 6448)
@@ -195,13 +195,14 @@
     struct iovec *iov;
     int niov;
     int nalloc;
+    size_t size;
 } 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);
+void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
 
 #endif /* dyngen-exec.h hack */
 

                 reply	other threads:[~2009-01-26 17:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1LRV5t-0008OA-RA@cvs.savannah.gnu.org \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).