]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix allocation of veth's to not skip an index
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 7 Jun 2011 13:26:48 +0000 (14:26 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 15 Jun 2011 09:56:08 +0000 (10:56 +0100)
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

src/lxc/veth.c

index 1a96f82e6278f000fb020ae18eeaafc7a16a863e..34cb804d1dbd7852caf4990359b85dc54107a27f 100644 (file)
@@ -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);