cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Allow-wait_serialising_requests-at-any-point.patch

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