[libvirt] [PATCH] The logic in veth.c that searches for free interface names takes into account

only current devices, but not device names already planned for the other half of a container's device pair. Thus, the search can result in attempting to create a pair of devices such as veth1 and veth1, which obviously does not work. This patch augments the logic to be a little smarter in this regard, and should fix one case where attempting to start a container results in an error message of "unable to create device pair". diff -r 8c5e6387e449 -r 8545f7ac1f0f src/veth.c --- a/src/veth.c Tue Aug 05 16:45:07 2008 +0000 +++ b/src/veth.c Wed Aug 06 08:14:16 2008 -0700 @@ -92,17 +92,18 @@ DEBUG("veth1: %s veth2: %s", veth1, veth2); - if (1 > strlen(veth1)) { + while ((1 > strlen(veth1)) || STREQ(veth1, veth2)) { vethDev = getFreeVethName(veth1, veth1MaxLen, 0); ++vethDev; DEBUG("assigned veth1: %s", veth1); } - if (1 > strlen(veth2)) { + while ((1 > strlen(veth2)) || STREQ(veth1, veth2)) { vethDev = getFreeVethName(veth2, veth2MaxLen, vethDev); DEBUG("assigned veth2: %s", veth2); } + DEBUG("veth1: %s veth2: %s", veth1, veth2); rc = virRun(NULL, (char**)argv, &cmdResult); if (0 == rc) {

On Wed, Aug 06, 2008 at 08:20:38AM -0700, Dan Smith wrote:
only current devices, but not device names already planned for the other half of a container's device pair. Thus, the search can result in attempting to create a pair of devices such as veth1 and veth1, which obviously does not work.
This patch augments the logic to be a little smarter in this regard, and should fix one case where attempting to start a container results in an error message of "unable to create device pair". [...] - if (1 > strlen(veth2)) { + while ((1 > strlen(veth2)) || STREQ(veth1, veth2)) { vethDev = getFreeVethName(veth2, veth2MaxLen, vethDev); DEBUG("assigned veth2: %s", veth2); }
Seems a side effect statement is needed in this loop to exit it if we happen to enter it, no ? Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Thu, Aug 07, 2008 at 04:30:30AM -0400, Daniel Veillard wrote:
On Wed, Aug 06, 2008 at 08:20:38AM -0700, Dan Smith wrote:
only current devices, but not device names already planned for the other half of a container's device pair. Thus, the search can result in attempting to create a pair of devices such as veth1 and veth1, which obviously does not work.
This patch augments the logic to be a little smarter in this regard, and should fix one case where attempting to start a container results in an error message of "unable to create device pair". [...] - if (1 > strlen(veth2)) { + while ((1 > strlen(veth2)) || STREQ(veth1, veth2)) { vethDev = getFreeVethName(veth2, veth2MaxLen, vethDev); DEBUG("assigned veth2: %s", veth2); }
Seems a side effect statement is needed in this loop to exit it if we happen to enter it, no ?
okay, i re-read and understand now, +1 Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Wed, Aug 06, 2008 at 08:20:38AM -0700, Dan Smith wrote:
only current devices, but not device names already planned for the other half of a container's device pair. Thus, the search can result in attempting to create a pair of devices such as veth1 and veth1, which obviously does not work.
This patch augments the logic to be a little smarter in this regard, and should fix one case where attempting to start a container results in an error message of "unable to create device pair".
ACK, this explains the failures I've hit with duplicate veth names ! Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Dan Smith
-
Daniel P. Berrange
-
Daniel Veillard