5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-24 02:04:10 +03:00

drive: factor out read-only helper

we also need it for efidisks.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-06-04 11:47:44 +02:00 committed by Thomas Lamprecht
parent 75c430cee8
commit 75748d4492
2 changed files with 12 additions and 6 deletions

View File

@ -48,7 +48,7 @@ use PVE::QemuServer::Helpers qw(min_version config_aware_timeout);
use PVE::QemuServer::Cloudinit;
use PVE::QemuServer::CGroup;
use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom parse_drive print_drive);
use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory;
use PVE::QemuServer::Monitor qw(mon_cmd);
@ -3679,11 +3679,7 @@ sub config_to_command {
$storecfg, $vmid, $drive, $pbs_name, min_version($kvmver, 6, 0));
# extra protection for templates, but SATA and IDE don't support it..
my $read_only = PVE::QemuConfig->is_template($conf)
&& $drive->{interface} ne 'sata'
&& $drive->{interface} ne 'ide';
$drive_cmd .= ',readonly=on' if $read_only;
$drive_cmd .= ',readonly=on' if drive_is_read_only($conf, $drive);
push @$devices, '-drive',$drive_cmd;
push @$devices, '-device', print_drivedevice_full(

View File

@ -12,6 +12,7 @@ our @EXPORT_OK = qw(
is_valid_drivename
drive_is_cloudinit
drive_is_cdrom
drive_is_read_only
parse_drive
print_drive
);
@ -422,6 +423,15 @@ sub drive_is_cdrom {
return $drive && $drive->{media} && ($drive->{media} eq 'cdrom');
}
sub drive_is_read_only {
my ($conf, $drive) = @_;
return 0 if !PVE::QemuConfig->is_template($conf);
# don't support being marked read-only
return $drive->{interface} ne 'sata' && $drive->{interface} ne 'ide';
}
# ideX = [volume=]volume-id[,media=d][,cyls=c,heads=h,secs=s[,trans=t]]
# [,snapshot=on|off][,cache=on|off][,format=f][,backup=yes|no]
# [,rerror=ignore|report|stop][,werror=enospc|ignore|report|stop]