mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
qemu iovec: keep track of total size, allow partial copies (Gerd Hoffman)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6448 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
28c699a2b6
commit
249aa745fb
2
block.c
2
block.c
@ -1265,7 +1265,7 @@ static void bdrv_aio_rw_vector_cb(void *opaque, int ret)
|
||||
VectorTranslationState *s = opaque;
|
||||
|
||||
if (!s->is_write) {
|
||||
qemu_iovec_from_buffer(s->iov, s->bounce);
|
||||
qemu_iovec_from_buffer(s->iov, s->bounce, s->iov->size);
|
||||
}
|
||||
qemu_free(s->bounce);
|
||||
s->this_aiocb->cb(s->this_aiocb->opaque, ret);
|
||||
|
15
cutils.c
15
cutils.c
@ -109,6 +109,7 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
|
||||
qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
|
||||
qiov->niov = 0;
|
||||
qiov->nalloc = alloc_hint;
|
||||
qiov->size = 0;
|
||||
}
|
||||
|
||||
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
|
||||
@ -119,6 +120,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
|
||||
}
|
||||
qiov->iov[qiov->niov].iov_base = base;
|
||||
qiov->iov[qiov->niov].iov_len = len;
|
||||
qiov->size += len;
|
||||
++qiov->niov;
|
||||
}
|
||||
|
||||
@ -138,13 +140,18 @@ void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
|
||||
}
|
||||
}
|
||||
|
||||
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf)
|
||||
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
|
||||
{
|
||||
const uint8_t *p = (const uint8_t *)buf;
|
||||
size_t copy;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < qiov->niov; ++i) {
|
||||
memcpy(qiov->iov[i].iov_base, p, qiov->iov[i].iov_len);
|
||||
p += qiov->iov[i].iov_len;
|
||||
for (i = 0; i < qiov->niov && count; ++i) {
|
||||
copy = count;
|
||||
if (copy > qiov->iov[i].iov_len)
|
||||
copy = qiov->iov[i].iov_len;
|
||||
memcpy(qiov->iov[i].iov_base, p, copy);
|
||||
p += copy;
|
||||
count -= copy;
|
||||
}
|
||||
}
|
||||
|
@ -195,13 +195,14 @@ typedef struct QEMUIOVector {
|
||||
struct iovec *iov;
|
||||
int niov;
|
||||
int nalloc;
|
||||
size_t size;
|
||||
} QEMUIOVector;
|
||||
|
||||
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
|
||||
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
|
||||
void qemu_iovec_destroy(QEMUIOVector *qiov);
|
||||
void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
|
||||
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf);
|
||||
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
|
||||
|
||||
#endif /* dyngen-exec.h hack */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user