fix #5998: import: avoid duplicate disk keys with multiple controllers
The disk key is built from the controller type and the address of the disk on that controller. The address is only unique per controller, so with more than one controller of the same type, like a VM with more than 16 disks spread over two SCSI controllers, several disks got the same key. 'qm importovf' then failed with "cowardly refusing to overwrite existing entry: scsi0", and the import wizard silently dropped all but one of those disks, as they are stored in a hash by key. Keep the address for the first disk using it and move any further disk with the same address to the lowest address of that bus that is not used by any other disk. Add a test manifest with a second SCSI controller. Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
1 parent
25ba04d0ba
commit
9f20cd4f75
3 files changed
+199
No files matched your search
@@ -369,6 +369,24 @@ ovf:Item[rasd:InstanceID='%s']/rasd:ResourceType", $controller_id,
|
||||
};
|
||||
}
|
||||
|
||||
# the address is only unique per controller, so disks on different controllers of the same
|
||||
# type can end up with the same address, move those to the next free one of that bus
|
||||
my $used_addresses = { map { $_->{disk_address} => 1 } @disks };
|
||||
my $assigned_addresses = {};
|
||||
for my $disk (@disks) {
|
||||
if (
|
||||
$assigned_addresses->{ $disk->{disk_address} }
|
||||
&& $disk->{disk_address} =~ m/^([a-z]+)\d+$/
|
||||
) {
|
||||
my $bus = $1;
|
||||
my $index = 0;
|
||||
$index++ while $used_addresses->{"$bus$index"};
|
||||
$disk->{disk_address} = "$bus$index";
|
||||
$used_addresses->{ $disk->{disk_address} } = 1;
|
||||
}
|
||||
$assigned_addresses->{ $disk->{disk_address} } = 1;
|
||||
}
|
||||
|
||||
my $nic_id = dtmf_name_to_id('Ethernet Adapter');
|
||||
my $xpath_find_nics =
|
||||
"/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType=${nic_id}]";
|
||||
|
||||
Reference in new issue
Block a user