From 32db8dd75b3c5fdf74d61fbf009d25bee58e025f Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Wed, 22 Jul 2009 20:17:14 +0100 Subject: [PATCH] Make qemuBuildHostNetStr() take tapfd as a string With hotplug, we're going to want to pass a tapfd name rather than an actual file descriptor, so prepare the way by passing a string tapfd to qemuBuildHostNetStr(). * src/qemu_conf.h: qemuBuildHostNetStr() takes a string tapfd now * src/qemu_conf.c: pass qemuBuildHostNetStr() a string rather than an actual file descriptor * src/qemu_driver.c: update qemudDomainAttachNetDevice() for change --- src/qemu_conf.c | 17 ++++++++++++----- src/qemu_conf.h | 2 +- src/qemu_driver.c | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 0bbaeb1e57..4fe4e399d0 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -1181,13 +1181,13 @@ qemuBuildHostNetStr(virConnectPtr conn, const char *prefix, char type_sep, int vlan, - int tapfd, + const char *tapfd, char **str) { switch (net->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_BRIDGE: - if (virAsprintf(str, "%stap%cfd=%d,vlan=%d%s%s", + if (virAsprintf(str, "%stap%cfd=%s,vlan=%d%s%s", prefix ? prefix : "", type_sep, tapfd, vlan, (net->hostnet_name ? ",name=" : ""), @@ -1805,7 +1805,7 @@ int qemudBuildCommandLine(virConnectPtr conn, for (i = 0 ; i < def->nnets ; i++) { virDomainNetDefPtr net = def->nets[i]; char *nic, *host; - int tapfd = -1; + char *tapfd_name = NULL; net->vlan = i; @@ -1821,7 +1821,7 @@ int qemudBuildCommandLine(virConnectPtr conn, if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK || net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { - tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags); + int tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags); if (tapfd < 0) goto error; @@ -1831,14 +1831,21 @@ int qemudBuildCommandLine(virConnectPtr conn, } (*tapfds)[(*ntapfds)++] = tapfd; + + if (virAsprintf(&tapfd_name, "%d", tapfd) < 0) + goto no_memory; } if (qemuBuildHostNetStr(conn, net, NULL, ',', - net->vlan, tapfd, &host) < 0) + net->vlan, tapfd_name, &host) < 0) { + VIR_FREE(tapfd_name); goto error; + } ADD_ARG_LIT("-net"); ADD_ARG(host); + + VIR_FREE(tapfd_name); } } diff --git a/src/qemu_conf.h b/src/qemu_conf.h index a68e236d70..517626ab40 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -155,7 +155,7 @@ int qemuBuildHostNetStr (virConnectPtr conn, const char *prefix, char type_sep, int vlan, - int tapfd, + const char *tapfd, char **str); int qemuBuildNicStr (virConnectPtr conn, diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 54e0f4fd6e..970da14e84 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -4896,7 +4896,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, net->vlan = vm->def->nets[i]->vlan; if (qemuBuildHostNetStr(conn, net, - "host_net_add ", ' ', net->vlan, -1, &cmd) < 0) + "host_net_add ", ' ', net->vlan, NULL, &cmd) < 0) return -1; remove_cmd = NULL;