[Libguestfs] [v2v PATCH 5/9] create_libvirt_xml: restrict 'match="minimum"' <cpu> attribute production

Laszlo Ersek
2022-04-20T16:23:29Z

The 'match="minimum"' attribute of the <cpu> element
only makes sense if
the CPU model is specified. If the CPU model is not specified by
"s_cpu_model", i.e., we produce the <cpu> element only due to
"s_cpu_topology", then we need no attributes for <cpu> at all.
Restrict
'match="minimum"' to when "s_cpu_model" is
specified.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076013
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 output/create_libvirt_xml.ml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index 4a71f8bb27f5..1e0242a768a0 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -159,76 +159,78 @@ let create_libvirt_xml ?pool source inspect
    | None -> ()
    | Some genid -> List.push_back body (e "genid" [] [PCData
genid])
   );


   (match get_osinfo_id inspect with
    | None -> ()
    | Some osinfo_id ->
      List.push_back_list body [
        e "metadata" [] [
          e "libosinfo:libosinfo" ["xmlns:libosinfo",
"http://libosinfo.org/xmlns/libvirt/domain/1.0"] [
            e "libosinfo:os" ["id", osinfo_id] [];
          ];
        ];
      ];
   );

   let memory_k = source.s_memory /^ 1024L in
   List.push_back_list body [
     e "memory" ["unit", "KiB"] [PCData
(Int64.to_string memory_k)];
     e "currentMemory" ["unit", "KiB"] [PCData
(Int64.to_string memory_k)];
     e "vcpu" [] [PCData (string_of_int source.s_vcpu)]
   ];

   if source.s_cpu_model <> None ||
      source.s_cpu_topology <> None then (
-    let cpu = ref [] in
+    let cpu_attrs = ref []
+    and cpu = ref [] in

     (match source.s_cpu_model with
      | None -> ()
      | Some model ->
+         List.push_back cpu_attrs ("match", "minimum");
          (match source.s_cpu_vendor with
           | None -> ()
           | Some vendor ->
               List.push_back cpu (e "vendor" [] [PCData vendor])
          );
          List.push_back cpu (e "model" ["fallback",
"allow"] [PCData model])
     );
     (match source.s_cpu_topology with
      | None -> ()
      | Some { s_cpu_sockets; s_cpu_cores; s_cpu_threads } ->
         let topology_attrs = [
           "sockets", string_of_int s_cpu_sockets;
           "cores", string_of_int s_cpu_cores;
           "threads", string_of_int s_cpu_threads;
         ] in
         List.push_back cpu (e "topology" topology_attrs [])
     );

-    List.push_back_list body [ e "cpu" [ "match",
"minimum" ] !cpu ]
+    List.push_back_list body [ e "cpu" !cpu_attrs !cpu ]
   );

   let uefi_firmware      match target_firmware with
     | TargetBIOS -> None
     | TargetUEFI -> Some (find_uefi_firmware guestcaps.gcaps_arch) in
   let machine, secure_boot_required      match guestcaps.gcaps_machine,
uefi_firmware with
     | _, Some { Uefi.flags = flags }
          when List.mem Uefi.UEFI_FLAG_SECURE_BOOT_REQUIRED flags ->
        (* Force machine type to Q35 because PC does not support
         * secure boot.  We must remove this when we get the
         * correct machine type from libosinfo in future. XXX
         *)
        Q35, true
     | machine, _ ->
        machine, false in
   let smm = secure_boot_required in

   (* We have the machine features of the guest when it was on the
    * source hypervisor (source.s_features).  We have the acpi flag
    * which tells us whether acpi is required by this guest
    * (guestcaps.gcaps_acpi).  And we have the set of hypervisor
    * features supported by the target (target_features).  Combine all
    * this into a final list of features.
    *)
--
2.19.1.3.g30247aa5d201