From 61a472f108447f6c932f3225cd34d13813331871 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 24 Apr 2018 18:06:58 +0200 Subject: [PATCH] chore(xo-server/vhd/createReadStream): improve genericity (#2865) It should now be pretty easy to make it work to generate a delta VHD, which should be very useful when mergin multiple deltas together (during deletion. --- packages/xo-server/src/vhd-merge.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/xo-server/src/vhd-merge.js b/packages/xo-server/src/vhd-merge.js index 347ff9c54..b151d81cf 100644 --- a/packages/xo-server/src/vhd-merge.js +++ b/packages/xo-server/src/vhd-merge.js @@ -878,12 +878,17 @@ export const createReadStream = asyncIteratorToStream(function * (handler, path) // this the VHD we want to synthetize const vhd = vhds[0] + // this is the root VHD + const rootVhd = vhds[nVhds - 1] + // data of our synthetic VHD - // TODO: empty parentUuid and parentLocatorEntry-s in header + // TODO: set parentLocatorEntry-s in header let header = { ...vhd.header, tableOffset: 512 + 1024, - parentUnicodeName: '', + parentTimestamp: rootVhd.header.parentTimestamp, + parentUnicodeName: rootVhd.header.parentUnicodeName, + parentUuid: rootVhd.header.parentUuid, } const bat = Buffer.allocUnsafe( @@ -891,7 +896,7 @@ export const createReadStream = asyncIteratorToStream(function * (handler, path) ) let footer = { ...vhd.footer, - diskType: HARD_DISK_TYPE_DYNAMIC, + diskType: rootVhd.footer.diskType, } const sectorsPerBlockData = vhd.sectorsPerBlock const sectorsPerBlock = @@ -940,7 +945,7 @@ export const createReadStream = asyncIteratorToStream(function * (handler, path) const blocksByVhd = new Map() const emitBlockSectors = function * (iVhd, i, n) { const vhd = vhds[iVhd] - const isRootVhd = vhd.footer.diskType === HARD_DISK_TYPE_DYNAMIC + const isRootVhd = vhd === rootVhd if (!vhd.containsBlock(iBlock)) { if (isRootVhd) { yield Buffer.alloc((n - i) * VHD_SECTOR_SIZE)