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

Fix allocation of veth's to not skip an index

The algorithm for autoassigning vethXXX devices, was always
skipping over the starting dev index when finding a free
name for the guest device. This should only be done if the host
device was autoallocated.

* src/lxc/veth.c: Don't skip over veth indexes
上级 c3068d4d
......@@ -46,6 +46,7 @@ static int getFreeVethName(char **veth, int startDev)
int devNum = startDev-1;
char *path = NULL;
VIR_DEBUG("Find free from veth%d", startDev);
do {
VIR_FREE(path);
++devNum;
......@@ -53,6 +54,7 @@ static int getFreeVethName(char **veth, int startDev)
virReportOOMError();
return -1;
}
VIR_DEBUG("Probe %s", path);
} while (virFileExists(path));
VIR_FREE(path);
......@@ -60,6 +62,7 @@ static int getFreeVethName(char **veth, int startDev)
virReportOOMError();
return -1;
}
return devNum;
}
......@@ -98,18 +101,19 @@ int vethCreate(char** veth1, char** veth2)
bool veth1_alloc = false;
bool veth2_alloc = false;
VIR_DEBUG("veth1: %s veth2: %s", NULLSTR(*veth1), NULLSTR(*veth2));
VIR_DEBUG("Host: %s guest: %s", NULLSTR(*veth1), NULLSTR(*veth2));
if (*veth1 == NULL) {
if ((vethDev = getFreeVethName(veth1, vethDev)) < 0)
goto cleanup;
VIR_DEBUG("Assigned veth1: %s", *veth1);
VIR_DEBUG("Assigned host: %s", *veth1);
veth1_alloc = true;
vethDev++;
}
argv[3] = *veth1;
while (*veth2 == NULL) {
if ((vethDev = getFreeVethName(veth2, vethDev + 1)) < 0) {
if ((vethDev = getFreeVethName(veth2, vethDev)) < 0) {
if (veth1_alloc)
VIR_FREE(*veth1);
goto cleanup;
......@@ -122,12 +126,12 @@ int vethCreate(char** veth1, char** veth2)
continue;
}
VIR_DEBUG("Assigned veth2: %s", *veth2);
VIR_DEBUG("Assigned guest: %s", *veth2);
veth2_alloc = true;
}
argv[8] = *veth2;
VIR_DEBUG("veth1: %s veth2: %s", *veth1, *veth2);
VIR_DEBUG("Create Host: %s guest: %s", *veth1, *veth2);
if (virRun(argv, NULL) < 0) {
if (veth1_alloc)
VIR_FREE(*veth1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册