diff options
author | Dominique Martinet <asmadeus@codewreck.org> | 2015-11-16 18:54:02 +0100 |
---|---|---|
committer | Dominique Martinet <asmadeus@codewreck.org> | 2015-12-04 11:45:54 +0100 |
commit | aa2c56e7457ece4256cdbc6c17d8d2983f943f5e (patch) | |
tree | 7effd69708d30c1cd28eabc05ed776cbfff1b057 /kvm-wrapper.sh | |
parent | 0681a79c6aa62f6b0240b6ac10fc59f3b19114ec (diff) |
Create tap interface ourselves
Since we no longer run the ifup script, we need to add a parameter for mtu,
which could be abused for other 'ip link' setups... Don't really want an eval here.
This also allows to run qemu as user without much work.
Diffstat (limited to 'kvm-wrapper.sh')
-rwxr-xr-x | kvm-wrapper.sh | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh index e830220..3198ab5 100755 --- a/kvm-wrapper.sh +++ b/kvm-wrapper.sh @@ -391,6 +391,12 @@ function pci_unstubify() function pci_vfiofy() { pci_bind_driver "vfio-pci" "$1" + + if [[ -n "$KVM_USER" ]]; then + local IOMMU_GROUP=$(readlink "/sys/bus/pci/drivers/vfio-pci/$1/iommu_group") + IOMMU_GROUP=${IOMMU_GROUP##*/} + chown $KVM_USER: /dev/vfio/$IOMMU_GROUP + fi } function pci_unvfiofy() @@ -398,7 +404,7 @@ function pci_unvfiofy() pci_unbind_driver "vfio-pci" "$1" } -# helper for vfio +# helper for sriov function ib_sriov() { local PKEYS="$1" @@ -661,16 +667,7 @@ function kvm_start_vm () } [[ "${KVM_IF[0]}" = "vhost_net" ]] && (KVM_NET_OPT[0]=",vhost=on"; KVM_IF[0]="virtio-net-pci") - # Check for the bridge-specific symlinks an' make them otherwise (no quotes on $KVM_BR* because it would otherwise try to create kvm--ifup) - for BR in "${KVM_BR[@]}"; do - test_exist "$KVM_NET_SCRIPT/kvm-$BR-ifup" || \ - (cd "$KVM_NET_SCRIPT"; ln -s kvm-ifup "kvm-$BR-ifup") - test_exist "$KVM_NET_SCRIPT/kvm-$BR-ifdown" || \ - (cd "$KVM_NET_SCRIPT"; ln -s kvm-ifdown "kvm-$BR-ifdown") - done - - - # Iterately build kvmnet string + # Iterately build kvmnet string and create tuntaps [[ "${#KVM_MACADDR[@]}" != 0 ]] && { # not checking KVM_NET_OPT because it _can_ be empty... others will raise an error [[ -z "${KVM_BR[@]:0:1}" ]] && fail_exit "No KVM_BR defined" @@ -679,7 +676,13 @@ function kvm_start_vm () KVM_BR[$i]="${KVM_BR[i]:-${KVM_BR[@]:0:1}}" KVM_IF[$i]="${KVM_IF[i]:-${KVM_IF[@]:0:1}}" KVM_NET_OPT[$i]="${KVM_NET_OPT[i]-${KVM_NET_OPT[@]:0:1}}" - KVM_NET+="-netdev type=tap,id=guest${i},script=$KVM_NET_SCRIPT/kvm-${KVM_BR[i]}-ifup,downscript=$KVM_NET_SCRIPT/kvm-${KVM_BR[i]}-ifdown${KVM_NET_OPT[i]} -device ${KVM_IF[i]},netdev=guest${i},mac=${KVM_MACADDR[i]} " + KVM_NET_MTU[$i]="${KVM_NET_MTU[i]-${KVM_NET_MTU[@]:0:1}}" + local TAPDEV=tap-${VM_NAME}-${i} + KVM_NET+="-netdev type=tap,id=guest${i},ifname=${TAPDEV},script=no,downscript=no${KVM_NET_OPT[i]} -device ${KVM_IF[i]},netdev=guest${i},mac=${KVM_MACADDR[i]} " + ip tuntap add dev $TAPDEV mode tap ${KVM_USER+user $KVM_USER} + ip link set $TAPDEV ${KVM_NET_MTU[$i]:+mtu ${KVM_NET_MTU[$i]}} up + brctl addif ${KVM_BR[i]} $TAPDEV + CLEANUP+=("ip tuntap del dev $TAPDEV mode tap") done } @@ -716,7 +719,11 @@ function kvm_start_vm () echo $EXEC_STRING echo "" echo "" - eval "$EXEC_STRING" + if [[ -n "$KVM_USER" ]]; then + su $KVM_USER -s /bin/sh -c "$EXEC_STRING" + else + eval "$EXEC_STRING" + fi local KVM_RETURN_VALUE="$?" |