diff options
author | Jeff Dike <jdike@x86_64.user-mode-linux.org> | 2010-08-05 15:13:45 -0400 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-20 16:20:10 +0100 |
commit | 81ff1ee2375161772a4e2471740e4d30f5577aae (patch) | |
tree | 291f1f0a99cd87cbd30e74b0d46bc08dec707d59 /scripts | |
parent | 4df9f11171530ca60043504ce011f34c42e93b46 (diff) | |
download | poky-81ff1ee2375161772a4e2471740e4d30f5577aae.tar.gz |
poky-qemu-internal: Support use of a preconfigured tap device
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>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/poky-qemu-internal | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/scripts/poky-qemu-internal b/scripts/poky-qemu-internal index acb6ff50ff..3d718391f7 100755 --- a/scripts/poky-qemu-internal +++ b/scripts/poky-qemu-internal | |||
@@ -54,9 +54,28 @@ fi | |||
54 | QEMUIFUP=`which poky-qemu-ifup` | 54 | QEMUIFUP=`which poky-qemu-ifup` |
55 | QEMUIFDOWN=`which poky-qemu-ifdown` | 55 | QEMUIFDOWN=`which poky-qemu-ifdown` |
56 | 56 | ||
57 | USER=`id -u` | 57 | LOCKDIR="/tmp/qemu-tap-locks" |
58 | echo 'Setting up tap interface under sudo' | 58 | [ ! -d "$LOCKDIR" ] && mkdir $LOCKDIR |
59 | TAP=`sudo $QEMUIFUP $USER` | 59 | |
60 | POSSIBLE=`ifconfig -a | grep '^tap' | awk '{print $1}'` | ||
61 | TAP="" | ||
62 | LOCKFILE="" | ||
63 | for tap in $POSSIBLE; do | ||
64 | LOCKFILE="$LOCKDIR/$tap" | ||
65 | if lockfile $LOCKFILE; then | ||
66 | TAP=$tap | ||
67 | break; | ||
68 | fi | ||
69 | done | ||
70 | |||
71 | if [ "$TAP" = "" ]; then | ||
72 | USER=`id -u` | ||
73 | echo 'Setting up tap interface under sudo' | ||
74 | TAP=`sudo $QEMUIFUP $USER` | ||
75 | LOCKFILE="" | ||
76 | else | ||
77 | echo "Using preconfigured tap device '$TAP'" | ||
78 | fi | ||
60 | 79 | ||
61 | KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0" | 80 | KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0" |
62 | QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no" | 81 | QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no" |
@@ -313,7 +332,12 @@ echo "Running $QEMU..." | |||
313 | echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" | 332 | echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" |
314 | $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true | 333 | $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true |
315 | 334 | ||
316 | $QEMUIFDOWN $TAP | 335 | if [ "$LOCKFILE" = "" ]; then |
336 | $QEMUIFDOWN $TAP | ||
337 | else | ||
338 | echo "Releasing preconfigured tap device '$TAP'" | ||
339 | rm -f $LOCKFILE | ||
340 | fi | ||
317 | 341 | ||
318 | trap - INT TERM QUIT | 342 | trap - INT TERM QUIT |
319 | return | 343 | return |