lib: Don't check for virCapabilitiesAddGuestDomain() retval

The virCapabilitiesAddGuestDomain() function can't fail. It
aborts on OOM. Therefore, there's no need to check for its
return value.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2021-10-07 10:47:28 +02:00
parent c18d9e23fa
commit 2996a94dd0
19 changed files with 68 additions and 176 deletions

View File

@ -54,18 +54,13 @@ virBhyveCapsBuild(void)
VIR_ARCH_X86_64, "bhyve",
NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_BHYVE,
NULL, NULL, 0, NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_BHYVE,
NULL, NULL, 0, NULL);
if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
VIR_WARN("Failed to get host CPU");
return caps;
error:
virObjectUnref(caps);
return NULL;
}
int

View File

@ -68,14 +68,8 @@ virCaps *virCHDriverCapsInit(void)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
caps->host.arch, NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_KVM,
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
return caps;
cleanup:

View File

@ -567,8 +567,8 @@ esxCapsInit(esxPrivate *priv)
NULL, NULL, 0,
NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL))
goto failure;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
/* x86_64 */
if (supportsLongMode == esxVI_Boolean_True) {
@ -577,8 +577,8 @@ esxCapsInit(esxPrivate *priv)
NULL, NULL,
0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL))
goto failure;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
}
return caps;

View File

@ -277,15 +277,15 @@ hypervCapsInit(hypervPrivate *priv)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686,
NULL, NULL, 0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, NULL, 0, NULL))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV,
NULL, NULL, 0, NULL);
/* x86_64 caps */
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
NULL, NULL, 0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, NULL, 0, NULL))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV,
NULL, NULL, 0, NULL);
return caps;

View File

@ -486,13 +486,8 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps)
machines);
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_XEN,
NULL,
NULL,
0,
NULL) == NULL)
return -1;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
NULL, NULL, 0, NULL);
if (guest_archs[i].pae)
virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_PAE);

View File

@ -100,26 +100,16 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
caps->host.arch, lxc_path, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_LXC,
NULL,
NULL,
0,
NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC,
NULL, NULL, 0, NULL);
/* On 64-bit hosts, we can use personality() to request a 32bit process */
if ((altArch = lxcContainerGetAlt32bitArch(caps->host.arch)) != VIR_ARCH_NONE) {
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
altArch, lxc_path, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_LXC,
NULL,
NULL,
0,
NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC,
NULL, NULL, 0, NULL);
}
if (driver) {

View File

@ -159,13 +159,8 @@ virCaps *openvzCapsInit(void)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
caps->host.arch, NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_OPENVZ,
NULL,
NULL,
0,
NULL) == NULL)
return NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_OPENVZ,
NULL, NULL, 0, NULL);
return g_steal_pointer(&caps);
}

View File

@ -1065,25 +1065,13 @@ virQEMUCapsInitGuestFromBinary(virCaps *caps,
true, false);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_TCG)) {
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_QEMU,
NULL,
NULL,
0,
NULL) == NULL) {
goto cleanup;
}
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL);
}
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_KVM,
NULL,
NULL,
0,
NULL) == NULL) {
goto cleanup;
}
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
}
if ((ARCH_IS_X86(guestarch) || guestarch == VIR_ARCH_AARCH64))

View File

@ -650,15 +650,8 @@ get_definition(vahControl * ctl, const char *xmlStr)
return -1;
}
if (virCapabilitiesAddGuestDomain(guest,
virtType,
NULL,
NULL,
0,
NULL) == NULL) {
vah_error(ctl, 0, _("could not allocate memory"));
return -1;
}
virCapabilitiesAddGuestDomain(guest, virtType,
NULL, NULL, 0, NULL);
ctl->def = virDomainDefParseString(xmlStr,
ctl->xmlopt, NULL,

View File

@ -348,13 +348,8 @@ testBuildCapabilities(virConnectPtr conn)
guest = virCapabilitiesAddGuest(caps, guest_types[i], VIR_ARCH_I686,
TEST_EMULATOR, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_TEST,
NULL,
NULL,
0,
NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST,
NULL, NULL, 0, NULL);
virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_PAE);
virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE);

View File

@ -104,13 +104,8 @@ vboxCapsInit(void)
caps->host.arch, NULL, NULL, 0, NULL);
return NULL;
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_VBOX,
NULL,
NULL,
0,
NULL) == NULL)
return NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VBOX,
NULL, NULL, 0, NULL);
return g_steal_pointer(&caps);
}

View File

@ -81,10 +81,8 @@ vmwareCapsInit(void)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_I686, NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
guest = NULL;
if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
@ -103,10 +101,8 @@ vmwareCapsInit(void)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_X86_64, NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL) == NULL)
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
guest = NULL;
}

View File

@ -88,9 +88,7 @@ vzCapsAddGuestDomain(virCaps *caps,
return -1;
if (virCapabilitiesAddGuestDomain(guest, virt_type,
NULL, NULL, 0, NULL) == NULL)
return -1;
virCapabilitiesAddGuestDomain(guest, virt_type, NULL, NULL, 0, NULL);
return 0;
}

View File

@ -906,27 +906,22 @@ virTestGenericCapsInit(void)
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686,
"/usr/bin/acme-virt", NULL, 0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST, NULL, NULL, 0, NULL))
return NULL;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL))
return NULL;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL))
return NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST,
NULL, NULL, 0, NULL);
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL);
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
"/usr/bin/acme-virt", NULL, 0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST, NULL, NULL, 0, NULL))
return NULL;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL))
return NULL;
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL))
return NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST,
NULL, NULL, 0, NULL);
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL);
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
if (virTestGetDebug() > 1) {
g_autofree char *caps_str = NULL;

View File

@ -23,18 +23,14 @@ testLXCCapsInit(void)
"/usr/libexec/libvirt_lxc", NULL,
0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL);
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
VIR_ARCH_X86_64,
"/usr/libexec/libvirt_lxc", NULL,
0, NULL);
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL);
if (virTestGetDebug()) {
g_autofree char *caps_str = NULL;

View File

@ -176,13 +176,8 @@ testQemuAddGuest(virCaps *caps,
arch == VIR_ARCH_X86_64)
virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION);
if (!virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_QEMU,
NULL,
NULL,
0,
NULL))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU,
NULL, NULL, 0, NULL);
if (kvm_machines[emu_arch] != NULL) {
nmachines = g_strv_length((char **)kvm_machines[emu_arch]);
@ -191,13 +186,9 @@ testQemuAddGuest(virCaps *caps,
if (machines == NULL)
goto error;
if (!virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_KVM,
qemu_emulators[emu_arch],
NULL,
nmachines,
machines))
goto error;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
qemu_emulators[emu_arch],
NULL, nmachines, machines);
}
return 0;

View File

@ -40,9 +40,8 @@ testXLInitCaps(void)
"/usr/lib/xen/boot/hvmloader",
nmachines, machines);
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
NULL, 0, NULL) == NULL)
goto cleanup;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
NULL, NULL, 0, NULL);
nmachines = G_N_ELEMENTS(xen_machines);
if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
goto cleanup;
@ -54,9 +53,8 @@ testXLInitCaps(void)
nmachines, machines);
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
NULL, 0, NULL) == NULL)
goto cleanup;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
NULL, NULL, 0, NULL);
nmachines = G_N_ELEMENTS(pvh_machines);
if ((machines = virCapabilitiesAllocMachines(pvh_machines, nmachines)) == NULL)
goto cleanup;
@ -68,9 +66,8 @@ testXLInitCaps(void)
nmachines, machines);
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
NULL, 0, NULL) == NULL)
goto cleanup;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
NULL, NULL, 0, NULL);
return caps;
cleanup:

View File

@ -35,26 +35,16 @@ testCapsInit(void)
VIR_ARCH_I686,
NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
NULL) == NULL) {
goto failure;
}
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
/* x86_64 guest */
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_X86_64,
NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
NULL) == NULL) {
goto failure;
}
return;
failure:
virObjectUnref(caps);
caps = NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
}
static int

View File

@ -36,27 +36,16 @@ testCapsInit(void)
VIR_ARCH_I686,
NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
NULL) == NULL) {
goto failure;
}
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
/* x86_64 guest */
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_X86_64,
NULL, NULL, 0, NULL);
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
NULL) == NULL) {
goto failure;
}
return;
failure:
virObjectUnref(caps);
virObjectUnref(xmlopt);
caps = NULL;
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL);
}
static int