From 0f1dcda7db451987d316d6ab4cd06355c1432f0f Mon Sep 17 00:00:00 2001 From: Florent Beauchamp Date: Tue, 30 Jan 2024 10:24:03 +0000 Subject: [PATCH] feat(vmware-explorer): don't read from parent when delta block is already complete --- .../vmware-explorer/VhdEsxiSeSparse.mjs | 19 ++++++++++++++++--- CHANGELOG.unreleased.md | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/@xen-orchestra/vmware-explorer/VhdEsxiSeSparse.mjs b/@xen-orchestra/vmware-explorer/VhdEsxiSeSparse.mjs index 93dfd6439d1..f3f7f71e43d 100644 --- a/@xen-orchestra/vmware-explorer/VhdEsxiSeSparse.mjs +++ b/@xen-orchestra/vmware-explorer/VhdEsxiSeSparse.mjs @@ -250,15 +250,28 @@ export default class VhdEsxiSeSparse extends VhdAbstract { async readBlock(blockId) { let changed = false - const parentBlock = await this.#parentVhd.readBlock(blockId) - const parentBuffer = parentBlock.buffer const grainOffsets = this.#grainIndex.get(blockId) // may be undefined if the child contains block and lookMissingBlockInParent=true + + // negative value indicate that it's not an offset + // SE_SPARSE_GRAIN_NON_ALLOCATED means we have to look into the parent data + const isLocallyFull = !grainOffsets.some(value => value === -SE_SPARSE_GRAIN_NON_ALLOCATED) + + let parentBuffer, parentBlock + // don't read from parent is current block is already completly described + if (isLocallyFull) { + parentBuffer = Buffer.alloc(512 /* bitmap */ + 2 * 1024 * 1024 /* data */, 0) + parentBuffer.fill(255, 0, 512) // bitmap is full of bit 1 + } else { + parentBlock = await this.#parentVhd.readBlock(blockId) + parentBuffer = parentBlock.buffer + } const EMPTY_GRAIN = Buffer.alloc(GRAIN_SIZE_BYTES, 0) for (const index in grainOffsets) { const value = grainOffsets[index] let data if (value > 0) { // it's the offset in byte of a grain type SE_SPARSE_GRAIN_ALLOCATED + // @todo this part can be quite slow when grain are not sorted data = await this.#read(value, GRAIN_SIZE_BYTES) } else { // back to the real grain type @@ -281,7 +294,7 @@ export default class VhdEsxiSeSparse extends VhdAbstract { } } // no need to copy if data all come from parent - return changed + return changed || !parentBlock ? { id: blockId, bitmap: parentBuffer.slice(0, 512), diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 502cc0bdaef..1bde40b2beb 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -34,6 +34,7 @@ - @xen-orchestra/backups patch +- @xen-orchestra/vmware-explorer minor - xo-server minor - xo-web minor