fix(xva): last block path
the last block may be added by a different code path where the block counter wasn't padded, leading to trying to allocate a few Ettabytes
This commit is contained in:
parent
3314ba6e08
commit
79abb97b1f
3
@xen-orchestra/xva/_formatBlockPath.mjs
Normal file
3
@xen-orchestra/xva/_formatBlockPath.mjs
Normal file
@ -0,0 +1,3 @@
|
||||
const formatCounter = counter => String(counter).padStart(8, '0')
|
||||
|
||||
export const formatBlockPath = (basePath, counter) => `${basePath}/${formatCounter(counter)}`
|
@ -1,3 +1,4 @@
|
||||
import { formatBlockPath } from './_formatBlockPath.mjs'
|
||||
import { fromCallback } from 'promise-toolbox'
|
||||
import { readChunkStrict } from '@vates/read-chunk'
|
||||
import { xxhash64 } from 'hash-wasm'
|
||||
@ -33,7 +34,7 @@ export default async function addDisk(pack, vhd, basePath) {
|
||||
Date.now() - lastBlockWrittenAt > MAX_INTERVAL_BETWEEN_BLOCKS
|
||||
) {
|
||||
written = true
|
||||
await writeBlock(pack, data, `${basePath}/${('' + counter).padStart(8, '0')}`)
|
||||
await writeBlock(pack, data, formatBlockPath(basePath, counter))
|
||||
lastBlockWrittenAt = Date.now()
|
||||
} else {
|
||||
written = false
|
||||
@ -42,6 +43,6 @@ export default async function addDisk(pack, vhd, basePath) {
|
||||
}
|
||||
if (!written) {
|
||||
// last block must be present
|
||||
writeBlock(pack, empty.slice(0, lastBlockLength), `${basePath}/${counter}`)
|
||||
writeBlock(pack, empty.slice(0, lastBlockLength), `${basePath}/${('' + counter).padStart(8, '0')}`)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user