From 7883d386229b34a3f06c8d6ffb1fbec0ae6ab459 Mon Sep 17 00:00:00 2001 From: Florent BEAUCHAMP Date: Wed, 31 Aug 2022 15:35:10 +0200 Subject: [PATCH] fix(vhd-lib/VhdDirectory/mergeBlock): write BAT on block creation (#6300) --- CHANGELOG.unreleased.md | 1 + packages/vhd-lib/Vhd/VhdDirectory.js | 7 +++++++ packages/vhd-lib/package.json | 1 + 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 1235e364e..d6b75f309 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -30,6 +30,7 @@ - @xen-orchestra/fs minor +- vhd-lib patch - xo-server minor - xo-web minor diff --git a/packages/vhd-lib/Vhd/VhdDirectory.js b/packages/vhd-lib/Vhd/VhdDirectory.js index 23af9ff1f..a681ab01e 100644 --- a/packages/vhd-lib/Vhd/VhdDirectory.js +++ b/packages/vhd-lib/Vhd/VhdDirectory.js @@ -6,6 +6,7 @@ const { fuFooter, fuHeader, checksumStruct } = require('../_structs') const { test, set: setBitmap } = require('../_bitmap') const { VhdAbstract } = require('./VhdAbstract') const assert = require('assert') +const { synchronized } = require('decorator-synchronized') const promisify = require('promise-toolbox/promisify') const zlib = require('zlib') @@ -131,6 +132,7 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract { this._path = path this._opts = opts this.#compressor = getCompressor(opts?.compression) + this.writeBlockAllocationTable = synchronized()(this.writeBlockAllocationTable) } async readBlockAllocationTable() { @@ -259,7 +261,12 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract { return super.mergeBlock(child, blockId) } try { + const blockExists = this.containsBlock(blockId) await this._handler.rename(childBlockPath, this._getFullBlockPath(blockId)) + if (!blockExists) { + setBitmap(this.#blockTable, blockId) + await this.writeBlockAllocationTable() + } } catch (error) { if (error.code === 'ENOENT' && isResumingMerge === true) { // when resuming, the blocks moved since the last merge state write are diff --git a/packages/vhd-lib/package.json b/packages/vhd-lib/package.json index 7515f5016..65e0b3795 100644 --- a/packages/vhd-lib/package.json +++ b/packages/vhd-lib/package.json @@ -21,6 +21,7 @@ "@xen-orchestra/fs": "^3.0.0", "@xen-orchestra/log": "^0.3.0", "async-iterator-to-stream": "^1.0.2", + "decorator-synchronized": "^0.6.0", "fs-extra": "^10.0.0", "limit-concurrency-decorator": "^0.5.0", "lodash": "^4.17.4",