aboutsummaryrefslogtreecommitdiff
path: root/migration
diff options
context:
space:
mode:
authorYury Kotov <yury-kotov@yandex-team.ru>2019-09-03 19:22:44 +0300
committerDr. David Alan Gilbert <dgilbert@redhat.com>2019-09-12 11:19:23 +0100
commitb9d68df62a1340529f7eef251353d2040c66f403 (patch)
tree570b847641e32e8b56889da237e364de658e33ac /migration
parent3b348706729c2154aae78f593b682d960bfb5930 (diff)
migration: Add validate-uuid capability
This capability realizes simple source validation by UUID. It's useful for live migration between hosts. Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru> Message-Id: <20190903162246.18524-2-yury-kotov@yandex-team.ru> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'migration')
-rw-r--r--migration/migration.c9
-rw-r--r--migration/migration.h1
-rw-r--r--migration/savevm.c45
3 files changed, 55 insertions, 0 deletions
diff --git a/migration/migration.c b/migration/migration.c
index 8b9f2fe30a..2391a8d418 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2140,6 +2140,15 @@ bool migrate_ignore_shared(void)
return s->enabled_capabilities[MIGRATION_CAPABILITY_X_IGNORE_SHARED];
}
+bool migrate_validate_uuid(void)
+{
+ MigrationState *s;
+
+ s = migrate_get_current();
+
+ return s->enabled_capabilities[MIGRATION_CAPABILITY_VALIDATE_UUID];
+}
+
bool migrate_use_events(void)
{
MigrationState *s;
diff --git a/migration/migration.h b/migration/migration.h
index 3e1ea2b5dc..4f2fe193dc 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -290,6 +290,7 @@ bool migrate_postcopy_ram(void);
bool migrate_zero_blocks(void);
bool migrate_dirty_bitmaps(void);
bool migrate_ignore_shared(void);
+bool migrate_validate_uuid(void);
bool migrate_auto_converge(void);
bool migrate_use_multifd(void);
diff --git a/migration/savevm.c b/migration/savevm.c
index 3454bc937e..ee06f91d42 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -256,6 +256,7 @@ typedef struct SaveState {
uint32_t target_page_bits;
uint32_t caps_count;
MigrationCapability *capabilities;
+ QemuUUID uuid;
} SaveState;
static SaveState savevm_state = {
@@ -307,6 +308,7 @@ static int configuration_pre_save(void *opaque)
state->capabilities[j++] = i;
}
}
+ state->uuid = qemu_uuid;
return 0;
}
@@ -464,6 +466,48 @@ static const VMStateDescription vmstate_capabilites = {
}
};
+static bool vmstate_uuid_needed(void *opaque)
+{
+ return qemu_uuid_set && migrate_validate_uuid();
+}
+
+static int vmstate_uuid_post_load(void *opaque, int version_id)
+{
+ SaveState *state = opaque;
+ char uuid_src[UUID_FMT_LEN + 1];
+ char uuid_dst[UUID_FMT_LEN + 1];
+
+ if (!qemu_uuid_set) {
+ /*
+ * It's warning because user might not know UUID in some cases,
+ * e.g. load an old snapshot
+ */
+ qemu_uuid_unparse(&state->uuid, uuid_src);
+ warn_report("UUID is received %s, but local uuid isn't set",
+ uuid_src);
+ return 0;
+ }
+ if (!qemu_uuid_is_equal(&state->uuid, &qemu_uuid)) {
+ qemu_uuid_unparse(&state->uuid, uuid_src);
+ qemu_uuid_unparse(&qemu_uuid, uuid_dst);
+ error_report("UUID received is %s and local is %s", uuid_src, uuid_dst);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static const VMStateDescription vmstate_uuid = {
+ .name = "configuration/uuid",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .needed = vmstate_uuid_needed,
+ .post_load = vmstate_uuid_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT8_ARRAY_V(uuid.data, SaveState, sizeof(QemuUUID), 1),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static const VMStateDescription vmstate_configuration = {
.name = "configuration",
.version_id = 1,
@@ -478,6 +522,7 @@ static const VMStateDescription vmstate_configuration = {
.subsections = (const VMStateDescription*[]) {
&vmstate_target_page_bits,
&vmstate_capabilites,
+ &vmstate_uuid,
NULL
}
};