26ba25
From 1669a71fd8a4bd570f09fc2df67279d6936cc5ad Mon Sep 17 00:00:00 2001
26ba25
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
26ba25
Date: Fri, 22 Jun 2018 19:00:03 +0200
26ba25
Subject: [PATCH 15/21] migration: Don't activate block devices if using -S
26ba25
26ba25
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
26ba25
Message-id: <20180801135522.11658-17-dgilbert@redhat.com>
26ba25
Patchwork-id: 81576
26ba25
O-Subject: [qemu-kvm RHEL8/virt212 PATCH 16/18] migration: Don't activate block devices if using -S
26ba25
Bugzilla: 1594384
26ba25
RH-Acked-by: Peter Xu <peterx@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Juan Quintela <quintela@redhat.com>
26ba25
26ba25
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
26ba25
26ba25
Activating the block devices causes the locks to be taken on
26ba25
the backing file.  If we're running with -S and the destination libvirt
26ba25
hasn't started the destination with 'cont', it's expecting the locks are
26ba25
still untaken.
26ba25
26ba25
Don't activate the block devices if we're not going to autostart the VM;
26ba25
'cont' already will do that anyway.   This change is tied to the new
26ba25
migration capability 'late-block-activate' that defaults to off, keeping
26ba25
the old behaviour by default.
26ba25
26ba25
bz: https://bugzilla.redhat.com/show_bug.cgi?id=1560854
26ba25
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
26ba25
Reviewed-by: Juan Quintela <quintela@redhat.com>
26ba25
Signed-off-by: Juan Quintela <quintela@redhat.com>
26ba25
(cherry picked from commit 0f073f44df109ea0910d67caede70dec95956ff6)
26ba25
---
26ba25
 migration/migration.c | 34 +++++++++++++++++++++++++++-------
26ba25
 qapi/migration.json   |  5 ++++-
26ba25
 2 files changed, 31 insertions(+), 8 deletions(-)
26ba25
26ba25
diff --git a/migration/migration.c b/migration/migration.c
26ba25
index b6294f6..edf1c06 100644
26ba25
--- a/migration/migration.c
26ba25
+++ b/migration/migration.c
26ba25
@@ -199,6 +199,16 @@ static void migrate_generate_event(int new_state)
26ba25
     }
26ba25
 }
26ba25
 
26ba25
+static bool migrate_late_block_activate(void)
26ba25
+{
26ba25
+    MigrationState *s;
26ba25
+
26ba25
+    s = migrate_get_current();
26ba25
+
26ba25
+    return s->enabled_capabilities[
26ba25
+        MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
26ba25
+}
26ba25
+
26ba25
 /*
26ba25
  * Called on -incoming with a defer: uri.
26ba25
  * The migration can be started later after any parameters have been
26ba25
@@ -308,13 +318,23 @@ static void process_incoming_migration_bh(void *opaque)
26ba25
     Error *local_err = NULL;
26ba25
     MigrationIncomingState *mis = opaque;
26ba25
 
26ba25
-    /* Make sure all file formats flush their mutable metadata.
26ba25
-     * If we get an error here, just don't restart the VM yet. */
26ba25
-    bdrv_invalidate_cache_all(&local_err);
26ba25
-    if (local_err) {
26ba25
-        error_report_err(local_err);
26ba25
-        local_err = NULL;
26ba25
-        autostart = false;
26ba25
+    /* If capability late_block_activate is set:
26ba25
+     * Only fire up the block code now if we're going to restart the
26ba25
+     * VM, else 'cont' will do it.
26ba25
+     * This causes file locking to happen; so we don't want it to happen
26ba25
+     * unless we really are starting the VM.
26ba25
+     */
26ba25
+    if (!migrate_late_block_activate() ||
26ba25
+         (autostart && (!global_state_received() ||
26ba25
+            global_state_get_runstate() == RUN_STATE_RUNNING))) {
26ba25
+        /* Make sure all file formats flush their mutable metadata.
26ba25
+         * If we get an error here, just don't restart the VM yet. */
26ba25
+        bdrv_invalidate_cache_all(&local_err);
26ba25
+        if (local_err) {
26ba25
+            error_report_err(local_err);
26ba25
+            local_err = NULL;
26ba25
+            autostart = false;
26ba25
+        }
26ba25
     }
26ba25
 
26ba25
     /*
26ba25
diff --git a/qapi/migration.json b/qapi/migration.json
26ba25
index 9d0bf82..618d2de 100644
26ba25
--- a/qapi/migration.json
26ba25
+++ b/qapi/migration.json
26ba25
@@ -357,13 +357,16 @@
26ba25
 # @dirty-bitmaps: If enabled, QEMU will migrate named dirty bitmaps.
26ba25
 #                 (since 2.12)
26ba25
 #
26ba25
+# @late-block-activate: If enabled, the destination will not activate block
26ba25
+#           devices (and thus take locks) immediately at the end of migration.
26ba25
+#           (since 3.0)
26ba25
 # Since: 1.2
26ba25
 ##
26ba25
 { 'enum': 'MigrationCapability',
26ba25
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
26ba25
            'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram',
26ba25
            'block', 'return-path', 'pause-before-switchover', 'x-multifd',
26ba25
-           'dirty-bitmaps' ] }
26ba25
+           'dirty-bitmaps', 'late-block-activate' ] }
26ba25
 
26ba25
 ##
26ba25
 # @MigrationCapabilityStatus:
26ba25
-- 
26ba25
1.8.3.1
26ba25