[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 15/31] qed: Make qed_aio_write_main() synchronous
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 15/31] qed: Make qed_aio_write_main() synchronous |
Date: |
Fri, 16 Jun 2017 19:37:00 +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: Stefan Hajnoczi <address@hidden>
---
block/qed.c | 61 +++++++++++++++++++------------------------------------------
1 file changed, 19 insertions(+), 42 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index cfebbae..d164b0e 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -260,13 +260,6 @@ static void qed_aio_start_io(QEDAIOCB *acb)
qed_aio_next_io(acb, 0);
}
-static void qed_aio_next_io_cb(void *opaque, int ret)
-{
- QEDAIOCB *acb = opaque;
-
- qed_aio_next_io(acb, ret);
-}
-
static void qed_plug_allocating_write_reqs(BDRVQEDState *s)
{
assert(!s->allocating_write_reqs_plugged);
@@ -1042,31 +1035,6 @@ err:
qed_aio_complete(acb, ret);
}
-static void qed_aio_write_l2_update_cb(void *opaque, int ret)
-{
- QEDAIOCB *acb = opaque;
- qed_aio_write_l2_update(acb, ret, acb->cur_cluster);
-}
-
-/**
- * Flush new data clusters before updating the L2 table
- *
- * This flush is necessary when a backing file is in use. A crash during an
- * allocating write could result in empty clusters in the image. If the write
- * only touched a subregion of the cluster, then backing image sectors have
- * been lost in the untouched region. The solution is to flush after writing a
- * new data cluster and before updating the L2 table.
- */
-static void qed_aio_write_flush_before_l2_update(void *opaque, int ret)
-{
- QEDAIOCB *acb = opaque;
- BDRVQEDState *s = acb_to_s(acb);
-
- if (!bdrv_aio_flush(s->bs->file->bs, qed_aio_write_l2_update_cb, opaque)) {
- qed_aio_complete(acb, -EIO);
- }
-}
-
/**
* Write data to the image file
*/
@@ -1076,7 +1044,6 @@ static void qed_aio_write_main(void *opaque, int ret)
BDRVQEDState *s = acb_to_s(acb);
uint64_t offset = acb->cur_cluster +
qed_offset_into_cluster(s, acb->cur_pos);
- BlockCompletionFunc *next_fn;
trace_qed_aio_write_main(s, acb, ret, offset, acb->cur_qiov.size);
@@ -1085,20 +1052,30 @@ static void qed_aio_write_main(void *opaque, int ret)
return;
}
+ BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
+ ret = bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov);
+ if (ret >= 0) {
+ ret = 0;
+ }
+
if (acb->find_cluster_ret == QED_CLUSTER_FOUND) {
- next_fn = qed_aio_next_io_cb;
+ qed_aio_next_io(acb, ret);
} else {
if (s->bs->backing) {
- next_fn = qed_aio_write_flush_before_l2_update;
- } else {
- next_fn = qed_aio_write_l2_update_cb;
+ /*
+ * Flush new data clusters before updating the L2 table
+ *
+ * This flush is necessary when a backing file is in use. A crash
+ * during an allocating write could result in empty clusters in the
+ * image. If the write only touched a subregion of the cluster,
+ * then backing image sectors have been lost in the untouched
+ * region. The solution is to flush after writing a new data
+ * cluster and before updating the L2 table.
+ */
+ ret = bdrv_flush(s->bs->file->bs);
}
+ qed_aio_write_l2_update(acb, ret, acb->cur_cluster);
}
-
- BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO);
- bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE,
- &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE,
- next_fn, acb);
}
/**
--
1.8.3.1
- [Qemu-block] [PATCH v2 07/31] qed: Make qed_copy_from_backing_file() synchronous, (continued)
- [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, 2017/06/16
- [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 <=
- [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
- [Qemu-block] [PATCH v2 20/31] qed: Add return value to qed_aio_write_cow(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 21/31] qed: Add return value to qed_aio_write_inplace/alloc(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 22/31] qed: Add return value to qed_aio_read/write_data(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 23/31] qed: Remove ret argument from qed_aio_next_io(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 24/31] qed: Remove recursion in qed_aio_next_io(), Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 25/31] qed: Implement .bdrv_co_readv/writev, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 26/31] qed: Use CoQueue for serialising allocations, Kevin Wolf, 2017/06/16