mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 09:23:23 +00:00
drive: add get_path_and_format() helper
To allow re-using it for CD-ROM hotplug. No functional change intended. 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:
parent
9f95aa78c7
commit
edaf48cf55
@ -1463,41 +1463,14 @@ my sub drive_uses_cache_direct {
|
||||
sub print_drive_commandline_full {
|
||||
my ($storecfg, $vmid, $drive, $live_restore_name, $io_uring) = @_;
|
||||
|
||||
my $path;
|
||||
my $volid = $drive->{file};
|
||||
my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
|
||||
|
||||
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
|
||||
my $scfg = $storeid ? PVE::Storage::storage_config($storecfg, $storeid) : undef;
|
||||
|
||||
if (drive_is_cdrom($drive)) {
|
||||
$path = PVE::QemuServer::Drive::get_iso_path($storecfg, $vmid, $volid);
|
||||
die "$drive_id: cannot back cdrom drive with a live restore image\n" if $live_restore_name;
|
||||
} else {
|
||||
if ($storeid) {
|
||||
$path = PVE::Storage::path($storecfg, $volid);
|
||||
} else {
|
||||
$path = $volid;
|
||||
}
|
||||
}
|
||||
|
||||
# For PVE-managed volumes, use the format from the storage layer and prevent overrides via the
|
||||
# drive's 'format' option. For unmanaged volumes, fallback to 'raw' to avoid auto-detection by
|
||||
# QEMU. For the special case 'none' (get_iso_path() returns an empty $path), there should be no
|
||||
# format or QEMU won't start.
|
||||
my $format;
|
||||
if (drive_is_cdrom($drive) && !$path) {
|
||||
# no format
|
||||
} elsif ($storeid) {
|
||||
$format = checked_volume_format($storecfg, $volid);
|
||||
|
||||
if ($drive->{format} && $drive->{format} ne $format) {
|
||||
die "drive '$drive->{interface}$drive->{index}' - volume '$volid'"
|
||||
." - 'format=$drive->{format}' option different from storage format '$format'\n";
|
||||
}
|
||||
} else {
|
||||
$format = $drive->{format} // 'raw';
|
||||
}
|
||||
my ($path, $format) = PVE::QemuServer::Drive::get_path_and_format(
|
||||
$storecfg, $vmid, $drive, $live_restore_name);
|
||||
|
||||
my $is_rbd = $path =~ m/^rbd:/;
|
||||
|
||||
|
@ -100,6 +100,49 @@ sub get_iso_path {
|
||||
}
|
||||
}
|
||||
|
||||
# Returns the path that can be used on the QEMU commandline and in QMP commands as well as the
|
||||
# checked format of the drive.
|
||||
sub get_path_and_format {
|
||||
my ($storecfg, $vmid, $drive, $live_restore_name) = @_;
|
||||
|
||||
my $path;
|
||||
my $volid = $drive->{file};
|
||||
my $drive_id = get_drive_id($drive);
|
||||
|
||||
my ($storeid) = PVE::Storage::parse_volume_id($volid, 1);
|
||||
|
||||
if (drive_is_cdrom($drive)) {
|
||||
$path = get_iso_path($storecfg, $vmid, $volid);
|
||||
die "$drive_id: cannot back cdrom drive with a live restore image\n" if $live_restore_name;
|
||||
} else {
|
||||
if ($storeid) {
|
||||
$path = PVE::Storage::path($storecfg, $volid);
|
||||
} else {
|
||||
$path = $volid;
|
||||
}
|
||||
}
|
||||
|
||||
# For PVE-managed volumes, use the format from the storage layer and prevent overrides via the
|
||||
# drive's 'format' option. For unmanaged volumes, fallback to 'raw' to avoid auto-detection by
|
||||
# QEMU. For the special case 'none' (get_iso_path() returns an empty $path), there should be no
|
||||
# format or QEMU won't start.
|
||||
my $format;
|
||||
if (drive_is_cdrom($drive) && !$path) {
|
||||
# no format
|
||||
} elsif ($storeid) {
|
||||
$format = checked_volume_format($storecfg, $volid);
|
||||
|
||||
if ($drive->{format} && $drive->{format} ne $format) {
|
||||
die "drive '$drive->{interface}$drive->{index}' - volume '$volid'"
|
||||
." - 'format=$drive->{format}' option different from storage format '$format'\n";
|
||||
}
|
||||
} else {
|
||||
$format = $drive->{format} // 'raw';
|
||||
}
|
||||
|
||||
return ($path, $format);
|
||||
}
|
||||
|
||||
my $MAX_IDE_DISKS = 4;
|
||||
my $MAX_SCSI_DISKS = 31;
|
||||
my $MAX_VIRTIO_DISKS = 16;
|
||||
|
Loading…
Reference in New Issue
Block a user