public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, Stefan Reiter <s.reiter@proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server 4/7] add postinst with Windows device incompatibility workaround
Date: Fri, 5 Mar 2021 09:03:15 +0100	[thread overview]
Message-ID: <34da3738-e5f4-8e50-33d7-ccf7fd31f668@proxmox.com> (raw)
In-Reply-To: <20210304125209.24078-5-s.reiter@proxmox.com>

Am 04.03.21 um 13:52 schrieb Stefan Reiter:
> ...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@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);

Is it worth trying to handle e.g. 'suspended' VMs too?

A more general thing: what about snapshots? Do we need to pin the 
version there too? Could be done here or with a hook on rollback, but 
for the latter a mechanism to detect when it's needed is required.

> +
> +            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
> 




  parent reply	other threads:[~2021-03-05  8:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 12:52 [pve-devel] [PATCH 0/7] Work around QEMU 5.2 windows incompatibility Stefan Reiter
2021-03-04 12:52 ` [pve-devel] [PATCH pve-qemu 1/7] add static supported machines file Stefan Reiter
2021-03-05 21:27   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH pve-qemu 2/7] add ACPI compat patch for 5.1 and older machine types Stefan Reiter
2021-03-05 21:27   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH qemu-server 3/7] api: add Machine module to query " Stefan Reiter
2021-03-05 21:28   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH qemu-server 4/7] add postinst with Windows device incompatibility workaround Stefan Reiter
2021-03-04 13:31   ` Stefan Reiter
2021-03-05  8:03   ` Fabian Ebner [this message]
2021-03-05 21:32   ` [pve-devel] NAK: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH manager 5/7] api: register Qemu::Machine call Stefan Reiter
2021-03-05 21:33   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH manager 6/7] ui: create MachineEdit window Stefan Reiter
2021-03-05 21:33   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-04 12:52 ` [pve-devel] [PATCH manager 7/7] ui: MachineEdit: add option for machine version pinning Stefan Reiter
2021-03-05 21:36   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-05  7:24 ` [pve-devel] [PATCH 0/7] Work around QEMU 5.2 windows incompatibility Fabian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34da3738-e5f4-8e50-33d7-ccf7fd31f668@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=s.reiter@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal