diff mbox series

[V9,25/46] cpr: only-cpr-capable

Message ID 1658851843-236870-26-git-send-email-steven.sistare@oracle.com
State New
Headers show
Series Live Update | expand

Commit Message

Steve Sistare July 26, 2022, 4:10 p.m. UTC
Add the only-cpr-capable option, which causes qemu to exit with an error
if any devices that are not capable of cpr are added.  This guarantees that
the migrate commanmd will not fail due to a blocker.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/migration/cpr.h |  2 ++
 migration/migration.c   | 13 +++++++++++++
 qemu-options.hx         |  8 ++++++++
 softmmu/vl.c            |  4 ++++
 4 files changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index c48be2d..f2dfb1b 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -8,6 +8,8 @@ 
 #ifndef MIGRATION_CPR_H
 #define MIGRATION_CPR_H
 
+#define CPR_MODES     (BIT(MIG_MODE_CPR_REBOOT) | BIT(MIG_MODE_CPR_EXEC))
+
 extern bool only_cpr_capable;
 
 void cpr_init(void);
diff --git a/migration/migration.c b/migration/migration.c
index 7b46213..e0fc2b8 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2181,6 +2181,11 @@  bool migrate_mode_enabled(MigMode mode)
     return !!(migrate_enabled_modes & BIT(mode));
 }
 
+static bool migrate_modes_enabled(int modes)
+{
+    return (modes & migrate_enabled_modes) == modes;
+}
+
 static int migrate_check_enabled(Error **errp)
 {
     MigMode mode = migrate_mode();
@@ -2262,6 +2267,14 @@  static int check_blockers(Error **reasonp, Error **errp, int modes)
         return -EACCES;
     }
 
+    if (only_cpr_capable && (modes & CPR_MODES) &&
+        migrate_modes_enabled(modes & CPR_MODES)) {
+        error_propagate_prepend(errp, *reasonp,
+                                "-only-cpr-capable specified, but: ");
+        *reasonp = NULL;
+        return -EACCES;
+    }
+
     return add_blockers(reasonp, errp, modes);
 }
 
diff --git a/qemu-options.hx b/qemu-options.hx
index 7797d3d..3ed9270 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4501,6 +4501,14 @@  SRST
     migration using any mode except 'normal'.
 ERST
 
+DEF("only-cpr-capable", 0, QEMU_OPTION_only_cpr_capable, \
+    "-only-cpr-capable    allow only cpr capable devices\n", QEMU_ARCH_ALL)
+SRST
+``-only-cpr-capable``
+    Only allow cpr capable devices, which guarantees that cpr will not
+    fail due to a cpr blocker.
+ERST
+
 DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \
     "-nodefaults     don't create default devices\n", QEMU_ARCH_ALL)
 SRST
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 5f6cd8c..bed147c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -77,6 +77,7 @@ 
 #include "hw/block/block.h"
 #include "hw/i386/x86.h"
 #include "hw/i386/pc.h"
+#include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration/snapshot.h"
 #include "sysemu/tpm.h"
@@ -3366,6 +3367,9 @@  void qemu_init(int argc, char **argv, char **envp)
             case QEMU_OPTION_only_migratable:
                 only_migratable = 1;
                 break;
+            case QEMU_OPTION_only_cpr_capable:
+                only_cpr_capable = true;
+                break;
             case QEMU_OPTION_migrate_mode_enable:
                 migrate_enable_mode(qapi_enum_parse(&MigMode_lookup, optarg, -1,
                                                     &error_fatal));