提交 4c10127b 编写于 作者: D Daniel P. Berrange

Add API for issuing 'host_net_add' monitor command

* src/qemu/qemu_conf.h, src/qemu/qemu_conf.c: Remove prefix arg
  from qemuBuildHostNetStr which is no longer required
* src/qemu/qemu_driver.c: Refactor to use qemuMonitorAddHostNetwork()
  API for adding host network
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add new
  qemuMonitorAddHostNetwork() method for adding host networks
上级 f8d54e7c
......@@ -1287,7 +1287,6 @@ qemuBuildNicStr(virConnectPtr conn,
int
qemuBuildHostNetStr(virConnectPtr conn,
virDomainNetDefPtr net,
const char *prefix,
char type_sep,
int vlan,
const char *tapfd,
......@@ -1296,8 +1295,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_BRIDGE:
if (virAsprintf(str, "%stap%cfd=%s,vlan=%d%s%s",
prefix ? prefix : "",
if (virAsprintf(str, "tap%cfd=%s,vlan=%d%s%s",
type_sep, tapfd, vlan,
(net->hostnet_name ? ",name=" : ""),
(net->hostnet_name ? net->hostnet_name : "")) < 0) {
......@@ -1310,8 +1308,6 @@ qemuBuildHostNetStr(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (prefix)
virBufferAdd(&buf, prefix, strlen(prefix));
virBufferAddLit(&buf, "tap");
if (net->ifname) {
virBufferVSprintf(&buf, "%cifname=%s", type_sep, net->ifname);
......@@ -1355,8 +1351,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
break;
}
if (virAsprintf(str, "%ssocket%c%s=%s:%d,vlan=%d%s%s",
prefix ? prefix : "",
if (virAsprintf(str, "socket%c%s=%s:%d,vlan=%d%s%s",
type_sep, mode,
net->data.socket.address,
net->data.socket.port,
......@@ -1371,8 +1366,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_USER:
default:
if (virAsprintf(str, "%suser%cvlan=%d%s%s",
prefix ? prefix : "",
if (virAsprintf(str, "user%cvlan=%d%s%s",
type_sep, vlan,
(net->hostnet_name ? ",name=" : ""),
(net->hostnet_name ? net->hostnet_name : "")) < 0) {
......@@ -2014,7 +2008,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto no_memory;
}
if (qemuBuildHostNetStr(conn, net, NULL, ',',
if (qemuBuildHostNetStr(conn, net, ',',
net->vlan, tapfd_name, &host) < 0) {
VIR_FREE(tapfd_name);
goto error;
......
......@@ -170,7 +170,6 @@ int qemudBuildCommandLine (virConnectPtr conn,
int qemuBuildHostNetStr (virConnectPtr conn,
virDomainNetDefPtr net,
const char *prefix,
char type_sep,
int vlan,
const char *tapfd,
......
......@@ -4556,6 +4556,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
char *tapfd_name = NULL;
int i, tapfd = -1;
char *nicstr = NULL;
char *netstr = NULL;
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_HOST_NET_ADD)) {
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
......@@ -4600,8 +4601,8 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
goto cleanup;
}
if (qemuBuildHostNetStr(conn, net, "host_net_add ", ' ',
net->vlan, tapfd_name, &cmd) < 0)
if (qemuBuildHostNetStr(conn, net, ' ',
net->vlan, tapfd_name, &netstr) < 0)
goto try_tapfd_close;
remove_cmd = NULL;
......@@ -4612,16 +4613,9 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
goto try_tapfd_close;
}
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
_("failed to add network backend with '%s'"), cmd);
if (qemuMonitorAddHostNetwork(vm, netstr) < 0)
goto try_tapfd_close;
}
DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
VIR_FREE(reply);
VIR_FREE(cmd);
VIR_FREE(tapfd_name);
if (tapfd != -1)
close(tapfd);
......@@ -4636,6 +4630,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
&net->pci_addr.slot) < 0)
goto try_remove;
VIR_FREE(netstr);
VIR_FREE(nicstr);
VIR_FREE(remove_cmd);
......@@ -4667,6 +4662,7 @@ no_memory:
virReportOOMError(conn);
cleanup:
VIR_FREE(nicstr);
VIR_FREE(netstr);
VIR_FREE(cmd);
VIR_FREE(reply);
VIR_FREE(remove_cmd);
......
......@@ -1666,3 +1666,33 @@ cleanup:
return ret;
}
int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
const char *netstr)
{
char *cmd;
char *reply = NULL;
int ret = -1;
if (virAsprintf(&cmd, "host_net_add %s", netstr) < 0) {
virReportOOMError(NULL);
return -1;
}
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("failed to close fd in qemu with '%s'"), cmd);
goto cleanup;
}
DEBUG("%s: host_net_add reply: %s", vm->def->name, reply);
/* XXX error messages here ? */
ret = 0;
cleanup:
VIR_FREE(cmd);
VIR_FREE(reply);
return ret;
}
......@@ -192,4 +192,11 @@ int qemuMonitorSendFileHandle(const virDomainObjPtr vm,
int qemuMonitorCloseFileHandle(const virDomainObjPtr vm,
const char *fdname);
/* XXX do we relaly want to hardcode 'netstr' as the
* sendable item here
*/
int qemuMonitorAddHostNetwork(const virDomainObjPtr vm,
const char *netstr);
#endif /* QEMU_MONITOR_TEXT_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册