mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
bhyve: use g_strdup instead of VIR_STRDUP
Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7b48bb8ca0
commit
652cdbe364
@ -58,12 +58,10 @@ bhyveBuildNetArgStr(virConnectPtr conn,
|
|||||||
virDomainNetType actualType = virDomainNetGetActualType(net);
|
virDomainNetType actualType = virDomainNetGetActualType(net);
|
||||||
|
|
||||||
if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) {
|
if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) {
|
||||||
if (VIR_STRDUP(nic_model, "virtio-net") < 0)
|
nic_model = g_strdup("virtio-net");
|
||||||
return -1;
|
|
||||||
} else if (net->model == VIR_DOMAIN_NET_MODEL_E1000) {
|
} else if (net->model == VIR_DOMAIN_NET_MODEL_E1000) {
|
||||||
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) {
|
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) {
|
||||||
if (VIR_STRDUP(nic_model, "e1000") < 0)
|
nic_model = g_strdup("e1000");
|
||||||
return -1;
|
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("NIC model 'e1000' is not supported "
|
_("NIC model 'e1000' is not supported "
|
||||||
@ -77,8 +75,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||||
if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0)
|
brname = g_strdup(virDomainNetGetActualBridgeName(net));
|
||||||
goto cleanup;
|
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Network type %d is not supported"),
|
_("Network type %d is not supported"),
|
||||||
@ -90,8 +87,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
|
|||||||
STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) ||
|
STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) ||
|
||||||
strchr(net->ifname, '%')) {
|
strchr(net->ifname, '%')) {
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0)
|
net->ifname = g_strdup(VIR_NET_GENERATED_TAP_PREFIX "%d");
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dryRun) {
|
if (!dryRun) {
|
||||||
@ -117,8 +113,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
|
|||||||
if (virNetDevSetOnline(net->ifname, true) != 0)
|
if (virNetDevSetOnline(net->ifname, true) != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if (VIR_STRDUP(realifname, "tap0") < 0)
|
realifname = g_strdup("tap0");
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ virBhyveDriverConfigNew(void)
|
|||||||
if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
|
if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_STRDUP(cfg->firmwareDir, DATADIR "/uefi-firmware") < 0)
|
cfg->firmwareDir = g_strdup(DATADIR "/uefi-firmware");
|
||||||
goto error;
|
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
|
|
||||||
|
@ -470,8 +470,7 @@ bhyveDomainGetOSType(virDomainPtr dom)
|
|||||||
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0)
|
ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
|
@ -299,16 +299,8 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(chr->source->data.nmdm.master, param) < 0) {
|
chr->source->data.nmdm.master = g_strdup(param);
|
||||||
virDomainChrDefFree(chr);
|
chr->source->data.nmdm.slave = g_strdup(chr->source->data.file.path);
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_STRDUP(chr->source->data.nmdm.slave, chr->source->data.file.path)
|
|
||||||
< 0) {
|
|
||||||
virDomainChrDefFree(chr);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the last character of the master is 'A', the slave will be 'B'
|
/* If the last character of the master is 'A', the slave will be 'B'
|
||||||
* and vice versa */
|
* and vice versa */
|
||||||
@ -456,13 +448,11 @@ bhyveParsePCIDisk(virDomainDefPtr def,
|
|||||||
if (bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
|
if (bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
|
||||||
idx = *nvirtiodisk;
|
idx = *nvirtiodisk;
|
||||||
*nvirtiodisk += 1;
|
*nvirtiodisk += 1;
|
||||||
if (VIR_STRDUP(disk->dst, "vda") < 0)
|
disk->dst = g_strdup("vda");
|
||||||
goto error;
|
|
||||||
} else if (bus == VIR_DOMAIN_DISK_BUS_SATA) {
|
} else if (bus == VIR_DOMAIN_DISK_BUS_SATA) {
|
||||||
idx = *nahcidisk;
|
idx = *nahcidisk;
|
||||||
*nahcidisk += 1;
|
*nahcidisk += 1;
|
||||||
if (VIR_STRDUP(disk->dst, "sda") < 0)
|
disk->dst = g_strdup("sda");
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx > 'z' - 'a') {
|
if (idx > 'z' - 'a') {
|
||||||
@ -507,8 +497,7 @@ bhyveParsePCINet(virDomainDefPtr def,
|
|||||||
* guess the actual bridge name from the command line,
|
* guess the actual bridge name from the command line,
|
||||||
* try to come up with some reasonable defaults */
|
* try to come up with some reasonable defaults */
|
||||||
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
||||||
if (VIR_STRDUP(net->data.bridge.brname, "virbr0") < 0)
|
net->data.bridge.brname = g_strdup("virbr0");
|
||||||
goto error;
|
|
||||||
|
|
||||||
net->model = model;
|
net->model = model;
|
||||||
net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
||||||
@ -738,8 +727,7 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (def->name == NULL) {
|
if (def->name == NULL) {
|
||||||
if (VIR_STRDUP(def->name, argv[argc]) < 0)
|
def->name = g_strdup(argv[argc]);
|
||||||
goto error;
|
|
||||||
} else if (STRNEQ(def->name, argv[argc])) {
|
} else if (STRNEQ(def->name, argv[argc])) {
|
||||||
/* the vm name of the loader and the bhyverun command differ, throw an
|
/* the vm name of the loader and the bhyverun command differ, throw an
|
||||||
* error here */
|
* error here */
|
||||||
@ -819,15 +807,12 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
|||||||
if (arguments != 3) {
|
if (arguments != 3) {
|
||||||
/* Set os.bootloader since virDomainDefFormatInternal will only format
|
/* Set os.bootloader since virDomainDefFormatInternal will only format
|
||||||
* the bootloader arguments if os->bootloader is set. */
|
* the bootloader arguments if os->bootloader is set. */
|
||||||
if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0)
|
def->os.bootloader = g_strdup(argv[0]);
|
||||||
goto error;
|
|
||||||
|
|
||||||
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->name == NULL) {
|
if (def->name == NULL) {
|
||||||
if (VIR_STRDUP(def->name, argv[argc]) < 0)
|
def->name = g_strdup(argv[argc]);
|
||||||
goto error;
|
|
||||||
} else if (STRNEQ(def->name, argv[argc])) {
|
} else if (STRNEQ(def->name, argv[argc])) {
|
||||||
/* the vm name of the loader and the bhyverun command differ, throw an
|
/* the vm name of the loader and the bhyverun command differ, throw an
|
||||||
* error here */
|
* error here */
|
||||||
@ -849,9 +834,7 @@ bhyveParseCustomLoaderCommandLine(virDomainDefPtr def,
|
|||||||
if (!argv)
|
if (!argv)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0)
|
def->os.bootloader = g_strdup(argv[0]);
|
||||||
goto error;
|
|
||||||
|
|
||||||
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user