From patchwork Fri Nov 16 13:55:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 199639 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 ADCE52C0092 for ; Sat, 17 Nov 2012 01:35:10 +1100 (EST) Received: from localhost ([::1]:41224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZMcN-0005Pg-MO for incoming@patchwork.ozlabs.org; Fri, 16 Nov 2012 09:10:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZMbl-0003pd-2o for qemu-devel@nongnu.org; Fri, 16 Nov 2012 09:09:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZMbh-0008IP-W1 for qemu-devel@nongnu.org; Fri, 16 Nov 2012 09:09:24 -0500 Received: from mail-we0-f173.google.com ([74.125.82.173]:51055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZMbh-0008FY-PU for qemu-devel@nongnu.org; Fri, 16 Nov 2012 09:09:21 -0500 Received: by mail-we0-f173.google.com with SMTP id r1so1008787wey.4 for ; Fri, 16 Nov 2012 06:09:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=+IdJCwF7mA74DHWwxawNpN9Am55BW6a3ezGK6foO1Tg=; b=j341ttMljkgkJuQLWMExxxZ7Iz9GTSDFcCoOJjsQ+ZhbGcWWckC5s81ZYD/bcAbtxJ sQZ+r16QPkacW3yMRD22gsI4zNmYOClr/w5jJxhmgfM5oF/MbnJXZ/k/vBOJSS3zXcTF uYu/aF5/FTtIBn1ZRC1MVvMS8E0MLiUc9zNCvcwMopRT2CrrS6WttRLIFUeIXXPZXZiH 7+TcbOJZjhf6YMyUXQZjBzGp+Jwv3D1rBzMSyhEhxN+UDcFUNQuhiGTFmhrIBVQ4cBGm XDH3w/ySZQqzQvUXRYJXC6HDRJd3GwJsiFFn1SLjUN4OrIPPbq1NJFMMVLBCM9sJmhaN t8Pw== Received: by 10.216.140.73 with SMTP id d51mr627588wej.222.1353074961477; Fri, 16 Nov 2012 06:09:21 -0800 (PST) Received: from Snarl.daynix ([91.205.155.63]) by mx.google.com with ESMTPS id d9sm1139633wiw.0.2012.11.16.06.09.19 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Nov 2012 06:09:20 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Fri, 16 Nov 2012 15:55:31 +0200 Message-Id: <1353074135-9674-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1353074135-9674-1-git-send-email-dmitry@daynix.com> References: <1353074135-9674-1-git-send-email-dmitry@daynix.com> X-Gm-Message-State: ALoCoQnoSCwe4qSzBME4NWWJdpgtfltTzng3qGKXTzd9z6fz/H1Keb6L7yPZcJTfEvwuIyYXJy0x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.82.173 Cc: Dmitry Fleytman , Yan Vugenfirer , Gerhard Wiesinger Subject: [Qemu-devel] [PATCH V7 2/6] Adding utility function iov_net_csum_add() for iovec checksum calculation Adding utility function iov_rebuild() for smart iovec copy 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 Signed-off-by: Dmitry Fleytman Signed-off-by: Yan Vugenfirer --- Makefile.objs | 1 + iov.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ iov.h | 13 +++++++++++++ tests/Makefile | 2 +- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Makefile.objs b/Makefile.objs index 593a592..5400c6c 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -43,6 +43,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o blockjob.o aes.o qemu-config.o +block-obj-y += net/checksum.o block-obj-y += thread-pool.o qemu-progress.o qemu-sockets.o uri.o notify.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += event_notifier-posix.o aio-posix.o diff --git a/iov.c b/iov.c index a81eedc..c9fd128 100644 --- a/iov.c +++ b/iov.c @@ -17,6 +17,7 @@ */ #include "iov.h" +#include "net/checksum.h" #ifdef _WIN32 # include @@ -252,6 +253,58 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt, return j; } +size_t iov_rebuild(struct iovec *dst, unsigned int dst_cnt, + const struct iovec *src, const unsigned int src_cnt, + size_t src_off) +{ + size_t curr_src_off = 0; + unsigned int i, j = 0; + + for (i = 0; i < src_cnt; i++) { + if (src_off < (curr_src_off + src[i].iov_len)) { + if (j == dst_cnt) { + return (size_t) -1; + } + + dst[j].iov_len = curr_src_off + src[i].iov_len - src_off; + dst[j].iov_base = src[i].iov_base + (src_off - curr_src_off); + + src_off += dst[j].iov_len; + j++; + } + curr_src_off += src[i].iov_len; + } + return j; +} + +uint32_t +iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt, + size_t iov_off, size_t size) +{ + size_t iovec_off, buf_off; + unsigned int i; + uint32_t res = 0; + uint32_t seq = 0; + + iovec_off = 0; + buf_off = 0; + for (i = 0; i < iov_cnt && size; i++) { + if (iov_off < (iovec_off + iov[i].iov_len)) { + size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size); + void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off); + + res += net_checksum_add_cont(len, chunk_buf, seq); + seq += len; + + buf_off += len; + iov_off += len; + size -= len; + } + iovec_off += iov[i].iov_len; + } + return res; +} + /* io vectors */ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint) diff --git a/iov.h b/iov.h index 34c8ec9..9439eb7 100644 --- a/iov.h +++ b/iov.h @@ -95,3 +95,16 @@ void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt, unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt, const struct iovec *iov, unsigned int iov_cnt, size_t offset, size_t bytes); + +/** + * Copy data between scatter-gather vectors + */ +size_t iov_rebuild(struct iovec *dest, unsigned int dest_cnt, + const struct iovec *src, const unsigned int src_cnt, + size_t src_off); + +/** + * Checksum calculation for scatter-gather vector + */ +uint32_t iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt, + size_t iov_off, size_t size); diff --git a/tests/Makefile b/tests/Makefile index 9bf0765..8fb5241 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -49,7 +49,7 @@ tests/check-qlist$(EXESUF): tests/check-qlist.o qlist.o qint.o tests/check-qfloat$(EXESUF): tests/check-qfloat.o qfloat.o tests/check-qjson$(EXESUF): tests/check-qjson.o $(qobject-obj-y) qemu-tool.o tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(coroutine-obj-y) $(tools-obj-y) $(block-obj-y) iov.o -tests/test-iov$(EXESUF): tests/test-iov.o iov.o +tests/test-iov$(EXESUF): tests/test-iov.o iov.o net/checksum.o tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py