mirror of https://github.com/xemu-project/xemu.git
block/io: split out bdrv_find_conflicting_request
To be reused in separate. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20201021145859.11201-4-vsementsov@virtuozzo.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
2e36da62cf
commit
3183937ff9
43
block/io.c
43
block/io.c
|
@ -754,43 +754,54 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool coroutine_fn
|
/* Called with self->bs->reqs_lock held */
|
||||||
bdrv_wait_serialising_requests_locked(BlockDriverState *bs,
|
static BdrvTrackedRequest *
|
||||||
BdrvTrackedRequest *self)
|
bdrv_find_conflicting_request(BdrvTrackedRequest *self)
|
||||||
{
|
{
|
||||||
BdrvTrackedRequest *req;
|
BdrvTrackedRequest *req;
|
||||||
bool retry;
|
|
||||||
bool waited = false;
|
|
||||||
|
|
||||||
do {
|
QLIST_FOREACH(req, &self->bs->tracked_requests, list) {
|
||||||
retry = false;
|
|
||||||
QLIST_FOREACH(req, &bs->tracked_requests, list) {
|
|
||||||
if (req == self || (!req->serialising && !self->serialising)) {
|
if (req == self || (!req->serialising && !self->serialising)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tracked_request_overlaps(req, self->overlap_offset,
|
if (tracked_request_overlaps(req, self->overlap_offset,
|
||||||
self->overlap_bytes))
|
self->overlap_bytes))
|
||||||
{
|
{
|
||||||
/* Hitting this means there was a reentrant request, for
|
/*
|
||||||
|
* Hitting this means there was a reentrant request, for
|
||||||
* example, a block driver issuing nested requests. This must
|
* example, a block driver issuing nested requests. This must
|
||||||
* never happen since it means deadlock.
|
* never happen since it means deadlock.
|
||||||
*/
|
*/
|
||||||
assert(qemu_coroutine_self() != req->co);
|
assert(qemu_coroutine_self() != req->co);
|
||||||
|
|
||||||
/* If the request is already (indirectly) waiting for us, or
|
/*
|
||||||
|
* If the request is already (indirectly) waiting for us, or
|
||||||
* will wait for us as soon as it wakes up, then just go on
|
* will wait for us as soon as it wakes up, then just go on
|
||||||
* (instead of producing a deadlock in the former case). */
|
* (instead of producing a deadlock in the former case).
|
||||||
|
*/
|
||||||
if (!req->waiting_for) {
|
if (!req->waiting_for) {
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool coroutine_fn
|
||||||
|
bdrv_wait_serialising_requests_locked(BlockDriverState *bs,
|
||||||
|
BdrvTrackedRequest *self)
|
||||||
|
{
|
||||||
|
BdrvTrackedRequest *req;
|
||||||
|
bool waited = false;
|
||||||
|
|
||||||
|
while ((req = bdrv_find_conflicting_request(self))) {
|
||||||
self->waiting_for = req;
|
self->waiting_for = req;
|
||||||
qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock);
|
qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock);
|
||||||
self->waiting_for = NULL;
|
self->waiting_for = NULL;
|
||||||
retry = true;
|
|
||||||
waited = true;
|
waited = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (retry);
|
|
||||||
return waited;
|
return waited;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue