Compare commits
1 Commits
token-last
...
feat_more_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1282aa999 |
51
packages/vhd-cli/commands/checkChain.js
Normal file
51
packages/vhd-cli/commands/checkChain.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { Bar } = require('cli-progress')
|
||||||
|
const { getHandler } = require('@xen-orchestra/fs')
|
||||||
|
const { VhdSynthetic } = require('vhd-lib')
|
||||||
|
const { Disposable } = require('promise-toolbox')
|
||||||
|
|
||||||
|
async function checkOneVhd(vhd) {
|
||||||
|
await vhd.readBlockAllocationTable()
|
||||||
|
const nBlocks = vhd.header.maxTableEntries
|
||||||
|
const bar = new Bar({
|
||||||
|
format: '[{bar}] {percentage}% | ETA: {eta}s | {value}/{total}',
|
||||||
|
})
|
||||||
|
bar.start(nBlocks, 0)
|
||||||
|
const missings = []
|
||||||
|
for (let blockId = 0; blockId < nBlocks; ++blockId) {
|
||||||
|
bar.update(blockId)
|
||||||
|
try {
|
||||||
|
if (vhd.containsBlock(blockId)) {
|
||||||
|
await vhd.readBlock(blockId)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('missing block ', blockId)
|
||||||
|
missings.push(blockId)
|
||||||
|
if (missings.length > 1000) {
|
||||||
|
throw new Error('Too much missing blocks')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bar.update(nBlocks)
|
||||||
|
bar.stop()
|
||||||
|
return missings
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async function merge(args) {
|
||||||
|
if (args.length < 1 || args.some(_ => _ === '-h' || _ === '--help')) {
|
||||||
|
return `Usage: ${this.command} <VHD>`
|
||||||
|
}
|
||||||
|
|
||||||
|
const handler = getHandler({ url: 'file:///' })
|
||||||
|
|
||||||
|
await Disposable.use(VhdSynthetic.fromVhdChain(handler, args[0]), async syntheticVhd => {
|
||||||
|
console.log('Check full VHD')
|
||||||
|
const missings = await checkOneVhd(syntheticVhd)
|
||||||
|
if (missings.length > 0) {
|
||||||
|
console.log(`${missings.length} blocks are missing`)
|
||||||
|
} else {
|
||||||
|
console.log('VHD data are ok')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
34
packages/vhd-cli/commands/mergeChain.js
Normal file
34
packages/vhd-cli/commands/mergeChain.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { Bar } = require('cli-progress')
|
||||||
|
const { getHandler } = require('@xen-orchestra/fs')
|
||||||
|
const { mergeVhdChain } = require('vhd-lib/merge')
|
||||||
|
const { VhdSynthetic } = require('vhd-lib')
|
||||||
|
const { Disposable } = require('promise-toolbox')
|
||||||
|
|
||||||
|
module.exports = async function merge(args) {
|
||||||
|
if (args.length < 1 || args.some(_ => _ === '-h' || _ === '--help')) {
|
||||||
|
return `Usage: ${this.command} <VHD>`
|
||||||
|
}
|
||||||
|
|
||||||
|
const handler = getHandler({ url: 'file:///' })
|
||||||
|
let bar
|
||||||
|
await Disposable.use(VhdSynthetic.fromVhdChain(handler, args[0]), async syntheticVhd => {
|
||||||
|
const chainPaths = syntheticVhd.vhds.map(({ _path }) => _path)
|
||||||
|
console.log({ chainPaths })
|
||||||
|
await mergeVhdChain(handler, chainPaths, {
|
||||||
|
onProgress({ done, total }) {
|
||||||
|
if (bar === undefined) {
|
||||||
|
bar = new Bar({
|
||||||
|
format: 'merging [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}',
|
||||||
|
})
|
||||||
|
bar.start(total, done)
|
||||||
|
} else {
|
||||||
|
bar.update(done)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
bar.stop()
|
||||||
|
console.log('you must delete the cache.json.gz file to ensure the changes are visible in XO UI')
|
||||||
|
}
|
||||||
@@ -55,6 +55,10 @@ const VhdSynthetic = class VhdSynthetic extends VhdAbstract {
|
|||||||
return compressionType
|
return compressionType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get vhds() {
|
||||||
|
return this.#vhds
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<VhdAbstract>} vhds the chain of Vhds used to compute this Vhd, from the deepest child (in position 0), to the root (in the last position)
|
* @param {Array<VhdAbstract>} vhds the chain of Vhds used to compute this Vhd, from the deepest child (in position 0), to the root (in the last position)
|
||||||
* only the last one can have any type. Other must have type DISK_TYPES.DIFFERENCING (delta)
|
* only the last one can have any type. Other must have type DISK_TYPES.DIFFERENCING (delta)
|
||||||
|
|||||||
Reference in New Issue
Block a user