As we are going to use the QEMU machine UUID to identify a LUO session,
reject cpr-luo when the machine UUID is not explicitly set or is the nil
UUID.

Validate this when cpr-luo mode is selected and also immediately before
starting migration.

(qemu) migrate_set_parameter mode cpr-luo
Error: cpr-luo requires a non-null machine UUID

So far, this commit has no effect because migrate_mode_is_cpr() does not
include cpr-luo. Add cpr-luo to migrate_mode_is_cpr() in a later commit,
when cpr-luo is fully supported.

Signed-off-by: Dongli Zhang <[email protected]>
---
There is a duplicate check for cpr-exec mode. I may remove it and send the
change as an independent patchset.

 include/system/system.h | 2 ++
 migration/migration.c   | 6 ++++++
 migration/options.c     | 6 ++++++
 system/globals.c        | 5 +++++
 4 files changed, 19 insertions(+)

diff --git a/include/system/system.h b/include/system/system.h
index 03a2d0e900..bd3fd24cbc 100644
--- a/include/system/system.h
+++ b/include/system/system.h
@@ -13,6 +13,8 @@ extern const char *qemu_name;
 extern QemuUUID qemu_uuid;
 extern bool qemu_uuid_set;
 
+bool qemu_machine_uuid_is_set(void);
+
 const char *qemu_get_vm_name(void);
 
 /* Exit notifiers will run with BQL held. */
diff --git a/migration/migration.c b/migration/migration.c
index fab7949fe1..6a51f212ca 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2090,6 +2090,12 @@ static bool migrate_prepare(MigrationState *s, bool 
resume, Error **errp)
             error_setg(errp, "Parameter 'cpr-exec-command' required for 
cpr-exec");
             return false;
         }
+
+        if (migrate_mode() == MIG_MODE_CPR_LUO &&
+            !qemu_machine_uuid_is_set()) {
+            error_setg(errp, "cpr-luo requires a non-null machine UUID");
+            return false;
+        }
     }
 
     if (migrate_init(s, errp)) {
diff --git a/migration/options.c b/migration/options.c
index 46d040fc3f..7d3504a100 100644
--- a/migration/options.c
+++ b/migration/options.c
@@ -27,6 +27,7 @@
 #include "qobject/qdict.h"
 #include "qobject/qnull.h"
 #include "system/runstate.h"
+#include "system/system.h"
 #include "migration/colo.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
@@ -1402,6 +1403,11 @@ bool migrate_params_check(MigrationParameters *params, 
Error **errp)
         return false;
     }
 
+    if (params->mode == MIG_MODE_CPR_LUO && !qemu_machine_uuid_is_set()) {
+        error_setg(errp, "cpr-luo requires a non-null machine UUID");
+        return false;
+    }
+
     return true;
 }
 
diff --git a/system/globals.c b/system/globals.c
index 34fd3ce9c7..d57011d168 100644
--- a/system/globals.c
+++ b/system/globals.c
@@ -67,6 +67,11 @@ int only_migratable; /* turn it off unless user states 
otherwise */
 QemuUUID qemu_uuid;
 bool qemu_uuid_set;
 
+bool qemu_machine_uuid_is_set(void)
+{
+    return qemu_uuid_set && !qemu_uuid_is_null(&qemu_uuid);
+}
+
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_DISABLED;
 bool xen_domid_restrict;
-- 
2.43.5


Reply via email to