fix(vmdk): ensure descriptor have enough free space (#6163)

This commit is contained in:
Florent BEAUCHAMP 2022-04-05 10:22:13 +02:00 committed by GitHub
parent ee47a361b1
commit 915e4b66a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Plugins] Automatically configure plugins when a configuration file is imported (PR [#6171](https://github.com/vatesfr/xen-orchestra/pull/6171))
- [VMDK Export] Fix `VBOX_E_FILE_ERROR (0x80BB0004)` when importing in VirtualBox (PR [#6163](https://github.com/vatesfr/xen-orchestra/pull/6163))
### Packages to release
@ -31,5 +32,6 @@
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xen-api minor
- xo-vmdk-to-vhd minor
- @xen-orchestra/proxy patch
- xo-server patch

View File

@ -53,7 +53,17 @@ ddb.geometry.heads = "${geometry.heads}"
ddb.geometry.cylinders = "${geometry.cylinders}"
`
const utf8Descriptor = Buffer.from(descriptor, 'utf8')
const descriptorSizeSectors = Math.ceil(utf8Descriptor.length / SECTOR_SIZE)
// virtual box add some additional properties to the descriptor like:
// ddb.uuid.image="9afa1dd0-d966-4279-a762-b7fbb0136308"
// ddb.uuid.modification="cd9be63c-4953-44d0-8325-45635a9ca396"
// ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
// ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
//
// but does not ensure there is enough free room and overwrite the data (the grain directory), breaking the file
//
// adding 10 sectors of padding seems to be enough to work-around the issue
const descriptorSizeSectors = Math.ceil(utf8Descriptor.length / SECTOR_SIZE) + 10
const descriptorBuffer = Buffer.alloc(descriptorSizeSectors * SECTOR_SIZE)
utf8Descriptor.copy(descriptorBuffer)
const headerData = createStreamOptimizedHeader(diskCapacitySectors, descriptorSizeSectors)