From patchwork Wed Jan 2 15:15:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 209061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B06212C0087 for ; Thu, 3 Jan 2013 02:48:55 +1100 (EST) Received: from localhost ([::1]:45196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQ4M-0002Aw-Rs for incoming@patchwork.ozlabs.org; Wed, 02 Jan 2013 10:17:26 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQ3Y-0000pc-4t for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqQ3Q-0005bx-JK for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQ3Q-0005bp-B1 for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r02FGRFw031990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Jan 2013 10:16:27 -0500 Received: from localhost (ovpn-112-16.ams2.redhat.com [10.36.112.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r02FGQ1P013149; Wed, 2 Jan 2013 10:16:27 -0500 From: Stefan Hajnoczi To: Date: Wed, 2 Jan 2013 16:15:47 +0100 Message-Id: <1357139756-11951-10-git-send-email-stefanha@redhat.com> In-Reply-To: <1357139756-11951-1-git-send-email-stefanha@redhat.com> References: <1357139756-11951-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 09/18] iov: add qemu_iovec_concat_iov() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The qemu_iovec_concat() function copies a subset of a QEMUIOVector. The new qemu_iovec_concat_iov() function does the same for a iov/cnt pair. It is easy to define qemu_iovec_concat() in terms of qemu_iovec_concat_iov(). The existing code is mostly unchanged, except for the assertion src->size >= soffset, which cannot be efficiently checked upfront on a iov/cnt pair. Instead we assert upon hitting the end of src with an unsatisfied soffset. Signed-off-by: Stefan Hajnoczi --- include/qemu-common.h | 3 +++ iov.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 6871cab..2b83de3 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -329,6 +329,9 @@ 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_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t soffset, size_t sbytes); +void qemu_iovec_concat_iov(QEMUIOVector *dst, + struct iovec *src_iov, unsigned int src_cnt, + size_t soffset, size_t sbytes); void qemu_iovec_destroy(QEMUIOVector *qiov); void qemu_iovec_reset(QEMUIOVector *qiov); size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset, diff --git a/iov.c b/iov.c index 92ad77b..c0f5c56 100644 --- a/iov.c +++ b/iov.c @@ -289,34 +289,49 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len) } /* - * Concatenates (partial) iovecs from src to the end of dst. + * Concatenates (partial) iovecs from src_iov to the end of dst. * It starts copying after skipping `soffset' bytes at the * beginning of src and adds individual vectors from src to * dst copies up to `sbytes' bytes total, or up to the end - * of src if it comes first. This way, it is okay to specify + * of src_iov if it comes first. This way, it is okay to specify * very large value for `sbytes' to indicate "up to the end * of src". * Only vector pointers are processed, not the actual data buffers. */ -void qemu_iovec_concat(QEMUIOVector *dst, - QEMUIOVector *src, size_t soffset, size_t sbytes) +void qemu_iovec_concat_iov(QEMUIOVector *dst, + struct iovec *src_iov, unsigned int src_cnt, + size_t soffset, size_t sbytes) { int i; size_t done; - struct iovec *siov = src->iov; assert(dst->nalloc != -1); - assert(src->size >= soffset); - for (i = 0, done = 0; done < sbytes && i < src->niov; i++) { - if (soffset < siov[i].iov_len) { - size_t len = MIN(siov[i].iov_len - soffset, sbytes - done); - qemu_iovec_add(dst, siov[i].iov_base + soffset, len); + for (i = 0, done = 0; done < sbytes && i < src_cnt; i++) { + if (soffset < src_iov[i].iov_len) { + size_t len = MIN(src_iov[i].iov_len - soffset, sbytes - done); + qemu_iovec_add(dst, src_iov[i].iov_base + soffset, len); done += len; soffset = 0; } else { - soffset -= siov[i].iov_len; + soffset -= src_iov[i].iov_len; } } - /* return done; */ + assert(soffset == 0); /* offset beyond end of src */ +} + +/* + * Concatenates (partial) iovecs from src to the end of dst. + * It starts copying after skipping `soffset' bytes at the + * beginning of src and adds individual vectors from src to + * dst copies up to `sbytes' bytes total, or up to the end + * of src if it comes first. This way, it is okay to specify + * very large value for `sbytes' to indicate "up to the end + * of src". + * Only vector pointers are processed, not the actual data buffers. + */ +void qemu_iovec_concat(QEMUIOVector *dst, + QEMUIOVector *src, size_t soffset, size_t sbytes) +{ + qemu_iovec_concat_iov(dst, src->iov, src->niov, soffset, sbytes); } void qemu_iovec_destroy(QEMUIOVector *qiov)