From dca563b296ab7479db898b033cce2563b61d8327 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 17 Mar 2023 13:55:54 +0100 Subject: [PATCH] libxlCapsInitGuests: Rework insane use of ternary operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/libxl/libxl_capabilities.c | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index cd40cff739..9fdc208f20 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -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 }; - 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, + 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, 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);