mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-01-08 21:18:03 +03:00
Add unused description to drivedesc_hash
Moved code so that initialization of drivedesc_hash stays a single block. Avoid auto-vivication in parse_drive. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
47f35977cb
commit
43c4c7b693
@ -1091,10 +1091,6 @@ for my $key (keys %{$PVE::QemuServer::Drive::drivedesc_hash}) {
|
||||
$confdesc->{$key} = $PVE::QemuServer::Drive::drivedesc_hash->{$key};
|
||||
}
|
||||
|
||||
for (my $i = 0; $i < $PVE::QemuServer::Drive::MAX_UNUSED_DISKS; $i++) {
|
||||
$confdesc->{"unused$i"} = $PVE::QemuServer::Drive::unuseddesc;
|
||||
}
|
||||
|
||||
for (my $i = 0; $i < $MAX_USB_DEVICES; $i++) {
|
||||
$confdesc->{"usb$i"} = $usbdesc;
|
||||
}
|
||||
|
@ -337,6 +337,23 @@ my $efidisk_desc = {
|
||||
|
||||
PVE::JSONSchema::register_standard_option("pve-qm-efidisk", $efidisk_desc);
|
||||
|
||||
my $unused_fmt = {
|
||||
volume => { alias => 'file' },
|
||||
file => {
|
||||
type => 'string',
|
||||
format => 'pve-volume-id',
|
||||
default_key => 1,
|
||||
format_description => 'volume',
|
||||
description => "The drive's backing volume.",
|
||||
},
|
||||
};
|
||||
|
||||
my $unuseddesc = {
|
||||
optional => 1,
|
||||
type => 'string', format => $unused_fmt,
|
||||
description => "Reference to unused volumes. This is used internally, and should not be modified manually.",
|
||||
};
|
||||
|
||||
for (my $i = 0; $i < $MAX_IDE_DISKS; $i++) {
|
||||
$drivedesc_hash->{"ide$i"} = $idedesc;
|
||||
}
|
||||
@ -355,22 +372,9 @@ for (my $i = 0; $i < $MAX_VIRTIO_DISKS; $i++) {
|
||||
|
||||
$drivedesc_hash->{efidisk0} = $efidisk_desc;
|
||||
|
||||
my $unused_fmt = {
|
||||
volume => { alias => 'file' },
|
||||
file => {
|
||||
type => 'string',
|
||||
format => 'pve-volume-id',
|
||||
default_key => 1,
|
||||
format_description => 'volume',
|
||||
description => "The drive's backing volume.",
|
||||
},
|
||||
};
|
||||
|
||||
our $unuseddesc = {
|
||||
optional => 1,
|
||||
type => 'string', format => $unused_fmt,
|
||||
description => "Reference to unused volumes. This is used internally, and should not be modified manually.",
|
||||
};
|
||||
for (my $i = 0; $i < $MAX_UNUSED_DISKS; $i++) {
|
||||
$drivedesc_hash->{"unused$i"} = $unuseddesc;
|
||||
}
|
||||
|
||||
sub valid_drive_names {
|
||||
# order is important - used to autoselect boot disk
|
||||
@ -384,7 +388,7 @@ sub valid_drive_names {
|
||||
sub is_valid_drivename {
|
||||
my $dev = shift;
|
||||
|
||||
return defined($drivedesc_hash->{$dev});
|
||||
return defined($drivedesc_hash->{$dev}) && $dev !~ /^unused\d+$/;
|
||||
}
|
||||
|
||||
PVE::JSONSchema::register_format('pve-qm-bootdisk', \&verify_bootdisk);
|
||||
@ -429,12 +433,12 @@ sub parse_drive {
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $desc = $key =~ /^unused\d+$/ ? $unuseddesc->{format}
|
||||
: $drivedesc_hash->{$key}->{format};
|
||||
if (!$desc) {
|
||||
if (!defined($drivedesc_hash->{$key})) {
|
||||
warn "invalid drive key: $key\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $desc = $drivedesc_hash->{$key}->{format};
|
||||
my $res = eval { PVE::JSONSchema::parse_property_string($desc, $data) };
|
||||
return undef if !$res;
|
||||
$res->{interface} = $interface;
|
||||
|
Loading…
Reference in New Issue
Block a user