[Libguestfs] [v2v PATCH 6/9] create_libvirt_xml: honor "gcaps_default_cpu"

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

If "s_cpu_model" is None and "gcaps_default_cpu" is
"false", generate the
<cpu mode="host-passthrough"/> element for libvirt.

This element produces an (almost) exact copy of the host (i.e., physical)
CPU for the guest, which is the best choice for guest OSes that cannot run
on QEMU's default VCPU type -- considering that domains converted by
virt-v2v are not expected to be migrateable without further tweaks by an
administrator.

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

diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index 1e0242a768a0..68d0a90918f3 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -158,58 +158,61 @@ let create_libvirt_xml ?pool source inspect
   (match source.s_genid with
    | 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 ||
+     not guestcaps.gcaps_default_cpu ||
      source.s_cpu_topology <> None then (
     let cpu_attrs = ref []
     and cpu = ref [] in

     (match source.s_cpu_model with
-     | None -> ()
+     | None ->
+         if not guestcaps.gcaps_default_cpu then
+           List.push_back cpu_attrs ("mode",
"host-passthrough");
      | 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" !cpu_attrs !cpu ]
   );

   let uefi_firmware      match target_firmware with
     | TargetBIOS -> None
--
2.19.1.3.g30247aa5d201