diff options
author | Dominique Martinet <dominique.martinet@cea.fr> | 2016-02-08 15:53:21 +0100 |
---|---|---|
committer | Dominique Martinet <dominique.martinet@cea.fr> | 2016-02-08 15:53:21 +0100 |
commit | 1c770203449beaa14cd4b5fc765f7919ccd3301b (patch) | |
tree | 094aa4b9357c4922cce2217fe0a284164a5ed0f4 | |
parent | c2670fbf77b452a81476745d9d7ad9bd20c61906 (diff) |
cleanup FD: need to close FDs before vfio to avoid deadlock with vhostfd
-rwxr-xr-x | kvm-wrapper.sh | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh index e60609d..7762558 100755 --- a/kvm-wrapper.sh +++ b/kvm-wrapper.sh @@ -687,11 +687,20 @@ function kvm_shutdown () function kvm_start_vm () { CLEANUP=( ) + CLEANUP_FD=( ) + cleanup() { + local LAST_ELEMENT + local FD + local i + echo "Cleaning up" + for FD in "${CLEANUP_FD[@]}"; do + eval "exec $FD<&-" + done if [ ${#CLEANUP[*]} -gt 0 ]; then - local LAST_ELEMENT=$((${#CLEANUP[*]}-1)) + LAST_ELEMENT=$((${#CLEANUP[*]}-1)) for i in `seq $LAST_ELEMENT -1 0`; do eval ${CLEANUP[$i]} done @@ -816,7 +825,7 @@ function kvm_start_vm () if [[ "${KVM_NET_OPT[i]}" == *"vhost=on"* ]] && [[ -n "$KVM_USER" ]]; then exec {VHOSTFD}<>/dev/vhost-net VHOSTFD_OPT=",vhostfd=${VHOSTFD}" - CLEANUP+=("exec ${VHOSTFD}<&-") + CLEANUP_FD+=("${VHOSTFD}") fi if [[ -n "$KVM_MACVTAP" ]]; then @@ -831,7 +840,7 @@ function kvm_start_vm () TAPFILE=/dev/tap$(cat "/sys/class/net/$TAPDEV/ifindex") exec {TAPFD}<>${TAPFILE} - CLEANUP+=("exec ${TAPFD}<&-") + CLEANUP_FD+=("${TAPFD}") KVM_NET+="-netdev type=tap,id=guest${i},fd=${TAPFD}${KVM_NET_OPT[i]}${VHOSTFD_OPT} -device ${KVM_IF[i]},netdev=guest${i},mac=${KVM_MACADDR[i]} " else ip tuntap add dev $TAPDEV mode tap ${KVM_USER+user $KVM_USER} |