From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C27628DD9 for ; Wed, 16 Nov 2022 18:14:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AC74C232A9 for ; Wed, 16 Nov 2022 18:14:12 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 16 Nov 2022 18:14:09 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6D06444D82; Wed, 16 Nov 2022 18:14:09 +0100 (CET) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Wed, 16 Nov 2022 18:14:03 +0100 Message-Id: <20221116171408.216775-2-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221116171408.216775-1-w.bumiller@proxmox.com> References: <20221116171408.216775-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL 0.231 Adjusted score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict =?UTF-8?Q?Alignment=0A=09?=SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF =?UTF-8?Q?record=0A=09?=URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [cloudinit.pm, qemuserver.pm] Subject: [pve-devel] [PATCH qemu-server 1/6] Revert "cloudinit: avoid unsafe write of VM config" X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2022 17:14:12 -0000 This reverts commit b137c30c3a5e4f5394e961a2048724fa18f86b2c. In preparation of turning the special:cloudinig section from a "current-state" into a "pending-changes" section. --- PVE/QemuServer.pm | 20 ++++++++------------ PVE/QemuServer/Cloudinit.pm | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 3a8bc26..a585680 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -5020,7 +5020,7 @@ sub vmconfig_hotplug_pending { # some changes can be done without hotplug my $drive = parse_drive($opt, $value); if (drive_is_cloudinit($drive)) { - $conf->{cloudinit} = PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid); + PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid); } vmconfig_update_disk($storecfg, $conf, $hotplug_features->{disk}, $vmid, $opt, $value, $arch, $machine_type); @@ -5062,7 +5062,7 @@ sub vmconfig_hotplug_pending { PVE::QemuConfig->write_config($vmid, $conf); - if ($hotplug_features->{cloudinit}) { + if($hotplug_features->{cloudinit}) { my $pending = PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid); my $regenerate = undef; for my $item (@$pending) { @@ -5169,11 +5169,9 @@ sub vmconfig_apply_pending { } } - $conf->{cloudinit} = PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid) - if $generate_cloudnit; - # write all changes at once to avoid unnecessary i/o PVE::QemuConfig->write_config($vmid, $conf); + PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid) if $generate_cloudnit; } sub vmconfig_update_net { @@ -5377,8 +5375,7 @@ sub vmconfig_update_cloudinit_drive { return if !$cloudinit_drive; - $conf->{cloudinit} = PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid); - # FIXME: write out changed config here? needs to be sure that config is locked though! + PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid); my $running = PVE::QemuServer::check_running($vmid); if ($running) { @@ -5560,13 +5557,12 @@ sub vm_start_nolock { if (!$statefile && scalar(keys %{$conf->{pending}})) { vmconfig_apply_pending($vmid, $conf, $storecfg); $conf = PVE::QemuConfig->load_config($vmid); # update/reload - } elsif (!$migratedfrom) { - # don't regenerate the ISO if the VM is started as part of a live migration - # this way we can reuse the old ISO with the correct config - $conf->{cloudinit} = PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid); - # FIXME: write out changed config here? if any changes } + # don't regenerate the ISO if the VM is started as part of a live migration + # this way we can reuse the old ISO with the correct config + PVE::QemuServer::Cloudinit::generate_cloudinitconfig($conf, $vmid) if !$migratedfrom; + # override offline migrated volumes, conf is out of date still if (my $offline_volumes = $migrate_opts->{offline_volumes}) { for my $key (sort keys $offline_volumes->%*) { diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index d4a34c4..b616c7b 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -566,6 +566,7 @@ sub generate_cloudinitconfig { PVE::QemuConfig->foreach_volume($conf, sub { my ($ds, $drive) = @_; + my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file}, 1); return if !$volname || $volname !~ m/vm-$vmid-cloudinit/; @@ -576,34 +577,36 @@ sub generate_cloudinitconfig { $generator->($conf, $vmid, $drive, $volname, $storeid); }); - my $cloudinit_conf = {}; + my $cloudinitconf = delete $conf->{cloudinit}; + $cloudinitconf = {}; my @cloudinit_opts = keys %{PVE::QemuServer::cloudinit_config_properties()}; push @cloudinit_opts, 'name'; for my $opt (@cloudinit_opts) { + if ($opt =~ m/^ipconfig(\d+)/) { my $netid = "net$1"; next if !defined($conf->{$netid}); - $cloudinit_conf->{$netid} = $conf->{$netid}; + $conf->{cloudinit}->{$netid} = $conf->{$netid}; } - $cloudinit_conf->{$opt} = $conf->{$opt} if $conf->{$opt}; + $conf->{cloudinit}->{$opt} = $conf->{$opt} if $conf->{$opt}; } - my $has_cloudinit_drive = 0; + $conf->{cloudinit}->{name} = "VM$vmid" if !$conf->{cloudinit}->{name}; + for my $opt (keys %{$conf}) { if (PVE::QemuServer::is_valid_drivename($opt)) { my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); if (PVE::QemuServer::drive_is_cloudinit($drive)) { - $has_cloudinit_drive = 1; - $cloudinit_conf->{$opt} = $conf->{$opt}; + $conf->{cloudinit}->{$opt} = $conf->{$opt}; } } } - $cloudinit_conf->{name} //= "VM$vmid" if $has_cloudinit_drive; - return $cloudinit_conf; + PVE::QemuConfig->write_config($vmid, $conf); + } sub dump_cloudinit_config { -- 2.30.2