From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 4DC7D1FF16B for ; Tue, 1 Jul 2025 17:48:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E7860AD00; Tue, 1 Jul 2025 17:49:06 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Tue, 1 Jul 2025 17:40:55 +0200 Message-ID: <20250701154117.434512-36-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250701154117.434512-1-f.ebner@proxmox.com> References: <20250701154117.434512-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server v2 35/49] blockdev: add change_medium() helper 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" There is a slight change in behavior for cloud-init disks, when the file for the new cloud-init disk is 'none'. Previously, the current drive would not be ejected, now it is. Not sure if that edge case can even happen in practice and it is more correct, becuase the config was already updated. Co-developed-by: Alexandre Derumier Signed-off-by: Fiona Ebner --- src/PVE/QemuServer.pm | 40 ++++++---------------------------- src/PVE/QemuServer/Blockdev.pm | 18 +++++++++++++++ 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 3f135fcb..6e44132e 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -5170,30 +5170,15 @@ sub vmconfig_update_disk { } } else { # cdrom + eval { PVE::QemuServer::Blockdev::change_medium($storecfg, $vmid, $opt, $drive); }; + my $err = $@; - if ($drive->{file} eq 'none') { - mon_cmd($vmid, "eject", force => JSON::true, id => "$opt"); - if (drive_is_cloudinit($old_drive)) { - vmconfig_register_unused_drive($storecfg, $vmid, $conf, $old_drive); - } - } else { - my ($path, $format) = - PVE::QemuServer::Drive::get_path_and_format($storecfg, $drive); - - # force eject if locked - mon_cmd($vmid, "eject", force => JSON::true, id => "$opt"); - - if ($path) { - mon_cmd( - $vmid, - "blockdev-change-medium", - id => "$opt", - filename => "$path", - format => "$format", - ); - } + if ($drive->{file} eq 'none' && drive_is_cloudinit($old_drive)) { + vmconfig_register_unused_drive($storecfg, $vmid, $conf, $old_drive); } + die $err if $err; + return 1; } } @@ -5230,18 +5215,7 @@ sub vmconfig_update_cloudinit_drive { my $running = PVE::QemuServer::check_running($vmid); if ($running) { - my ($path, $format) = - PVE::QemuServer::Drive::get_path_and_format($storecfg, $cloudinit_drive); - if ($path) { - mon_cmd($vmid, "eject", force => JSON::true, id => "$cloudinit_ds"); - mon_cmd( - $vmid, - "blockdev-change-medium", - id => "$cloudinit_ds", - filename => "$path", - format => "$format", - ); - } + PVE::QemuServer::Blockdev::change_medium($storecfg, $vmid, $cloudinit_ds, $cloudinit_drive); } } diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm index ce9dc63d..147bf047 100644 --- a/src/PVE/QemuServer/Blockdev.pm +++ b/src/PVE/QemuServer/Blockdev.pm @@ -563,4 +563,22 @@ sub resize { ); } +sub change_medium { + my ($storecfg, $vmid, $qdev_id, $drive) = @_; + + # force eject if locked + mon_cmd($vmid, "eject", force => JSON::true, id => "$qdev_id"); + + my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format($storecfg, $drive); + + if ($path) { # no path for 'none' + mon_cmd( + $vmid, "blockdev-change-medium", + id => "$qdev_id", + filename => "$path", + format => "$format", + ); + } +} + 1; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel