Blame SOURCES/kvm-migration-Change-SaveStateEntry.instance_id-into-uin.patch

22c213
From 38a032829b6b8d523b4cee05f732031e66fc2e41 Mon Sep 17 00:00:00 2001
22c213
From: Peter Xu <peterx@redhat.com>
22c213
Date: Fri, 31 Jan 2020 17:12:56 +0000
22c213
Subject: [PATCH 14/15] migration: Change SaveStateEntry.instance_id into
22c213
 uint32_t
22c213
22c213
RH-Author: Peter Xu <peterx@redhat.com>
22c213
Message-id: <20200131171257.1066593-3-peterx@redhat.com>
22c213
Patchwork-id: 93629
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 2/3] migration: Change SaveStateEntry.instance_id into uint32_t
22c213
Bugzilla: 1529231
22c213
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
22c213
RH-Acked-by: Juan Quintela <quintela@redhat.com>
22c213
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
22c213
It was always used as 32bit, so define it as used to be clear.
22c213
Instead of using -1 as the auto-gen magic value, we switch to
22c213
UINT32_MAX.  We also make sure that we don't auto-gen this value to
22c213
avoid overflowed instance IDs without being noticed.
22c213
22c213
Suggested-by: Juan Quintela <quintela@redhat.com>
22c213
Signed-off-by: Peter Xu <peterx@redhat.com>
22c213
Reviewed-by: Juan Quintela <quintela@redhat.com>
22c213
Signed-off-by: Juan Quintela <quintela@redhat.com>
22c213
(cherry picked from commit 93062e23619e057743757ee53bf7f8e07f7a3710)
22c213
Signed-off-by: Peter Xu <peterx@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
22c213
Conflicts:
22c213
  include/migration/vmstate.h
22c213
  migration/savevm.c
22c213
  stubs/vmstate.c
22c213
    Due to missing 3cad405bab ("vmstate: replace DeviceState with
22c213
    VMStateIf", 2020-01-06)
22c213
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 hw/intc/apic_common.c        |  2 +-
22c213
 include/migration/register.h |  2 +-
22c213
 include/migration/vmstate.h  |  2 +-
22c213
 migration/savevm.c           | 18 ++++++++++--------
22c213
 stubs/vmstate.c              |  2 +-
22c213
 5 files changed, 14 insertions(+), 12 deletions(-)
22c213
22c213
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
22c213
index f2c3a7f..54b8731 100644
22c213
--- a/hw/intc/apic_common.c
22c213
+++ b/hw/intc/apic_common.c
22c213
@@ -268,7 +268,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp)
22c213
     APICCommonState *s = APIC_COMMON(dev);
22c213
     APICCommonClass *info;
22c213
     static DeviceState *vapic;
22c213
-    int instance_id = s->id;
22c213
+    uint32_t instance_id = s->id;
22c213
 
22c213
     info = APIC_COMMON_GET_CLASS(s);
22c213
     info->realize(dev, errp);
22c213
diff --git a/include/migration/register.h b/include/migration/register.h
22c213
index a13359a..f3ba10b 100644
22c213
--- a/include/migration/register.h
22c213
+++ b/include/migration/register.h
22c213
@@ -69,7 +69,7 @@ typedef struct SaveVMHandlers {
22c213
 } SaveVMHandlers;
22c213
 
22c213
 int register_savevm_live(const char *idstr,
22c213
-                         int instance_id,
22c213
+                         uint32_t instance_id,
22c213
                          int version_id,
22c213
                          const SaveVMHandlers *ops,
22c213
                          void *opaque);
22c213
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
22c213
index 883f1cf..296609c 100644
22c213
--- a/include/migration/vmstate.h
22c213
+++ b/include/migration/vmstate.h
22c213
@@ -1158,7 +1158,7 @@ bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
22c213
 #define  VMSTATE_INSTANCE_ID_ANY  -1
22c213
 
22c213
 /* Returns: 0 on success, -1 on failure */
22c213
-int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
22c213
+int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id,
22c213
                                    const VMStateDescription *vmsd,
22c213
                                    void *base, int alias_id,
22c213
                                    int required_for_version,
22c213
diff --git a/migration/savevm.c b/migration/savevm.c
22c213
index e2e8e0a..a80bb52 100644
22c213
--- a/migration/savevm.c
22c213
+++ b/migration/savevm.c
22c213
@@ -233,7 +233,7 @@ typedef struct CompatEntry {
22c213
 typedef struct SaveStateEntry {
22c213
     QTAILQ_ENTRY(SaveStateEntry) entry;
22c213
     char idstr[256];
22c213
-    int instance_id;
22c213
+    uint32_t instance_id;
22c213
     int alias_id;
22c213
     int version_id;
22c213
     /* version id read from the stream */
22c213
@@ -665,10 +665,10 @@ void dump_vmstate_json_to_file(FILE *out_file)
22c213
     fclose(out_file);
22c213
 }
22c213
 
22c213
-static int calculate_new_instance_id(const char *idstr)
22c213
+static uint32_t calculate_new_instance_id(const char *idstr)
22c213
 {
22c213
     SaveStateEntry *se;
22c213
-    int instance_id = 0;
22c213
+    uint32_t instance_id = 0;
22c213
 
22c213
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
22c213
         if (strcmp(idstr, se->idstr) == 0
22c213
@@ -676,6 +676,8 @@ static int calculate_new_instance_id(const char *idstr)
22c213
             instance_id = se->instance_id + 1;
22c213
         }
22c213
     }
22c213
+    /* Make sure we never loop over without being noticed */
22c213
+    assert(instance_id != VMSTATE_INSTANCE_ID_ANY);
22c213
     return instance_id;
22c213
 }
22c213
 
22c213
@@ -730,7 +732,7 @@ static void savevm_state_handler_insert(SaveStateEntry *nse)
22c213
    Meanwhile pass -1 as instance_id if you do not already have a clearly
22c213
    distinguishing id for all instances of your device class. */
22c213
 int register_savevm_live(const char *idstr,
22c213
-                         int instance_id,
22c213
+                         uint32_t instance_id,
22c213
                          int version_id,
22c213
                          const SaveVMHandlers *ops,
22c213
                          void *opaque)
22c213
@@ -784,7 +786,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
22c213
     }
22c213
 }
22c213
 
22c213
-int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
22c213
+int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id,
22c213
                                    const VMStateDescription *vmsd,
22c213
                                    void *opaque, int alias_id,
22c213
                                    int required_for_version,
22c213
@@ -1600,7 +1602,7 @@ int qemu_save_device_state(QEMUFile *f)
22c213
     return qemu_file_get_error(f);
22c213
 }
22c213
 
22c213
-static SaveStateEntry *find_se(const char *idstr, int instance_id)
22c213
+static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id)
22c213
 {
22c213
     SaveStateEntry *se;
22c213
 
22c213
@@ -2267,7 +2269,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
22c213
     /* Find savevm section */
22c213
     se = find_se(idstr, instance_id);
22c213
     if (se == NULL) {
22c213
-        error_report("Unknown savevm section or instance '%s' %d. "
22c213
+        error_report("Unknown savevm section or instance '%s' %"PRIu32". "
22c213
                      "Make sure that your current VM setup matches your "
22c213
                      "saved VM setup, including any hotplugged devices",
22c213
                      idstr, instance_id);
22c213
@@ -2291,7 +2293,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
22c213
 
22c213
     ret = vmstate_load(f, se);
22c213
     if (ret < 0) {
22c213
-        error_report("error while loading state for instance 0x%x of"
22c213
+        error_report("error while loading state for instance 0x%"PRIx32" of"
22c213
                      " device '%s'", instance_id, idstr);
22c213
         return ret;
22c213
     }
22c213
diff --git a/stubs/vmstate.c b/stubs/vmstate.c
22c213
index e1e89b8..4ed5cc6 100644
22c213
--- a/stubs/vmstate.c
22c213
+++ b/stubs/vmstate.c
22c213
@@ -4,7 +4,7 @@
22c213
 const VMStateDescription vmstate_dummy = {};
22c213
 
22c213
 int vmstate_register_with_alias_id(DeviceState *dev,
22c213
-                                   int instance_id,
22c213
+                                   uint32_t instance_id,
22c213
                                    const VMStateDescription *vmsd,
22c213
                                    void *base, int alias_id,
22c213
                                    int required_for_version,
22c213
-- 
22c213
1.8.3.1
22c213