提交 3211936b 编写于 作者: M Michal Privoznik

lxc: Turn @veths into a string list in virLXCProcessStart

This way it will be easier to use autofree.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 71a390e0
...@@ -514,8 +514,7 @@ static int virLXCProcessSetupNamespaces(virConnectPtr conn, ...@@ -514,8 +514,7 @@ static int virLXCProcessSetupNamespaces(virConnectPtr conn,
* virLXCProcessSetupInterfaces: * virLXCProcessSetupInterfaces:
* @conn: pointer to connection * @conn: pointer to connection
* @def: pointer to virtual machine structure * @def: pointer to virtual machine structure
* @nveths: number of interfaces * @veths: string list of interface names
* @veths: interface names
* *
* Sets up the container interfaces by creating the veth device pairs and * Sets up the container interfaces by creating the veth device pairs and
* attaching the parent end to the appropriate bridge. The container end * attaching the parent end to the appropriate bridge. The container end
...@@ -525,7 +524,6 @@ static int virLXCProcessSetupNamespaces(virConnectPtr conn, ...@@ -525,7 +524,6 @@ static int virLXCProcessSetupNamespaces(virConnectPtr conn,
*/ */
static int virLXCProcessSetupInterfaces(virConnectPtr conn, static int virLXCProcessSetupInterfaces(virConnectPtr conn,
virDomainDefPtr def, virDomainDefPtr def,
size_t *nveths,
char ***veths) char ***veths)
{ {
int ret = -1; int ret = -1;
...@@ -534,6 +532,9 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, ...@@ -534,6 +532,9 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
virDomainNetDefPtr net; virDomainNetDefPtr net;
virDomainNetType type; virDomainNetType type;
if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0)
return -1;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
char *veth = NULL; char *veth = NULL;
virNetDevBandwidthPtr actualBandwidth; virNetDevBandwidthPtr actualBandwidth;
...@@ -549,9 +550,6 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, ...@@ -549,9 +550,6 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
if (virDomainNetAllocateActualDevice(def, net) < 0) if (virDomainNetAllocateActualDevice(def, net) < 0)
goto cleanup; goto cleanup;
if (VIR_EXPAND_N(*veths, *nveths, 1) < 0)
goto cleanup;
type = virDomainNetGetActualType(net); type = virDomainNetGetActualType(net);
switch (type) { switch (type) {
case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_NETWORK:
...@@ -604,7 +602,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, ...@@ -604,7 +602,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
} }
} }
(*veths)[(*nveths)-1] = veth; (*veths)[i] = veth;
if (VIR_STRDUP(def->nets[i]->ifname_guest_actual, veth) < 0) if (VIR_STRDUP(def->nets[i]->ifname_guest_actual, veth) < 0)
goto cleanup; goto cleanup;
...@@ -902,7 +900,6 @@ int virLXCProcessStop(virLXCDriverPtr driver, ...@@ -902,7 +900,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
static virCommandPtr static virCommandPtr
virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
int nveths,
char **veths, char **veths,
int *ttyFDs, int *ttyFDs,
size_t nttyFDs, size_t nttyFDs,
...@@ -987,7 +984,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, ...@@ -987,7 +984,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
virCommandAddArg(cmd, "--handshake"); virCommandAddArg(cmd, "--handshake");
virCommandAddArgFormat(cmd, "%d", handshakefd); virCommandAddArgFormat(cmd, "%d", handshakefd);
for (i = 0; i < nveths; i++) for (i = 0; veths && veths[i]; i++)
virCommandAddArgList(cmd, "--veth", veths[i], NULL); virCommandAddArgList(cmd, "--veth", veths[i], NULL);
virCommandPassFD(cmd, handshakefd, 0); virCommandPassFD(cmd, handshakefd, 0);
...@@ -1184,7 +1181,6 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1184,7 +1181,6 @@ int virLXCProcessStart(virConnectPtr conn,
size_t i; size_t i;
char *logfile = NULL; char *logfile = NULL;
int logfd = -1; int logfd = -1;
size_t nveths = 0;
char **veths = NULL; char **veths = NULL;
int handshakefds[2] = { -1, -1 }; int handshakefds[2] = { -1, -1 };
off_t pos = -1; off_t pos = -1;
...@@ -1355,7 +1351,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1355,7 +1351,7 @@ int virLXCProcessStart(virConnectPtr conn,
} }
VIR_DEBUG("Setting up Interfaces"); VIR_DEBUG("Setting up Interfaces");
if (virLXCProcessSetupInterfaces(conn, vm->def, &nveths, &veths) < 0) if (virLXCProcessSetupInterfaces(conn, vm->def, &veths) < 0)
goto cleanup; goto cleanup;
VIR_DEBUG("Setting up namespaces if any"); VIR_DEBUG("Setting up namespaces if any");
...@@ -1379,7 +1375,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1379,7 +1375,7 @@ int virLXCProcessStart(virConnectPtr conn,
if (!(cmd = virLXCProcessBuildControllerCmd(driver, if (!(cmd = virLXCProcessBuildControllerCmd(driver,
vm, vm,
nveths, veths, veths,
ttyFDs, nttyFDs, ttyFDs, nttyFDs,
nsInheritFDs, nsInheritFDs,
files, nfiles, files, nfiles,
...@@ -1559,9 +1555,7 @@ int virLXCProcessStart(virConnectPtr conn, ...@@ -1559,9 +1555,7 @@ int virLXCProcessStart(virConnectPtr conn,
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
} }
virCommandFree(cmd); virCommandFree(cmd);
for (i = 0; i < nveths; i++) virStringListFree(veths);
VIR_FREE(veths[i]);
VIR_FREE(veths);
for (i = 0; i < nttyFDs; i++) for (i = 0; i < nttyFDs; i++)
VIR_FORCE_CLOSE(ttyFDs[i]); VIR_FORCE_CLOSE(ttyFDs[i]);
VIR_FREE(ttyFDs); VIR_FREE(ttyFDs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册