[libvirt] [PATCH] libvirt-guests: Allow time sync on guests resume

Well, imagine domains were running, and as the host went down, they were managesaved. Later, after some time, the host went up again and domains got restored. But without correct time. And depending on how long was the host shut off, it may take some time for ntp to sync the time too. But hey, wait a minute. We have an API just for that! So: 1) Introduce SYNC_TIME variable in libvirt-guests.sysconf to allow users control over the new functionality 2) Call 'virsh domtime --sync $dom' in the libvirt-guests script. Unfortunately, this is all-or-nothing approach (just like anything else with the script). Domains are required to have configured and running qemu-ga inside. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/libvirt-guests.sh.in | 6 ++++++ tools/libvirt-guests.sysconf | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index 1b17bbe..21e39b0 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -171,7 +171,9 @@ start() { isfirst=true bypass= + sync_time=false test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache + test "x$SYNC_TIME" = x0 || sync_time=true while read uri list; do configured=false set -f @@ -206,6 +208,10 @@ start() { retval run_virsh "$uri" start $bypass "$name" \ >/dev/null && \ gettext "done"; echo + if "$sync_time"; then + retval run_virsh "$uri" domtime --sync "$name" \ + >/dev/null + fi fi fi done diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index d1f2051..03e732f 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -39,3 +39,10 @@ # restoring guests, even though this may give slower operation for # some file systems. #BYPASS_CACHE=0 + +# If non-zero, try to sync guest time on a domain resume. Be aware, that +# this requires guest agent, which, moreover, has to run under supported +# system. For instance, qemu-ga doesn't support guest time synchronization +# on Windows guests, but Linux ones. By default, this piece of +# functionality is turned off. +#SYNC_TIME=1 -- 2.0.5

On Wed, Feb 18, 2015 at 15:31:27 +0100, Michal Privoznik wrote:
Well, imagine domains were running, and as the host went down, they were managesaved. Later, after some time, the host went up again and domains got restored. But without correct time. And depending on how long was the host shut off, it may take some time for ntp to sync the time too. But hey, wait a minute. We have an API just for that! So:
1) Introduce SYNC_TIME variable in libvirt-guests.sysconf to allow users control over the new functionality 2) Call 'virsh domtime --sync $dom' in the libvirt-guests script.
Unfortunately, this is all-or-nothing approach (just like anything else with the script). Domains are required to have configured and running qemu-ga inside.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/libvirt-guests.sh.in | 6 ++++++ tools/libvirt-guests.sysconf | 7 +++++++ 2 files changed, 13 insertions(+)
diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index 1b17bbe..21e39b0 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -171,7 +171,9 @@ start() {
isfirst=true bypass= + sync_time=false test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache + test "x$SYNC_TIME" = x0 || sync_time=true while read uri list; do configured=false set -f @@ -206,6 +208,10 @@ start() { retval run_virsh "$uri" start $bypass "$name" \ >/dev/null && \ gettext "done"; echo + if "$sync_time"; then + retval run_virsh "$uri" domtime --sync "$name" \
I think 'retva' shouldn't be used here. Time sync is very prone to fail as it uses the guest agent and we should not fail to start the service for this operation that I'd consider "best effort".
+ >/dev/null + fi fi fi done
Peter

On Wed, Feb 18, 2015 at 04:52:48PM +0100, Peter Krempa wrote:
On Wed, Feb 18, 2015 at 15:31:27 +0100, Michal Privoznik wrote:
Well, imagine domains were running, and as the host went down, they were managesaved. Later, after some time, the host went up again and domains got restored. But without correct time. And depending on how long was the host shut off, it may take some time for ntp to sync the time too. But hey, wait a minute. We have an API just for that! So:
1) Introduce SYNC_TIME variable in libvirt-guests.sysconf to allow users control over the new functionality 2) Call 'virsh domtime --sync $dom' in the libvirt-guests script.
Unfortunately, this is all-or-nothing approach (just like anything else with the script). Domains are required to have configured and running qemu-ga inside.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/libvirt-guests.sh.in | 6 ++++++ tools/libvirt-guests.sysconf | 7 +++++++ 2 files changed, 13 insertions(+)
diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index 1b17bbe..21e39b0 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -171,7 +171,9 @@ start() {
isfirst=true bypass= + sync_time=false test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache + test "x$SYNC_TIME" = x0 || sync_time=true while read uri list; do configured=false set -f @@ -206,6 +208,10 @@ start() { retval run_virsh "$uri" start $bypass "$name" \ >/dev/null && \ gettext "done"; echo + if "$sync_time"; then + retval run_virsh "$uri" domtime --sync "$name" \
I think 'retva' shouldn't be used here. Time sync is very prone to fail as it uses the guest agent and we should not fail to start the service for this operation that I'd consider "best effort".
Yeah I thin that makes sense, as we don't even know if the agent is installed in all guests. We just want it to work in as many as possible without breaking startup entirely. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Michal Privoznik
-
Peter Krempa