summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-internal
diff options
context:
space:
mode:
authorAndrei Dinu <andrei.adrianx.dinu@intel.com>2013-05-20 16:16:30 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-24 14:14:40 +0100
commit52c9f6650f4c8fb06636f03803005054aa520191 (patch)
tree060bbd48c209237ccc3c240bb11d0c18e00cb1fa /scripts/runqemu-internal
parent600f4e38ad93368ec0bfd6e1a69c0fd592a66649 (diff)
downloadpoky-52c9f6650f4c8fb06636f03803005054aa520191.tar.gz
SLiRP support in runqemu
runqemu script now takes argument "slirp" in order to run networking on the qemu machine, without root privileges. changed the runqemu-internal script in order not to activate the tap devices if the option is set. [YOCTO #1474] (From OE-Core rev: fa7fd7b1cbcfbd01af1949d2ea09b880a0ae0175) Signed-off-by: Andrei Dinu <andrei.adrianx.dinu@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu-internal')
-rwxr-xr-xscripts/runqemu-internal272
1 files changed, 147 insertions, 125 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal
index 3c5282d89a..d4825d1548 100755
--- a/scripts/runqemu-internal
+++ b/scripts/runqemu-internal
@@ -104,135 +104,152 @@ fi
104 104
105NFSRUNNING="false" 105NFSRUNNING="false"
106 106
107acquire_lock() { 107if [ "$SLIRP_ENABLED" = "yes" ]; then
108 lockfile=$1 108 KERNEL_NETWORK_CMD=""
109 if [ -z "$lockfile" ]; then 109 QEMU_TAP_CMD=""
110 echo "Error: missing lockfile arg passed to acquire_lock()" 110 QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
111 return 1 111 if [ "$KVM_ACTIVE" = "yes" ]; then
112 fi 112 QEMU_NETWORK_CMD=""
113 113 DROOT="/dev/vda"
114 touch $lockfile.lock 114 ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio"
115 exec 8>$lockfile.lock 115 else
116 flock -n -x 8 116 QEMU_NETWORK_CMD=""
117 if [ $? -ne 0 ]; then 117 DROOT="/dev/hda"
118 exec 8>&- 118 ROOTFS_OPTIONS="-hda $ROOTFS"
119 return 1
120 fi
121
122 return 0
123}
124
125release_lock() {
126 lockfile=$1
127 if [ -z "$lockfile" ]; then
128 echo "Error: missing lockfile arg passed to release_lock()"
129 return 1
130 fi
131
132 rm -f $lockfile.lock
133 exec 8>&-
134}
135
136LOCKDIR="/tmp/qemu-tap-locks"
137if [ ! -d "$LOCKDIR" ]; then
138 mkdir $LOCKDIR
139 chmod 777 $LOCKDIR
140fi
141
142IFCONFIG=`which ip 2> /dev/null`
143if [ -z "$IFCONFIG" ]; then
144 IFCONFIG=/sbin/ip
145fi
146if [ ! -x "$IFCONFIG" ]; then
147 echo "$IFCONFIG cannot be executed"
148 exit 1
149fi
150
151POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`
152TAP=""
153LOCKFILE=""
154for tap in $POSSIBLE; do
155 LOCKFILE="$LOCKDIR/$tap"
156 echo "Acquiring lockfile for $tap..."
157 acquire_lock $LOCKFILE
158 if [ $? -eq 0 ]; then
159 TAP=$tap
160 break
161 fi
162done
163
164if [ "$TAP" = "" ]; then
165 if [ -e "$NOSUDO_FLAG" ]; then
166 echo "Error: There are no available tap devices to use for networking,"
167 echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating"
168 echo "a new one with sudo."
169 exit 1
170 fi 119 fi
171 120
172 GROUPID=`id -g`
173 USERID=`id -u`
174 echo "Setting up tap interface under sudo"
175 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
176 # but inactive. This looks scary but is harmless
177 tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null`
178 if [ $? -ne 0 ]; then
179 # Re-run standalone to see verbose errors
180 sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT
181 return 1
182 fi
183 LOCKFILE="$LOCKDIR/$tap"
184 echo "Acquiring lockfile for $tap..."
185 acquire_lock $LOCKFILE
186 if [ $? -eq 0 ]; then
187 TAP=$tap
188 fi
189else 121else
190 echo "Using preconfigured tap device '$TAP'" 122 acquire_lock() {
191fi 123 lockfile=$1
192 124 if [ -z "$lockfile" ]; then
193cleanup() { 125 echo "Error: missing lockfile arg passed to acquire_lock()"
194 if [ ! -e "$NOSUDO_FLAG" ]; then 126 return 1
195 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded 127 fi
196 # but inactive. This looks scary but is harmless 128
197 sudo $QEMUIFDOWN $TAP $OECORE_NATIVE_SYSROOT 2> /dev/null 129 touch $lockfile.lock
198 fi 130 exec 8>$lockfile.lock
199 echo "Releasing lockfile of preconfigured tap device '$TAP'" 131 flock -n -x 8
200 release_lock $LOCKFILE 132 if [ $? -ne 0 ]; then
133 exec 8>&-
134 return 1
135 fi
136
137 return 0
138 }
139
140 release_lock() {
141 lockfile=$1
142 if [ -z "$lockfile" ]; then
143 echo "Error: missing lockfile arg passed to release_lock()"
144 return 1
145 fi
146
147 rm -f $lockfile.lock
148 exec 8>&-
149 }
150
151 LOCKDIR="/tmp/qemu-tap-locks"
152 if [ ! -d "$LOCKDIR" ]; then
153 mkdir $LOCKDIR
154 chmod 777 $LOCKDIR
155 fi
201 156
202 if [ "$NFSRUNNING" = "true" ]; then 157 IFCONFIG=`which ip 2> /dev/null`
203 echo "Shutting down the userspace NFS server..." 158 if [ -z "$IFCONFIG" ]; then
204 echo "runqemu-export-rootfs stop $ROOTFS" 159 IFCONFIG=/sbin/ip
205 runqemu-export-rootfs stop $ROOTFS 160 fi
206 fi 161 if [ ! -x "$IFCONFIG" ]; then
207 # If QEMU crashes or somehow tty properties are not restored 162 echo "$IFCONFIG cannot be executed"
208 # after qemu exits, we need to run stty sane 163 exit 1
209 stty sane 164 fi
210}
211 165
212n0=$(echo $TAP | sed 's/tap//') 166 POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`
213n1=$(($n0 * 2 + 1)) 167 TAP=""
214n2=$(($n1 + 1)) 168 LOCKFILE=""
169 for tap in $POSSIBLE; do
170 LOCKFILE="$LOCKDIR/$tap"
171 echo "Acquiring lockfile for $tap..."
172 acquire_lock $LOCKFILE
173 if [ $? -eq 0 ]; then
174 TAP=$tap
175 break
176 fi
177 done
178
179 if [ "$TAP" = "" ]; then
180 if [ -e "$NOSUDO_FLAG" ]; then
181 echo "Error: There are no available tap devices to use for networking,"
182 echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating"
183 echo "a new one with sudo."
184 exit 1
185 fi
186
187 GROUPID=`id -g`
188 USERID=`id -u`
189 echo "Setting up tap interface under sudo"
190 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
191 # but inactive. This looks scary but is harmless
192 tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null`
193 if [ $? -ne 0 ]; then
194 # Re-run standalone to see verbose errors
195 sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT
196 return 1
197 fi
198 LOCKFILE="$LOCKDIR/$tap"
199 echo "Acquiring lockfile for $tap..."
200 acquire_lock $LOCKFILE
201 if [ $? -eq 0 ]; then
202 TAP=$tap
203 fi
204 else
205 echo "Using preconfigured tap device '$TAP'"
206 fi
215 207
216KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0" 208 cleanup() {
217QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no" 209 if [ ! -e "$NOSUDO_FLAG" ]; then
218if [ "$KVM_ACTIVE" = "yes" ]; then 210 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
219 QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on" 211 # but inactive. This looks scary but is harmless
220 DROOT="/dev/vda" 212 sudo $QEMUIFDOWN $TAP $OECORE_NATIVE_SYSROOT 2> /dev/null
221 ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio" 213 fi
222else 214 echo "Releasing lockfile of preconfigured tap device '$TAP'"
223 QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD" 215 release_lock $LOCKFILE
224 DROOT="/dev/hda" 216
225 ROOTFS_OPTIONS="-hda $ROOTFS" 217 if [ "$NFSRUNNING" = "true" ]; then
226fi 218 echo "Shutting down the userspace NFS server..."
227KERNCMDLINE="mem=$QEMU_MEMORY" 219 echo "runqemu-export-rootfs stop $ROOTFS"
228QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet" 220 runqemu-export-rootfs stop $ROOTFS
221 fi
222 # If QEMU crashes or somehow tty properties are not restored
223 # after qemu exits, we need to run stty sane
224 stty sane
225 }
226
227
228 n0=$(echo $TAP | sed 's/tap//')
229 n1=$(($n0 * 2 + 1))
230 n2=$(($n1 + 1))
231
232 KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0"
233 QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
234 if [ "$KVM_ACTIVE" = "yes" ]; then
235 QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on"
236 DROOT="/dev/vda"
237 ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio"
238 else
239 QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
240 DROOT="/dev/hda"
241 ROOTFS_OPTIONS="-hda $ROOTFS"
242 fi
243 KERNCMDLINE="mem=$QEMU_MEMORY"
244 QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
229 245
230NFS_INSTANCE=`echo $TAP | sed 's/tap//'` 246 NFS_INSTANCE=`echo $TAP | sed 's/tap//'`
231export NFS_INSTANCE 247 export NFS_INSTANCE
232 248
233SERIALOPTS="" 249 SERIALOPTS=""
234if [ "x$SERIAL_LOGFILE" != "x" ]; then 250 if [ "x$SERIAL_LOGFILE" != "x" ]; then
235 SERIALOPTS="-serial file:$SERIAL_LOGFILE" 251 SERIALOPTS="-serial file:$SERIAL_LOGFILE"
252 fi
236fi 253fi
237 254
238case "$MACHINE" in 255case "$MACHINE" in
@@ -414,7 +431,11 @@ if [ "$MACHINE" = "qemuppc" ]; then
414 MACHINE_SUBTYPE=mac99 431 MACHINE_SUBTYPE=mac99
415 CPU_SUBTYPE=G4 432 CPU_SUBTYPE=G4
416 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" 433 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS"
417 QEMU_NETWORK_CMD="-net nic,model=pcnet $QEMU_TAP_CMD" 434 if [ "$SLIRP_ENABLED" = "yes" ]; then
435 QEMU_NETWORK_CMD=""
436 else
437 QEMU_NETWORK_CMD="-net nic,model=pcnet $QEMU_TAP_CMD"
438 fi
418 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then 439 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
419 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" 440 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
420 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" 441 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
@@ -560,12 +581,13 @@ elif [ "$FSTYPE" = "iso" ]; then
560 echo $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT 581 echo $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
561 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT 582 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
562else 583else
563 echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"' 584 echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SLIRP_CMD $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"'
564 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT" 585 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT"
565fi 586fi
566ret=$? 587ret=$?
567 588if [ "$SLIRP_ENABLED" != "yes" ]; then
568cleanup 589 cleanup
590fi
569 591
570trap - INT TERM QUIT 592trap - INT TERM QUIT
571 593