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

[XENIFACE PATCH] xenagent: Add DisableTimeSync option



xenagent's time sync mechanism interferes with w32time's own time sync,
especially in a domain environment where domain members are expected to
follow the PDCe.

Add a REG_DWORD value DisableTimeSync in xenagent\Parameters to allow
disabling the XenTime sync.
Note that this setting is not honored during time sync attempts after
resume.

Also add an empty xenagent\Parameters key in xeniface.inf to ease
creating the setting.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenagent/service.cpp        |  4 ++--
 src/xenagent/xenifacedevice.cpp | 32 ++++++++++++++++++++++++++++----
 src/xenagent/xenifacedevice.h   |  4 ++--
 src/xeniface.inf                |  4 ++++
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
index 535d761..6ef7b1a 100644
--- a/src/xenagent/service.cpp
+++ b/src/xenagent/service.cpp
@@ -216,7 +216,7 @@ bool CXenAgent::ServiceMainLoop()
 
     case WAIT_OBJECT_0+2:
         ResetEvent(m_xeniface.m_evt_suspend);
-        m_xeniface.CheckXenTime();
+        m_xeniface.CheckXenTime(true);
         m_xeniface.CheckSuspend();
         return true; // continue loop
 
@@ -230,7 +230,7 @@ bool CXenAgent::ServiceMainLoop()
         return true; // continue loop
     }
     case WAIT_TIMEOUT:
-        m_xeniface.CheckXenTime();
+        m_xeniface.CheckXenTime(false);
         __fallthrough;
     case WAIT_IO_COMPLETION:
         m_xeniface.CheckSuspend();
diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp
index 69a584b..c476ccd 100644
--- a/src/xenagent/xenifacedevice.cpp
+++ b/src/xenagent/xenifacedevice.cpp
@@ -40,6 +40,14 @@
 #include "xeniface_ioctls.h"
 #include "messages.h"
 
+#define SERVICES_KEY "SYSTEM\\CurrentControlSet\\Services"
+
+#define SERVICE_KEY(_Service) \
+        SERVICES_KEY ## "\\" ## _Service
+
+#define PARAMETERS_KEY(_Service) \
+        SERVICE_KEY(_Service) ## "\\Parameters"
+
 CXenIfaceDevice::CXenIfaceDevice(const wchar_t* path) : CDevice(path)
 {}
 
@@ -213,7 +221,7 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) 
: CDeviceList(GUID_IN
     if (m_agent->ConvDevicePresent())
         StartSlateModeWatch(device);
 
-    SetXenTime(device);
+    SetXenTime(device, false);
 }
 
 /*virtual*/ void CXenIfaceDeviceList::OnDeviceRemoved(CDevice* dev)
@@ -339,7 +347,7 @@ bool CXenIfaceDeviceList::CheckShutdown()
     return false;
 }
 
-void CXenIfaceDeviceList::CheckXenTime()
+void CXenIfaceDeviceList::CheckXenTime(bool forced)
 {
     CCritSec crit(&m_crit);
     CXenIfaceDevice* device = (CXenIfaceDevice*)GetFirstDevice();
@@ -347,7 +355,7 @@ void CXenIfaceDeviceList::CheckXenTime()
     if (device == NULL)
         return;
 
-    SetXenTime(device);
+    SetXenTime(device, forced);
 }
 
 void CXenIfaceDeviceList::CheckSuspend()
@@ -485,10 +493,26 @@ void CXenIfaceDeviceList::AcquireShutdownPrivilege()
     CloseHandle(token);
 }
 
-void CXenIfaceDeviceList::SetXenTime(CXenIfaceDevice* device)
+void CXenIfaceDeviceList::SetXenTime(CXenIfaceDevice* device, bool forced)
 {
     bool local;
 
+    if (!forced) {
+        DWORD   disable = 0;
+        DWORD   size = sizeof(disable);
+        LSTATUS lstatus;
+
+        lstatus = RegGetValue(HKEY_LOCAL_MACHINE,
+                              TEXT(PARAMETERS_KEY(__MODULE__)),
+                              TEXT("DisableTimeSync"),
+                              RRF_RT_DWORD,
+                              NULL,
+                              &disable,
+                              &size);
+        if (lstatus == ERROR_SUCCESS && disable)
+            return;
+    }
+
     FILETIME now = { 0 };
     if (!device->SharedInfoGetTime(&now, &local))
         return;
diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h
index d85e469..8a89036 100644
--- a/src/xenagent/xenifacedevice.h
+++ b/src/xenagent/xenifacedevice.h
@@ -84,7 +84,7 @@ public:
 
     void Log(const char* message);
     bool CheckShutdown();
-    void CheckXenTime();
+    void CheckXenTime(bool forced);
     void CheckSuspend();
     bool CheckSlateMode(std::string& mode);
     void LogIfRebootPending();
@@ -95,7 +95,7 @@ private:
     void StartSlateModeWatch(CXenIfaceDevice* device);
     void StopSlateModeWatch(CXenIfaceDevice* device);
     void AcquireShutdownPrivilege();
-    void SetXenTime(CXenIfaceDevice* device);
+    void SetXenTime(CXenIfaceDevice* device, bool forced);
 
 private:
     CXenAgent*  m_agent;
diff --git a/src/xeniface.inf b/src/xeniface.inf
index 07e2a91..3b54f2a 100644
--- a/src/xeniface.inf
+++ b/src/xeniface.inf
@@ -110,6 +110,10 @@ ServiceType=%SERVICE_WIN32_OWN_PROCESS%
 StartType=%SERVICE_AUTO_START%
 ErrorControl=%SERVICE_ERROR_NORMAL%
 
ServiceBinary=%11%\xenagent_@MAJOR_VERSION@_@MINOR_VERSION@_@MICRO_VERSION@_@BUILD_NUMBER@.exe
+AddReg=XenAgent_Parameters
+
+[XenAgent_Parameters]
+HKR,"Parameters",,0x00000010
 
 [XenAgent_EventLog]
 AddReg=XenAgent_AddReg
-- 
2.50.0.windows.2



Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech




 


Rackspace

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