]> code.ossystems Code Review - openembedded-core.git/commitdiff
poky-qemu-internal: Support use of a preconfigured tap device
authorJeff Dike <jdike@x86_64.user-mode-linux.org>
Thu, 5 Aug 2010 19:13:45 +0000 (15:13 -0400)
committerRichard Purdie <rpurdie@linux.intel.com>
Fri, 20 Aug 2010 15:20:10 +0000 (16:20 +0100)
This patch makes poky-qemu-internal check for the existence of an
available preconfigured tap device before running poky-qemu-ifup to
make a new one.

Locking is handled with a lockfile in /tmp/qemu-tap-locks/.  This uses
the lockfile utility, so that needs to be present on the host.  On
exit, this script removes the lock file so that the tap device may be
reused.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
scripts/poky-qemu-internal

index acb6ff50ffe63c671c1fd9d00235e5329c31f8c4..3d718391f74dca7d4936b6621bf480e9bf6447fc 100755 (executable)
@@ -54,9 +54,28 @@ fi
 QEMUIFUP=`which poky-qemu-ifup`
 QEMUIFDOWN=`which poky-qemu-ifdown`
 
-USER=`id -u`
-echo 'Setting up tap interface under sudo'
-TAP=`sudo $QEMUIFUP $USER`
+LOCKDIR="/tmp/qemu-tap-locks"
+[ ! -d "$LOCKDIR" ] && mkdir $LOCKDIR
+
+POSSIBLE=`ifconfig -a | grep '^tap' | awk '{print $1}'`
+TAP=""
+LOCKFILE=""
+for tap in $POSSIBLE; do
+    LOCKFILE="$LOCKDIR/$tap"
+    if lockfile $LOCKFILE; then
+       TAP=$tap
+       break;
+    fi
+done
+
+if [ "$TAP" = "" ]; then
+    USER=`id -u`
+    echo 'Setting up tap interface under sudo'
+    TAP=`sudo $QEMUIFUP $USER`
+    LOCKFILE=""
+else
+    echo "Using preconfigured tap device '$TAP'"
+fi
 
 KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0"
 QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
@@ -313,7 +332,12 @@ echo "Running $QEMU..."
 echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE"
 $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true
 
-$QEMUIFDOWN $TAP
+if [ "$LOCKFILE" = "" ]; then
+    $QEMUIFDOWN $TAP
+else
+    echo "Releasing preconfigured tap device '$TAP'"
+    rm -f $LOCKFILE
+fi
 
 trap - INT TERM QUIT
 return