5d360b
From 51568d18bbfef1adce26d8cd33f3f4a4c12b1e78 Mon Sep 17 00:00:00 2001
5d360b
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
5d360b
Date: Fri, 26 Jan 2018 18:53:15 +0100
5d360b
Subject: [PATCH 4/4] savevm: fail if migration blockers are present
5d360b
5d360b
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
5d360b
Message-id: <20180126185315.2342-3-dgilbert@redhat.com>
5d360b
Patchwork-id: 78732
5d360b
O-Subject: [RHEL7.5 qemu-kvm PATCH 2/2] savevm: fail if migration blockers are present
5d360b
Bugzilla: 1536883
5d360b
RH-Acked-by: Peter Xu <peterx@redhat.com>
5d360b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
From: Greg Kurz <gkurz@linux.vnet.ibm.com>
5d360b
5d360b
QEMU has currently two ways to prevent migration to occur:
5d360b
- migration blocker when it depends on runtime state
5d360b
- VMStateDescription.unmigratable when migration is not supported at all
5d360b
5d360b
This patch gathers all the logic into a single function to be called from
5d360b
both the savevm and the migrate paths.
5d360b
5d360b
This fixes a bug with 9p, at least, where savevm would succeed and the
5d360b
following would happen in the guest after loadvm:
5d360b
5d360b
$ ls /host
5d360b
ls: cannot access /host: Protocol error
5d360b
5d360b
With this patch:
5d360b
5d360b
(qemu) savevm foo
5d360b
Migration is disabled when VirtFS export path '/' is mounted in the guest
5d360b
using mount_tag 'host'
5d360b
5d360b
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
5d360b
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
Message-Id: <146239057139.11271.9011797645454781543.stgit@bahia.huguette.org>
5d360b
[Update subject according to Paolo's suggestion - Amit]
5d360b
(cherry picked from commit 24f3902b088cd4f2dbebfd90527b5d81d6a050e9)
5d360b
  dgilbert: Manual merge
5d360b
5d360b
Signed-off-by: Amit Shah <amit.shah@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 include/migration/migration.h |  1 +
5d360b
 migration.c                   | 21 +++++++++++++++------
5d360b
 savevm.c                      |  2 +-
5d360b
 3 files changed, 17 insertions(+), 7 deletions(-)
5d360b
5d360b
diff --git a/include/migration/migration.h b/include/migration/migration.h
5d360b
index c99a67c..0760984 100644
5d360b
--- a/include/migration/migration.h
5d360b
+++ b/include/migration/migration.h
5d360b
@@ -90,6 +90,7 @@ int migrate_fd_close(MigrationState *s);
5d360b
 
5d360b
 void add_migration_state_change_notifier(Notifier *notify);
5d360b
 void remove_migration_state_change_notifier(Notifier *notify);
5d360b
+bool migration_is_blocked(Error **errp);
5d360b
 bool migration_in_setup(MigrationState *);
5d360b
 bool migration_has_finished(MigrationState *);
5d360b
 bool migration_has_failed(MigrationState *);
5d360b
diff --git a/migration.c b/migration.c
5d360b
index e8c5939..5591601 100644
5d360b
--- a/migration.c
5d360b
+++ b/migration.c
5d360b
@@ -417,6 +417,20 @@ void migrate_del_blocker(Error *reason)
5d360b
     migration_blockers = g_slist_remove(migration_blockers, reason);
5d360b
 }
5d360b
 
5d360b
+bool migration_is_blocked(Error **errp)
5d360b
+{
5d360b
+    if (qemu_savevm_state_blocked(errp)) {
5d360b
+        return true;
5d360b
+    }
5d360b
+
5d360b
+    if (migration_blockers) {
5d360b
+        *errp = error_copy(migration_blockers->data);
5d360b
+        return true;
5d360b
+    }
5d360b
+
5d360b
+    return false;
5d360b
+}
5d360b
+
5d360b
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
5d360b
                  bool has_inc, bool inc, bool has_detach, bool detach,
5d360b
                  Error **errp)
5d360b
@@ -447,12 +461,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
5d360b
         return;
5d360b
     }
5d360b
 
5d360b
-    if (qemu_savevm_state_blocked(errp)) {
5d360b
-        return;
5d360b
-    }
5d360b
-
5d360b
-    if (migration_blockers) {
5d360b
-        *errp = error_copy(migration_blockers->data);
5d360b
+    if (migration_is_blocked(errp)) {
5d360b
         return;
5d360b
     }
5d360b
 
5d360b
diff --git a/savevm.c b/savevm.c
5d360b
index d34004e..0216df2 100644
5d360b
--- a/savevm.c
5d360b
+++ b/savevm.c
5d360b
@@ -2207,7 +2207,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
5d360b
         .shared = 0
5d360b
     };
5d360b
 
5d360b
-    if (qemu_savevm_state_blocked(errp)) {
5d360b
+    if (migration_is_blocked(errp)) {
5d360b
         return -EINVAL;
5d360b
     }
5d360b
 
5d360b
-- 
5d360b
1.8.3.1
5d360b