Patchwork [03/16] Add iov_clear()

login
register
mail settings
Submitter Gerd Hoffmann
Date Aug. 5, 2011, 2:19 p.m.
Message ID <4E3BFBD4.7090302@redhat.com>
Download mbox | patch
Permalink /patch/108668/
State New
Headers show

Comments

Gerd Hoffmann - Aug. 5, 2011, 2:19 p.m.
On 08/05/11 13:30, Kevin Wolf wrote:
> Am 04.08.2011 17:10, schrieb Gerd Hoffmann:
>> Fill the spefified area with zeros.
>>
>> Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>
>
> Looks like we're starting to duplicate everything in qemu_iovec_* and
> iov_*...
>
> Any reason not to use QEMUIOVector?

I *do* use QEMUIOVector, but for the actual copy I'm using 
iov_{from,to}_buf() instead of qemu_iovec_{from,to}_buffer because the 
former allows to specify an offset.

But, yea, we have some duplication here, qemu_iovec_* can just call 
iov_* instead of reimplementing stuff ...

cheers,
   Gerd

Patch

diff --git a/cutils.c b/cutils.c
index f9a7e36..b8ca4c2 100644
--- a/cutils.c
+++ b/cutils.c
@@ -24,6 +24,7 @@ 
 #include "qemu-common.h"
 #include "host-utils.h"
 #include <math.h>
+#include "iov.h"
 
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
@@ -230,29 +231,12 @@  void qemu_iovec_reset(QEMUIOVector *qiov)
 
 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;
-    }
+    iov_to_buf(qiov->iov, qiov->niov, buf, 0, qiov->size);
 }
 
 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 && 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;
-    }
+    iov_from_buf(qiov->iov, qiov->niov, buf, 0, count);
 }
 
 void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count)