mirror of https://gitee.com/openkylin/libvirt.git
Add API for issuing 'host_net_remove' monitor command
* src/qemu/qemu_monitor.h, src/qemu/qemu_monitor.c: Add new qemuMonitorRemoveHostNetwork() command for removing host networks * src/qemu/qemu_driver.c: Convert NIC hotplug methods over to use qemuMonitorRemoveHostNetwork()
This commit is contained in:
parent
4c10127b2c
commit
b06c97e51d
|
@ -4552,11 +4552,11 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
||||||
unsigned int qemuCmdFlags)
|
unsigned int qemuCmdFlags)
|
||||||
{
|
{
|
||||||
virDomainNetDefPtr net = dev->data.net;
|
virDomainNetDefPtr net = dev->data.net;
|
||||||
char *cmd = NULL, *reply = NULL, *remove_cmd = NULL;
|
|
||||||
char *tapfd_name = NULL;
|
char *tapfd_name = NULL;
|
||||||
int i, tapfd = -1;
|
int i, tapfd = -1;
|
||||||
char *nicstr = NULL;
|
char *nicstr = NULL;
|
||||||
char *netstr = NULL;
|
char *netstr = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_HOST_NET_ADD)) {
|
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_HOST_NET_ADD)) {
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
|
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
|
||||||
|
@ -4605,18 +4605,9 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
||||||
net->vlan, tapfd_name, &netstr) < 0)
|
net->vlan, tapfd_name, &netstr) < 0)
|
||||||
goto try_tapfd_close;
|
goto try_tapfd_close;
|
||||||
|
|
||||||
remove_cmd = NULL;
|
|
||||||
if (net->vlan >= 0 && net->hostnet_name &&
|
|
||||||
virAsprintf(&remove_cmd, "host_net_remove %d %s",
|
|
||||||
net->vlan, net->hostnet_name) < 0) {
|
|
||||||
virReportOOMError(conn);
|
|
||||||
goto try_tapfd_close;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorAddHostNetwork(vm, netstr) < 0)
|
if (qemuMonitorAddHostNetwork(vm, netstr) < 0)
|
||||||
goto try_tapfd_close;
|
goto try_tapfd_close;
|
||||||
|
|
||||||
VIR_FREE(tapfd_name);
|
|
||||||
if (tapfd != -1)
|
if (tapfd != -1)
|
||||||
close(tapfd);
|
close(tapfd);
|
||||||
tapfd = -1;
|
tapfd = -1;
|
||||||
|
@ -4630,28 +4621,28 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
||||||
&net->pci_addr.slot) < 0)
|
&net->pci_addr.slot) < 0)
|
||||||
goto try_remove;
|
goto try_remove;
|
||||||
|
|
||||||
VIR_FREE(netstr);
|
ret = 0;
|
||||||
VIR_FREE(nicstr);
|
|
||||||
VIR_FREE(remove_cmd);
|
|
||||||
|
|
||||||
vm->def->nets[vm->def->nnets++] = net;
|
vm->def->nets[vm->def->nnets++] = net;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
VIR_FREE(nicstr);
|
||||||
|
VIR_FREE(netstr);
|
||||||
|
VIR_FREE(tapfd_name);
|
||||||
|
if (tapfd != -1)
|
||||||
|
close(tapfd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
try_remove:
|
try_remove:
|
||||||
VIR_FREE(reply);
|
if (!net->hostnet_name || net->vlan == 0)
|
||||||
|
|
||||||
if (!remove_cmd)
|
|
||||||
VIR_WARN0(_("Unable to remove network backend\n"));
|
VIR_WARN0(_("Unable to remove network backend\n"));
|
||||||
else if (qemudMonitorCommand(vm, remove_cmd, &reply) < 0)
|
else if (qemuMonitorRemoveHostNetwork(vm, net->vlan, net->hostnet_name) < 0)
|
||||||
VIR_WARN(_("Failed to remove network backend with '%s'\n"), remove_cmd);
|
VIR_WARN(_("Failed to remove network backend for vlan %d, net %s"),
|
||||||
else
|
net->vlan, net->hostnet_name);
|
||||||
VIR_DEBUG("%s: host_net_remove reply: %s\n", vm->def->name, reply);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
try_tapfd_close:
|
try_tapfd_close:
|
||||||
VIR_FREE(reply);
|
|
||||||
|
|
||||||
if (tapfd_name &&
|
if (tapfd_name &&
|
||||||
qemuMonitorCloseFileHandle(vm, tapfd_name) < 0)
|
qemuMonitorCloseFileHandle(vm, tapfd_name) < 0)
|
||||||
VIR_WARN(_("Failed to close tapfd with '%s'\n"), tapfd_name);
|
VIR_WARN(_("Failed to close tapfd with '%s'\n"), tapfd_name);
|
||||||
|
@ -4660,16 +4651,7 @@ try_tapfd_close:
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
cleanup:
|
goto cleanup;
|
||||||
VIR_FREE(nicstr);
|
|
||||||
VIR_FREE(netstr);
|
|
||||||
VIR_FREE(cmd);
|
|
||||||
VIR_FREE(reply);
|
|
||||||
VIR_FREE(remove_cmd);
|
|
||||||
VIR_FREE(tapfd_name);
|
|
||||||
if (tapfd != -1)
|
|
||||||
close(tapfd);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
|
static int qemudDomainAttachHostPciDevice(virConnectPtr conn,
|
||||||
|
@ -4968,8 +4950,6 @@ qemudDomainDetachNetDevice(virConnectPtr conn,
|
||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
int i, ret = -1;
|
int i, ret = -1;
|
||||||
char *cmd = NULL;
|
|
||||||
char *reply = NULL;
|
|
||||||
virDomainNetDefPtr detach = NULL;
|
virDomainNetDefPtr detach = NULL;
|
||||||
|
|
||||||
for (i = 0 ; i < vm->def->nnets ; i++) {
|
for (i = 0 ; i < vm->def->nnets ; i++) {
|
||||||
|
@ -5002,19 +4982,8 @@ qemudDomainDetachNetDevice(virConnectPtr conn,
|
||||||
detach->pci_addr.slot) < 0)
|
detach->pci_addr.slot) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&cmd, "host_net_remove %d %s",
|
if (qemuMonitorRemoveHostNetwork(vm, detach->vlan, detach->hostnet_name) < 0)
|
||||||
detach->vlan, detach->hostnet_name) < 0) {
|
|
||||||
virReportOOMError(conn);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
|
|
||||||
_("network device dettach command '%s' failed"), cmd);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("%s: host_net_remove reply: %s", vm->def->name, reply);
|
|
||||||
|
|
||||||
if (vm->def->nnets > 1) {
|
if (vm->def->nnets > 1) {
|
||||||
memmove(vm->def->nets + i,
|
memmove(vm->def->nets + i,
|
||||||
|
@ -5034,8 +5003,6 @@ qemudDomainDetachNetDevice(virConnectPtr conn,
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(reply);
|
|
||||||
VIR_FREE(cmd);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1696,3 +1696,35 @@ cleanup:
|
||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorRemoveHostNetwork(const virDomainObjPtr vm,
|
||||||
|
int vlan,
|
||||||
|
const char *netname)
|
||||||
|
{
|
||||||
|
char *cmd;
|
||||||
|
char *reply = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (virAsprintf(&cmd, "host_net_remove %d %s", vlan, netname) < 0) {
|
||||||
|
virReportOOMError(NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
||||||
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("failed to remove host metnwork in qemu with '%s'"), cmd);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("%s: host_net_remove reply: %s", vm->def->name, reply);
|
||||||
|
|
||||||
|
/* XXX error messages here ? */
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(cmd);
|
||||||
|
VIR_FREE(reply);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -199,4 +199,8 @@ int qemuMonitorCloseFileHandle(const virDomainObjPtr vm,
|
||||||
int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
|
int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
|
||||||
const char *netstr);
|
const char *netstr);
|
||||||
|
|
||||||
|
int qemuMonitorRemoveHostNetwork(const virDomainObjPtr vm,
|
||||||
|
int vlan,
|
||||||
|
const char *netname);
|
||||||
|
|
||||||
#endif /* QEMU_MONITOR_TEXT_H */
|
#endif /* QEMU_MONITOR_TEXT_H */
|
||||||
|
|
Loading…
Reference in New Issue