From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Blue Swirl <blauwirbel@gmail.com>,
khoa@us.ibm.com, Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Asias He <asias@redhat.com>
Subject: [Qemu-devel] [PATCH v6 09/12] iov: add qemu_iovec_concat_iov()
Date: Mon, 10 Dec 2012 14:09:42 +0100 [thread overview]
Message-ID: <1355144985-12897-10-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1355144985-12897-1-git-send-email-stefanha@redhat.com>
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 <stefanha@redhat.com>
---
iov.c | 39 +++++++++++++++++++++++++++------------
qemu-common.h | 3 +++
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/iov.c b/iov.c
index d3b19e3..0feab8e 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)
diff --git a/qemu-common.h b/qemu-common.h
index cef264c..4cc63e1 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -379,6 +379,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,
--
1.8.0.1
next prev parent reply other threads:[~2012-12-10 13:11 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-10 13:09 [Qemu-devel] [PATCH v6 00/12] virtio: virtio-blk data plane Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 01/12] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 02/12] configure: add CONFIG_VIRTIO_BLK_DATA_PLANE Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 03/12] dataplane: add host memory mapping code Stefan Hajnoczi
2012-12-11 14:13 ` Michael S. Tsirkin
2012-12-11 15:27 ` Stefan Hajnoczi
2012-12-11 15:42 ` Michael S. Tsirkin
2012-12-11 16:32 ` Anthony Liguori
2012-12-11 18:09 ` Michael S. Tsirkin
2012-12-12 15:34 ` Stefan Hajnoczi
2012-12-12 15:49 ` Michael S. Tsirkin
2012-12-14 11:45 ` Stefan Hajnoczi
2012-12-16 16:11 ` Michael S. Tsirkin
2012-12-17 9:09 ` Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 04/12] dataplane: add virtqueue vring code Stefan Hajnoczi
2012-12-11 14:18 ` Michael S. Tsirkin
2012-12-12 15:55 ` Stefan Hajnoczi
2012-12-12 16:32 ` Michael S. Tsirkin
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 05/12] dataplane: add event loop Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 06/12] dataplane: add Linux AIO request queue Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 07/12] iov: add iov_discard_front/back() to remove data Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 08/12] test-iov: add iov_discard_front/back() testcases Stefan Hajnoczi
2012-12-10 13:09 ` Stefan Hajnoczi [this message]
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 10/12] virtio-blk: restore VirtIOBlkConf->config_wce flag Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 11/12] dataplane: add virtio-blk data plane code Stefan Hajnoczi
2012-12-10 13:09 ` [Qemu-devel] [PATCH v6 12/12] virtio-blk: add x-data-plane=on|off performance feature Stefan Hajnoczi
2012-12-16 16:08 ` Michael S. Tsirkin
2012-12-18 14:57 ` Stefan Hajnoczi
2012-12-18 15:22 ` Michael S. Tsirkin
2012-12-20 4:04 ` Rusty Russell
2012-12-10 13:13 ` [Qemu-devel] [PATCH v6 00/12] virtio: virtio-blk data plane Stefan Hajnoczi
2012-12-11 8:53 ` Stefan Hajnoczi
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=1355144985-12897-10-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=asias@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=khoa@us.ibm.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).