[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 19/24] block: Allow wait_serialising_requests() a
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v2 19/24] block: Allow wait_serialising_requests() at any point |
Date: |
Fri, 13 Dec 2013 14:22:54 +0100 |
We can only have a single wait_serialising_requests() call per request
because otherwise we can run into deadlocks where requests are waiting
for each other. The same is true when wait_serialising_requests() is not
at the very beginning of a request, so that other requests can be issued
between the start of the tracking and wait_serialising_requests().
Fix this by changing wait_serialising_requests() to ignore requests that
are already (directly or indirectly) waiting for the calling request.
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 26 +++++++++++++++++++++++---
include/block/block_int.h | 2 ++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/block.c b/block.c
index 73bba47..8a0225d 100644
--- a/block.c
+++ b/block.c
@@ -2123,6 +2123,20 @@ static bool tracked_request_overlaps(BdrvTrackedRequest
*req,
return true;
}
+static bool coroutine_fn is_waiting_for(BdrvTrackedRequest *waiting,
+ BdrvTrackedRequest *waited_for)
+{
+ BdrvTrackedRequest *req;
+
+ for (req = waiting; req != NULL; req = req->waiting_for) {
+ if (req == waited_for) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
static void coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
{
BlockDriverState *bs = self->bs;
@@ -2148,9 +2162,15 @@ static void coroutine_fn
wait_serialising_requests(BdrvTrackedRequest *self)
*/
assert(qemu_coroutine_self() != req->co);
- qemu_co_queue_wait(&req->wait_queue);
- retry = true;
- break;
+ /* If the request is already (indircetly) waiting for us, then
+ * just go on instead of producing a deadlock. */
+ if (!is_waiting_for(req, self)) {
+ self->waiting_for = req;
+ qemu_co_queue_wait(&req->wait_queue);
+ self->waiting_for = NULL;
+ retry = true;
+ break;
+ }
}
}
} while (retry);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1aee02b..0f7fcef 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -68,6 +68,8 @@ typedef struct BdrvTrackedRequest {
QLIST_ENTRY(BdrvTrackedRequest) list;
Coroutine *co; /* owner, used for deadlock detection */
CoQueue wait_queue; /* coroutines blocked on this request */
+
+ struct BdrvTrackedRequest *waiting_for;
} BdrvTrackedRequest;
struct BlockDriver {
--
1.8.1.4
- Re: [Qemu-devel] [PATCH v2 09/24] block: Introduce bdrv_aligned_preadv(), (continued)
- [Qemu-devel] [PATCH v2 10/24] block: Introduce bdrv_co_do_preadv(), Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 11/24] block: Introduce bdrv_aligned_pwritev(), Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 12/24] block: write: Handle COR dependency after I/O throttling, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 13/24] block: Introduce bdrv_co_do_pwritev(), Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 14/24] block: Switch BdrvTrackedRequest to byte granularity, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 16/24] block: Make zero-after-EOF work with larger alignment, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 15/24] block: Allow waiting for overlapping requests between begin/end, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 17/24] block: Generalise and optimise COR serialisation, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 19/24] block: Allow wait_serialising_requests() at any point,
Kevin Wolf <=
- [Qemu-devel] [PATCH v2 18/24] block: Make overlap range for serialisation dynamic, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 20/24] block: Align requests in bdrv_co_do_pwritev(), Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 21/24] block: Change coroutine wrapper to byte granularity, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 22/24] block: Make bdrv_pread() a bdrv_prwv_co() wrapper, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 24/24] iscsi: Set bs->request_alignment, Kevin Wolf, 2013/12/13
- [Qemu-devel] [PATCH v2 23/24] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper, Kevin Wolf, 2013/12/13
- Re: [Qemu-devel] [PATCH v2 00/24] block: Support for 512b-on-4k emulatio, Wenchao Xia, 2013/12/26