From 14b8cda543091e6748e68b9e2c5777e4a4cf9aeb Mon Sep 17 00:00:00 2001 From: Nicolas Raynaud Date: Wed, 16 Sep 2020 11:46:10 +0200 Subject: [PATCH] fix(xo-vmdk-to-vhd/grabTables): read each entry independently (#5255) Reading all entries at once cause problems on some VMDKs (those generated by VirtualBox) because they appear to be distributed throughout the VMDK thus making the buffer not fit in memory. See https://xcp-ng.org/forum/topic/3374/cannot-import-ova-from-virtualbox/14?_=1599689219209 --- CHANGELOG.unreleased.md | 3 +++ .../xo-vmdk-to-vhd/src/vmdk-read-table.js | 22 ++++--------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index e59e5a121..d8acbd6ae 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -16,6 +16,8 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” +- [Import VMDK] Fix `No position specified for vmdisk1` error (PR [#5255](https://github.com/vatesfr/xen-orchestra/pull/5255)) + ### Packages to release > Packages will be released in the order they are here, therefore, they should @@ -33,4 +35,5 @@ > > In case of conflict, the highest (lowest in previous list) `$version` wins. +- xo-vmdk-to-vhd patch - xo-web minor diff --git a/packages/xo-vmdk-to-vhd/src/vmdk-read-table.js b/packages/xo-vmdk-to-vhd/src/vmdk-read-table.js index c6cb6c680..1916943bb 100644 --- a/packages/xo-vmdk-to-vhd/src/vmdk-read-table.js +++ b/packages/xo-vmdk-to-vhd/src/vmdk-read-table.js @@ -50,28 +50,14 @@ async function grabTables( fileAccessor ) { const cachedGrainTables = [] - let grainTableAddresMin = Infinity - let grainTableAddressMax = -Infinity for (let i = 0; i < grainDirectoryEntries; i++) { const grainTableAddr = grainDir[i] * SECTOR_SIZE if (grainTableAddr !== 0) { - grainTableAddresMin = Math.min(grainTableAddresMin, grainTableAddr) - grainTableAddressMax = Math.max( - grainTableAddressMax, - grainTableAddr + grainTablePhysicalSize - ) - } - } - const grainTableBuffer = await fileAccessor( - grainTableAddresMin, - grainTableAddressMax - ) - for (let i = 0; i < grainDirectoryEntries; i++) { - const grainTableAddr = grainDir[i] * SECTOR_SIZE - if (grainTableAddr !== 0) { - const addr = grainTableAddr - grainTableAddresMin cachedGrainTables[i] = new Uint32Array( - grainTableBuffer.slice(addr, addr + grainTablePhysicalSize) + await fileAccessor( + grainTableAddr, + grainTableAddr + grainTablePhysicalSize + ) ) } }