[libvirt] [PATCH] libvirt-guests: Weaken dependency on libvirtd

The Requires relationship is very strong, in that it prevents a unit from running unless all the units it Requires are running as well. This turns out to be a problem because we want to be able to restart libvirtd at any time without having libvirt-guests suspend or shutdown running guests. Turn the Requires relationship into a Wants relationship: this way starting libvirt-guests will cause systemd to (attempt to) start libvirtd as well, but stopping or restarting libvirtd will not alter libvirt-guests' running state. --- tools/libvirt-guests.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in index b4f54f2..02e6747 100644 --- a/tools/libvirt-guests.service.in +++ b/tools/libvirt-guests.service.in @@ -1,6 +1,6 @@ [Unit] Description=Suspend/Resume Running libvirt Guests -Requires=libvirtd.service +Wants=libvirtd.service After=network.target After=time-sync.target After=libvirtd.service -- 2.7.4

On 10/07/2016 10:19 AM, Andrea Bolognani wrote:
The Requires relationship is very strong, in that it prevents a unit from running unless all the units it Requires are running as well.
This turns out to be a problem because we want to be able to restart libvirtd at any time without having libvirt-guests suspend or shutdown running guests.
Turn the Requires relationship into a Wants relationship: this way starting libvirt-guests will cause systemd to (attempt to) start libvirtd as well, but stopping or restarting libvirtd will not alter libvirt-guests' running state. --- tools/libvirt-guests.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in index b4f54f2..02e6747 100644 --- a/tools/libvirt-guests.service.in +++ b/tools/libvirt-guests.service.in @@ -1,6 +1,6 @@ [Unit] Description=Suspend/Resume Running libvirt Guests -Requires=libvirtd.service +Wants=libvirtd.service After=network.target After=time-sync.target After=libvirtd.service
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> -- Mit freundlichen Grüßen/Kind regards Boris Fiuczynski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

On Fri, Oct 07, 2016 at 10:19:53AM +0200, Andrea Bolognani wrote:
The Requires relationship is very strong, in that it prevents a unit from running unless all the units it Requires are running as well.
This turns out to be a problem because we want to be able to restart libvirtd at any time without having libvirt-guests suspend or shutdown running guests.
Turn the Requires relationship into a Wants relationship: this way starting libvirt-guests will cause systemd to (attempt to) start libvirtd as well, but stopping or restarting libvirtd will not alter libvirt-guests' running state.
I can't figure out how exactly this works, even when looking at the systemd.unit documentation. You are saying that Wants= means that if you issue 'service libvirtd stop' it will not save your guests after this patch. What if you stop the service and then shutdown the machine? I would agree that it's your fault if it doesn't save your guests. From what I am reading, it makes sense, so ACK from me. Basically because I can't come up with scenarios that could be broken by this change =) Martin

On Mon, 2016-10-10 at 15:59 +0200, Martin Kletzander wrote:
On Fri, Oct 07, 2016 at 10:19:53AM +0200, Andrea Bolognani wrote:
The Requires relationship is very strong, in that it prevents a unit from running unless all the units it Requires are running as well. This turns out to be a problem because we want to be able to restart libvirtd at any time without having libvirt-guests suspend or shutdown running guests. Turn the Requires relationship into a Wants relationship: this way starting libvirt-guests will cause systemd to (attempt to) start libvirtd as well, but stopping or restarting libvirtd will not alter libvirt-guests' running state. I can't figure out how exactly this works, even when looking at the systemd.unit documentation. You are saying that Wants= means that if you issue 'service libvirtd stop'
You mean systemctl stop libvirtd Unless distributions have converted service(8) into a wrapper for systemctl(1)... Oh, it looks like at least Fedora and Debian have. Makes sense :)
it will not save your guests after this patch.
Correct. If B Requires=A and A becomes unavailable, B will be stopped as well; the same doesn't happen if B merely Wants=A.
What if you stop the service and then shutdown the machine? I would agree that it's your fault if it doesn't save your guests.
It would be super neat if we could stop libvirt-guests when stopping libvirtd, so that guests are saved properly, but not stop it when libvirtd is merely being restarted. Unfortunately systemd doesn't allow that level of granularity, so we're basically forced to choose between two partially unsatisfying solutions :(
From what I am reading, it makes sense, so ACK from me. Basically because I can't come up with scenarios that could be broken by this change =)
I will wait a while before pushing it, so other people can have a chance to weigh in. In the meantime, thanks for the review! :) -- Andrea Bolognani / Red Hat / Virtualization

On Tue, Oct 11, 2016 at 03:17:07PM +0200, Andrea Bolognani wrote:
On Mon, 2016-10-10 at 15:59 +0200, Martin Kletzander wrote:
On Fri, Oct 07, 2016 at 10:19:53AM +0200, Andrea Bolognani wrote:
The Requires relationship is very strong, in that it prevents a unit from running unless all the units it Requires are running as well. This turns out to be a problem because we want to be able to restart libvirtd at any time without having libvirt-guests suspend or shutdown running guests. Turn the Requires relationship into a Wants relationship: this way starting libvirt-guests will cause systemd to (attempt to) start libvirtd as well, but stopping or restarting libvirtd will not alter libvirt-guests' running state. I can't figure out how exactly this works, even when looking at the systemd.unit documentation. You are saying that Wants= means that if you issue 'service libvirtd stop'
You mean
systemctl stop libvirtd
Unless distributions have converted service(8) into a wrapper for systemctl(1)... Oh, it looks like at least Fedora and Debian have. Makes sense :)
it will not save your guests after this patch.
Correct. If B Requires=A and A becomes unavailable, B will be stopped as well; the same doesn't happen if B merely Wants=A.
What if you stop the service and then shutdown the machine? I would agree that it's your fault if it doesn't save your guests.
It would be super neat if we could stop libvirt-guests when stopping libvirtd, so that guests are saved properly, but not stop it when libvirtd is merely being restarted.
Unfortunately systemd doesn't allow that level of granularity, so we're basically forced to choose between two partially unsatisfying solutions :(
Sometimes you don't even want that. Maybe systemd could add yet another new thing that would mean this service needs this other service when it is being stopped or started, but not in between. And also this service should change state when starting or shutting down only... and bunch of others. Until that we'll always have bunch of workarounds anyway.
From what I am reading, it makes sense, so ACK from me. Basically because I can't come up with scenarios that could be broken by this change =)
I will wait a while before pushing it, so other people can have a chance to weigh in.
In the meantime, thanks for the review! :)
-- Andrea Bolognani / Red Hat / Virtualization
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Andrea Bolognani
-
Boris Fiuczynski
-
Martin Kletzander