[libvirt PATCH v2] Make systemd unit ordering more robust

Martin Kletzander posted 1 patch 2 years, 2 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/09ddc40b2714a4328917a4ad8c74d3e96fc98205.1644936726.git.mkletzan@redhat.com
src/util/virsystemd.c           |  8 ++++++--
tools/libvirt-guests.service.in | 12 +++++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)
[libvirt PATCH v2] Make systemd unit ordering more robust
Posted by Martin Kletzander 2 years, 2 months ago
Since libvirt-guests script/service can operate on various URIs and we do
support both socket activation and traditional services, the ordering should be
specified for all the possible sockets and services.

Also remove the Wants= dependency since do not want to start any service.  We
cannot know which one libvirt-guests is configured, so we'd have to start all
the daemons which would break if unused colliding services are not
masked (libvirtd.service in the modular case and all the modular daemon service
units in the monolithic scenario).  Fortunately we can assume that the system is
configured properly to start services/sockets that are of interest to the user.
That also works with the setup described in https://libvirt.org/daemons.html .

To make it even more robust we add the daemon service into the machine units
created for individual domains as it was missing there.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/util/virsystemd.c           |  8 ++++++--
 tools/libvirt-guests.service.in | 12 +++++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index a86d4c6bb905..f156c2f39ae5 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -441,8 +441,10 @@ int virSystemdCreateMachine(const char *name,
                                                 nicindexes, nnicindexes, sizeof(int));
         gprops = g_variant_new_parsed("[('Slice', <%s>),"
                                       " ('After', <['libvirtd.service']>),"
+                                      " ('After', <['virt%sd.service']>),"
                                       " ('Before', <['virt-guest-shutdown.target']>)]",
-                                      slicename);
+                                      slicename,
+                                      drivername);
         message = g_variant_new("(s@ayssus@ai@a(sv))",
                                 name,
                                 guuid,
@@ -489,8 +491,10 @@ int virSystemdCreateMachine(const char *name,
                                           uuid, 16, sizeof(unsigned char));
         gprops = g_variant_new_parsed("[('Slice', <%s>),"
                                       " ('After', <['libvirtd.service']>),"
+                                      " ('After', <['virt%sd.service']>),"
                                       " ('Before', <['virt-guest-shutdown.target']>)]",
-                                      slicename);
+                                      slicename,
+                                      drivername);
         message = g_variant_new("(s@ayssus@a(sv))",
                                 name,
                                 guuid,
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index 1a9b233e1177..3cf647619612 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -1,10 +1,20 @@
 [Unit]
 Description=Suspend/Resume Running libvirt Guests
-Wants=libvirtd.service
 Requires=virt-guest-shutdown.target
 After=network.target
 After=time-sync.target
+After=libvirtd.socket
+After=virtqemud.socket
+After=virtlxcd.socket
+After=virtvboxd.socket
+After=virtvzd.socket
+After=virtxend.socket
 After=libvirtd.service
+After=virtqemud.service
+After=virtlxcd.service
+After=virtvboxd.service
+After=virtvzd.service
+After=virtxend.service
 After=virt-guest-shutdown.target
 Documentation=man:libvirt-guests(8)
 Documentation=https://libvirt.org
-- 
2.35.1

Re: [libvirt PATCH v2] Make systemd unit ordering more robust
Posted by Michal Prívozník 2 years, 2 months ago
On 2/15/22 15:52, Martin Kletzander wrote:
> Since libvirt-guests script/service can operate on various URIs and we do
> support both socket activation and traditional services, the ordering should be
> specified for all the possible sockets and services.
> 
> Also remove the Wants= dependency since do not want to start any service.  We
> cannot know which one libvirt-guests is configured, so we'd have to start all
> the daemons which would break if unused colliding services are not
> masked (libvirtd.service in the modular case and all the modular daemon service
> units in the monolithic scenario).  Fortunately we can assume that the system is
> configured properly to start services/sockets that are of interest to the user.
> That also works with the setup described in https://libvirt.org/daemons.html .
> 
> To make it even more robust we add the daemon service into the machine units
> created for individual domains as it was missing there.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1868537
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/util/virsystemd.c           |  8 ++++++--
>  tools/libvirt-guests.service.in | 12 +++++++++++-
>  2 files changed, 17 insertions(+), 3 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal