Blame SOURCES/0034-convert_linux-start-the-QEMU-guest-agent-in-a-distro.patch

696189
From 7dd396af54df3f7563aa3a42b3c17547710aec67 Mon Sep 17 00:00:00 2001
696189
From: Laszlo Ersek <lersek@redhat.com>
696189
Date: Wed, 17 Aug 2022 16:47:36 +0200
696189
Subject: [PATCH] convert_linux: start the QEMU guest agent in a
696189
 distro-specific way
696189
696189
The current command "service <package-name> start" does not apply to
696189
RHEL-6; the service name ("qemu-ga") differs from the package name
696189
("qemu-guest-agent") there.
696189
696189
Overhaul the logic -- detach the command from the package name; cover the
696189
RHEL, ALT, SUSE and Debian families separately. Remove the "chkconfig"
696189
command, as in all tested / investigated cases, it is unnecessary.
696189
696189
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2028764
696189
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
696189
Message-Id: <20220817144736.18850-1-lersek@redhat.com>
696189
Acked-by: Richard W.M. Jones <rjones@redhat.com>
696189
(cherry picked from commit ad2b4f2e50950a5798a75359badb526290aa92e7)
696189
---
696189
 convert/convert_linux.ml | 56 ++++++++++++++++++++++++++++------------
696189
 1 file changed, 40 insertions(+), 16 deletions(-)
696189
696189
diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
696189
index 2aaa438e..b8e9ad15 100644
696189
--- a/convert/convert_linux.ml
696189
+++ b/convert/convert_linux.ml
696189
@@ -66,6 +66,34 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
696189
     | _ -> None
696189
   in
696189
 
696189
+  let qga_svc_start_cmd family distro major =
696189
+    match family, distro, major with
696189
+    | `RHEL_family, ( "rhel" | "centos" | "scientificlinux" | "redhat-based" |
696189
+                      "oraclelinux" ), 6 ->
696189
+      (* https://bugzilla.redhat.com/show_bug.cgi?id=2028764#c52 *)
696189
+      Some "service qemu-ga start"
696189
+
696189
+    | `RHEL_family, _, _ ->
696189
+      (* https://bugzilla.redhat.com/show_bug.cgi?id=2028764#c52 *)
696189
+      Some "systemctl start qemu-guest-agent"
696189
+
696189
+    | `ALT_family, _, _ ->
696189
+      (* https://bugzilla.redhat.com/show_bug.cgi?id=2028764#c45 *)
696189
+      Some "systemctl start qemu-guest-agent"
696189
+
696189
+    | `SUSE_family, _, _ ->
696189
+      (* https://bugzilla.redhat.com/show_bug.cgi?id=2028764#c51 *)
696189
+      None
696189
+
696189
+    | `Debian_family, _, _ ->
696189
+      (* https://bugzilla.redhat.com/show_bug.cgi?id=2028764#c42 *)
696189
+      Some "service qemu-guest-agent start"
696189
+
696189
+    | _ ->
696189
+      (* should never be called when "qga_pkg_of_family" returns None *)
696189
+      assert false
696189
+  in
696189
+
696189
   assert (inspect.i_package_format = "rpm" || inspect.i_package_format = "deb");
696189
 
696189
   (* Fail early if i_apps is empty.  Certain steps such as kernel
696189
@@ -615,23 +643,19 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
696189
                         \ \ rm -f %s\n\
696189
                         fi\n" selinux_enforcing selinux_enforcing);
696189
 
696189
-            (* Start the agent now and at subsequent boots. The following
696189
-             * commands should work on both sysvinit distros / distro versions
696189
-             * (regardless of "/etc/rc.d/" vs. "/etc/init.d/" being the scheme
696189
-             * in use) and systemd distros (via redirection to systemctl).
696189
-             *
696189
-             * On distros where the chkconfig command is redirected to
696189
-             * systemctl, the chkconfig command is likely superfluous. That's
696189
-             * because on systemd distros, the QGA package comes with such
696189
-             * runtime dependencies / triggers that the presence of the
696189
-             * virtio-serial port named "org.qemu.guest_agent.0" automatically
696189
-             * starts the agent during (second and later) boots. However, even
696189
-             * on such distros, the chkconfig command should do no harm.
696189
+            (* On all the distro families covered by "qga_pkg_of_family" and
696189
+             * "qga_svc_start_cmd", the QEMU guest agent service is always
696189
+             * enabled by package installation for *subsequent* boots. Package
696189
+             * installation may or may not enable the service for the current
696189
+             * (i.e., first) boot, however, so try that here manually.
696189
              *)
696189
-            fbs "start qga"
696189
-              (sprintf "#!/bin/sh\n\
696189
-                        service %s start\n\
696189
-                        chkconfig %s on\n" qga_pkg qga_pkg)
696189
+            match qga_svc_start_cmd family inspect.i_distro inspect.i_major_version
696189
+            with
696189
+            | None -> ()
696189
+            | Some start_cmd ->
696189
+              fbs "start qga"
696189
+                (sprintf "#!/bin/sh\n\
696189
+                          %s\n" start_cmd)
696189
           with
696189
           | Guest_packages.Unknown_package_manager msg
696189
           | Guest_packages.Unimplemented_package_manager msg ->