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

[libvirt] [PATCH RFC] qemu: make time adjustment persistent if RTC changes in guest



Domain's clock xml is as below.
<clock offset='variable' basis='utc' adjustment='10'/>

If the guest modifies its RTC, libvirt will hanlde the time offset
and save the active status in qemuProcessHandleRTCChange(). However,
libvirt won't save the persistent config. So next time when vm is
restarted(shutdown and start), the time adjuestment(RTC change)
set by user will be lost.

This patch make the adjustment persistent for persistent domain.

Signed-off-by: Wang Rui <moon wangrui huawei com>
---
I'm not sure about the current purpose so I sent a RFC patch. Is it
for some reason that RTC change from guest isn't saved to persistent
config ? 
  
I have tested this patch by changing RTC, starting, shutting down and
migrating. It seems good. There's only a nit I have found. Some guests
will set hardware clock to current system time when shut down. So if
hardware clock is different from system clock(the difference doesn't
come from user setting, maybe from clock shift by system), the
persistent config file will be saved to a new adjustment after shutdown
with this patch. But I think the hypervisor or guest OS should fix
the nit, not libvirt. 
---
 src/qemu/qemu_process.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 407da5e..b03bf02 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -863,7 +863,13 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
         vm->def->clock.data.variable.adjustment = offset;
 
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
-           VIR_WARN("unable to save domain status with RTC change");
+            VIR_WARN("unable to save domain status with RTC change");
+
+        if (vm->persistent && vm->newDef) {
+            vm->newDef->clock.data.variable.adjustment = offset;
+            if (virDomainSaveConfig(cfg->configDir, vm->newDef) < 0)
+                VIR_WARN("unable to save domain config with RTC change");
+        }
     }
 
     event = virDomainEventRTCChangeNewFromObj(vm, offset);
-- 
1.7.12.4



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