From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kW1-0004uq-ML for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:26:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6kVw-0000Qk-Jh for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:26:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40272) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kVv-0000QK-Jx for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:25:55 -0500 From: Kevin Wolf Date: Fri, 24 Jan 2014 18:22:06 +0100 Message-Id: <1390584136-24703-84-git-send-email-kwolf@redhat.com> In-Reply-To: <1390584136-24703-1-git-send-email-kwolf@redhat.com> References: <1390584136-24703-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 83/93] block: Allow wait_serialising_requests() at any point List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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 Reviewed-by: Max Reitz Reviewed-by: Benoit Canet --- block.c | 13 ++++++++++--- include/block/block_int.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 784ff07..9690585 100644 --- a/block.c +++ b/block.c @@ -2328,9 +2328,16 @@ 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 (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); + self->waiting_for = NULL; + retry = true; + break; + } } } } while (retry); diff --git a/include/block/block_int.h b/include/block/block_int.h index 0ee955c..0bcf1c9 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