Laszlo Ersek
2022-Apr-20 16:23 UTC
[Libguestfs] [v2v PATCH 2/9] create_libvirt_xml: simplify match on (s_cpu_vendor, s_cpu_model)
Squash the patterns | None, None -> () | Some _, None -> () into the identical | _, None -> () We preserve the behavior added by commit 2a576b7cc5c3 ("v2v: -o libvirt: Don't write only <vendor> without <model> (RHBZ#1591789).", 2018-06-21); the change only simplifies the code. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076013 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- output/create_libvirt_xml.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml index 36173e58cd6c..4e5bbceffabd 100644 --- a/output/create_libvirt_xml.ml +++ b/output/create_libvirt_xml.ml @@ -162,55 +162,57 @@ let create_libvirt_xml ?pool source inspect (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_vendor <> None || source.s_cpu_model <> None || source.s_cpu_topology <> None then ( let cpu = ref [] in (match source.s_cpu_vendor, source.s_cpu_model with - | None, None - (* Avoid libvirt error: "CPU vendor specified without CPU model" *) - | Some _, None -> () + | _, None -> + (* This also avoids the libvirt error: + * "CPU vendor specified without CPU model". + *) + () | None, Some model -> List.push_back cpu (e "model" ["fallback", "allow"] [PCData model]) | Some vendor, Some model -> List.push_back_list cpu [ e "vendor" [] [PCData vendor]; 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 ] ); let uefi_firmware match target_firmware with | TargetBIOS -> None | TargetUEFI -> Some (find_uefi_firmware guestcaps.gcaps_arch) in -- 2.19.1.3.g30247aa5d201
Richard W.M. Jones
2022-Apr-20 16:49 UTC
[Libguestfs] [v2v PATCH 2/9] create_libvirt_xml: simplify match on (s_cpu_vendor, s_cpu_model)
On Wed, Apr 20, 2022 at 06:23:26PM +0200, Laszlo Ersek wrote:> Squash the patterns > > | None, None -> () > | Some _, None -> () > > into the identical > > | _, None -> () > > We preserve the behavior added by commit 2a576b7cc5c3 ("v2v: -o libvirt: > Don't write only <vendor> without <model> (RHBZ#1591789).", 2018-06-21); > the change only simplifies the code. > > Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2076013 > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > output/create_libvirt_xml.ml | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml > index 36173e58cd6c..4e5bbceffabd 100644 > --- a/output/create_libvirt_xml.ml > +++ b/output/create_libvirt_xml.ml > @@ -162,55 +162,57 @@ let create_libvirt_xml ?pool source inspect > > > (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_vendor <> None || source.s_cpu_model <> None || > source.s_cpu_topology <> None then ( > let cpu = ref [] in > > (match source.s_cpu_vendor, source.s_cpu_model with > - | None, None > - (* Avoid libvirt error: "CPU vendor specified without CPU model" *) > - | Some _, None -> () > + | _, None -> > + (* This also avoids the libvirt error: > + * "CPU vendor specified without CPU model". > + *) > + () > | None, Some model -> > List.push_back cpu (e "model" ["fallback", "allow"] [PCData model]) > | Some vendor, Some model -> > List.push_back_list cpu [ > e "vendor" [] [PCData vendor]; > 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 ] > ); > > let uefi_firmware > match target_firmware with > | TargetBIOS -> None > | TargetUEFI -> Some (find_uefi_firmware guestcaps.gcaps_arch) inReviewed-by: Richard W.M. Jones <rjones at redhat.com> As an aside, your git includes a crazy large amount of context around the changes ... Is that a configuration change? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html