-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
161dc94
commit 52f23d0
Showing
10 changed files
with
84 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { getSyncedHandler } from '@xen-orchestra/fs' | ||
import { VhdRemote, RemoteMetadata } from './from/VhdRemote.mjs' | ||
import { FileAccessor } from './file-accessor/FileAccessor.mjs' | ||
import { VhdRemote } from './from/VhdRemote.mts' | ||
import { FileAccessor } from './file-accessor/FileAccessor.mts' | ||
import { writeVhdFileToRemote } from './to/VhdRemote.mts' | ||
|
||
async function run() { | ||
const { value: handler } = await getSyncedHandler({ url: 'file:///mnt/ssd/vhdblock' }) | ||
const { value: handlerSource } = await getSyncedHandler({ url: 'file:///mnt/ssd/vhdblock' }) | ||
const { value: handlerTarget } = await getSyncedHandler({ url: 'file:///mnt/ssd/out' }) | ||
const metadataPath = './xo-vm-backups/cbb46b48-12aa-59dc-4039-8a587fdc67d5/20230831T100000Z.json' | ||
|
||
const vhd = new VhdRemote({ | ||
handler: handler as FileAccessor, | ||
handler: handlerSource as FileAccessor, | ||
metadataPath, | ||
diskUuid: '1282b678-cb12-4b13-ab17-7a4fdac403d8', | ||
}) | ||
const { value: iterator } = await vhd.getBlockIterator() | ||
for await (const block of iterator) { | ||
console.log(block) | ||
} | ||
|
||
await writeVhdFileToRemote(handlerTarget, 'out.vhd', vhd) | ||
} | ||
|
||
run() |
2 changes: 1 addition & 1 deletion
2
@xen-orchestra/disk-transform/src/file-accessor/InBrowserFileAccessor.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
@xen-orchestra/disk-transform/src/file-accessor/RemoteFileAccessor.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { VhdFile } from 'vhd-lib' | ||
import { DiskBlockGenerator, PortableDifferencingDisk } from '../PortableDifferencingDisk.mts' | ||
import { Disposable } from 'promise-toolbox' | ||
import { type Vhd } from '../from/VhdRemote.mts' | ||
import { type FileAccessor } from '../file-accessor/FileAccessor.mts' | ||
import { createFooter, createHeader } from 'vhd-lib/_createFooterHeader.js' | ||
import { unpackFooter, unpackHeader } from 'vhd-lib/Vhd/_utils.js' | ||
import { DISK_TYPES, FOOTER_SIZE } from 'vhd-lib/_constants.js' | ||
import _computeGeometryForSize from 'vhd-lib/_computeGeometryForSize.js' | ||
|
||
async function writeVhdToRemote(targetVhd: Vhd, disk: PortableDifferencingDisk): Promise<void> { | ||
return Disposable.use(disk.getBlockIterator(), async (blockIterator: DiskBlockGenerator): Promise<void> => { | ||
// @todo : handle differencing disk parent | ||
|
||
const metada = await disk.getMetadata() | ||
console.log('metadata', { metada }) | ||
targetVhd.footer = unpackFooter( | ||
// length can be smaller than disk capacity due to alignment to head/cylinder/sector | ||
createFooter( | ||
metada.virtualSize, | ||
Math.floor(Date.now() / 1000), | ||
_computeGeometryForSize(metada.virtualSize), | ||
FOOTER_SIZE, | ||
DISK_TYPES.DYNAMIC | ||
) | ||
) | ||
console.log('got footer ', targetVhd.footer, Math.ceil((metada.virtualSize / 2) * 1024 * 1024)) | ||
targetVhd.header = unpackHeader(createHeader(Math.ceil(metada.virtualSize / (2 * 1024 * 1024)))) | ||
const bitmap = Buffer.alloc(255, 512) | ||
|
||
for await (const block of blockIterator) { | ||
await targetVhd.writeEntireBlock({ | ||
id: block.index, | ||
bitmap, | ||
data: block.data, | ||
buffer: Buffer.concat([bitmap, block.data]), | ||
}) | ||
} | ||
await targetVhd.writeFooter() | ||
await targetVhd.writeHeader() | ||
await targetVhd.writeBlockAllocationTable() | ||
}) | ||
} | ||
|
||
export async function writeVhdFileToRemote(handler: FileAccessor, path: string, disk: PortableDifferencingDisk) { | ||
return Disposable.use(VhdFile.create(handler, path), async (vhd: Vhd) => { | ||
// @todo : precompute target bat to ensure we can write the block without updating the bat at each block | ||
return writeVhdToRemote(vhd, disk) | ||
}) | ||
} | ||
|
||
// @todo: vhddirectory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters