fix(xo-vmdk-to-vhd): handle ova with disk position collision (#7051)

Some OVA have multiple disks with the same position, which prevent the VM from being created (error while creating VBD). Renumeroting the problematic disk works around the issue.

This may lead to unbootable VM in case the renumeroted disk was the bootable one (VMware-VirtualSAN-Witness-7.0.0-15843807.ova for example).

Fixes #7046
This commit is contained in:
Florent BEAUCHAMP 2023-09-22 11:44:12 +02:00 committed by GitHub
parent 1eb4c20844
commit c8bfda9cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -20,6 +20,7 @@
- [OVA Export] Fix support of disks with more than 8.2GiB of content (PR [#7047](https://github.com/vatesfr/xen-orchestra/pull/7047))
- [Backup] Fix `VHDFile implementation is not compatible with encrypted remote` when using VHD directory with encryption (PR [#7045](https://github.com/vatesfr/xen-orchestra/pull/7045))
- [Backup/Mirror] Fix `xo:fs:local WARN lock compromised` when mirroring a Backup Repository to a local/NFS/SMB repository ([#7043](https://github.com/vatesfr/xen-orchestra/pull/7043))
- [Ova import] Fix importing VM with collision in disk position (PR [#7051](https://github.com/vatesfr/xen-orchestra/pull/7051)) (issue [7046](https://github.com/vatesfr/xen-orchestra/issues/7046))
### Packages to release
@ -39,6 +40,7 @@
- @xen-orchestra/backups patch
- vhd-lib minor
- xo-vmdk-to-vhd patch
- xo-server patch
- xo-server-auth-github patch
- xo-server-auth-google patch

View File

@ -131,12 +131,24 @@ const allocationUnitsToFactor = unit => {
return intValue != null ? Math.pow(2, intValue[1]) : MEMORY_UNIT_TO_FACTOR[unit.charAt(0).toLowerCase()]
}
const filterDisks = disks => {
const cleanDisks = disks => {
const usedPositions = new Set()
let nextPosition = Object.keys(disks).length
for (const diskId in disks) {
if (disks[diskId].position == null) {
let position = disks[diskId].position
if (position == null) {
// TODO: Log error in U.I.
console.error(`No position specified for '${diskId}'.`)
delete disks[diskId]
} else {
if (usedPositions.has(position)) {
console.warn(
`There is at least two disks with position ${position}, we're changing the second one to ${nextPosition}`
)
disks[diskId].position = position = nextPosition
nextPosition++
}
usedPositions.add(position)
}
}
}
@ -202,7 +214,7 @@ export async function parseOVF(fileFragment, stringDeserializer) {
forEach(ensureArray(hardware.EthernetPortItem), handleItem)
// Remove disks which not have a position.
// (i.e. no info in hardware.Item section.)
filterDisks(data.disks)
cleanDisks(data.disks)
resolve(data)
}
)