From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>
Subject: [Qemu-devel] [PATCH 09/18] iov: add qemu_iovec_concat_iov()
Date: Wed, 19 Dec 2012 16:38:10 +0100 [thread overview]
Message-ID: <1355931499-7912-10-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1355931499-7912-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 e674786..2492189 100644
--- a/qemu-common.h
+++ b/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,
--
1.8.0.2
next prev parent reply other threads:[~2012-12-19 15:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 15:38 [Qemu-devel] [PULL 00/18] Block patches Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 01/18] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 02/18] configure: add CONFIG_VIRTIO_BLK_DATA_PLANE Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 03/18] dataplane: add host memory mapping code Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 04/18] dataplane: add virtqueue vring code Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 05/18] dataplane: add event loop Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 06/18] dataplane: add Linux AIO request queue Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 07/18] iov: add iov_discard_front/back() to remove data Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 08/18] test-iov: add iov_discard_front/back() testcases Stefan Hajnoczi
2012-12-19 15:38 ` Stefan Hajnoczi [this message]
2012-12-19 15:38 ` [Qemu-devel] [PATCH 10/18] virtio-blk: restore VirtIOBlkConf->config_wce flag Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 11/18] dataplane: add virtio-blk data plane code Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 12/18] virtio-blk: add x-data-plane=on|off performance feature Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 13/18] virtio-blk: Return UNSUPP for unknown request types Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 14/18] cutils: change strtosz_suffix_unit function Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 15/18] qemu-img: report size overflow error message Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 16/18] block/raw-win32: Fix compiler warnings (wrong format specifiers) Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 17/18] sheepdog: don't update inode when create_and_write fails Stefan Hajnoczi
2012-12-19 15:38 ` [Qemu-devel] [PATCH 18/18] sheepdog: pass oid directly to send_pending_req() Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2013-01-02 15:15 [Qemu-devel] [PULL v2 00/18] Block patches Stefan Hajnoczi
2013-01-02 15:15 ` [Qemu-devel] [PATCH 09/18] iov: add qemu_iovec_concat_iov() 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=1355931499-7912-10-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.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).