From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpLFA-0005Yt-EN for qemu-devel@nongnu.org; Fri, 05 Aug 2011 10:19:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QpLF5-0008NN-If for qemu-devel@nongnu.org; Fri, 05 Aug 2011 10:19:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpLF5-0008Mw-5w for qemu-devel@nongnu.org; Fri, 05 Aug 2011 10:19:15 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p75EJDNE022563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 5 Aug 2011 10:19:13 -0400 Message-ID: <4E3BFBD4.7090302@redhat.com> Date: Fri, 05 Aug 2011 16:19:00 +0200 From: Gerd Hoffmann MIME-Version: 1.0 References: <1312470626-25872-1-git-send-email-kraxel@redhat.com> <1312470626-25872-4-git-send-email-kraxel@redhat.com> <4E3BD469.6090008@redhat.com> In-Reply-To: <4E3BD469.6090008@redhat.com> Content-Type: multipart/mixed; boundary="------------080403070606060808010500" Subject: Re: [Qemu-devel] [PATCH 03/16] Add iov_clear() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------080403070606060808010500 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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 > > 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 --------------080403070606060808010500 Content-Type: text/plain; name="x" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="x" 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 +#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) --------------080403070606060808010500--