Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 30

kvm-83-164.el5_5.9.src.rpm

From 014f9f7f0185808ade539d14d28387f9afa64a05 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Sun, 21 Dec 2008 15:06:58 +0200
Subject: [PATCH 29/54] qemu: rtc: Use async notifications for time change messages

If "notify rtc on" is issued on the monitor, RTC change events will be
shown on the monitor, prefixed with the '#' character.

[ehabkost: original term_printf() patch from Dan Kenigsberg folded
           onto this patch. original description follows]

> qemu: notify management of rtc changes
>
> Real machines keep their time even when their are off. Virtual machines
> should do them same.
>
> Long time ago on qemu-devel, and more recently here, some said that this
> should be done by implementing bios non-volatile ram. Until that
> happens, the following patch delivers the goods.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Upstream-status: pending
---
 qemu/console.h        |    3 ++-
 qemu/hw/mc146818rtc.c |   12 ++++++++++++
 qemu/monitor.c        |    4 +++-
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/qemu/console.h b/qemu/console.h
index bc7750b..ff04790 100644
--- a/qemu/console.h
+++ b/qemu/console.h
@@ -189,7 +189,8 @@ void curses_display_init(DisplayState *ds, int full_screen);
 extern uint8_t _translate_keycode(const int key);
 
 #define VNC_ASYNC_EVENT   1
-#define MAX_ASYNC_EVENTS  VNC_ASYNC_EVENT
+#define RTC_ASYNC_EVENT   2
+#define MAX_ASYNC_EVENTS  RTC_ASYNC_EVENT
 
 /* FIXME: term_printf et al should probably go elsewhere so everything
    does not need to include console.h  */
diff --git a/qemu/hw/mc146818rtc.c b/qemu/hw/mc146818rtc.c
index faf847d..65456e4 100644
--- a/qemu/hw/mc146818rtc.c
+++ b/qemu/hw/mc146818rtc.c
@@ -27,6 +27,7 @@
 #include "pc.h"
 #include "isa.h"
 #include "hpet_emul.h"
+#include "console.h"
 
 //#define DEBUG_CMOS
 
@@ -217,6 +218,17 @@ static void rtc_set_time(RTCState *s)
     tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
     tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
     tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
+    {   /* notify monitoring software of the change */
+        int rtc_ti;
+
+        /* rtc_utc is now declared static. just assume -localtime */
+        /* if (rtc_utc)
+            rtc_ti = timegm(tm);
+        else */
+            rtc_ti = mktime(tm);
+            term_printf_async(RTC_ASYNC_EVENT,
+			      "RTC: new time is UTC%+d\n", rtc_ti - time(NULL));
+    }
 }
 
 static void rtc_copy_date(RTCState *s)
diff --git a/qemu/monitor.c b/qemu/monitor.c
index 8418236..0046980 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -249,6 +249,8 @@ static void do_notify_async_events(char *event_str, char *enable)
 
     if (!strcmp(event_str, "vnc"))
         event = VNC_ASYNC_EVENT;
+    else if (!strcmp(event_str, "rtc"))
+        event = RTC_ASYNC_EVENT;
     else
         return;
 
@@ -1607,7 +1609,7 @@ static term_cmd_t term_cmds[] = {
     { "set_qxl_log_level", "i", qxl_do_set_log_level, "", "set qxl log level" },
 #endif
     { "notify", "ss", do_notify_async_events,
-      "vnc on|off", "enable / disable printing of notifications for the specified event" },
+      "vnc|rtc on|off", "enable / disable printing of notifications for the specified event" },
     { NULL, NULL, },
 };
 
-- 
1.6.1