thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 0bbe9e3a205c48c32f41ddd79292761cc625c747 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Fri, 13 Dec 2013 13:04:35 +0100
9ae3a8
Subject: [PATCH 23/37] block: Allow wait_serialising_requests() at any point
9ae3a8
9ae3a8
Message-id: <1392117622-28812-24-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 57188
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 23/37] block: Allow wait_serialising_requests() at any point
9ae3a8
Bugzilla: 748906
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
We can only have a single wait_serialising_requests() call per request
9ae3a8
because otherwise we can run into deadlocks where requests are waiting
9ae3a8
for each other. The same is true when wait_serialising_requests() is not
9ae3a8
at the very beginning of a request, so that other requests can be issued
9ae3a8
between the start of the tracking and wait_serialising_requests().
9ae3a8
9ae3a8
Fix this by changing wait_serialising_requests() to ignore requests that
9ae3a8
are already (directly or indirectly) waiting for the calling request.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Benoit Canet <benoit@irqsave.net>
9ae3a8
(cherry picked from commit 6460440f34c709461b84375cfd8a86b27d433225)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	include/block/block_int.h
9ae3a8
9ae3a8
Conflicts because in RHEL 7 BdrvTrackedRequest is in block.c
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block.c | 15 ++++++++++++---
9ae3a8
 1 file changed, 12 insertions(+), 3 deletions(-)
9ae3a8
---
9ae3a8
 block.c |   15 ++++++++++++---
9ae3a8
 1 files changed, 12 insertions(+), 3 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 94fd702..fd37037 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -2047,6 +2047,8 @@ struct BdrvTrackedRequest {
9ae3a8
     QLIST_ENTRY(BdrvTrackedRequest) list;
9ae3a8
     Coroutine *co; /* owner, used for deadlock detection */
9ae3a8
     CoQueue wait_queue; /* coroutines blocked on this request */
9ae3a8
+
9ae3a8
+    struct BdrvTrackedRequest *waiting_for;
9ae3a8
 };
9ae3a8
 
9ae3a8
 /**
9ae3a8
@@ -2176,9 +2178,16 @@ static void coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
9ae3a8
                  */
9ae3a8
                 assert(qemu_coroutine_self() != req->co);
9ae3a8
 
9ae3a8
-                qemu_co_queue_wait(&req->wait_queue);
9ae3a8
-                retry = true;
9ae3a8
-                break;
9ae3a8
+                /* If the request is already (indirectly) waiting for us, or
9ae3a8
+                 * will wait for us as soon as it wakes up, then just go on
9ae3a8
+                 * (instead of producing a deadlock in the former case). */
9ae3a8
+                if (!req->waiting_for) {
9ae3a8
+                    self->waiting_for = req;
9ae3a8
+                    qemu_co_queue_wait(&req->wait_queue);
9ae3a8
+                    self->waiting_for = NULL;
9ae3a8
+                    retry = true;
9ae3a8
+                    break;
9ae3a8
+                }
9ae3a8
             }
9ae3a8
         }
9ae3a8
     } while (retry);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8