From d6a777be72cfd64d40104012da3f4f0130a0a978 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 5 Oct 2023 22:05:17 +0200 Subject: [PATCH] kvm-host: migrate-vm: set migration speed even on bridges --- CHANGELOG.md | 2 +- kvm-host/files/migrate-vm.sh | 51 +++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a197cf09..88490bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ The **patch** part changes is incremented if multiple releases happen the same m * evolinux: install HPE Agentless Management Service (amsd) * fail2ban: add default variable fail2ban_dbpurgeage_default * fail2ban: add `fail2ban_sshd_port` variable to configure sshd port -* kvm-host: release 23.09.1 for migrate-vm.sh +* kvm-host: release 23.10 for migrate-vm.sh * metricbeat/logstash: fix Ansible syntax * mysql: new munin graph to follow binlog_days over time * nagios-nrpe: add a NRPE check-local command with completion. diff --git a/kvm-host/files/migrate-vm.sh b/kvm-host/files/migrate-vm.sh index d745e4fb..26883e4c 100644 --- a/kvm-host/files/migrate-vm.sh +++ b/kvm-host/files/migrate-vm.sh @@ -11,7 +11,7 @@ # * migrate "from" # * switch to Bash to use local and readonly variables -VERSION="23.09.1" +VERSION="23.10" show_version() { cat <&2 + case "$(ls "${bridge_path}" | wc -l)" in + 0) + # echo "${interface} bridge is empty, fallback to ${fallback_speed}" >&2 + echo "${fallback_speed}" + ;; + 1) + bridge_iface="$(ls "${bridge_path}" | head -n 1)" + # echo "${interface} bridge has 1 interface: ${bridge_iface}" >&2 + interface_speed "${bridge_iface}" + ;; + *) + # echo "${interface} bridge has many interfaces" >&2 + min_speed="" + for bridge_iface in $(ls "${bridge_path}"); do + if realpath "/sys/class/net/${bridge_iface}" | grep --quiet --invert-match virtual; then + speed=$(head -n 1 "/sys/class/net/${bridge_iface}/speed") + # echo "${bridge_iface} is a physical interface, keep" >&2 + if [ -z "${min_speed}" ] || [ "${min_speed}" -gt "${speed}" ]; then + # echo "new min speed with ${bridge_iface}: ${speed}" >&2 + min_speed="${speed}" + fi + else + # echo "${bridge_iface} is a virtual interface, skip" >&2 + : # noop + fi + done + if [ -n "${min_speed}" ] && [ "${min_speed}" -gt "0" ]; then + echo "${min_speed}" + else + echo "${fallback_speed}" + fi + ;; + esac + elif [ -e "${speed_path}" ]; then + head -n 1 "${speed_path}" else - # fallback on 1Gb/s if unknown - echo "1000" + echo "${fallback_speed}" fi } @@ -230,7 +267,7 @@ migrate_vm_to() { interface_speed=$(interface_speed "${drbd_interface}") migrate_speed=$(echo "${interface_speed}*0.8/8" | bc) - # echo "Migration speed set to ${migrate_speed}MiB/s" + echo "Migration speed set to ${migrate_speed}MiB/s" virsh --quiet migrate-setspeed "${vm}" "${migrate_speed}" export VIRSH_DEFAULT_CONNECT_URI="qemu:///system"