[pve-devel] [PATCH qemu-server 4/7] add postinst with Windows device incompatibility workaround

Stefan Reiter s.reiter at proxmox.com
Thu Mar 4 13:52:06 CET 2021


...for QEMU 5.2

Add a postinst with some inline perl (to avoid having to install a
seperate file to run) that conservatively does its best to set the
machine version for all VMs the bug might affect to 5.1.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

Requires Fabian's #3301 series:
https://lists.proxmox.com/pipermail/pve-devel/2021-March/047175.html

I did it as inline perl because I wasn't sure where to put a file containing
this to be able to execute it from postinst without cluttering the machine after
it is done. Feel free to extract it somewhere else if you see fit.

Might also make sense to update the link from the forum for "more details" to
the cover of this series, or something else...

 debian/postinst | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100755 debian/postinst

diff --git a/debian/postinst b/debian/postinst
new file mode 100755
index 0000000..c93dd5d
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+# Abort if any command returns an error value
+set -e
+
+# This script is called as the last step of the installation of the 
+# package.  All the package's files are in place, dpkg has already
+# done its automatic conffile handling, and all the packages we depend
+# of are already fully installed and configured.
+
+case "$1" in
+  configure)
+    if test -n "$2"; then
+	if dpkg --compare-versions "$2" 'lt' '6.3-6'; then
+            echo
+            perl <<"EOPERL"
+
+use warnings;
+use strict;
+
+use PVE::Cluster;
+use PVE::QemuConfig;
+use PVE::QemuServer;
+use PVE::QemuServer::Helpers qw(min_version);
+
+print "Pinning Windows VM machine versions to 5.1\n";
+print "See https://forum.proxmox.com/threads/warning-latest-patch-just-broke-all-my-windows-vms-6-3-4-patch-inside.84915/ for details\n";
+
+PVE::Cluster::check_cfs_is_mounted();
+PVE::Cluster::cfs_update();
+
+my $vms = PVE::QemuServer::vmstatus(undef, 1);
+foreach my $vmid (sort keys %$vms) {
+    my $running = defined($vms->{$vmid}->{pid}) ? 1 : 0;
+    eval {
+        PVE::QemuConfig->lock_config($vmid, sub {
+            my $conf = PVE::QemuConfig->load_config($vmid);
+            PVE::QemuConfig->check_lock($conf);
+
+            return if !$conf->{ostype} || !PVE::QemuServer::windows_version($conf->{ostype});
+
+            if ($running) {
+                my $cur_machine = $vms->{$vmid}->{'running-machine'};
+                $cur_machine =~ s/pc(-i440fx|-q35)?-//;
+                if (min_version($cur_machine, 5, 2)) {
+                    print "$vmid: [skip] already running with machine version '$cur_machine'\n";
+                    return;
+                }
+            }
+
+            if ($conf->{machine} && $conf->{machine} =~ m/^pc-/) {
+                print "$vmid: [skip] already pinned to '$conf->{machine}'\n";
+                return;
+            }
+
+            if ($conf->{pending}->{machine}) {
+                print "$vmid: [skip] machine changed in pending\n";
+                return;
+            }
+
+            my $cur = $conf->{machine} || "i440fx";
+            $cur = "i440fx" if $cur eq "pc";
+            my $new = "pc-$cur-5.1";
+
+            my $notice = "";
+            if ($running) {
+                $conf->{pending}->{machine} = $new;
+                $notice = " (after restart)";
+            } else {
+                $conf->{machine} = $new;
+            }
+
+            PVE::QemuConfig->write_config($vmid, $conf);
+            print "$vmid: [ OK ] now pinned to '$new'$notice\n";
+        });
+    };
+    warn "$vmid: [warn] failed to update: $@\n" if $@;
+}
+
+print "If you want to upgrade to the newest version, set the machine back to 'latest' in the GUI, or 'pc'/'q35' on the CLI.\n";
+
+EOPERL
+        echo
+	fi
+    fi
+    ;;
+
+  abort-upgrade|abort-remove|abort-deconfigure)
+    ;;
+
+  *) echo "$0: didn't understand being called with \`$1'" 1>&2
+     exit 0;;
+esac
+
+exit 0
-- 
2.20.1






More information about the pve-devel mailing list