From 0d34bb1c8e720960b3fc5f3cfafe384ccf155fdb Mon Sep 17 00:00:00 2001 From: modeco80 Date: Wed, 19 Jun 2024 18:03:10 -0400 Subject: [PATCH] cvmts/qemu: support snapshots properly --- cvmts/src/index.ts | 3 ++- qemu/src/QemuVM.ts | 15 +++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cvmts/src/index.ts b/cvmts/src/index.ts index 3ead48a..df45e80 100644 --- a/cvmts/src/index.ts +++ b/cvmts/src/index.ts @@ -60,7 +60,8 @@ async function start() { // Fire up the VM let def: QemuVmDefinition = { id: Config.collabvm.node, - command: Config.qemu.qemuArgs + command: Config.qemu.qemuArgs, + snapshot: Config.qemu.snapshots }; VM = new QemuVM(def); diff --git a/qemu/src/QemuVM.ts b/qemu/src/QemuVM.ts index b1ab475..1378601 100644 --- a/qemu/src/QemuVM.ts +++ b/qemu/src/QemuVM.ts @@ -16,8 +16,9 @@ export enum VMState { // TODO: Add bits to this to allow usage (optionally) // of VNC/QMP port. This will be needed to fix up Windows support. export type QemuVmDefinition = { - id: string; - command: string; + id: string, + command: string, + snapshot: boolean }; /// Temporary path base (for UNIX sockets/etc.) @@ -27,12 +28,6 @@ const kVmTmpPathBase = `/tmp`; /// the VM is forcefully stopped. const kMaxFailCount = 5; -// TODO: This should be added to QemuVmDefinition and the below export removed -let gVMShouldSnapshot = true; - -export function setSnapshot(val: boolean) { - gVMShouldSnapshot = val; -} export class QemuVM extends EventEmitter { private state = VMState.Stopped; @@ -68,7 +63,7 @@ export class QemuVM extends EventEmitter { // FIXME: Still use TCP if on Windows. if (!this.addedAdditionalArguments) { cmd += ' -no-shutdown'; - if (gVMShouldSnapshot) cmd += ' -snapshot'; + if (this.definition.snapshot) cmd += ' -snapshot'; cmd += ` -qmp unix:${this.GetQmpPath()},server,wait -vnc unix:${this.GetVncPath()}`; this.definition.command = cmd; this.addedAdditionalArguments = true; @@ -79,7 +74,7 @@ export class QemuVM extends EventEmitter { } SnapshotsSupported() : boolean { - return gVMShouldSnapshot; + return this.definition.snapshot; } async Reboot() : Promise {