[Libguestfs] [v2v PATCH 7/9] output_qemu: reflect source VCPU model to the QEMU command line

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

At the moment, QEMU is always started with the default "qemu64" VCPU
model, even if the source hypervisor sets a particular VCPU model.
"qemu64" is not suitable for some guest OSes. Honor
"source.s_cpu_model"
via the "-cpu" option, if the source specifies the VCPU model. The
logic
is basically copied from "lib/create_ovf.ml".

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

diff --git a/output/output_qemu.ml b/output/output_qemu.ml
index f5e43705d101..385065f0579d 100644
--- a/output/output_qemu.ml
+++ b/output/output_qemu.ml
@@ -146,52 +146,58 @@ 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
+    );
+
     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
       | _ -> false
     and floppy_filter --
2.19.1.3.g30247aa5d201