From: Dmitry Fleytman <dmitry@daynix.com>
To: qemu-devel@nongnu.org
Cc: Dmitry Fleytman <dmitry@daynix.com>,
Yan Vugenfirer <yan@daynix.com>,
Gerhard Wiesinger <lists@wiesinger.com>
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
Date: Fri, 16 Nov 2012 15:55:31 +0200 [thread overview]
Message-ID: <1353074135-9674-3-git-send-email-dmitry@daynix.com> (raw)
In-Reply-To: <1353074135-9674-1-git-send-email-dmitry@daynix.com>
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Yan Vugenfirer <yan@daynix.com>
---
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 <windows.h>
@@ -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
--
1.7.11.7
next prev parent reply other threads:[~2012-11-16 14:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-16 13:55 [Qemu-devel] [PATCH V7 0/6] VMXNET3 paravirtual NIC device implementation Dmitry Fleytman
2012-11-16 13:55 ` [Qemu-devel] [PATCH V7 1/6] Adding utility function net_checksum_add_cont() that allows checksum calculation of scattered data with odd chunk sizes Dmitry Fleytman
2012-11-16 13:55 ` Dmitry Fleytman [this message]
2012-11-30 15:35 ` [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 Stefan Hajnoczi
2012-11-16 13:55 ` [Qemu-devel] [PATCH V7 3/6] Adding common definitions for VMWARE devices Dmitry Fleytman
2012-11-16 13:55 ` [Qemu-devel] [PATCH V7 4/6] Adding common code for VMWARE network devices Dmitry Fleytman
2012-11-30 15:56 ` Stefan Hajnoczi
2012-11-16 13:55 ` [Qemu-devel] [PATCH V7 5/6] Adding packet abstraction " Dmitry Fleytman
2012-11-30 16:23 ` Stefan Hajnoczi
2012-11-16 13:55 ` [Qemu-devel] [PATCH V7 6/6] Adding VMXNET3 device implementation Dmitry Fleytman
2012-11-30 16:37 ` Stefan Hajnoczi
2012-12-02 8:33 ` Dmitry Fleytman
2012-11-21 8:37 ` [Qemu-devel] [PATCH V7 0/6] VMXNET3 paravirtual NIC " Stefan Hajnoczi
2012-11-21 8:50 ` Dmitry Fleytman
2012-11-29 17:45 ` Stefan Hajnoczi
2012-11-29 19:10 ` Dmitry Fleytman
2012-11-30 14:14 ` Paolo Bonzini
2012-11-30 16:17 ` Anthony Liguori
2012-12-02 8:31 ` Dmitry Fleytman
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=1353074135-9674-3-git-send-email-dmitry@daynix.com \
--to=dmitry@daynix.com \
--cc=lists@wiesinger.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
/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).