Patchwork [10/10] RTC: Allow to migrate from old QEMU

login
register
mail settings
Submitter Paolo Bonzini
Date Aug. 1, 2012, 4:41 p.m.
Message ID <1343839312-24030-11-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/174530/
State New
Headers show

Comments

Paolo Bonzini - Aug. 1, 2012, 4:41 p.m.
From: Yang Zhang <yang.z.zhang@intel.com>

The new logic is compatible with old, and it should not block migration
from old QEMU.  However, the new version cannot migrate to the old one.

Cc: Juan Quintela <quintela@redhat.com>
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/mc146818rtc.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 57a481a..0d7c6f4 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -697,11 +697,47 @@  static int rtc_post_load(void *opaque, int version_id)
     return 0;
 }
 
+static int rtc_load_old(QEMUFile *f, void *opaque, int version_id)
+{
+    RTCState *s = opaque;
+    uint8_t buf[77];
+
+    if (version_id > 2) {
+        return -EINVAL;
+    }
+
+    qemu_get_buffer(f, s->cmos_data, sizeof(s->cmos_data));
+    qemu_get_8s(f, &s->cmos_index);
+
+    /* We used to store a struct tm, but we already have the information
+     * in cmos_data.
+     */
+    qemu_get_buffer(f, buf, 7*4);
+
+    qemu_get_timer(f, s->periodic_timer);
+    s->next_periodic_time = qemu_get_be64(f);
+
+    /* Skip loading of next_second_time, second_timer, second_timer2.  */
+    qemu_get_buffer(f, buf, 3*8);
+
+    rtc_set_time(s);
+    s->offset = 0;
+    check_update_timer(s);
+
+    if (version_id >= 2) {
+        s->irq_coalesced = qemu_get_be32(f);
+        s->period = qemu_get_be32(f);
+    }
+
+    return rtc_post_load(opaque, version_id);
+}
+
 static const VMStateDescription vmstate_rtc = {
     .name = "mc146818rtc",
     .version_id = 3,
     .minimum_version_id = 3,
-    .minimum_version_id_old = 3,
+    .minimum_version_id_old = 1,
+    .load_state_old = rtc_load_old,
     .post_load = rtc_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_BUFFER(cmos_data, RTCState),
@@ -825,7 +861,7 @@  static int rtc_initfn(ISADevice *dev)
     memory_region_init_io(&s->io, &cmos_ops, s, "rtc", 2);
     isa_register_ioport(dev, &s->io, base);
 
-    qdev_set_legacy_instance_id(&dev->qdev, base, 2);
+    qdev_set_legacy_instance_id(&dev->qdev, base, 3);
     qemu_register_reset(rtc_reset, s);
 
     object_property_add(OBJECT(s), "date", "struct tm",