[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 20/31] qed: Add return value to qed_aio_write_cow
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 20/31] qed: Add return value to qed_aio_write_cow() |
Date: |
Fri, 16 Jun 2017 19:37:05 +0200 |
Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but
just return an error code and let the caller handle it.
While refactoring qed_aio_write_alloc() to accomodate the change,
qed_aio_write_zero_cluster() ended up with a single line, so I chose to
inline that line and remove the function completely.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/qed.c | 58 +++++++++++++++++++++-------------------------------------
1 file changed, 21 insertions(+), 37 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index a4b13f8..84864e0 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1065,11 +1065,11 @@ static int qed_aio_write_main(QEDAIOCB *acb)
/**
* Populate untouched regions of new data cluster
*/
-static void qed_aio_write_cow(void *opaque, int ret)
+static int qed_aio_write_cow(QEDAIOCB *acb)
{
- QEDAIOCB *acb = opaque;
BDRVQEDState *s = acb_to_s(acb);
uint64_t start, len, offset;
+ int ret;
/* Populate front untouched region of new data cluster */
start = qed_start_of_cluster(s, acb->cur_pos);
@@ -1077,9 +1077,8 @@ static void qed_aio_write_cow(void *opaque, int ret)
trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster);
ret = qed_copy_from_backing_file(s, start, len, acb->cur_cluster);
- if (ret) {
- qed_aio_complete(acb, ret);
- return;
+ if (ret < 0) {
+ return ret;
}
/* Populate back untouched region of new data cluster */
@@ -1091,17 +1090,11 @@ static void qed_aio_write_cow(void *opaque, int ret)
trace_qed_aio_write_postfill(s, acb, start, len, offset);
ret = qed_copy_from_backing_file(s, start, len, offset);
- if (ret) {
- qed_aio_complete(acb, ret);
- return;
- }
-
- ret = qed_aio_write_main(acb);
if (ret < 0) {
- qed_aio_complete(acb, ret);
- return;
+ return ret;
}
- qed_aio_next_io(acb, 0);
+
+ return qed_aio_write_main(acb);
}
/**
@@ -1117,23 +1110,6 @@ static bool qed_should_set_need_check(BDRVQEDState *s)
return !(s->header.features & QED_F_NEED_CHECK);
}
-static void qed_aio_write_zero_cluster(void *opaque, int ret)
-{
- QEDAIOCB *acb = opaque;
-
- if (ret) {
- qed_aio_complete(acb, ret);
- return;
- }
-
- ret = qed_aio_write_l2_update(acb, 1);
- if (ret < 0) {
- qed_aio_complete(acb, ret);
- return;
- }
- qed_aio_next_io(acb, 0);
-}
-
/**
* Write new data cluster
*
@@ -1145,7 +1121,6 @@ static void qed_aio_write_zero_cluster(void *opaque, int
ret)
static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len)
{
BDRVQEDState *s = acb_to_s(acb);
- BlockCompletionFunc *cb;
int ret;
/* Cancel timer when the first allocating request comes in */
@@ -1172,20 +1147,29 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t
len)
qed_aio_start_io(acb);
return;
}
-
- cb = qed_aio_write_zero_cluster;
} else {
- cb = qed_aio_write_cow;
acb->cur_cluster = qed_alloc_clusters(s, acb->cur_nclusters);
}
if (qed_should_set_need_check(s)) {
s->header.features |= QED_F_NEED_CHECK;
ret = qed_write_header(s);
- cb(acb, ret);
+ if (ret < 0) {
+ qed_aio_complete(acb, ret);
+ return;
+ }
+ }
+
+ if (acb->flags & QED_AIOCB_ZERO) {
+ ret = qed_aio_write_l2_update(acb, 1);
} else {
- cb(acb, 0);
+ ret = qed_aio_write_cow(acb);
}
+ if (ret < 0) {
+ qed_aio_complete(acb, ret);
+ return;
+ }
+ qed_aio_next_io(acb, 0);
}
/**
--
1.8.3.1
- [Qemu-block] [PATCH v2 10/31] qed: Remove callback from qed_write_header(), (continued)
- [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
- [Qemu-block] [PATCH v2 20/31] qed: Add return value to qed_aio_write_cow(),
Kevin Wolf <=
- [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
- [Qemu-block] [PATCH v2 27/31] qed: Simplify request handling, Kevin Wolf, 2017/06/16
- [Qemu-block] [PATCH v2 30/31] qed: Use bdrv_co_* for coroutine_fns, Kevin Wolf, 2017/06/16