int
qemuBuildHostNetStr(virConnectPtr conn,
virDomainNetDefPtr net,
- const char *prefix,
char type_sep,
int vlan,
const char *tapfd,
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) {
{
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);
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,
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) {
goto no_memory;
}
- if (qemuBuildHostNetStr(conn, net, NULL, ',',
+ if (qemuBuildHostNetStr(conn, net, ',',
net->vlan, tapfd_name, &host) < 0) {
VIR_FREE(tapfd_name);
goto error;
int qemuBuildHostNetStr (virConnectPtr conn,
virDomainNetDefPtr net,
- const char *prefix,
char type_sep,
int vlan,
const char *tapfd,
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",
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;
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);
&net->pci_addr.slot) < 0)
goto try_remove;
+ VIR_FREE(netstr);
VIR_FREE(nicstr);
VIR_FREE(remove_cmd);
virReportOOMError(conn);
cleanup:
VIR_FREE(nicstr);
+ VIR_FREE(netstr);
VIR_FREE(cmd);
VIR_FREE(reply);
VIR_FREE(remove_cmd);
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;
+}
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 */