[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH xeniface] Set local time to UTC if Windows has "RealTimeIsUniversal"



Commit 3b8723b1 "Set VM's time based on host's time exposed by Xen"
modified the guest agent to adjust Xen time to UTC before setting the
system time (i.e. the emulated RTC) if a vendor specific registry value
was set.

Windows' idea of whether the RTC is programmed in UTC is actually
controlled by:

[HKLM\System\CurrentControlSet\Control\TimeZoneInformation]
DWORD:RealTimeIsUniversal

If this value is present and non-zero then the RTC is set in UTC otherwise
it is in local time. So, there is no need for a vendor specific key.

This patch removes use of the vendor specific key and checks
"RealTimeIsUniversal" directly to determine how to set the system time.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 build.py                 |  7 ----
 src/xenagent/service.cpp | 84 ++++++++++++++----------------------------------
 src/xenagent/service.h   |  3 +-
 3 files changed, 25 insertions(+), 69 deletions(-)

diff --git a/build.py b/build.py
index 3bd17b1..20a3ff4 100755
--- a/build.py
+++ b/build.py
@@ -70,9 +70,6 @@ def make_header():
     file.write('#define DAY_STR\t\t\t"' + str(now.day) + '"\n')
     file.write('\n')
 
-    file.write('#define REG_KEY_NAME\t\t\t"' + os.environ['REG_KEY_NAME'] + 
'"\n')
-    file.write('\n')
-
     file.close()
 
 
@@ -418,9 +415,6 @@ def main():
     if 'OBJECT_PREFIX' not in os.environ.keys():
         os.environ['OBJECT_PREFIX'] = 'XenProject'
 
-    if 'REG_KEY_NAME' not in os.environ.keys():
-        os.environ['REG_KEY_NAME'] = 'Windows PV Drivers'
-
     os.environ['MAJOR_VERSION'] = '9'
     os.environ['MINOR_VERSION'] = '0'
     os.environ['MICRO_VERSION'] = '0'
@@ -441,7 +435,6 @@ def main():
 
     print("PRODUCT_NAME\t\t'%s'" % os.environ['PRODUCT_NAME'])
     print("OBJECT_PREFIX\t\t'%s'" % os.environ['OBJECT_PREFIX'])
-    print("REG_KEY_NAME\t\t'%s'" % os.environ['REG_KEY_NAME'])
     print("MAJOR_VERSION\t\t%s" % os.environ['MAJOR_VERSION'])
     print("MINOR_VERSION\t\t%s" % os.environ['MINOR_VERSION'])
     print("MICRO_VERSION\t\t%s" % os.environ['MICRO_VERSION'])
diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
index a8d45fc..dfcf8a5 100644
--- a/src/xenagent/service.cpp
+++ b/src/xenagent/service.cpp
@@ -371,18 +371,29 @@ void CXenIfaceCreator::AcquireShutdownPrivilege()
     CloseHandle(token);
 }
 
-bool CXenIfaceCreator::IsHostTimeUTC()
+bool CXenIfaceCreator::IsRTCInUTC()
 {
-#ifdef _WIN64
-    // Check SOFTWARE\Wow6432Node\$(VENDOR_NAME_STR)\$(REG_KEY_NAME) 
$(REG_UTC_NAME) == UTC
-    if (RegCheckIsUTC("SOFTWARE\\Wow6432Node"))
-        return true;
-#endif
-    // Check SOFTWARE\$(VENDOR_NAME_STR)\$(REG_KEY_NAME) $(REG_UTC_NAME) == UTC
-    if (RegCheckIsUTC("SOFTWARE"))
-        return true;
+    HKEY key;
+    std::string path;
+    DWORD val = 0;
+    DWORD length = sizeof(val);
+    LRESULT lr;
 
-    return false;
+    path = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation";
+
+    lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_READ, &key);
+    if (lr != ERROR_SUCCESS)
+        return false;
+
+    lr = RegQueryValueEx(key, "RealTimeIsUniversal", NULL, NULL,
+                         (LPBYTE)&val, &length);
+    RegCloseKey(key);
+
+    // A non-present value -> false
+    if (lr != ERROR_SUCCESS)
+        return false;
+
+    return val;
 }
 
 void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
@@ -407,62 +418,14 @@ void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
     now->dwHighDateTime = lnow.HighPart;
 }
 
-bool CXenIfaceCreator::RegCheckIsUTC(const char* rootpath)
-{
-    HKEY    key;
-    LRESULT lr;
-    std::string path;
-    bool    match = false;
-
-    path = rootpath;
-    path += "\\";
-    path += VENDOR_NAME_STR;
-    path += "\\";
-    path += REG_KEY_NAME;
-
-    lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_READ, &key);
-    if (lr != ERROR_SUCCESS)
-        goto fail1;
-
-    DWORD size = 32;
-    DWORD length;
-    char* buffer = NULL;
-
-    do {
-        length = size;
-        if (buffer)
-            delete [] buffer;
-
-        buffer = new char[size];
-        if (buffer == NULL)
-            goto fail2;
-
-        lr = RegQueryValueEx(key, "HostTime", NULL, NULL, (LPBYTE)buffer, 
&length);
-        size *= 2;
-    } while (lr == ERROR_MORE_DATA);
-    if (lr != ERROR_SUCCESS)
-        goto fail3;
-
-    if (!_strnicoll("UTC", buffer, length))
-        match = true;
-
-fail3:
-    delete [] buffer;
-fail2:
-    RegCloseKey(key);
-fail1:
-
-    return match;
-}
-
 void CXenIfaceCreator::SetXenTime()
 {
-    // Set VM's time to Xen's time (adjust for UTC settings of VM and guest)
+    // Set VM's time to Xen's time (adjust for UTC setting)
     FILETIME now = { 0 };
     if (!m_device->SharedInfoGetTime(&now))
         return;
 
-    bool IsUTC = IsHostTimeUTC();
+    bool IsUTC = IsRTCInUTC();
     if (IsUTC)
         AdjustXenTimeToUTC(&now);
 
@@ -473,6 +436,7 @@ void CXenIfaceCreator::SetXenTime()
     SYSTEMTIME cur = { 0 };
     GetLocalTime(&cur);
 
+    CXenAgent::Log("RTC is in %s\n", IsUTC ? "UTC" : "local time");
     CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d\n",
                    cur.wYear, cur.wMonth, cur.wDay,
                    cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds);
diff --git a/src/xenagent/service.h b/src/xenagent/service.h
index 47b7352..2f1bbd2 100644
--- a/src/xenagent/service.h
+++ b/src/xenagent/service.h
@@ -84,9 +84,8 @@ private:
     void StartSlateModeWatch();
     void StopSlateModeWatch();
     void AcquireShutdownPrivilege();
-    bool IsHostTimeUTC();
+    bool IsRTCInUTC();
     void AdjustXenTimeToUTC(FILETIME* time);
-    bool RegCheckIsUTC(const char* path);
     void SetXenTime();
 
 private:
-- 
2.5.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.