mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 14:35:25 +00:00
Clean up error handling in qemudDomainAttachNetDevice()
In subsequent patches we're going to have a file descriptor to close too, so centralize the error handling cleanups to make things easier. * src/qemu_conf.c: in qemudDomainAttachNetDevice() consolidate the error handling cleanups together
This commit is contained in:
parent
32db8dd75b
commit
be44cabd7f
@ -4858,7 +4858,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
unsigned int qemuCmdFlags)
|
unsigned int qemuCmdFlags)
|
||||||
{
|
{
|
||||||
virDomainNetDefPtr net = dev->data.net;
|
virDomainNetDefPtr net = dev->data.net;
|
||||||
char *cmd, *reply, *remove_cmd;
|
char *cmd = NULL, *reply = NULL, *remove_cmd = NULL;
|
||||||
int i;
|
int i;
|
||||||
unsigned domain, bus, slot;
|
unsigned domain, bus, slot;
|
||||||
|
|
||||||
@ -4876,16 +4876,12 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) {
|
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0)
|
||||||
virReportOOMError(conn);
|
goto no_memory;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
|
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
|
||||||
qemuAssignNetNames(vm->def, net) < 0) {
|
qemuAssignNetNames(vm->def, net) < 0)
|
||||||
virReportOOMError(conn);
|
goto no_memory;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Choose a vlan value greater than all other values since
|
/* Choose a vlan value greater than all other values since
|
||||||
* older versions did not store the value in the state file.
|
* older versions did not store the value in the state file.
|
||||||
@ -4897,23 +4893,19 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
|
|
||||||
if (qemuBuildHostNetStr(conn, net,
|
if (qemuBuildHostNetStr(conn, net,
|
||||||
"host_net_add ", ' ', net->vlan, NULL, &cmd) < 0)
|
"host_net_add ", ' ', net->vlan, NULL, &cmd) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
remove_cmd = NULL;
|
remove_cmd = NULL;
|
||||||
if (net->vlan >= 0 && net->hostnet_name &&
|
if (net->vlan >= 0 && net->hostnet_name &&
|
||||||
virAsprintf(&remove_cmd, "host_net_remove %d %s",
|
virAsprintf(&remove_cmd, "host_net_remove %d %s",
|
||||||
net->vlan, net->hostnet_name) < 0) {
|
net->vlan, net->hostnet_name) < 0) {
|
||||||
VIR_FREE(cmd);
|
goto no_memory;
|
||||||
virReportOOMError(conn);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
_("failed to add network backend with '%s'"), cmd);
|
_("failed to add network backend with '%s'"), cmd);
|
||||||
VIR_FREE(remove_cmd);
|
goto cleanup;
|
||||||
VIR_FREE(cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
|
DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
|
||||||
@ -4928,19 +4920,16 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
_("failed to add NIC with '%s'"), cmd);
|
_("failed to add NIC with '%s'"), cmd);
|
||||||
VIR_FREE(cmd);
|
|
||||||
goto try_remove;
|
goto try_remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(cmd);
|
|
||||||
|
|
||||||
if (qemudParsePciAddReply(vm, reply, &domain, &bus, &slot) < 0) {
|
if (qemudParsePciAddReply(vm, reply, &domain, &bus, &slot) < 0) {
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
_("parsing pci_add reply failed: %s"), reply);
|
_("parsing pci_add reply failed: %s"), reply);
|
||||||
VIR_FREE(reply);
|
|
||||||
goto try_remove;
|
goto try_remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_FREE(cmd);
|
||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
VIR_FREE(remove_cmd);
|
VIR_FREE(remove_cmd);
|
||||||
|
|
||||||
@ -4953,7 +4942,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
try_remove:
|
try_remove:
|
||||||
reply = NULL;
|
VIR_FREE(reply);
|
||||||
|
|
||||||
if (!remove_cmd)
|
if (!remove_cmd)
|
||||||
VIR_WARN0(_("Unable to remove network backend\n"));
|
VIR_WARN0(_("Unable to remove network backend\n"));
|
||||||
@ -4961,10 +4950,14 @@ try_remove:
|
|||||||
VIR_WARN(_("Failed to remove network backend with '%s'\n"), remove_cmd);
|
VIR_WARN(_("Failed to remove network backend with '%s'\n"), remove_cmd);
|
||||||
else
|
else
|
||||||
VIR_DEBUG("%s: host_net_remove reply: %s\n", vm->def->name, reply);
|
VIR_DEBUG("%s: host_net_remove reply: %s\n", vm->def->name, reply);
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
no_memory:
|
||||||
|
virReportOOMError(conn);
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(cmd);
|
||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
VIR_FREE(remove_cmd);
|
VIR_FREE(remove_cmd);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user