diff options
author | Michael Weiser <michael.weiser@gmx.de> | 2019-12-09 22:53:11 +0100 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2019-12-17 17:51:05 -0500 |
commit | 84571456089934b6ee65b08ba7a1d83e3f85e805 (patch) | |
tree | 8b67d8ba00085e2f0512f32654ba2f4e928a4fbd /virtManager | |
parent | 616ac2ebe38841e0f09e9bbdaced979609d24f16 (diff) | |
download | virt-manager-84571456089934b6ee65b08ba7a1d83e3f85e805.tar.gz |
virtManager: object: domain: Set time on resume
Use a potentially available agent inside the domain to update guest time
after resume. Based on the same function in Nova[1].
[1] https://github.com/openstack/nova/commit/414df1e56ea9df700756a1732125e06c5d97d792
Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
https: //bugzilla.redhat.com/show_bug.cgi?id=1222069
Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
Diffstat (limited to 'virtManager')
-rw-r--r-- | virtManager/object/domain.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py index 272c96b4..758caac8 100644 --- a/virtManager/object/domain.py +++ b/virtManager/object/domain.py @@ -1137,6 +1137,34 @@ class vmmDomain(vmmLibvirtObject): def refresh_snapshots(self): self._snapshot_list = None + def _set_time(self): + """ + Try to set VM time to the current value. This is typically useful when + clock wasn't running on the VM for some time (e.g. during suspension or + migration), especially if the time delay exceeds NTP tolerance. + It is not guaranteed that the time is actually set (it depends on guest + environment, especially QEMU agent presence) or that the set time is + very precise (NTP in the guest should take care of it if needed). + + Heavily based on + https://github.com/openstack/nova/commit/414df1e56ea9df700756a1732125e06c5d97d792. + """ + # retry an arbitrary number of times to give the agent some time to + # come back online after e.g. resuming the domain + attempt = 1 + while attempt < 5: + t = time.time() + seconds = int(t) + nseconds = int((t - seconds) * 10 ** 9) + try: + self._backend.setTime(time={"seconds": seconds, + "nseconds": nseconds}) + log.debug("Successfully set guest time") + except Exception as e: + log.debug("Failed to set time: %s", e) + + attempt += 1 + ######################## # XML Parsing routines # @@ -1274,7 +1302,10 @@ class vmmDomain(vmmLibvirtObject): @vmmLibvirtObject.lifecycle_action def startup(self): + sync_time = self.has_managed_save() self._backend.create() + if sync_time: + self._set_time() @vmmLibvirtObject.lifecycle_action def suspend(self): |