]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxlCapsInitGuests: Rework insane use of ternary operators
authorPeter Krempa <pkrempa@redhat.com>
Fri, 17 Mar 2023 12:55:54 +0000 (13:55 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Apr 2023 07:19:07 +0000 (09:19 +0200)
Get rid of nested ternaries by adding a few helper variables and more
explicit if conditions to fill them appropriately.

Note that 'virCapabilitiesAllocMachines' doesn't require return value
check any more as it can't fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libxl/libxl_capabilities.c

index cd40cff739cf9bb29867a646fe847be4410973bd..9fdc208f205d2cabc0615c13f7e25db1c6ca3a4f 100644 (file)
@@ -463,26 +463,32 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps)
 
     for (i = 0; i < nr_guest_archs; ++i) {
         virCapsGuest *guest;
-        char const *const xen_machines[] = {
-            guest_archs[i].hvm ? "xenfv" :
-                (guest_archs[i].pvh ? "xenpvh" : "xenpv")};
         virCapsGuestMachine **machines;
+        virDomainOSType ostype = VIR_DOMAIN_OSTYPE_XEN;
+        const char *loader = NULL;
 
-        if ((machines = virCapabilitiesAllocMachines(xen_machines, 1)) == NULL)
-            return -1;
+        if (guest_archs[i].hvm) {
+            char const *const xen_machines[] = { "xenfv", NULL };
+
+            ostype = VIR_DOMAIN_OSTYPE_HVM;
+            loader = LIBXL_FIRMWARE_DIR "/hvmloader";
+
+            machines = virCapabilitiesAllocMachines(xen_machines, 1);
+        } else if (guest_archs[i].pvh) {
+            char const *const xen_machines[] = { "xenpvh", NULL };
+
+            ostype = VIR_DOMAIN_OSTYPE_XENPVH;
+            machines = virCapabilitiesAllocMachines(xen_machines, 1);
+        } else {
+            char const *const xen_machines[] = { "xenpv", NULL };
+
+            ostype = VIR_DOMAIN_OSTYPE_XEN;
+            machines = virCapabilitiesAllocMachines(xen_machines, 1);
+        }
 
-        guest = virCapabilitiesAddGuest(caps,
-                                        guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM :
-                                        (guest_archs[i].pvh ? VIR_DOMAIN_OSTYPE_XENPVH :
-                                         VIR_DOMAIN_OSTYPE_XEN),
-                                        guest_archs[i].arch,
+        guest = virCapabilitiesAddGuest(caps, ostype, guest_archs[i].arch,
                                         LIBXL_EXECBIN_DIR "/qemu-system-i386",
-                                        (guest_archs[i].hvm ?
-                                         LIBXL_FIRMWARE_DIR "/hvmloader" :
-                                         NULL),
-                                        1,
-                                        machines);
-        machines = NULL;
+                                        loader, 1, machines);
 
         virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
                                       NULL, NULL, 0, NULL);