mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-01-24 02:04:10 +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};
|
$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++) {
|
for (my $i = 0; $i < $MAX_USB_DEVICES; $i++) {
|
||||||
$confdesc->{"usb$i"} = $usbdesc;
|
$confdesc->{"usb$i"} = $usbdesc;
|
||||||
}
|
}
|
||||||
|
@ -337,6 +337,23 @@ my $efidisk_desc = {
|
|||||||
|
|
||||||
PVE::JSONSchema::register_standard_option("pve-qm-efidisk", $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++) {
|
for (my $i = 0; $i < $MAX_IDE_DISKS; $i++) {
|
||||||
$drivedesc_hash->{"ide$i"} = $idedesc;
|
$drivedesc_hash->{"ide$i"} = $idedesc;
|
||||||
}
|
}
|
||||||
@ -355,22 +372,9 @@ for (my $i = 0; $i < $MAX_VIRTIO_DISKS; $i++) {
|
|||||||
|
|
||||||
$drivedesc_hash->{efidisk0} = $efidisk_desc;
|
$drivedesc_hash->{efidisk0} = $efidisk_desc;
|
||||||
|
|
||||||
my $unused_fmt = {
|
for (my $i = 0; $i < $MAX_UNUSED_DISKS; $i++) {
|
||||||
volume => { alias => 'file' },
|
$drivedesc_hash->{"unused$i"} = $unuseddesc;
|
||||||
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.",
|
|
||||||
};
|
|
||||||
|
|
||||||
sub valid_drive_names {
|
sub valid_drive_names {
|
||||||
# order is important - used to autoselect boot disk
|
# order is important - used to autoselect boot disk
|
||||||
@ -384,7 +388,7 @@ sub valid_drive_names {
|
|||||||
sub is_valid_drivename {
|
sub is_valid_drivename {
|
||||||
my $dev = shift;
|
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);
|
PVE::JSONSchema::register_format('pve-qm-bootdisk', \&verify_bootdisk);
|
||||||
@ -429,12 +433,12 @@ sub parse_drive {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $desc = $key =~ /^unused\d+$/ ? $unuseddesc->{format}
|
if (!defined($drivedesc_hash->{$key})) {
|
||||||
: $drivedesc_hash->{$key}->{format};
|
|
||||||
if (!$desc) {
|
|
||||||
warn "invalid drive key: $key\n";
|
warn "invalid drive key: $key\n";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $desc = $drivedesc_hash->{$key}->{format};
|
||||||
my $res = eval { PVE::JSONSchema::parse_property_string($desc, $data) };
|
my $res = eval { PVE::JSONSchema::parse_property_string($desc, $data) };
|
||||||
return undef if !$res;
|
return undef if !$res;
|
||||||
$res->{interface} = $interface;
|
$res->{interface} = $interface;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user