[Libguestfs] [v2v PATCH 8/9] output_qemu: honor "gcaps_default_cpu"

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

If "s_cpu_model" is None and "gcaps_default_cpu" is
"false", generate the
"-cpu host" option for QEMU.

"-cpu host" 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/output_qemu.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/output/output_qemu.ml b/output/output_qemu.ml
index 385065f0579d..29adcba901a3 100644
--- a/output/output_qemu.ml
+++ b/output/output_qemu.ml
@@ -147,55 +147,56 @@ module QEMU = struct
     flag "-no-user-config"; flag "-nodefaults";
     arg "-name" output_name;

     (match source.s_genid with
      | None -> ()
      | Some genid ->
         arg_list "-device" ["vmgenid"; sprintf
"guid=%s" genid; "id=vmgenid0"]
     );

     arg_list "-machine" (machine_str ::
                            (if smm then ["smm=on"] else []) @
                            ["accel=kvm:tcg"]);

     (match uefi_firmware with
      | None -> ()
      | Some { Uefi.code } ->
         if secure_boot_required then
           arg_list "-global"
             ["driver=cfi.pflash01"; "property=secure";
"value=on"];
         arg_list "-drive"
           ["if=pflash"; "format=raw"; "file=" ^
code; "readonly"];
         arg_noquote "-drive"
"if=pflash,format=raw,file=\"$uefi_vars\"";
     );

     arg "-m" (Int64.to_string (source.s_memory /^ 1024L /^ 1024L));

-    (match source.s_cpu_model with
-      | None -> ()
-      | Some model -> arg "-cpu" model
+    (match source.s_cpu_model, guestcaps.gcaps_default_cpu with
+      | None, true -> ()
+      | None, false -> arg "-cpu" "host"
+      | Some model, _ -> arg "-cpu" model
     );

     if source.s_vcpu > 1 then (
       (match source.s_cpu_topology with
        | None ->
           arg "-smp" (string_of_int source.s_vcpu)
        | Some { s_cpu_sockets; s_cpu_cores; s_cpu_threads } ->
           let args = [
               sprintf "cpus=%d" source.s_vcpu;
               sprintf "sockets=%d" s_cpu_sockets;
               sprintf "cores=%d" s_cpu_cores;
               sprintf "threads=%d" s_cpu_threads;
             ] in
           arg_list "-smp" args
       );
     );

     (* For IDE disks, IDE CD-ROMs, SCSI disks, SCSI CD-ROMs, and floppies, we
      * need host-bus adapters (HBAs) between these devices and the PCI(e) root
      * bus. Some machine types create these HBAs automatically (despite
      * "-no-user-config -nodefaults"), some don't...
      *)
     let disk_cdrom_filter        function
       | BusSlotDisk _
       | BusSlotRemovable { s_removable_type = CDROM } -> true
--
2.19.1.3.g30247aa5d201