[virt-tools-list] Guest time sync on snapshot resume

Michael Weiser michael.weiser at gmx.de
Thu Nov 14 15:30:58 UTC 2019


Hello,

I expect this pops up every couple of months and apologise if indeed it
does. But I couldn't find a discussion specific to virt-manager and so
it goes:

When working with snapshots, guests will have outdated date and time
upon resume. Although the (virtual) hardware clock seems to get updated
upon resume, it can take quite a long time until the guest OS resyncs
its current time from either that or via NTP. I've seen workarounds
employing hwclock --hctosys in once-a-minute cron jobs or very
aggressive NTP client configs.

Now I have come across an agent based solution in Nova[1] and ported it
PoC-style to virt-manager. It works very well for me.

Would this be something that could be considered for inclusion?
Or is there another mechanism that should already take care of this and
just doesn't work in my case?

[1] https://github.com/openstack/nova/commit/414df1e56ea9df700756a1732125e06c5d97d792.

PoC code:

--- virt-manager/virtManager/object/domain.py.orig	2019-10-31 17:35:04.829950245 +0100
+++ virt-manager/virtManager/object/domain.py	2019-10-31 18:19:39.834899951 +0100
@@ -1276,7 +1276,28 @@
 
     @vmmLibvirtObject.lifecycle_action
     def startup(self):
+        sync_time = self.has_managed_save()
         self._backend.create()
+        if sync_time:
+            dry = 1
+            while dry < 5:
+                t = time.time()
+                seconds = int(t)
+                nseconds = int((t - seconds) * 10 ** 9)
+                try:
+                    self._backend.setTime(time = {'seconds': seconds, 'nseconds': nseconds})
+                except libvirt.libvirtError as e:
+                    code = e.get_error_code()
+                    if code == libvirt.VIR_ERR_AGENT_UNRESPONSIVE:
+                        log.debug('Failed to set time: QEMU agent unresponsive')
+                    elif code == libvirt.VIR_ERR_NO_SUPPORT:
+                        log.debug('Failed to set time: not supported')
+                    elif code == libvirt.VIR_ERR_ARGUMENT_UNSUPPORTED:
+                        log.debug('Failed to set time: agent not configured')
+                    else:
+                        log.warning('Failed to set time: %s', e)
+
+                dry += 1
 
     @vmmLibvirtObject.lifecycle_action
     def suspend(self):
-- 
Thanks,
Michael





More information about the virt-tools-list mailing list