Skip to contentSkip to conversation

KVM test: setup tap fd and pass it to qemu-kvm v2

PATCH New Lucas Meneghel Rodrigues 1 participant 1 message May 23, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 KVM test: setup tap fd and pass it to qemu-kvm v2

We used to use qemu-ifup to manage the tap which have several limitations:

1) If we want to specify a bridge, we must create a customized qemu-ifup file as the default script always match the first bridge.
2) It's hard to add support for macvtap device.

So this patch let kvm subtest control the tap creation and setup then pass it to qemu-kvm. User could specify the bridge he want to used in configuration file.

The original autoconfiguration was changed by private bridge setup.

Changes from v1:
* Combine the private bridge config and TAP fd in one patchset, dropped the "auto" mode
* Close TAP fds on VM.destroy() (thanks to Amos Kong for finding the problem)

---
 client/tests/kvm/scripts/qemu-ifup |   11 ------
 client/virt/kvm_vm.py              |   60 ++++++++++++++++++++++++------------
 client/virt/virt_utils.py          |   11 ++++--
 3 files changed, 47 insertions(+), 35 deletions(-)
 delete mode 100755 client/tests/kvm/scripts/qemu-ifup
client/tests/kvm/scripts/qemu-ifup deleted +0 -11
deleted file mode 100755
index c4debf5..0000000
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-# The following expression selects the first bridge listed by 'brctl show'.
-# Modify it to suit your needs.
-switch=$(/usr/sbin/brctl show | awk 'NR==2 { print $1 }')
-
-/bin/echo 1 > /proc/sys/net/ipv6/conf/${switch}/disable_ipv6
-/sbin/ifconfig $1 0.0.0.0 up
-/usr/sbin/brctl addif ${switch} $1
-/usr/sbin/brctl setfd ${switch} 0
-/usr/sbin/brctl stp ${switch} off
client/virt/kvm_vm.py +40 -20

116 lines not on this page · raw message

client/virt/virt_utils.py +7 -4
index 96b9c84..a1c9df2 100644
@@ -56,12 +56,15 @@ class NetError(Exception):
 
 
 class TAPModuleError(NetError):
-    def __init__(self, devname):
+    def __init__(self, devname, action="open", details=None):
         NetError.__init__(self, devname)
         self.devname = devname
 
     def __str__(self):
-        return "Can't open %s" % self.devname
+        e_msg = "Can't %s %s" % (self.action, self.devname)
+        if self.details is not None:
+            e_msg += " : %s" % details
+
 
 class TAPNotExistError(NetError):
     def __init__(self, ifname):
@@ -2448,8 +2451,8 @@ def open_tap(devname, ifname, vnet_hdr=True):
     """
     try:
         tapfd = os.open(devname, os.O_RDWR)
-    except OSError:
-        raise TAPModuleError(devname)
+    except OSError, e:
+        raise TAPModuleError(devname, "open", e)
     flags = IFF_TAP | IFF_NO_PI
     if vnet_hdr and vnet_hdr_probe(tapfd):
         flags |= IFF_VNET_HDR
Signature · 1 line
1.7.5.1