[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 09/31] qed: Make qed_write_header() synchronous
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 09/31] qed: Make qed_write_header() synchronous |
Date: |
Fri, 16 Jun 2017 19:36:54 +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 | 76 +++++++++++++++++++++++--------------------------------------
1 file changed, 29 insertions(+), 47 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index 658b31b..2665efc 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -92,41 +92,6 @@ int qed_write_header_sync(BDRVQEDState *s)
return 0;
}
-typedef struct {
- GenericCB gencb;
- BDRVQEDState *s;
- struct iovec iov;
- QEMUIOVector qiov;
- int nsectors;
- uint8_t *buf;
-} QEDWriteHeaderCB;
-
-static void qed_write_header_cb(void *opaque, int ret)
-{
- QEDWriteHeaderCB *write_header_cb = opaque;
-
- qemu_vfree(write_header_cb->buf);
- gencb_complete(write_header_cb, ret);
-}
-
-static void qed_write_header_read_cb(void *opaque, int ret)
-{
- QEDWriteHeaderCB *write_header_cb = opaque;
- BDRVQEDState *s = write_header_cb->s;
-
- if (ret) {
- qed_write_header_cb(write_header_cb, ret);
- return;
- }
-
- /* Update header */
- qed_header_cpu_to_le(&s->header, (QEDHeader *)write_header_cb->buf);
-
- bdrv_aio_writev(s->bs->file, 0, &write_header_cb->qiov,
- write_header_cb->nsectors, qed_write_header_cb,
- write_header_cb);
-}
-
/**
* Update header in-place (does not rewrite backing filename or other strings)
*
@@ -144,18 +109,35 @@ static void qed_write_header(BDRVQEDState *s,
BlockCompletionFunc cb,
int nsectors = DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE);
size_t len = nsectors * BDRV_SECTOR_SIZE;
- QEDWriteHeaderCB *write_header_cb = gencb_alloc(sizeof(*write_header_cb),
- cb, opaque);
-
- write_header_cb->s = s;
- write_header_cb->nsectors = nsectors;
- write_header_cb->buf = qemu_blockalign(s->bs, len);
- write_header_cb->iov.iov_base = write_header_cb->buf;
- write_header_cb->iov.iov_len = len;
- qemu_iovec_init_external(&write_header_cb->qiov, &write_header_cb->iov, 1);
-
- bdrv_aio_readv(s->bs->file, 0, &write_header_cb->qiov, nsectors,
- qed_write_header_read_cb, write_header_cb);
+ uint8_t *buf;
+ struct iovec iov;
+ QEMUIOVector qiov;
+ int ret;
+
+ buf = qemu_blockalign(s->bs, len);
+ iov = (struct iovec) {
+ .iov_base = buf,
+ .iov_len = len,
+ };
+ qemu_iovec_init_external(&qiov, &iov, 1);
+
+ ret = bdrv_preadv(s->bs->file, 0, &qiov);
+ if (ret < 0) {
+ goto out;
+ }
+
+ /* Update header */
+ qed_header_cpu_to_le(&s->header, (QEDHeader *) buf);
+
+ ret = bdrv_pwritev(s->bs->file, 0, &qiov);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = 0;
+out:
+ qemu_vfree(buf);
+ cb(opaque, ret);
}
static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_size)
--
1.8.3.1
- [Qemu-block] [PATCH v2 00/31] qed: Convert to coroutines, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 01/31] qed: Use bottom half to resume waiting requests, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 02/31] qed: Make qed_read_table() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 03/31] qed: Remove callback from qed_read_table(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 06/31] qed: Make qed_read_backing_file() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 05/31] qed: Remove callback from qed_find_cluster(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 04/31] qed: Remove callback from qed_read_l2_table(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 07/31] qed: Make qed_copy_from_backing_file() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 08/31] qed: Remove callback from qed_copy_from_backing_file(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 09/31] qed: Make qed_write_header() synchronous,
Kevin Wolf <=
- [Qemu-block] [PATCH v2 10/31] qed: Remove callback from qed_write_header(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 11/31] qed: Make qed_write_table() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 12/31] qed: Remove GenericCB, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 13/31] qed: Remove callback from qed_write_table(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 16/31] qed: Inline qed_commit_l2_update(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 14/31] qed: Make qed_aio_read_data() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 17/31] qed: Add return value to qed_aio_write_l1_update(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 15/31] qed: Make qed_aio_write_main() synchronous, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 18/31] qed: Add return value to qed_aio_write_l2_update(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 19/31] qed: Add return value to qed_aio_write_main(), Kevin Wolf, 2017/06/16