Skip to content

Commit

Permalink
refresh vmm/(pre)reconfigure patches
Browse files Browse the repository at this point in the history
Change-Id: I3d35c2bfe91cf199809ac31b40bd37a758d87b77
  • Loading branch information
atodorov-storpool committed Nov 8, 2024
1 parent b147c5c commit d8cda08
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
60 changes: 60 additions & 0 deletions patches/vmm/6.10/01-prereconfigure-fix-updateconf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--- remotes/vmm/kvm/prereconfigure.~2~ 2022-02-22 18:47:17.649648643 +0200
+++ remotes/vmm/kvm/prereconfigure 2022-02-22 18:54:59.407952982 +0200
@@ -24,7 +24,42 @@

if [[ -n "$DOMAIN" ]] && [[ -n "$TARGET_DEVICE" ]]
then
- DISK="$(virsh --connect $LIBVIRT_URI domblklist $DOMAIN | awk "/^\s*$TARGET_DEVICE/ {print \$2; exit}")"
+ qemu_json=$(virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-version"}')
+ qemu_version_arr=($(echo "$qemu_json"|jq -r '.return|(.qemu.major|tostring)+" "+(.qemu.minor|tostring)+" "+(.qemu.micro|tostring)+" "+.package'))
+ qemu_version_int=$((qemu_version_arr[0]*10000 + qemu_version_arr[1]*100 + qemu_version_arr[2]))
+ logger -t "vmm_sp_pre" -- "${qemu_version_arr[3]} ($qemu_version_int) libvirt:$(virsh --version)"
+
+ DISK="$(virsh --connect $LIBVIRT_URI domblklist $DOMAIN | awk "/^\s*$TARGET_DEVICE/ {print \$2; exit}")"
+
+ while read -u ${fdh} qdev tray_open inserted_file locked; do
+ logger -t "vmm_sp_pre" -- "$qdev locked:$locked tray_open:$tray_open file:$inserted_file //loop"
+ if [ "${inserted_file##*/}" == "${DISK##*/}" ]; then
+ QDEV="$qdev"
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"eject\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_pre" -- "qemu-monitor-command $DOMAIN --cmd '{\"execute\":\"eject\",\"arguments\":{\"id\":\"$qdev\"}}' ($?)"
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_pre" -- "qemu-monitor-command $DOMAIN --cmd {\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}} ($?)"
+ devid=$qdev
+ fi
+ if [ "$inserted_file" == "null" ] && [ "$tray_open" == "false" ]; then
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_pre" -- "qemu-monitor-command $DOMAIN --cmd {\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}} ($?) tray_open"
+ devid=$qdev
+ fi
+ done {fdh}< <(virsh --connect $LIBVIRT_URI \
+ qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r '.return[]|select(.removable)|.qdev+" "+(.tray_open|tostring)+" "+(.inserted.file|tostring)+" "+(.locked|tostring)' || true)
+ cnt=0
+ [ -z "$devid" ] || while : ; do
+ tray_open=$(virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r --arg qdev "$devid" '.return[]|select(.qdev==$qdev)|.tray_open')
+ logger -t "vmm_sp_pre" -- "$devid tray_open:$tray_open //wait $((cnt*100))ms"
+ cnt=$((cnt + 1))
+ if [ "$tray_open" == "true" ] || [ $cnt -gt 20 ]; then
+ break
+ fi
+ sleep 0.1
+ done
if [[ "$DISK" = "-" ]]; then
log_debug "CDROM already ejected"
exit 0
@@ -33,6 +68,12 @@
CMD="virsh --connect $LIBVIRT_URI change-media $DOMAIN $TARGET_DEVICE \
--eject --force"

+ logger -t "vmm_sp_pre" -- "$CMD # DISK:$DISK"
exec_and_log "$CMD" "Could not eject CDROM $TARGET_DEVICE"
fi

+while read -u ${fdh} q t f l; do
+ logger -t "vmm_sp_pre" -- "$q locked:$l tray_open:$t file:$f //END"
+done {fdh}< <(virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r '.return[]|select(.removable)|.qdev+" "+(.tray_open|tostring)+" "+(.inserted.file|tostring)+" "+(.locked|tostring)')
+

49 changes: 49 additions & 0 deletions patches/vmm/6.10/01-reconfigure-fix-updateconf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
diff -ur remotes.orig/vmm/kvm/reconfigure remotes/vmm/kvm/reconfigure
--- remotes.orig/vmm/kvm/reconfigure 2024-11-06 19:34:11.000000000 +0200
+++ remotes/vmm/kvm/reconfigure 2024-11-07 16:27:23.855972531 +0200
@@ -25,10 +25,45 @@

if [[ -n "$DOMAIN" ]] && [[ -n "$TARGET_DEVICE" ]] && [[ -n "$ISO_PATH" ]]
then
+ while read -u ${fdh} qdev tray_open inserted_file locked; do
+ logger -t "vmm_sp_rec" -- "$qdev locked:$locked tray_open:$tray_open file:$inserted_file //loop"
+ if [ "${inserted_file##*/}" == "${ISO_PATH##*/}" ]; then
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"eject\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_rec" -- "qemu-monitor-command $DOMAIN --cmd '{\"execute\":\"eject\",\"arguments\":{\"id\":\"$qdev\"}}' ($?)"
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_rec" -- "qemu-monitor-command $DOMAIN --cmd {\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}} ($?)"
+ devid="$qdev"
+ fi
+ if [ "$inserted_file" == "null" ] && [ "$tray_open" == "false" ]; then
+ virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd "{\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}}"
+ logger -t "vmm_sp_rec" -- "qemu-monitor-command $DOMAIN --cmd {\"execute\":\"blockdev-open-tray\",\"arguments\":{\"id\":\"$qdev\"}} ($?)"
+ devid="$qdev"
+ fi
+ done {fdh}< <(virsh --connect $LIBVIRT_URI \
+ qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r '.return[]|select(.removable)|.qdev+" "+(.tray_open|tostring)+" "+(.inserted.file|tostring)+" "+(.locked|tostring)' || true)
+
+ cnt=0
+ [ -z "$devid" ] || while : ; do
+ tray_open=$(virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r --arg qdev "$devid" '.return[]|select(.qdev==$qdev)|.tray_open')
+ logger -t "vmm_sp_rec" -- "$devid tray_open:$tray_open //wait $((cnt*100))ms"
+ cnt=$((cnt + 1))
+ if [ "$tray_open" == "true" ] || [ $cnt -gt 20 ]; then
+ break
+ fi
+ sleep 0.1
+ done
+
test -b "$ISO_PATH" && EXTRA_ARGS="--block" || EXTRA_ARGS=""
CMD="virsh --connect $LIBVIRT_URI \
change-media $DOMAIN $TARGET_DEVICE $ISO_PATH --insert $EXTRA_ARGS"

exec_and_log "$CMD" "Could not insert CDROM $ISO_PATH to $TARGET_DEVICE"
+
+ while read -u ${fdh} q t f l; do
+ logger -t "vmm_sp_rec" -- "$q locked:$l tray_open:$t file:$f //END"
+ done {fdh}< <(virsh --connect $LIBVIRT_URI qemu-monitor-command "$DOMAIN" --cmd '{"execute":"query-block"}' |\
+ jq -r '.return[]|select(.removable)|.qdev+" "+(.tray_open|tostring)+" "+(.inserted.file|tostring)+" "+(.locked|tostring)')
fi

0 comments on commit d8cda08

Please sign in to comment.