print drive commandline: die if drive with ISO sets no explicit media

The `media` option defaults to `disk` if not present, which attaches
the drive read-write. This can be unexpected for ISO volumes. Hence,
when constructing the QEMU command line, require that drives with ISO
volumes explicitly set `media` and die if this is not the case.

This breaks VM start and live-migration if such a drive is present,
and hotplug for such drives. Users can fix this by editing the VM
config to set `media` explicitly.

Also add a cfg2cmd test for the error.

Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Friedrich Weber 2025-03-27 11:33:51 +01:00 committed by Thomas Lamprecht
parent 6a956f8604
commit 2e2f8cb7a3
2 changed files with 19 additions and 0 deletions

View File

@ -1443,6 +1443,7 @@ sub print_drive_commandline_full {
my ($storeid) = PVE::Storage::parse_volume_id($drive->{file}, 1); my ($storeid) = PVE::Storage::parse_volume_id($drive->{file}, 1);
my $scfg = $storeid ? PVE::Storage::storage_config($storecfg, $storeid) : undef; my $scfg = $storeid ? PVE::Storage::storage_config($storecfg, $storeid) : undef;
my $vtype = $storeid ? (PVE::Storage::parse_volname($storecfg, $drive->{file}))[0] : undef;
my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format( my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format(
$storecfg, $vmid, $drive, $live_restore_name); $storecfg, $vmid, $drive, $live_restore_name);
@ -1514,6 +1515,9 @@ sub print_drive_commandline_full {
} }
} }
die "$drive_id: explicit media parameter is required for iso images\n"
if !defined($drive->{media}) && defined($vtype) && $vtype eq 'iso';
if (!drive_is_cdrom($drive)) { if (!drive_is_cdrom($drive)) {
my $detectzeroes; my $detectzeroes;
if (defined($drive->{detect_zeroes}) && !$drive->{detect_zeroes}) { if (defined($drive->{detect_zeroes}) && !$drive->{detect_zeroes}) {

View File

@ -0,0 +1,15 @@
# TEST: Config that doesn't specify an explicit `media` for an ISO drive
# EXPECT_ERROR: ide3: explicit media parameter is required for iso images
bootdisk: scsi0
cores: 2
ide0: cifs-store:iso/zero.iso,media=cdrom,size=112M
ide1: cifs-store:iso/one.iso,media=cdrom,size=112M
ide2: cifs-store:iso/two.iso,media=disk,size=112M
ide3: cifs-store:iso/three.iso,size=112M
memory: 512
net0: virtio=2E:01:68:F9:9C:87,bridge=vmbr0
ostype: l26
scsi0: local:100/vm-100-disk-2.qcow2,size=10G
scsihw: virtio-scsi-pci
smbios1: uuid=3dd750ce-d910-44d0-9493-525c0be4e687
vmgenid: 54d1c06c-8f5b-440f-b5b2-6eab1380e13d