CD-ROM change: re-use get_path_and_format() helper

While the path for changing a CD-ROM medium was already consistent
with the path for an already inserted CD-ROM at VM start, i.e. the one
from print_drive_commandline_full(), this makes that fact more
explicit. While at it, make sure the format is also consistent with
how it is determined in print_drive_commandline_full(). Do the same
for cloud-init drives, which often are in non-raw format.

Reported-by: Friedrich Weber <f.weber@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
This commit is contained in:
Fiona Ebner 2025-01-17 12:54:34 +01:00 committed by Fabian Grünbichler
parent edaf48cf55
commit b9677ce1ee

View File

@ -5354,14 +5354,20 @@ sub vmconfig_update_disk {
vmconfig_register_unused_drive($storecfg, $vmid, $conf, $old_drive);
}
} else {
my $path = PVE::QemuServer::Drive::get_iso_path($storecfg, $vmid, $drive->{file});
my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format(
$storecfg, $vmid, $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");
mon_cmd(
$vmid,
"blockdev-change-medium",
id => "$opt",
filename => "$path",
format => "$format",
);
}
}
@ -5398,10 +5404,17 @@ sub vmconfig_update_cloudinit_drive {
my $running = PVE::QemuServer::check_running($vmid);
if ($running) {
my $path = PVE::Storage::path($storecfg, $cloudinit_drive->{file});
my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format(
$storecfg, $vmid, $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");
mon_cmd(
$vmid,
"blockdev-change-medium",
id => "$cloudinit_ds",
filename => "$path",
format => "$format",
);
}
}
}