mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 01:18:00 +03:00
qemu: capabilities: Don't make callers check return of virQEMUCapsNew(Binary)
The allocation of the object itself can't fail. What can fail is the creation of the class on a programming error. Rather than punting the error up the stack abort() directly on the first occurence as the error can't be fixed during runtime. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
bc52cc2fe4
commit
e61adbf26b
@ -1827,11 +1827,9 @@ virQEMUCapsNew(void)
|
||||
virQEMUCaps *qemuCaps;
|
||||
|
||||
if (virQEMUCapsInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(qemuCaps = virObjectNew(virQEMUCapsClass)))
|
||||
return NULL;
|
||||
abort();
|
||||
|
||||
qemuCaps = virObjectNew(virQEMUCapsClass);
|
||||
qemuCaps->invalidation = true;
|
||||
qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST);
|
||||
|
||||
@ -1844,8 +1842,7 @@ virQEMUCapsNewBinary(const char *binary)
|
||||
{
|
||||
virQEMUCaps *qemuCaps = virQEMUCapsNew();
|
||||
|
||||
if (qemuCaps)
|
||||
qemuCaps->binary = g_strdup(binary);
|
||||
qemuCaps->binary = g_strdup(binary);
|
||||
|
||||
return qemuCaps;
|
||||
}
|
||||
@ -1990,9 +1987,6 @@ virQEMUCaps *virQEMUCapsNewCopy(virQEMUCaps *qemuCaps)
|
||||
g_autoptr(virQEMUCaps) ret = virQEMUCapsNewBinary(qemuCaps->binary);
|
||||
size_t i;
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->invalidation = qemuCaps->invalidation;
|
||||
ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting;
|
||||
ret->kvmSupportsSecureGuest = qemuCaps->kvmSupportsSecureGuest;
|
||||
@ -5877,12 +5871,9 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
|
||||
const char *kernelVersion,
|
||||
virCPUData* cpuData)
|
||||
{
|
||||
g_autoptr(virQEMUCaps) qemuCaps = NULL;
|
||||
g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsNewBinary(binary);
|
||||
struct stat sb;
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
|
||||
return NULL;
|
||||
|
||||
/* We would also want to check faccessat if we cared about ACLs,
|
||||
* but we don't. */
|
||||
if (stat(binary, &sb) < 0) {
|
||||
@ -5968,9 +5959,6 @@ virQEMUCapsLoadFile(const char *filename,
|
||||
virQEMUCapsCachePriv *priv = privData;
|
||||
int ret;
|
||||
|
||||
if (!qemuCaps)
|
||||
return NULL;
|
||||
|
||||
ret = virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename, false);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
|
@ -3198,8 +3198,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
|
||||
return -1;
|
||||
}
|
||||
if (n > 0) {
|
||||
if (!(qemuCaps = virQEMUCapsNew()))
|
||||
return -1;
|
||||
qemuCaps = virQEMUCapsNew();
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
g_autofree char *str = virXMLPropString(nodes[i], "name");
|
||||
|
@ -458,8 +458,7 @@ cpuTestMakeQEMUCaps(const struct data *data)
|
||||
cpu, true, false, fail_no_props, &model) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNew()))
|
||||
return NULL;
|
||||
qemuCaps = virQEMUCapsNew();
|
||||
|
||||
virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
|
||||
if (data->flags == JSON_MODELS ||
|
||||
|
@ -95,9 +95,9 @@ testQemuCaps(const void *opaque)
|
||||
binary = g_strdup_printf("/usr/bin/qemu-system-%s",
|
||||
data->archName);
|
||||
|
||||
if (!(capsActual = virQEMUCapsNewBinary(binary)) ||
|
||||
virQEMUCapsInitQMPMonitor(capsActual,
|
||||
qemuMonitorTestGetMonitor(mon)) < 0)
|
||||
capsActual = virQEMUCapsNewBinary(binary);
|
||||
|
||||
if (virQEMUCapsInitQMPMonitor(capsActual, qemuMonitorTestGetMonitor(mon)) < 0)
|
||||
return -1;
|
||||
|
||||
if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) {
|
||||
|
@ -64,8 +64,7 @@ testQemuGetCaps(char *caps)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNew()))
|
||||
return NULL;
|
||||
qemuCaps = virQEMUCapsNew();
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
g_autofree char *str = virXMLPropString(nodes[i], "name");
|
||||
|
@ -68,8 +68,7 @@ qemuHotplugCreateObjects(virDomainXMLOption *xmlopt,
|
||||
|
||||
priv = (*vm)->privateData;
|
||||
|
||||
if (!(priv->qemuCaps = virQEMUCapsNew()))
|
||||
return -1;
|
||||
priv->qemuCaps = virQEMUCapsNew();
|
||||
|
||||
virQEMUCapsInitQMPBasicArch(priv->qemuCaps);
|
||||
|
||||
|
@ -81,10 +81,7 @@ mymain(void)
|
||||
DO_TEST("pc-kvm", 0);
|
||||
DO_TEST("pc-tcg", 0);
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNew())) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
qemuCaps = virQEMUCapsNew();
|
||||
|
||||
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
|
||||
|
||||
|
@ -322,8 +322,7 @@ mymain(void)
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNew()))
|
||||
return EXIT_FAILURE;
|
||||
qemuCaps = virQEMUCapsNew();
|
||||
|
||||
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA);
|
||||
virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC);
|
||||
|
@ -372,12 +372,11 @@ virQEMUCaps *
|
||||
qemuTestParseCapabilitiesArch(virArch arch,
|
||||
const char *capsFile)
|
||||
{
|
||||
g_autoptr(virQEMUCaps) qemuCaps = NULL;
|
||||
g_autofree char *binary = g_strdup_printf("/usr/bin/qemu-system-%s",
|
||||
virArchToString(arch));
|
||||
g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsNewBinary(binary);
|
||||
|
||||
if (!(qemuCaps = virQEMUCapsNewBinary(binary)) ||
|
||||
virQEMUCapsLoadCache(arch, qemuCaps, capsFile, true) < 0)
|
||||
if (virQEMUCapsLoadCache(arch, qemuCaps, capsFile, true) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&qemuCaps);
|
||||
@ -896,8 +895,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
|
||||
testQemuInfoArgName argname;
|
||||
int flag;
|
||||
|
||||
if (!(info->args.fakeCaps = virQEMUCapsNew()))
|
||||
abort();
|
||||
info->args.fakeCaps = virQEMUCapsNew();
|
||||
|
||||
info->conf = conf;
|
||||
info->args.newargs = true;
|
||||
|
Loading…
Reference in New Issue
Block a user