qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 7/7] RTC:Allow to migrate from old version
@ 2012-03-19  6:14 Zhang, Yang Z
  2012-03-19 10:56 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang, Yang Z @ 2012-03-19  6:14 UTC (permalink / raw)
  To: qemu-devel@nongnu.org
  Cc: Paolo Bonzini, aliguori@us.ibm.com, kvm@vger.kernel.org

The new logic is compatible with old. So it should not block migrate from old version. But new version cannot migrate to old.

Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
---
 hw/mc146818rtc.c |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index c03606f..61ac3c3 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -827,11 +827,51 @@ 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;
+
+    if (version_id > 2) {
+        return -EINVAL;
+    }
+
+    qemu_get_buffer(f, s->cmos_data, sizeof(s->cmos_data));
+    /* dummy load for compatibility */
+    qemu_get_byte(f); /* cmos_index */
+    qemu_get_be32(f); /* tm_sec */
+    qemu_get_be32(f); /* tm_min */
+    qemu_get_be32(f); /* tm_hour */
+    qemu_get_be32(f); /* tm_wday */
+    qemu_get_be32(f); /* tm_mday */
+    qemu_get_be32(f); /* tm_mon */
+    qemu_get_be32(f); /* tm_year */
+    qemu_get_be64(f); /* periodic_timer */
+    qemu_get_be64(f); /* next_periodic_time */
+    qemu_get_be64(f); /* next_second_time */
+    qemu_get_be64(f); /* second_timer */
+    qemu_get_be64(f); /* second_timer2 */
+    qemu_get_be32(f); /* irq_coalesced */
+    qemu_get_be32(f); /* period */
+
+
+    rtc_set_date_from_host(&s->dev);
+    periodic_timer_update(s,  qemu_get_clock_ns(rtc_clock));
+    check_update_timer(s);
+
+#ifdef TARGET_I386
+    if (s->lost_tick_policy == LOST_TICK_SLEW) {
+        rtc_coalesced_timer_update(s);
+    }
+#endif
+    return 0;
+}
+
 static const VMStateDescription vmstate_rtc = {
     .name = "mc146818rtc",
-    .version_id = 2,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
+    .version_id = 3,
+    .minimum_version_id = 3,
+    .minimum_version_id_old = 2,
+    .load_state_old = rtc_load_old,
     .post_load = rtc_post_load,
     .fields      = (VMStateField []) {
         VMSTATE_BUFFER(cmos_data, RTCState),
@@ -969,7 +1009,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",
--
1.7.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/7] RTC:Allow to migrate from old version
  2012-03-19  6:14 [Qemu-devel] [PATCH v4 7/7] RTC:Allow to migrate from old version Zhang, Yang Z
@ 2012-03-19 10:56 ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2012-03-19 10:56 UTC (permalink / raw)
  To: Zhang, Yang Z
  Cc: Paolo Bonzini, aliguori@us.ibm.com, qemu-devel@nongnu.org,
	kvm@vger.kernel.org

On 03/19/2012 08:14 AM, Zhang, Yang Z wrote:
> The new logic is compatible with old. So it should not block migrate from old version. But new version cannot migrate to old.
>
> +static int rtc_load_old(QEMUFile *f, void *opaque, int version_id)
> +{
> +    RTCState *s = opaque;
> +
> +    if (version_id > 2) {
> +        return -EINVAL;
> +    }
> +
> +    qemu_get_buffer(f, s->cmos_data, sizeof(s->cmos_data));
> +    /* dummy load for compatibility */
> +    qemu_get_byte(f); /* cmos_index */
> +    qemu_get_be32(f); /* tm_sec */
> +    qemu_get_be32(f); /* tm_min */
> +    qemu_get_be32(f); /* tm_hour */
> +    qemu_get_be32(f); /* tm_wday */
> +    qemu_get_be32(f); /* tm_mday */
> +    qemu_get_be32(f); /* tm_mon */
> +    qemu_get_be32(f); /* tm_year */
> +    qemu_get_be64(f); /* periodic_timer */
> +    qemu_get_be64(f); /* next_periodic_time */
> +    qemu_get_be64(f); /* next_second_time */
> +    qemu_get_be64(f); /* second_timer */
> +    qemu_get_be64(f); /* second_timer2 */
> +    qemu_get_be32(f); /* irq_coalesced */
> +    qemu_get_be32(f); /* period */
> +

Why don't you just convert the data to the new in-memory format?  Then
you don't need a version update.

> +
> +    rtc_set_date_from_host(&s->dev);

If the guest is intentionally running with an incorrect date, this breaks.


-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-19 10:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-19  6:14 [Qemu-devel] [PATCH v4 7/7] RTC:Allow to migrate from old version Zhang, Yang Z
2012-03-19 10:56 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).