diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-11-14 14:56:32 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-06-26 14:51:14 +0200 |
commit | 0f7aa24d2ccfa8c6a1894c50e46c1f300d7e6db0 (patch) | |
tree | 1342d900e07ce15ecd2da7e10ad12c4fe0806e7d | |
parent | e85c5281426364f9c499cd4b71ec6dea20c5b4b2 (diff) | |
download | qemu-0f7aa24d2ccfa8c6a1894c50e46c1f300d7e6db0.zip qemu-0f7aa24d2ccfa8c6a1894c50e46c1f300d7e6db0.tar.gz qemu-0f7aa24d2ccfa8c6a1894c50e46c1f300d7e6db0.tar.bz2 |
qed: Make qed_copy_from_backing_file() synchronous
Note that this code is generally not running in coroutine context, so
this is an actual blocking synchronous operation. We'll fix this in a
moment.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r-- | block/qed.c | 78 |
1 files changed, 29 insertions, 49 deletions
diff --git a/block/qed.c b/block/qed.c index 1105f19..af53b8f 100644 --- a/block/qed.c +++ b/block/qed.c @@ -854,44 +854,6 @@ static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos, return 0; } -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - QEMUIOVector qiov; - QEMUIOVector *backing_qiov; - struct iovec iov; - uint64_t offset; -} CopyFromBackingFileCB; - -static void qed_copy_from_backing_file_cb(void *opaque, int ret) -{ - CopyFromBackingFileCB *copy_cb = opaque; - qemu_vfree(copy_cb->iov.iov_base); - gencb_complete(©_cb->gencb, ret); -} - -static void qed_copy_from_backing_file_write(void *opaque, int ret) -{ - CopyFromBackingFileCB *copy_cb = opaque; - BDRVQEDState *s = copy_cb->s; - - if (copy_cb->backing_qiov) { - qemu_iovec_destroy(copy_cb->backing_qiov); - g_free(copy_cb->backing_qiov); - copy_cb->backing_qiov = NULL; - } - - if (ret) { - qed_copy_from_backing_file_cb(copy_cb, ret); - return; - } - - BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE); - bdrv_aio_writev(s->bs->file, copy_cb->offset / BDRV_SECTOR_SIZE, - ©_cb->qiov, copy_cb->qiov.size / BDRV_SECTOR_SIZE, - qed_copy_from_backing_file_cb, copy_cb); -} - /** * Copy data from backing file into the image * @@ -907,7 +869,9 @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, BlockCompletionFunc *cb, void *opaque) { - CopyFromBackingFileCB *copy_cb; + QEMUIOVector qiov; + QEMUIOVector *backing_qiov = NULL; + struct iovec iov; int ret; /* Skip copy entirely if there is no work to do */ @@ -916,17 +880,33 @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, return; } - copy_cb = gencb_alloc(sizeof(*copy_cb), cb, opaque); - copy_cb->s = s; - copy_cb->offset = offset; - copy_cb->backing_qiov = NULL; - copy_cb->iov.iov_base = qemu_blockalign(s->bs, len); - copy_cb->iov.iov_len = len; - qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1); + iov = (struct iovec) { + .iov_base = qemu_blockalign(s->bs, len), + .iov_len = len, + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + ret = qed_read_backing_file(s, pos, &qiov, &backing_qiov); + + if (backing_qiov) { + qemu_iovec_destroy(backing_qiov); + g_free(backing_qiov); + backing_qiov = NULL; + } + + if (ret) { + goto out; + } - ret = qed_read_backing_file(s, pos, ©_cb->qiov, - ©_cb->backing_qiov); - qed_copy_from_backing_file_write(copy_cb, ret); + BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE); + ret = bdrv_pwritev(s->bs->file, offset, &qiov); + if (ret < 0) { + goto out; + } + ret = 0; +out: + qemu_vfree(iov.iov_base); + cb(opaque, ret); } /** |