From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Christoph Hellwig <hch@lst.de>, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCH 3/7] cutils: qemu_iovec_copy and qemu_iovec_memset
Date: Thu, 23 Sep 2010 16:41:50 +0100 [thread overview]
Message-ID: <1285256514-21138-4-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1285256514-21138-1-git-send-email-stefanha@linux.vnet.ibm.com>
From: Kevin Wolf <kwolf@redhat.com>
This adds two functions that work on QEMUIOVectors and will be used by the next
qcow2 patches.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
Kevin already has this queued up for mainline. QED uses qemu_iovec_memset().
cutils.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
qemu-common.h | 3 +++
2 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/cutils.c b/cutils.c
index 76f7501..de00472 100644
--- a/cutils.c
+++ b/cutils.c
@@ -168,30 +168,50 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
}
/*
- * Copies iovecs from src to the end dst until src is completely copied or the
- * total size of the copied iovec reaches size. The size of the last copied
- * iovec is changed in order to fit the specified total size if it isn't a
- * perfect fit already.
+ * Copies iovecs from src to the end of dst. It starts copying after skipping
+ * the given number of bytes in src and copies until src is completely copied
+ * or the total size of the copied iovec reaches size.The size of the last
+ * copied iovec is changed in order to fit the specified total size if it isn't
+ * a perfect fit already.
*/
-void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size)
+void qemu_iovec_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip,
+ size_t size)
{
int i;
size_t done;
+ void *iov_base;
+ uint64_t iov_len;
assert(dst->nalloc != -1);
done = 0;
for (i = 0; (i < src->niov) && (done != size); i++) {
- if (done + src->iov[i].iov_len > size) {
- qemu_iovec_add(dst, src->iov[i].iov_base, size - done);
+ if (skip >= src->iov[i].iov_len) {
+ /* Skip the whole iov */
+ skip -= src->iov[i].iov_len;
+ continue;
+ } else {
+ /* Skip only part (or nothing) of the iov */
+ iov_base = (uint8_t*) src->iov[i].iov_base + skip;
+ iov_len = src->iov[i].iov_len - skip;
+ skip = 0;
+ }
+
+ if (done + iov_len > size) {
+ qemu_iovec_add(dst, iov_base, size - done);
break;
} else {
- qemu_iovec_add(dst, src->iov[i].iov_base, src->iov[i].iov_len);
+ qemu_iovec_add(dst, iov_base, iov_len);
}
- done += src->iov[i].iov_len;
+ done += iov_len;
}
}
+void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size)
+{
+ qemu_iovec_copy(dst, src, 0, size);
+}
+
void qemu_iovec_destroy(QEMUIOVector *qiov)
{
assert(qiov->nalloc != -1);
@@ -234,6 +254,18 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
}
}
+void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count)
+{
+ size_t n;
+ int i;
+
+ for (i = 0; i < qiov->niov && count; ++i) {
+ n = MIN(count, qiov->iov[i].iov_len);
+ memset(qiov->iov[i].iov_base, c, n);
+ count -= n;
+ }
+}
+
#ifndef _WIN32
/* Sets a specific flag */
int fcntl_setfl(int fd, int flag)
diff --git a/qemu-common.h b/qemu-common.h
index e0900b8..0404817 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -280,11 +280,14 @@ typedef struct QEMUIOVector {
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
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_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip,
+ size_t size);
void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
void qemu_iovec_destroy(QEMUIOVector *qiov);
void qemu_iovec_reset(QEMUIOVector *qiov);
void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
+void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count);
struct Monitor;
typedef struct Monitor Monitor;
--
1.7.1
next prev parent reply other threads:[~2010-09-23 15:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 15:41 [Qemu-devel] [PATCH 0/7] qed: Add QEMU Enhanced Disk format Stefan Hajnoczi
2010-09-23 15:41 ` [Qemu-devel] [PATCH 1/7] qcow2: Make get_bits_from_size() common Stefan Hajnoczi
2010-09-23 21:50 ` malc
2010-09-24 8:37 ` Stefan Hajnoczi
2010-09-24 12:56 ` [Qemu-devel] " Paolo Bonzini
2010-09-24 14:18 ` Stefan Hajnoczi
2010-09-23 15:41 ` [Qemu-devel] [PATCH 2/7] cutils: Add bytes_to_str() to format byte values Stefan Hajnoczi
2010-09-23 15:41 ` Stefan Hajnoczi [this message]
2010-09-23 15:41 ` [Qemu-devel] [PATCH 4/7] qed: Add QEMU Enhanced Disk image format Stefan Hajnoczi
2010-09-23 15:41 ` [Qemu-devel] [PATCH 5/7] qed: Table, L2 cache, and cluster functions Stefan Hajnoczi
2010-09-23 15:41 ` [Qemu-devel] [PATCH 6/7] qed: Read/write support Stefan Hajnoczi
2010-09-27 10:12 ` Avi Kivity
2010-09-27 10:19 ` Stefan Hajnoczi
2010-09-23 15:41 ` [Qemu-devel] [PATCH 7/7] qed: Consistency check support Stefan Hajnoczi
2010-09-27 9:58 ` [Qemu-devel] [PATCH 0/7] qed: Add QEMU Enhanced Disk format Avi Kivity
2010-09-27 10:13 ` Avi Kivity
2010-09-27 10:15 ` 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=1285256514-21138-4-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=hch@lst.de \
--cc=kwolf@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).