aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Zyngier <maz@kernel.org>2020-06-08 09:07:51 +0100
committerMarc Zyngier <maz@kernel.org>2020-06-08 09:10:27 +0100
commit7a4e8db253e00f8c61c145959fae875f31400aec (patch)
treec736dfe6dc2e6ec4ed36ed8b68163d4f7a566053
parent58de04925584c389418d5a3fbbe585503867f444 (diff)
downloadvminstall-7a4e8db253e00f8c61c145959fae875f31400aec.tar.gz
runefivm: Allow multiple tap interfaces
Allow multiple interfaces by passing them as a colon-separated list in the NETIF variable: NETIF="tap0:tap1" Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r--README4
-rwxr-xr-xrunefivm.sh84
2 files changed, 52 insertions, 36 deletions
diff --git a/README b/README
index f18e4b2..3658dbb 100644
--- a/README
+++ b/README
@@ -45,7 +45,9 @@ at some point. Maybe.
- NETIF: The host network interface for this VM. Can be a tap or
macvtap interface (which enables vhost), or "none" (which
indicates that no networking is to be provided). When absent,
- userspace networking is provided to the guest.
+ userspace networking is provided to the guest. Multiple taps
+ can be passed as a colon separated list, each of them resulting
+ in a guest network interface.
- GIC: The GIC version. Use "2" to force GICv2, "3" for GICv3+ITS,
"3,noits" for GICv3 without an ITS. Defaults to "host", which is
diff --git a/runefivm.sh b/runefivm.sh
index a67179b..6525b37 100755
--- a/runefivm.sh
+++ b/runefivm.sh
@@ -16,6 +16,49 @@ cputype=${CPUTYPE-host}
dumpdtb=${DUMPDTB}
withdtb=${WITHDTB}
+nifidx=0
+tapfd=128
+tapredir=""
+vhredir=""
+netdev=""
+
+build_netdev()
+{
+ nif=$1
+ if [ -e /dev/tap$(< /sys/class/net/$nif/ifindex) ]; then
+ addr=$(< /sys/class/net/$nif/address)
+ tap=/dev/tap$(< /sys/class/net/$nif/ifindex)
+ mq=$((`ls -1 /sys/class/net/$nif/queues/ | wc -l ` / 2))
+
+ tapfds="$(($tapfd))"
+ tapredir+="$(($tapfd))<>$tap "
+ vhfds="$(($tapfd+$mq))"
+ vhredir+="$(($tapfd+$mq))<>/dev/vhost-net "
+
+ for i in `seq 1 $(($mq-1))`
+ do
+ tapfds+=":$((i+$tapfd))"
+ tapredir+="$((i+$tapfd))<>$tap "
+ vhfds+=":$((i+$tapfd+$mq))"
+ vhredir+="$((i+$tapfd+$mq))<>/dev/vhost-net "
+ done
+
+ netdev+="-netdev tap,fds=$tapfds,id=hostnet$nifidx,vhost=on,vhostfds=$vhfds \
+ -device virtio-net-$bus$virtio,mac=$addr,netdev=hostnet$nifidx,mq=on,vectors=$((2*$mq+2)) "
+
+ else
+ mq=$((`ls -1 /sys/class/net/$nif/queues/ | wc -l ` / 2))
+ mq=4
+ vectors="mq=on,vectors=$((2*$mq+2))"
+ suffix=`echo $disk | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(.*\)/\1:\2:\3/'`
+ netdev="-netdev tap,vhost=on,queues=$mq,id=hostnet$nifidx,ifname=$nif,script=no,downscript=no \
+ -device virtio-net-$bus$virtio,netdev=hostnet$nifidx,mac=5a:fe:00:$suffix,$vectors"
+ fi
+
+ tapfd=$(($tapfd + $mq + 1))
+ nifidx=$(($nifidx + 1))
+}
+
if [ "$bit" = 64 ]; then
sf=on
else
@@ -49,43 +92,14 @@ if [ "$disk" != none ]; then
fi
if [ "$netif" == none ]; then
-
- netdev="-net none"
-
+ netdev="-net none"
elif [ -z "$netif" -o $bus != pci ]; then
-
- netdev="-netdev user,id=hostnet0 -device virtio-net-$bus$virtio,netdev=hostnet0"
-
-elif [ -e /dev/tap$(< /sys/class/net/$netif/ifindex) ]; then
-
- addr=$(< /sys/class/net/$netif/address)
- tap=/dev/tap$(< /sys/class/net/$netif/ifindex)
- mq=$((`ls -1 /sys/class/net/$netif/queues/ | wc -l ` / 2))
- tapfd=128
-
- tapfds="$(($tapfd))"
- tapredir="$(($tapfd))<>$tap"
- vhfds="$(($tapfd+$mq))"
- vhredir="$(($tapfd+$mq))<>/dev/vhost-net"
-
- for i in `seq 1 $(($mq-1))`
- do
- tapfds+=":$((i+$tapfd))"
- tapredir+=" $((i+$tapfd))<>$tap"
- vhfds+=":$((i+$tapfd+$mq))"
- vhredir+=" $((i+$tapfd+$mq))<>/dev/vhost-net"
- done
-
- netdev="-netdev tap,fds=$tapfds,id=hostnet0,vhost=on,vhostfds=$vhfds \
- -device virtio-net-$bus$virtio,mac=$addr,netdev=hostnet0,mq=on,vectors=$((2*$mq+2))"
-
+ netdev="-netdev user,id=hostnet0 -device virtio-net-$bus$virtio,netdev=hostnet0"
else
- mq=$((`ls -1 /sys/class/net/$netif/queues/ | wc -l ` / 2))
- mq=4
- vectors="mq=on,vectors=$((2*$mq+2))"
- suffix=`echo $disk | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(.*\)/\1:\2:\3/'`
- netdev="-netdev tap,vhost=on,queues=$mq,id=hostnet0,ifname=$netif,script=no,downscript=no \
- -device virtio-net-$bus$virtio,netdev=hostnet0,mac=5a:fe:00:$suffix,$vectors"
+ IFS=':' read -ra nifs <<< "$netif"
+ for i in "${nifs[@]}"; do
+ build_netdev $i
+ done
fi
args=" -m $ram -smp $cpus -cpu $cputype,aarch64=$sf -machine virt,accel=$accel,gic-version=$gic \