Commit Graph

23 Commits

Author SHA1 Message Date
Jim Fehlig
fa048f88ef libvirt-guests: Remove unused variable 'libvirtd'
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-08-01 10:46:11 -06:00
Andrea Bolognani
32f772e986 meson: Use initconfdir
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-05-05 15:08:25 +02:00
Orion Poplawski
a501fa7cae libvirt-guests: Sync time for autostarted guests
Setting SYNC_TIME=1 does not work on autostarted guests.

See https://bugzilla.redhat.com/show_bug.cgi?id=1555398.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2020-11-04 12:18:05 +01:00
Christian Ehrhardt
ab5b5f22b9
tools: fix libvirt-guests.sh text assignments
In libvirt 6.6 stopping guests with libvirt-guests.sh is broken.
As soon as there is more than one guest one can see
`systemctl stop libvirt-guests` failing and in the log we see:
  libvirt-guests.sh[2455]: Running guests on default URI:
  libvirt-guests.sh[2457]: /usr/lib/libvirt/libvirt-guests.sh: 120:
      local: 2a49cb0f-1ff8-44b5-a61d-806b9e52dae2: bad variable name
  libvirt-guests.sh[2462]: no running guests.

That is due do mutliple guests becoming a list of UUIDs. Without
recognizing this as one single string the assignment breaks when using 'local'
(which was recently added in 6.3.0). This is because local is defined as
  local [option] [name[=value] ... | - ]
which makes the shell trying handle the further part of the string as
variable names. In the error above that string isn't a valid variable
name triggering the issue that is seen.

This depends on the shell being used. POSIX shells don't have 'local'
specified yet and for the common shells it depends. It worked in bash and
bash-in-POSIX-mode, but for example dash in POSIX mode triggers the issue.

To resolve that 'textify' all assignments that are strings or potentially
can become such lists (even if they are not using the local qualifier).

Fixes: 08071ec0 "tools: variables clean-up in libvirt-guests script"

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2020-08-21 08:31:18 +02:00
Ján Tomko
cc48360fc9 tools: libvirt-guests: correctly check shutdown value
The variable cleanup introduced a typo.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 08071ec0f1
Reported-by: Bronek Kozicki
Closes: https://gitlab.com/libvirt/libvirt/-/issues/27
2020-06-03 13:56:20 +02:00
Prathamesh Chavan
08071ec0f1 tools: variables clean-up in libvirt-guests script
Redeclared variables in script functions marked as local.
Variables `guest_running` and `guests_shutting_down` in the
functions 'guest_is_on` and `check_guests_shutdown` were
untouched, as the functions returned values in these
variables.

Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-04-06 15:00:00 +02:00
Christian Ehrhardt
8ea9e032dd tools: do not loop in libvirt-guests test_connect
These days libvirt is pretty reliable and even remote connections
(not the default for libvirt-guests anyway) either work or fail but are
uncommon to be flaky.

On the other hand users might have disabled the service and while we are
After=libvirtd for ordering we are not Requiring it. Adding that or any
harder dependency might break our ordering. But if people have disabled
libvirt they will do a full retry loop until timeout.

Lets drop the loop to be much faster if a remote is not reachable.

Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1854653

This reverts

  commit 4e7fc8305a
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Fri Feb 21 12:46:08 2014 +0100

    libvirt-guests: Wait for libvirtd to initialize

The race described in that commit no longer exists using systemd as
we now have socket activation. If not using systemd, then it is also
safe if using the libvirtd --daemon flag, since the parent process
won't return to the caller until the child is accepting connections.

Reported-by: Doug Smythies <dsmythies@telus.net>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2019-12-16 10:10:49 +00:00
Christian Ehrhardt
cce57265c4 tools: do not report unknown guests in print_guests_shutdown
If another event in background while running libvirt-guests.sh
completely undefines a guest it will no more be available for proper
reporting of its shutdown.

This appears in the log as:
  Failed to determint state of guest: <UUID>. Not tracking it anymore
  Shutdown of guest  complete

The first message already reports that we are giving up on the guest
(per UUID which is all we have left at that point). To avoid the message
with an empty guest_name in such a case lets check what guest_name
returned and only print a report on valid content.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Dariusz Gadomski <dariusz.gadomski@canonical.com>
2018-04-24 10:46:41 +02:00
Christian Ehrhardt
08bb5eeba7 tools: fix check_guests_shutdown loop
The recent fix to libvirt-guests.sh.in works for what it intended to fix
(variable scope) but failed to adapt the loop in check_guests_shutdown
correctly. Due to that it currently might detect all guests as "Failed to
determine state of guest" by bad var content or just assumes they are shut
down by picking up an empty variable.

This commit fixes loop to use the passed value and the call in the loop
to actually use the variable assigned in the iterated.

Fixes: 7e476356 "tools: fix variable scope in in check_guests_shutdown"
Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1764668

Reviewed-by: Dariusz Gadomski <dariusz.gadomski@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-04-24 10:43:42 +02:00
Christian Ehrhardt
7e476356c2 tools: fix variable scope in in check_guests_shutdown
libvirt-guests.sh when run with more active guests than requested to
shut down in parallel will run until it times out only shutting down
the first set of guests.

This patch fixes parallel shutdown by fixing a variable scope issue
where check_guests_shutdown unintentionally reset $guests which
prevented further progress.

Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1688508

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-03-19 13:06:03 +01:00
Christian Ehrhardt
ff02d1af40 tools: avoid text spilling into variables
While libvirt-guests.sh is running cases can let guest_is_on fail which
causes check_guests_shutdown to print output.
That output shall not spill into the users of function
check_guests_shutdown which is therefore now returning values in a
variable like guest_is_on already did.

Original-Author: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Modified-By: Jorge Niedbalski <niedbalski@ubuntu.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-02-23 13:03:56 +01:00
Jim Fehlig
8599aedd43 Improve filtering of Xen domain0 in libvirt-guests
The list_guests function in libvirt-guests uses 'grep -v' to filter
Xen domain0 from a list of guests. If domain0 is the only item in
the list, 'grep -v' returns 1, causing the 'stop' operation to fail
when action is 'suspend'. Improve the filtering by using sed to remove
domain0 from the list of guests.
2017-12-18 09:24:13 -07:00
Stefan Bader
cc38d5661f tools: Exclude Xen dom0 from libvirt-guests.sh list
With newer versions of libvirt Domain-0 is again visible in the list of
running guests but it should not be considered as a guest for shutdown
or suspend.

Signed-off-by Stefan Bader <stefan.bader@canonical.com>
2016-10-10 16:52:08 +08:00
Stefan Bader
69722fd7ac tools: Ignore newlines in libvirt-guests.sh guest list
The list file expects all guest UUIDs on the same line as the URI
which the guests run on. This does not happen when the list is
echo'ed in quotes. When stripping the quotes, newlines get transformed
into spaces. Without this, only the first guest on the list is actually
handled.

Based on a fix by Omar Siam <simar@gmx.net>

Bug-Ubuntu: http://bugs.launchpad.net/bugs/1591695

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2016-10-10 16:52:08 +08:00
Michal Privoznik
64e070e8fe libvirt-guests: Initialize SYNC_TIME
https://bugzilla.redhat.com/show_bug.cgi?id=1191227

Since 0fa15b19 we have this variable SYNC_TIME which allows users to
synchronize time on domain resume. However, despite what documentation
says, it's by default on because it's never initialized. Fix this by
setting it to zero at the beginning of the libvirt-guests script.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-05-12 08:53:14 +02:00
Michal Privoznik
0fa15b19a9 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>
2015-02-23 08:49:21 +01:00
Martin Kletzander
15e38ebbf1 libvirt-guests: fix some typos in a comment
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-25 12:06:07 +02:00
Guido Günther
5a05865773 libvirt-guests: avoid bashism
At least Debian uses dash to run the init scripts
2014-04-07 12:51:05 +02:00
Michal Privoznik
4e7fc8305a libvirt-guests: Wait for libvirtd to initialize
I've noticed that in some cases systemd was quick enough and even
if libvirt-guests.service is marked to be started after the
libvirtd.service my guests were not resumed as
libvirt-guests.sh failed to connect. This is because of a
simple fact: systemd correctly starts libvirt-guests after it
execs libvirtd. However, the daemon is not able to accept
connections right from the start. It's doing some
initialization which may take ages. This problem is not limited
to systemd only, indeed. Any init system that is able to startup
services in parallel (e.g. OpenRC) may run into this situation.
The fix is to try connecting not only once, but continuously a few
times with a small sleep in between tries.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-02-24 10:54:37 +01:00
Eric Blake
d7f53c7b97 maint: use LGPL correctly
Several files called out COPYING or COPYING.LIB instead of using
the normal boilerplate.  It's especially important that we don't
call out COPYING from an LGPL file, since COPYING is traditionally
used for the GPL.  A few files were lacking copyright altogether.

* src/rpc/gendispatch.pl: Add missing copyright.
* Makefile.nonreentrant: Likewise.
* src/check-symfile.pl: Likewise.
* src/check-symsorting.pl: Likewise.
* src/driver.h: Likewise.
* src/internal.h: Likewise.
* tools/libvirt-guests.sh.in: Likewise.
* tools/virt-pki-validate.in: Mention copyright in comment, not just code.
* tools/virt-sanlock-cleanup.in: Likewise.
* src/rpc/genprotocol.pl: Spell out license terms.
* src/xen/xend_internal.h: Likewise.
* src/xen/xend_internal.c: Likewise.
* Makefile.am: Likewise.
* daemon/Makefile.am: Likewise.
* docs/Makefile.am: Likewise.
* docs/schemas/Makefile.am: Likewise.
* examples/apparmor/Makefile.am: Likewise.
* examples/domain-events/events-c/Makefile.am: Likewise.
* examples/dominfo/Makefile.am: Likewise.
* examples/domsuspend/Makefile.am: Likewise.
* examples/hellolibvirt/Makefile.am: Likewise.
* examples/openauth/Makefile.am: Likewise.
* examples/python/Makefile.am: Likewise.
* examples/systemtap/Makefile.am: Likewise.
* examples/xml/nwfilter/Makefile.am: Likewise.
* gnulib/lib/Makefile.am: Likewise.
* gnulib/tests/Makefile.am: Likewise.
* include/Makefile.am: Likewise.
* include/libvirt/Makefile.am: Likewise.
* python/Makefile.am: Likewise.
* python/tests/Makefile.am: Likewise.
* src/Makefile.am: Likewise.
* tests/Makefile.am: Likewise.
* tools/Makefile.am: Likewise.
* configure.ac: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-05-20 14:03:48 -06:00
Ján Tomko
9c51de2b4e libvirt-guests: status: return non-zero when stopped
Return 3 when the service is stopped, whether there
are saved guests or not, to conform with the LSB standards:

http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
2013-04-30 18:38:18 +02:00
Eric Blake
7c12055def libvirt-guests: newline between output sentences
Right now, libvirt-guests gives awkward output.  It's possible to
force faster failure by setting /etc/sysconfig/libvirt-guests to use:

ON_SHUTDOWN=shutdown
PARALLEL_SHUTDOWN=0
SHUTDOWN_TIMEOUT=1
ON_BOOT=ignore

at which point, we see:

$ service libvirt-guests restart
Running guests on default URI: a, b, d, c
Shutting down guests on default URI...
Starting shutdown on guest: a
Shutdown of guest a failed to complete in time.Starting shutdown on guest: b
Shutdown of guest b failed to complete in time.Starting shutdown on guest: d
Shutdown of guest d failed to complete in time.Starting shutdown on guest: c
Shutdown of guest c failed to complete in time.libvirt-guests is configured not to start any guests on boot

* tools/libvirt-guests.sh.in (shutdown_guest): Add missing newline.
Reported by Xuesong Zhang.
2013-03-25 08:38:35 -06:00
Cole Robinson
d13155c20c tools: Only install guests init script if --with-init=script=redhat
Most of this deals with moving the libvirt-guests.sh script which
does all the work to /usr/libexec, so it can be shared by both
systemd and traditional init. Previously systemd depended on
the script being in /etc/init.d

Required to fix https://bugzilla.redhat.com/show_bug.cgi?id=789747
2012-12-11 19:54:37 -05:00