[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 31/61] qed: Make qed_copy_from_backing_file() synchro
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 31/61] qed: Make qed_copy_from_backing_file() synchronous |
Date: |
Fri, 23 Jun 2017 18:21:29 +0200 |
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/qed.c | 78 +++++++++++++++++++++++--------------------------------------
1 file 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);
}
/**
--
1.8.3.1
- [Qemu-block] [PULL 21/61] qcow2: Allow reading both COW regions with only one request, (continued)
- [Qemu-block] [PULL 21/61] qcow2: Allow reading both COW regions with only one request, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 22/61] qcow2: Pass a QEMUIOVector to do_perform_cow_{read, write}(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 26/61] qed: Make qed_read_table() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 24/61] qcow2: Use offset_into_cluster() and offset_to_l2_index(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 25/61] qed: Use bottom half to resume waiting requests, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 27/61] qed: Remove callback from qed_read_table(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 23/61] qcow2: Merge the writing of the COW regions with the guest data, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 28/61] qed: Remove callback from qed_read_l2_table(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 29/61] qed: Remove callback from qed_find_cluster(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 30/61] qed: Make qed_read_backing_file() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 31/61] qed: Make qed_copy_from_backing_file() synchronous,
Kevin Wolf <=
- [Qemu-block] [PULL 33/61] qed: Make qed_write_header() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 32/61] qed: Remove callback from qed_copy_from_backing_file(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 34/61] qed: Remove callback from qed_write_header(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 37/61] qed: Remove callback from qed_write_table(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 38/61] qed: Make qed_aio_read_data() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 40/61] qed: Inline qed_commit_l2_update(), Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 39/61] qed: Make qed_aio_write_main() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 35/61] qed: Make qed_write_table() synchronous, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 36/61] qed: Remove GenericCB, Kevin Wolf, 2017/06/23
- [Qemu-block] [PULL 42/61] qed: Add return value to qed_aio_write_l2_update(), Kevin Wolf, 2017/06/23