Blame SOURCES/kvm-migration-Don-t-activate-block-devices-if-using-S.patch

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