yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From c9e3d13d70a24bf606ce351886b27bdca25ef4dc Mon Sep 17 00:00:00 2001
ddf19c
From: Juan Quintela <quintela@redhat.com>
ddf19c
Date: Tue, 3 Mar 2020 14:51:41 +0000
ddf19c
Subject: [PATCH 09/18] migration: Create migration_is_running()
ddf19c
ddf19c
RH-Author: Juan Quintela <quintela@redhat.com>
ddf19c
Message-id: <20200303145143.149290-9-quintela@redhat.com>
ddf19c
Patchwork-id: 94115
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 08/10] migration: Create migration_is_running()
ddf19c
Bugzilla: 1738451
ddf19c
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ddf19c
RH-Acked-by: Peter Xu <peterx@redhat.com>
ddf19c
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
ddf19c
This function returns true if we are in the middle of a migration.
ddf19c
It is like migration_is_setup_or_active() with CANCELLING and COLO.
ddf19c
Adapt all callers that are needed.
ddf19c
ddf19c
Signed-off-by: Juan Quintela <quintela@redhat.com>
ddf19c
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit 392d87e21325fdb01210176faa07472b4985ccf0)
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 migration/migration.c | 29 ++++++++++++++++++++++++-----
ddf19c
 migration/migration.h |  1 +
ddf19c
 migration/savevm.c    |  4 +---
ddf19c
 3 files changed, 26 insertions(+), 8 deletions(-)
ddf19c
ddf19c
diff --git a/migration/migration.c b/migration/migration.c
ddf19c
index 30c53c6..eb50d77 100644
ddf19c
--- a/migration/migration.c
ddf19c
+++ b/migration/migration.c
ddf19c
@@ -831,6 +831,27 @@ bool migration_is_setup_or_active(int state)
ddf19c
     }
ddf19c
 }
ddf19c
 
ddf19c
+bool migration_is_running(int state)
ddf19c
+{
ddf19c
+    switch (state) {
ddf19c
+    case MIGRATION_STATUS_ACTIVE:
ddf19c
+    case MIGRATION_STATUS_POSTCOPY_ACTIVE:
ddf19c
+    case MIGRATION_STATUS_POSTCOPY_PAUSED:
ddf19c
+    case MIGRATION_STATUS_POSTCOPY_RECOVER:
ddf19c
+    case MIGRATION_STATUS_SETUP:
ddf19c
+    case MIGRATION_STATUS_PRE_SWITCHOVER:
ddf19c
+    case MIGRATION_STATUS_DEVICE:
ddf19c
+    case MIGRATION_STATUS_WAIT_UNPLUG:
ddf19c
+    case MIGRATION_STATUS_CANCELLING:
ddf19c
+    case MIGRATION_STATUS_COLO:
ddf19c
+        return true;
ddf19c
+
ddf19c
+    default:
ddf19c
+        return false;
ddf19c
+
ddf19c
+    }
ddf19c
+}
ddf19c
+
ddf19c
 static void populate_time_info(MigrationInfo *info, MigrationState *s)
ddf19c
 {
ddf19c
     info->has_status = true;
ddf19c
@@ -1090,7 +1111,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
ddf19c
     MigrationCapabilityStatusList *cap;
ddf19c
     bool cap_list[MIGRATION_CAPABILITY__MAX];
ddf19c
 
ddf19c
-    if (migration_is_setup_or_active(s->state)) {
ddf19c
+    if (migration_is_running(s->state)) {
ddf19c
         error_setg(errp, QERR_MIGRATION_ACTIVE);
ddf19c
         return;
ddf19c
     }
ddf19c
@@ -1603,7 +1624,7 @@ static void migrate_fd_cancel(MigrationState *s)
ddf19c
 
ddf19c
     do {
ddf19c
         old_state = s->state;
ddf19c
-        if (!migration_is_setup_or_active(old_state)) {
ddf19c
+        if (!migration_is_running(old_state)) {
ddf19c
             break;
ddf19c
         }
ddf19c
         /* If the migration is paused, kick it out of the pause */
ddf19c
@@ -1900,9 +1921,7 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
ddf19c
         return true;
ddf19c
     }
ddf19c
 
ddf19c
-    if (migration_is_setup_or_active(s->state) ||
ddf19c
-        s->state == MIGRATION_STATUS_CANCELLING ||
ddf19c
-        s->state == MIGRATION_STATUS_COLO) {
ddf19c
+    if (migration_is_running(s->state)) {
ddf19c
         error_setg(errp, QERR_MIGRATION_ACTIVE);
ddf19c
         return false;
ddf19c
     }
ddf19c
diff --git a/migration/migration.h b/migration/migration.h
ddf19c
index 0b1b0d4..a2b2336 100644
ddf19c
--- a/migration/migration.h
ddf19c
+++ b/migration/migration.h
ddf19c
@@ -279,6 +279,7 @@ void migrate_fd_error(MigrationState *s, const Error *error);
ddf19c
 void migrate_fd_connect(MigrationState *s, Error *error_in);
ddf19c
 
ddf19c
 bool migration_is_setup_or_active(int state);
ddf19c
+bool migration_is_running(int state);
ddf19c
 
ddf19c
 void migrate_init(MigrationState *s);
ddf19c
 bool migration_is_blocked(Error **errp);
ddf19c
diff --git a/migration/savevm.c b/migration/savevm.c
ddf19c
index a80bb52..144ecf0 100644
ddf19c
--- a/migration/savevm.c
ddf19c
+++ b/migration/savevm.c
ddf19c
@@ -1506,9 +1506,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
ddf19c
     MigrationState *ms = migrate_get_current();
ddf19c
     MigrationStatus status;
ddf19c
 
ddf19c
-    if (migration_is_setup_or_active(ms->state) ||
ddf19c
-        ms->state == MIGRATION_STATUS_CANCELLING ||
ddf19c
-        ms->state == MIGRATION_STATUS_COLO) {
ddf19c
+    if (migration_is_running(ms->state)) {
ddf19c
         error_setg(errp, QERR_MIGRATION_ACTIVE);
ddf19c
         return -EINVAL;
ddf19c
     }
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c