26ba25
From dcfa2a8c812791ab69e0ac9656fc3613d750e00d Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Tue, 26 Jun 2018 09:48:24 +0200
26ba25
Subject: [PATCH 116/268] block: Cancel job in bdrv_close_all() callers
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20180626094856.6924-42-kwolf@redhat.com>
26ba25
Patchwork-id: 81098
26ba25
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 41/73] block: Cancel job in bdrv_close_all() callers
26ba25
Bugzilla: 1513543
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Fam Zheng <famz@redhat.com>
26ba25
26ba25
Now that we cancel all jobs and not only block jobs on shutdown, doing
26ba25
that in bdrv_close_all() isn't really appropriate any more. Move the
26ba25
job_cancel_sync_all() call to the callers, and only assert that there
26ba25
are no job running in bdrv_close_all().
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit b3b5299d58bce4366c647af40374e6b063f371eb)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block.c    | 4 +---
26ba25
 qemu-nbd.c | 8 +++++++-
26ba25
 vl.c       | 1 +
26ba25
 3 files changed, 9 insertions(+), 4 deletions(-)
26ba25
26ba25
diff --git a/block.c b/block.c
26ba25
index a83787f..afe30ca 100644
26ba25
--- a/block.c
26ba25
+++ b/block.c
26ba25
@@ -3374,9 +3374,7 @@ static void bdrv_close(BlockDriverState *bs)
26ba25
 
26ba25
 void bdrv_close_all(void)
26ba25
 {
26ba25
-    /* TODO We do want to cancel all jobs instead of just block jobs on
26ba25
-     * shutdown, but bdrv_close_all() isn't the right place any more. */
26ba25
-    job_cancel_sync_all();
26ba25
+    assert(job_next(NULL) == NULL);
26ba25
     nbd_export_close_all();
26ba25
 
26ba25
     /* Drop references from requests still in flight, such as canceled block
26ba25
diff --git a/qemu-nbd.c b/qemu-nbd.c
26ba25
index 0af0560..51b9d38 100644
26ba25
--- a/qemu-nbd.c
26ba25
+++ b/qemu-nbd.c
26ba25
@@ -482,6 +482,12 @@ static const char *socket_activation_validate_opts(const char *device,
26ba25
     return NULL;
26ba25
 }
26ba25
 
26ba25
+static void qemu_nbd_shutdown(void)
26ba25
+{
26ba25
+    job_cancel_sync_all();
26ba25
+    bdrv_close_all();
26ba25
+}
26ba25
+
26ba25
 int main(int argc, char **argv)
26ba25
 {
26ba25
     BlockBackend *blk;
26ba25
@@ -928,7 +934,7 @@ int main(int argc, char **argv)
26ba25
         exit(EXIT_FAILURE);
26ba25
     }
26ba25
     bdrv_init();
26ba25
-    atexit(bdrv_close_all);
26ba25
+    atexit(qemu_nbd_shutdown);
26ba25
 
26ba25
     srcpath = argv[optind];
26ba25
     if (imageOpts) {
26ba25
diff --git a/vl.c b/vl.c
26ba25
index ce7d04d..f253876 100644
26ba25
--- a/vl.c
26ba25
+++ b/vl.c
26ba25
@@ -4766,6 +4766,7 @@ int main(int argc, char **argv, char **envp)
26ba25
     /* No more vcpu or device emulation activity beyond this point */
26ba25
     vm_shutdown();
26ba25
 
26ba25
+    job_cancel_sync_all();
26ba25
     bdrv_close_all();
26ba25
 
26ba25
     res_free();
26ba25
-- 
26ba25
1.8.3.1
26ba25