[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/9] block/io: split out bdrv_find_conflicting_request
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 3/9] block/io: split out bdrv_find_conflicting_request |
Date: |
Fri, 14 Aug 2020 16:03:42 +0300 |
To be reused in separate.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/io.c | 71 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 30 deletions(-)
diff --git a/block/io.c b/block/io.c
index b18680a842..5b96715058 100644
--- a/block/io.c
+++ b/block/io.c
@@ -727,43 +727,54 @@ static bool tracked_request_overlaps(BdrvTrackedRequest
*req,
return true;
}
+/* Called with self->bs->reqs_lock held */
+static BdrvTrackedRequest *
+bdrv_find_conflicting_request(BdrvTrackedRequest *self)
+{
+ BdrvTrackedRequest *req;
+
+ QLIST_FOREACH(req, &self->bs->tracked_requests, list) {
+ if (req == self || (!req->serialising && !self->serialising)) {
+ continue;
+ }
+ if (tracked_request_overlaps(req, self->overlap_offset,
+ self->overlap_bytes))
+ {
+ /*
+ * Hitting this means there was a reentrant request, for
+ * example, a block driver issuing nested requests. This must
+ * never happen since it means deadlock.
+ */
+ assert(qemu_coroutine_self() != req->co);
+
+ /*
+ * If the request is already (indirectly) waiting for us, or
+ * will wait for us as soon as it wakes up, then just go on
+ * (instead of producing a deadlock in the former case).
+ */
+ if (!req->waiting_for) {
+ return req;
+ }
+ }
+ }
+
+ return NULL;
+}
+
static bool coroutine_fn
bdrv_wait_serialising_requests_locked(BlockDriverState *bs,
BdrvTrackedRequest *self)
{
BdrvTrackedRequest *req;
- bool retry;
bool waited = false;
- do {
- retry = false;
- QLIST_FOREACH(req, &bs->tracked_requests, list) {
- if (req == self || (!req->serialising && !self->serialising)) {
- continue;
- }
- if (tracked_request_overlaps(req, self->overlap_offset,
- self->overlap_bytes))
- {
- /* Hitting this means there was a reentrant request, for
- * example, a block driver issuing nested requests. This must
- * never happen since it means deadlock.
- */
- assert(qemu_coroutine_self() != req->co);
-
- /* If the request is already (indirectly) waiting for us, or
- * will wait for us as soon as it wakes up, then just go on
- * (instead of producing a deadlock in the former case). */
- if (!req->waiting_for) {
- self->waiting_for = req;
- qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock);
- self->waiting_for = NULL;
- retry = true;
- waited = true;
- break;
- }
- }
- }
- } while (retry);
+ while ((req = bdrv_find_conflicting_request(self))) {
+ self->waiting_for = req;
+ qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock);
+ self->waiting_for = NULL;
+ waited = true;
+ }
+
return waited;
}
--
2.21.3
- [PATCH v2 0/9] preallocate filter, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 2/9] block/io.c: drop assertion on double waiting for request serialisation, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 3/9] block/io: split out bdrv_find_conflicting_request,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v2 4/9] block/io: bdrv_wait_serialising_requests_locked: drop extra bs arg, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 5/9] block: bdrv_mark_request_serialising: split non-waiting function, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 1/9] block: simplify comment to BDRV_REQ_SERIALISING, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 6/9] block: introduce BDRV_REQ_NO_WAIT flag, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 7/9] block: introduce preallocate filter, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 8/9] iotests.py: add verify_o_direct helper, Vladimir Sementsov-Ogievskiy, 2020/08/14
- [PATCH v2 9/9] iotests: add 298 to test new preallocate filter driver, Vladimir Sementsov-Ogievskiy, 2020/08/14
- Re: [PATCH v2 0/9] preallocate filter, no-reply, 2020/08/14
- Re: [PATCH v2 0/9] preallocate filter, no-reply, 2020/08/14
- DROP Re: [PATCH v2 0/9] preallocate filter, Vladimir Sementsov-Ogievskiy, 2020/08/14