Bug 852005

Summary: KVM libvirtd Client killed on reboot shutdown
Product: [openSUSE] openSUSE 13.1 Reporter: Forgotten User QtBI7gWTIh <forgotten_QtBI7gWTIh>
Component: BasesystemAssignee: Cédric Bosdonnat <cbosdonnat>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Critical    
Priority: P5 - None CC: brogers, haenig, jdouglas, jfehlig, systemd-maintainers, werner
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 13.1   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Forgotten User QtBI7gWTIh 2013-11-24 08:06:31 UTC
User-Agent:       Mozilla/5.0 (X11; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0

On my system the shutdown or reboot in a KVM System (clients) is never working.

When I make a reboot shutdown the clients are "killed", no suspend ore a shutdown.

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Comment 1 James Fehlig 2013-11-26 05:10:02 UTC
Sorry, but I'm not quite sure I understand the problem.  Is the reboot of virtual machines (e.g. 'virsh reboot ...') not working?  Or are you using libvirt-guests to shutdown/start VMs when the host is shutdown/started?
Comment 2 Forgotten User QtBI7gWTIh 2013-11-26 07:10:38 UTC
I tested libvirt-guests, after I found it ;).

I is working on command line

service libvirt-guests start / stop

but NOT working on a reboot or poweroff.

I mean it is a broken in systemd.

When you install a DB in a client, all is broken afterward :(.
Comment 3 James Fehlig 2013-12-06 23:18:43 UTC
Stupid question I suppose, but did you enable the libvirt-guests service?  E.g.

systemctl enable libvirt-guests.service

Without that, libvirt-guests wont be run when the host boots.
Comment 4 Forgotten User QtBI7gWTIh 2013-12-07 09:54:35 UTC
:-)))

YES, it is enabled.

My situation, I have enabled automatic start on boot, by the installation.

Afterward i install libvirt-guests and enable it.

(Why is this not automatic installed ?)

I found also a Error Messages on start (Boot) the system
libvirt-guests can't start / run ...
Comment 5 James Fehlig 2013-12-11 01:45:51 UTC
It took a bit of time to figure out what the problem is here.  While investigating ways to solve it, came across a RH bug for the same issue

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

Currently, no solution in that bug...
Comment 6 Forgotten User QtBI7gWTIh 2014-01-23 08:21:58 UTC
Hello Jim,

have you new information for this Bug ?

Now it is a very bad situation (SLES 12 is coming ....) ;)
Comment 7 James Fehlig 2014-01-24 21:30:50 UTC
I don't have any new information.  Seems Cole's question on how to handle this in systemd has went unanswered

http://lists.freedesktop.org/archives/systemd-devel/2013-December/015534.html

Maybe a SUSE systemd expert (or systemd expert in the openSUSE community) could help.  Any idea who that might be?  Frederic, who is the maintainer of systemd these days?  We could use some help on libvirt <-> systemd interaction.  Thanks!
Comment 8 Frederic Crozat 2014-01-27 09:53:58 UTC
added systemd-maintainers@suse.de which is the alias for systemd maintainers.
Comment 9 James Fehlig 2014-01-27 19:35:21 UTC
Thanks Frederic.  systemd-maintainers, can you provide some advice?  Specifically, can you help answer Cole's question referenced in #7?  The libvirt community is not sure how to proceed.  Thanks!
Comment 10 Dr. Werner Fink 2014-01-28 07:55:31 UTC
(In reply to comment #9)

What exactly is done here?  All VirtualBox systems here (12.3 and 13.1) do reboot as well as halt perfectly.  Do you want to reboot/halt your server and this should be propagated to the clients?  Then this seems to more a problem of the libvirt-guests.service which is part of the package libvirt-client.

Maybe a few further services are missed which does similar to e.g. the sequence
plymouth-quit.service and plymouth-quit-wait.service wait on the shutdown of the virtual clients and this would use a suitable timeout like TimeoutSec=10m ... IMHO those quit and quit-wait services should run before shutdown.target
Comment 11 James Fehlig 2014-01-28 18:49:17 UTC
(In reply to comment #10)
> Do you want to reboot/halt your server and
> this should be propagated to the clients?

Well, not really propagated to the guests, but a chance for libvirt-guests to do whatever the user has configured it to do on host shutdown/startup.

> Then this seems to more a problem of
> the libvirt-guests.service which is part of the package libvirt-client.

The problem is that systemd has killed off the guests by the time libvirt-guests runs.  When libvirt starts a qemu guest, it uses the CreateMachine dbus call to create a scope for the guest.  So each qemu guest is running inside a scope, which is not connected by any dependencies to either systemd-machine.service or libvirt-guests.service.  When the host is shutdown, the scopes will be stopped in parallel to running libvirt-guests, and depending on timing, guests may killed with SIGTERM before libvirt-guests is able to process them.

The libvirt community is looking for ways to solve this problem.  One idea was to inject a 'After=libvirt-guests.service' when creating the scope, e.g.

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 503fff7..3243d35 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -243,8 +243,9 @@ int virSystemdCreateMachine(const char *name,
                           iscontainer ? "container" : "vm",
                           (unsigned int)pidleader,
                           rootdir ? rootdir : "",
-                          1, "Slice", "s",
-                          slicename) < 0)
+                          2,
+                          "Slice", "s", slicename,
+                          "After", "s", "libvirt-guests.service") < 0)
         goto cleanup;
 
     ret = 0;

but that caused the CreateMachine dbus call to fail.  So it is not clear how to describe the dependency when creating the scope.  This is where some advice from the systemd community would be helpful, but there has been no response to Cole's question on systemd-devel

http://lists.freedesktop.org/archives/systemd-devel/2013-December/015534.html

Since upstream has been silent, I'm hoping to get some advice from internal systemd experts on how to proceed.
Comment 12 Dr. Werner Fink 2014-01-29 08:26:15 UTC
Hmmm ... upstream had designed and implemented the slice/scope unit scheme.  More than reading the manual pages systemd.slice(5), systemd.scope(5) and the URL http://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/ is out of my current experience :(

Only what I can guess is that the slice scheme suggests to me that the dependency should the other way around, that is libvirt-guests.service should be part of the slice `slicename' which would imply `Before' and not `After'.  Beside it could be interesting to inspect the Drop-In configuration of the corresponding scope if any.

Maybe one of the other members systemd-maintainers@suse.de can provide some more information.  Frederic?
Comment 13 Frederic Crozat 2014-01-29 08:47:53 UTC
No real idea, it would be best to revive the upstream thread about this issue.
Comment 14 Dr. Werner Fink 2014-01-29 09:14:50 UTC
Nevertheless IMHO the slice should be set up with `Before' libvirt-guests.service to make sense.  The slice its self uses the DefaultDependencies, that is it is part of the system.slice (After=system.slice + Wants=system.slice) and will conflicting with the shutdown.target (Conflicts=shutdown.target) and will be closed before shutdown.target (Before=shutdown.target).  Also a WantedBy=libvirt-guests.service would help to enable systemd to detect the correct order.
Comment 15 Dr. Werner Fink 2014-02-13 13:00:25 UTC
Are there any News?
Comment 16 James Fehlig 2014-02-14 17:15:16 UTC
Sorry Werner, I haven't had time to investigate and have a huge backlog.  I'm going to put this bug in the very capable hands of Cedric.
Comment 17 James Fehlig 2014-02-21 16:29:08 UTC
Heh, a fix for this issue has landed upstream, along with a few fixes for libvirt-guests

https://www.redhat.com/archives/libvir-list/2014-February/msg01357.html

For SLE12, we'll pick up the fixes in the next beta when I update to libvirt 1.2.2.  For 13.1, we'll need to backport the patches and release in a maintenance update.
Comment 18 Cédric Bosdonnat 2014-03-18 12:09:30 UTC
All 3 patches from that series backported in 13.1 dev project.
Comment 19 Bernhard Wiedemann 2014-03-21 19:00:15 UTC
This is an autogenerated message for OBS integration:
This bug (852005) was mentioned in
https://build.opensuse.org/request/show/227061 13.1 / libvirt
Comment 20 Swamp Workflow Management 2014-05-02 13:04:31 UTC
openSUSE-SU-2014:0593-1: An update that solves two vulnerabilities and has three fixes is now available.

Category: security (moderate)
Bug References: 852005,857490,868943,871154,873103
CVE References: CVE-2013-6456,CVE-2013-7336
Sources used:
openSUSE 13.1 (src):    libvirt-1.1.2-2.26.1
Comment 21 Thomas Hänig 2014-05-27 11:18:41 UTC
please reopen this bug because the (underlying) problem appears not to be resolved.

When shutting down the host system, I see messages like these:
"Unable to connect to libvirtd currently"

so systemd does NOT wait for libvirt-guests to finish saving VMs state but stops libvirtd immediately after issuing the stop command for the libvirt-guests

Another hint for this behaviour is, even though ON_SHUTDOWN is set to suspend in /etc/sysconfig/libvirt-guests, each time the guest is started it does a normal boot.

The mentioned fix however seems to be included:

nbk:~ # rpm -qi --changelog libvirt-client | less
nbk:~ # rpm -qi --changelog libvirt-daemon | less

...
* Di Mär 18 2014 cbosdonnat@suse.com
- Backport libvirt-guests fixes
  4e7fc83-bnc852005.patch, 68954fb-bnc852005.patch,
  ba79e38-bnc852005.patch
  bnc#852005
...


nbk:~ # rpm -qf /usr/lib/systemd/system/libvirtd.service
libvirt-daemon-1.1.2-2.32.1.i586

nbk:~ # rpm -qf /usr/lib/systemd/system/libvirt-guests.service
libvirt-client-1.1.2-2.32.1.i586


nbk:~ # systemctl is-enabled libvirtd   
enabled

nbk:~ # systemctl is-enabled libvirt-guests
enabled


The system is openSuSE 13.1 32bit
Comment 22 James Fehlig 2014-07-15 22:38:36 UTC
(In reply to comment #21)
> The system is openSuSE 13.1 32bit

Really?  Does the processor support VT, or are you running qemu in TCG mode.  At any rate, we don't support 32-bit virtualization hosts.

Feel free to reopen this bug yourself if you can reproduce on a 64-bit system.  Thanks.