@braedonsaunders/appkit-desk 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -1
- package/backend.d.ts +9 -2
- package/backend.d.ts.map +1 -1
- package/backend.js +27 -4
- package/backend.js.map +1 -1
- package/host.d.ts +22 -4
- package/host.d.ts.map +1 -1
- package/host.js +176 -23
- package/host.js.map +1 -1
- package/machine.d.ts +2 -0
- package/machine.d.ts.map +1 -1
- package/machine.js +43 -2
- package/machine.js.map +1 -1
- package/package.json +1 -1
- package/plan.d.ts +15 -0
- package/plan.d.ts.map +1 -1
- package/plan.js +30 -4
- package/plan.js.map +1 -1
package/machine.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare function createGuestMachine(options: {
|
|
|
64
64
|
* guest channel has been closed. Must leave the VMM stopped on failure too.
|
|
65
65
|
*/
|
|
66
66
|
park?: (snapshotDir: string) => Promise<void>;
|
|
67
|
+
pause?: () => Promise<void>;
|
|
68
|
+
resume?: () => Promise<void>;
|
|
67
69
|
/** Open a host-to-guest TCP stream, for backends with no routable guest. */
|
|
68
70
|
connect?: (port: number) => Promise<Duplex>;
|
|
69
71
|
}): DeskMachine;
|
package/machine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAK7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAA0D,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AACpG,OAAO,EAAa,KAAK,oBAAoB,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAA;AAS7E,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAChD,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAChD,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C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAmDjB;AAaD,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzG;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBjF;AAED,6EAA6E;AAC7E,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAI1G;AAMD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,oBAAoB,CAAA;CAAE,GAC3C,YAAY,CAMd;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK/C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD"}
|
package/machine.js
CHANGED
|
@@ -64,6 +64,8 @@ export function createGuestMachine(options) {
|
|
|
64
64
|
let state = 'live';
|
|
65
65
|
let reconnects = 0;
|
|
66
66
|
let reconnecting = null;
|
|
67
|
+
let paused = false;
|
|
68
|
+
let deferredDrop = null;
|
|
67
69
|
function failAll(error) {
|
|
68
70
|
for (const entry of pending.values()) {
|
|
69
71
|
clearTimeout(entry.timer);
|
|
@@ -158,7 +160,10 @@ export function createGuestMachine(options) {
|
|
|
158
160
|
// is told its fate is unknown and the caller decides.
|
|
159
161
|
failAll(new DeskRequestFateUnknownError(`Desk ${deskId} lost its guest agent connection while this request was in flight `
|
|
160
162
|
+ `(${reason}); the guest may or may not have run it.`));
|
|
161
|
-
|
|
163
|
+
if (paused)
|
|
164
|
+
deferredDrop = { reason, at: lostAt };
|
|
165
|
+
else
|
|
166
|
+
reconnecting = restore(reason, lostAt);
|
|
162
167
|
}
|
|
163
168
|
/** Always resolves: callers await it to learn the outcome, not to be thrown at. */
|
|
164
169
|
async function restore(reason, lostAt) {
|
|
@@ -189,6 +194,8 @@ export function createGuestMachine(options) {
|
|
|
189
194
|
// caller a desk is gone when it is about to be fine is the bug this
|
|
190
195
|
// machine exists to end. The wait is bounded by the same window the
|
|
191
196
|
// reconnect itself is.
|
|
197
|
+
if (paused)
|
|
198
|
+
throw new DeskError(`Desk ${deskId} is paused; resume it first.`);
|
|
192
199
|
const waitUntil = now() + reconnectWindowMs;
|
|
193
200
|
while (state === 'reconnecting') {
|
|
194
201
|
const attempt = reconnecting;
|
|
@@ -196,6 +203,8 @@ export function createGuestMachine(options) {
|
|
|
196
203
|
break;
|
|
197
204
|
await attempt;
|
|
198
205
|
}
|
|
206
|
+
if (paused)
|
|
207
|
+
throw new DeskError(`Desk ${deskId} is paused; resume it first.`);
|
|
199
208
|
if (state !== 'live') {
|
|
200
209
|
// This one never left the host, so — unlike a request that was in
|
|
201
210
|
// flight when the channel dropped — repeating it is safe.
|
|
@@ -233,6 +242,31 @@ export function createGuestMachine(options) {
|
|
|
233
242
|
await options.stop();
|
|
234
243
|
},
|
|
235
244
|
};
|
|
245
|
+
if (options.pause && options.resume) {
|
|
246
|
+
const pause = options.pause;
|
|
247
|
+
const resume = options.resume;
|
|
248
|
+
machine.pause = async () => {
|
|
249
|
+
if (paused)
|
|
250
|
+
return;
|
|
251
|
+
if (state !== 'live')
|
|
252
|
+
throw new DeskError(`Desk ${deskId} is not connected.`);
|
|
253
|
+
paused = true;
|
|
254
|
+
failAll(new DeskRequestFateUnknownError(`Desk ${deskId} paused with a request in flight; its fate is unknown.`));
|
|
255
|
+
// On failure the VMM state may be unknown; retain the fence until resume succeeds.
|
|
256
|
+
await pause();
|
|
257
|
+
};
|
|
258
|
+
machine.resume = async () => {
|
|
259
|
+
if (!paused)
|
|
260
|
+
return;
|
|
261
|
+
await resume();
|
|
262
|
+
paused = false;
|
|
263
|
+
if (deferredDrop && state === 'reconnecting') {
|
|
264
|
+
const drop = deferredDrop;
|
|
265
|
+
deferredDrop = null;
|
|
266
|
+
reconnecting = restore(drop.reason, drop.at);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
236
270
|
if (options.park) {
|
|
237
271
|
const park = options.park;
|
|
238
272
|
machine.park = async (snapshotDir) => {
|
|
@@ -248,9 +282,16 @@ export function createGuestMachine(options) {
|
|
|
248
282
|
if (options.connect) {
|
|
249
283
|
const connect = options.connect;
|
|
250
284
|
machine.connect = async (port) => {
|
|
285
|
+
if (paused)
|
|
286
|
+
throw new DeskError(`Desk ${deskId} is paused; resume it first.`);
|
|
251
287
|
if (state === 'closed')
|
|
252
288
|
throw new DeskError(`Desk ${deskId} is no longer connected.`);
|
|
253
|
-
|
|
289
|
+
const connection = await connect(port);
|
|
290
|
+
if (state === 'closed') {
|
|
291
|
+
connection.destroy();
|
|
292
|
+
throw new DeskError(`Desk ${deskId} is no longer connected.`);
|
|
293
|
+
}
|
|
294
|
+
return connection;
|
|
254
295
|
};
|
|
255
296
|
}
|
|
256
297
|
return machine;
|
package/machine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machine.js","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAA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,eAAe,CAC7B,OAAe,EACf,IAAuB,EACvB,OAA4C;IAE5C,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE;QAC/B,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;QACjC,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG;QAC1B,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG;KAC3B,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;QAC5C,KAAK,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["/**\n * The guest channel every backend shares: the hybrid-vsock handshake, the\n * proof that a guest is really behind it, the reconnecting machine, and the\n * child-process plumbing around a VMM. Cloud Hypervisor and the\n * Virtualization.framework helper both expose the guest agent through a host\n * Unix socket with the same `CONNECT <port>` preamble, so everything from the\n * socket inwards is one implementation. Internal to the package.\n */\nimport { spawn, type ChildProcess } from 'node:child_process'\nimport { readFile, writeFile } from 'node:fs/promises'\nimport { createConnection } from 'node:net'\nimport { join } from 'node:path'\nimport { Buffer } from 'node:buffer'\nimport type { Duplex } from 'node:stream'\nimport { DeskRequestFateUnknownError, type DeskConnectionChange, type DeskMachine } from './backend'\nimport { DeskError, type DeskLauncherIdentity, type DeskShare } from './plan'\nimport {\n encodeFrame,\n FrameDecoder,\n parseHostBoundMessage,\n type GuestEventMessage,\n type HostBoundMessage,\n} from './protocol'\n\nexport const DEFAULT_REQUEST_TIMEOUT_MS = 30_000\nexport const DEFAULT_CONNECT_TIMEOUT_MS = 20_000\nexport const DEFAULT_CONNECT_RETRY_DELAY_MS = 100\nexport const DEFAULT_HANDSHAKE_TIMEOUT_MS = 5_000\nexport const DEFAULT_RECONNECT_WINDOW_MS = 30_000\nexport const DEFAULT_RECONNECT_RETRY_DELAY_MS = 250\n/**\n * How far the reconnect delay is allowed to double. A guest agent that systemd\n * is restarting is not helped by being hammered four times a second for the\n * whole window, and an unbounded doubling would spend most of the window\n * asleep after two failures.\n */\nexport const RECONNECT_BACKOFF_CEILING = 8\nexport const DEFAULT_KILL_GRACE_MS = 2_000\nconst HANDSHAKE_LINE_LIMIT = 128\n\n/**\n * The machine, and the small state machine that keeps it connected.\n *\n * A vsock channel is not a fact the host learns once at boot — the transport\n * can lie about being connected, and it can go away mid-lease for reasons that\n * have nothing to do with the desk being unusable: the guest agent restarts,\n * the socat bridge drops, a transient vsock error, the guest wedges for a\n * moment. Treating any of those as terminal stranded the desk for the rest of\n * its lease with a perfectly healthy guest behind it, answering every call\n * with \"no longer connected\". So a live connection is something this machine\n * RE-ESTABLISHES:\n *\n * live ──unexpected drop──▶ reconnecting ──confirmed guest──▶ live\n * │ │\n * │ └──window exhausted / VMM exited──▶ closed\n * └──shutdown(), VMM already exited, protocol violation───────────▶ closed\n *\n * `closed` is terminal. Nothing reconnects out of it, which is what makes\n * `shutdown()` and a dead VMM final rather than the start of a retry loop.\n *\n * What differs between hypervisors is only how the VM stops, parks, and\n * reaches guest ports, and those arrive as functions.\n */\nexport function createGuestMachine(options: {\n deskId: string\n exit: ExitWatcher\n stream: Duplex\n /** Re-establishes the channel; resolves only once a guest has answered. */\n reconnect: (abandoned: () => boolean) => Promise<Duplex>\n reconnectWindowMs: number\n now: () => number\n idFactory: () => string\n requestTimeoutMs: number\n /** Stop the VMM; resolves once its process has exited. */\n stop: () => Promise<void>\n /**\n * Pause, snapshot into `snapshotDir`, and stop the VMM. Called after the\n * guest channel has been closed. Must leave the VMM stopped on failure too.\n */\n park?: (snapshotDir: string) => Promise<void>\n /** Open a host-to-guest TCP stream, for backends with no routable guest. */\n connect?: (port: number) => Promise<Duplex>\n}): DeskMachine {\n const { deskId, exit, now, idFactory, requestTimeoutMs, reconnectWindowMs } = options\n const pending = new Map<\n string,\n { resolve: (result: unknown) => void; reject: (error: Error) => void; timer: NodeJS.Timeout }\n >()\n // Listeners live on the machine rather than on the socket, so a reconnect\n // re-points the data path at the new stream and every subscriber keeps\n // working without re-registering.\n const listeners = new Set<(event: GuestEventMessage) => void>()\n const watchers = new Set<(change: DeskConnectionChange) => void>()\n let stream = options.stream\n let state: 'live' | 'reconnecting' | 'closed' = 'live'\n let reconnects = 0\n let reconnecting: Promise<void> | null = null\n\n function failAll(error: Error): void {\n for (const entry of pending.values()) {\n clearTimeout(entry.timer)\n entry.reject(error)\n }\n pending.clear()\n }\n\n function announce(change: DeskConnectionChange): void {\n for (const watcher of [...watchers]) watcher(change)\n }\n\n function close(error: DeskError, intentional: boolean): void {\n if (state === 'closed') return\n state = 'closed'\n failAll(error)\n stream.destroy()\n // A desk the consumer asked to stop is not news; one that stopped on its\n // own is the thing an operator needs to be told about.\n if (!intentional) announce({ state: 'lost', deskId, reason: error.message })\n }\n\n function attach(next: Duplex): void {\n stream = next\n // Each connection decodes with its OWN decoder: a frame the drop cut in\n // half must never be completed by the first bytes of its replacement.\n const decoder = new FrameDecoder()\n const current = () => stream === next && state !== 'closed'\n const onData = (chunk: Buffer): void => {\n if (!current()) return\n let values: unknown[]\n try {\n values = decoder.push(chunk)\n } catch (error) {\n close(\n new DeskError(`Guest agent protocol violation on desk ${deskId}: ${errorMessage(error)}`),\n false,\n )\n return\n }\n for (const value of values) {\n let message: HostBoundMessage\n try {\n message = parseHostBoundMessage(value)\n } catch (error) {\n close(\n new DeskError(`Guest agent sent a malformed message on desk ${deskId}: ${errorMessage(error)}`),\n false,\n )\n return\n }\n if ('id' in message) {\n const entry = pending.get(message.id)\n if (!entry) continue\n pending.delete(message.id)\n clearTimeout(entry.timer)\n if (message.ok) entry.resolve(message.result)\n else entry.reject(new DeskError(`Guest agent error on desk ${deskId}: ${message.error}`))\n } else {\n for (const listener of [...listeners]) listener(message)\n }\n }\n }\n next.on('data', onData)\n next.once('close', () => {\n drop(next, `the guest agent connection closed on desk ${deskId}`)\n })\n next.once('error', (error: Error) => {\n drop(next, `the guest agent connection failed on desk ${deskId}: ${error.message}`)\n })\n }\n\n function drop(from: Duplex, reason: string): void {\n if (state !== 'live' || from !== stream) return\n from.destroy()\n if (exit.done) {\n // A dead VMM is not a connection problem. There is no guest to get back\n // to, and retrying against it forever only delays the fresh boot the\n // desk actually needs.\n close(new DeskError(`Desk ${deskId} is no longer connected: the VMM exited (${reason}).`), false)\n return\n }\n state = 'reconnecting'\n const lostAt = now()\n // In-flight requests CANNOT be silently retried. Each of their frames\n // already reached the guest, and whether the guest ran it before the\n // channel went away is not knowable from here: an `exec` may have sent\n // mail, a `click` may have landed. Replaying a side-effecting operation to\n // paper over a blip is the wrong kind of resilience, so every one of them\n // is told its fate is unknown and the caller decides.\n failAll(\n new DeskRequestFateUnknownError(\n `Desk ${deskId} lost its guest agent connection while this request was in flight `\n + `(${reason}); the guest may or may not have run it.`,\n ),\n )\n reconnecting = restore(reason, lostAt)\n }\n\n /** Always resolves: callers await it to learn the outcome, not to be thrown at. */\n async function restore(reason: string, lostAt: number): Promise<void> {\n let next: Duplex\n try {\n next = await options.reconnect(() => state !== 'reconnecting')\n } catch (error) {\n close(\n new DeskError(\n `Desk ${deskId} lost its guest agent connection and could not get it back: ${errorMessage(error)}`,\n ),\n false,\n )\n return\n }\n if (state !== 'reconnecting') {\n // shutdown() won the race while the replacement socket was coming up.\n next.destroy()\n return\n }\n attach(next)\n state = 'live'\n reconnects += 1\n announce({ state: 'reconnected', deskId, reason, downtimeMs: now() - lostAt, reconnects })\n }\n\n attach(options.stream)\n\n const machine: DeskMachine = {\n deskId,\n async request(command, requestOptions = {}) {\n // A call that lands mid-reconnect waits for it rather than failing on\n // the spot: the guest is usually back within seconds, and telling a\n // caller a desk is gone when it is about to be fine is the bug this\n // machine exists to end. The wait is bounded by the same window the\n // reconnect itself is.\n const waitUntil = now() + reconnectWindowMs\n while (state === 'reconnecting') {\n const attempt = reconnecting\n if (!attempt || now() >= waitUntil) break\n await attempt\n }\n if (state !== 'live') {\n // This one never left the host, so — unlike a request that was in\n // flight when the channel dropped — repeating it is safe.\n throw new DeskError(`Desk ${deskId} is no longer connected.`)\n }\n const id = idFactory()\n const timeoutMs = requestOptions.timeoutMs ?? requestTimeoutMs\n const target = stream\n return await new Promise<unknown>((resolvePromise, rejectPromise) => {\n const timer = setTimeout(() => {\n pending.delete(id)\n rejectPromise(new DeskError(`Guest request ${command.op} timed out on desk ${deskId}.`))\n }, timeoutMs)\n timer.unref()\n pending.set(id, { resolve: resolvePromise, reject: rejectPromise, timer })\n target.write(encodeFrame({ ...command, id }))\n })\n },\n subscribe(listener) {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n },\n onConnectionChange(listener) {\n watchers.add(listener)\n return () => {\n watchers.delete(listener)\n }\n },\n async shutdown() {\n // Terminal by construction: `closed` is the state the reconnect loop\n // checks, so an explicit shutdown can never be followed by a reconnect.\n close(new DeskError(`Desk ${deskId} is shutting down.`), true)\n await options.stop()\n },\n }\n if (options.park) {\n const park = options.park\n machine.park = async (snapshotDir: string) => {\n // Close the guest channel FIRST. Pausing a VM strands whatever was in\n // flight on the vsock, and a reconnect attempt against a paused guest\n // would burn the whole reconnect window before giving up — so the channel\n // is made terminal before the VM stops answering, exactly as shutdown\n // does it.\n close(new DeskError(`Desk ${deskId} is being parked.`), true)\n await park(snapshotDir)\n }\n }\n if (options.connect) {\n const connect = options.connect\n machine.connect = async (port: number) => {\n if (state === 'closed') throw new DeskError(`Desk ${deskId} is no longer connected.`)\n return await connect(port)\n }\n }\n return machine\n}\n\nexport interface ExitWatcher {\n done: boolean\n promise: Promise<void>\n}\n\n/**\n * Read a child's output and keep only the last few kilobytes.\n *\n * This is not for logging — it is load-bearing. A child spawned with its\n * streams as PIPES blocks once a pipe nobody reads fills, after about 64KB.\n * Cloud Hypervisor logs while it runs, so an unread pipe freezes the guest\n * partway through boot: the process is alive, the disk is untouched, and the\n * guest agent never reaches vsock. Every symptom points at the image and none\n * of them are its fault.\n *\n * Draining costs nothing and buys the tail of what the process said, which is\n * the difference between \"the VMM exited\" and knowing why. `streams` names the\n * pipes to drain: a helper that speaks a protocol on stdout drains only stderr.\n */\nexport function drainOutput(\n child: ChildProcess,\n limit = 8 * 1024,\n streams: readonly ('stdout' | 'stderr')[] = ['stdout', 'stderr'],\n): { tail: () => string } {\n let buffered = ''\n const absorb = (chunk: unknown) => {\n buffered += String(chunk)\n if (buffered.length > limit) buffered = buffered.slice(buffered.length - limit)\n }\n for (const name of streams) {\n const pipe = child[name]\n pipe?.on('data', absorb)\n // A pipe that errors must not take the process down with it.\n pipe?.on('error', () => undefined)\n }\n return { tail: () => buffered.trim() }\n}\n\nexport function watchExit(child: ChildProcess): ExitWatcher {\n const watcher: ExitWatcher = { done: false, promise: Promise.resolve() }\n watcher.promise = new Promise<void>((resolvePromise) => {\n const settle = () => {\n watcher.done = true\n resolvePromise()\n }\n child.once('exit', settle)\n child.once('error', settle)\n })\n return watcher\n}\n\nexport async function terminate(child: ChildProcess, exit: ExitWatcher, killGraceMs: number): Promise<void> {\n if (exit.done) return\n child.kill('SIGTERM')\n const forceKill = setTimeout(() => {\n if (!exit.done) child.kill('SIGKILL')\n }, killGraceMs)\n forceKill.unref()\n await exit.promise\n clearTimeout(forceKill)\n}\n\nexport function runToCompletion(child: ChildProcess, label: string): Promise<void> {\n return new Promise<void>((resolvePromise, rejectPromise) => {\n let stderr = ''\n child.stderr?.on('data', (chunk) => {\n stderr += String(chunk)\n })\n child.once('error', (error) => {\n rejectPromise(new DeskError(`${label} failed to start: ${error.message}`))\n })\n child.once('exit', (code, signal) => {\n if (code === 0) {\n resolvePromise()\n return\n }\n const detail = stderr.trim()\n rejectPromise(\n new DeskError(\n `${label} exited with code ${code ?? 'unknown'}`\n + `${signal ? ` (${signal})` : ''}${detail ? `: ${detail}` : '.'}`,\n ),\n )\n })\n })\n}\n\n/**\n * Cloud Hypervisor exposes guest vsock ports through a host Unix socket with\n * a line-oriented preamble: the client writes `CONNECT <port>\\n` and the VMM\n * answers `OK <assigned>\\n` before the byte stream becomes the guest\n * connection. The VMM creates the socket during boot, so connection attempts\n * retry until the deadline. The Virtualization.framework helper speaks the\n * same preamble on its own socket.\n *\n * The same loop serves the first connection and every later reconnect, so a\n * reconnect gets `confirmGuest` too — a mid-lease reconnect that trusted the\n * banner would re-adopt exactly the hollow stream the boot path learned not to.\n */\nexport async function connectWithRetry(options: {\n connect: (socketPath: string) => Duplex\n now: () => number\n socketPath: string\n port: number\n timeoutMs: number\n retryDelayMs: number\n /** Ceiling the delay doubles toward; omitted keeps the delay constant. */\n maxRetryDelayMs?: number\n attemptTimeoutMs: number\n exited: ExitWatcher\n /** A dead VMM means something different at boot than it does mid-lease. */\n exitedMessage?: string\n /** Stops the loop early when the caller no longer wants the connection. */\n abandoned?: () => boolean\n}): Promise<Duplex> {\n const deadline = options.now() + options.timeoutMs\n let lastFailure = 'the guest agent never answered'\n let retryDelayMs = options.retryDelayMs\n while (options.now() <= deadline) {\n if (options.exited.done) {\n throw new DeskError(options.exitedMessage ?? 'The VMM exited before the guest agent came up.')\n }\n if (options.abandoned?.() === true) {\n throw new DeskError('the connection attempt was abandoned.')\n }\n try {\n const stream = await attemptHandshake(\n options.connect,\n options.socketPath,\n options.port,\n options.attemptTimeoutMs,\n )\n try {\n await confirmGuest(stream, options.attemptTimeoutMs)\n } catch (error) {\n stream.destroy()\n throw error\n }\n return stream\n } catch (error) {\n lastFailure = errorMessage(error)\n }\n await delay(retryDelayMs)\n if (options.maxRetryDelayMs !== undefined) {\n retryDelayMs = Math.min(retryDelayMs * 2, options.maxRetryDelayMs)\n }\n }\n throw new DeskError(\n `Timed out connecting to the guest agent at ${options.socketPath}: ${lastFailure}`,\n )\n}\n\n/**\n * Prove a guest is behind the handshake by asking it something.\n *\n * Cloud Hypervisor answers `CONNECT <port>` with `OK` whether or not anything\n * in the guest is listening on that port, and only closes the socket a moment\n * later when it finds nobody there. A caller that trusts the banner therefore\n * \"connects\" to a guest that is still booting, gets a closed stream seconds\n * later, and — because a closed machine is not retried — leaves the desk dead\n * for as long as it is leased, with a healthy guest sitting behind it. So the\n * handshake is not the test; a reply is.\n */\nasync function confirmGuest(stream: Duplex, timeoutMs: number): Promise<void> {\n const decoder = new FrameDecoder()\n await new Promise<void>((resolvePromise, rejectPromise) => {\n let settled = false\n const finish = (error?: Error) => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n stream.off('data', onData)\n stream.off('close', onClose)\n stream.off('error', finish)\n if (error) rejectPromise(error)\n else resolvePromise()\n }\n const timer = setTimeout(\n () => finish(new DeskError('the guest agent did not answer the first request.')),\n timeoutMs,\n )\n timer.unref?.()\n const onClose = () =>\n finish(new DeskError('the connection closed before the guest agent answered.'))\n const onData = (chunk: Buffer) => {\n let values: unknown[]\n try {\n values = decoder.push(chunk)\n } catch (error) {\n finish(error instanceof Error ? error : new Error(String(error)))\n return\n }\n for (const value of values) {\n // Anything at all proves a guest is there; the reply is parsed for\n // real by the machine once it owns the stream.\n if (value && typeof value === 'object') {\n finish()\n return\n }\n }\n }\n stream.on('data', onData)\n stream.once('close', onClose)\n stream.once('error', finish)\n stream.write(encodeFrame({ id: 'hello', op: 'ping' }))\n })\n}\n\n/**\n * One handshake attempt, which MUST settle.\n *\n * Cloud Hypervisor accepts a connection on the vsock socket whether or not\n * anything in the guest is listening on the port, and when nothing is it may\n * answer nothing at all: no reply, no error, no close. Without a deadline of\n * its own this promise then never settles — and because the caller awaits it\n * inside the retry loop, the loop stops iterating, the overall deadline is\n * never re-checked, and the boot hangs forever rather than failing. That is\n * indistinguishable from a wedged host and it is why every attempt is bounded\n * here as well as in aggregate.\n *\n * A close before the reply line is a refusal: that is how a port with nothing\n * listening presents through Cloud Hypervisor, and the Virtualization.framework\n * helper presents a refused vsock or TCP port the same way.\n */\nexport function attemptHandshake(\n connect: (socketPath: string) => Duplex,\n socketPath: string,\n port: number,\n attemptTimeoutMs: number,\n): Promise<Duplex> {\n return new Promise<Duplex>((resolvePromise, rejectPromise) => {\n let stream: Duplex\n try {\n stream = connect(socketPath)\n } catch (error) {\n rejectPromise(error instanceof Error ? error : new Error(String(error)))\n return\n }\n let banner = ''\n let settled = false\n const timer = setTimeout(() => {\n fail(new DeskError('vsock handshake went unanswered.'))\n }, attemptTimeoutMs)\n // An unref'd timer must not hold the process open on its own.\n timer.unref?.()\n const fail = (error: Error) => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n stream.destroy()\n rejectPromise(error)\n }\n const onData = (chunk: Buffer) => {\n banner += chunk.toString('latin1')\n const newline = banner.indexOf('\\n')\n if (newline === -1) {\n if (banner.length > HANDSHAKE_LINE_LIMIT) {\n fail(new DeskError('vsock handshake reply exceeded the line limit.'))\n }\n return\n }\n const line = banner.slice(0, newline)\n const rest = banner.slice(newline + 1)\n stream.off('data', onData)\n stream.off('error', fail)\n if (!line.startsWith('OK ')) {\n fail(new DeskError(`vsock handshake was refused: ${line}`))\n return\n }\n settled = true\n clearTimeout(timer)\n if (rest.length > 0) stream.unshift(Buffer.from(rest, 'latin1'))\n resolvePromise(stream)\n }\n stream.on('data', onData)\n stream.once('error', fail)\n // A close before the banner is a refusal, not a hang.\n stream.once('close', () => fail(new DeskError('vsock handshake closed before a reply.')))\n stream.write(`CONNECT ${port}\\n`)\n })\n}\n\n/**\n * The shares a snapshot was taken with, kept beside it.\n *\n * A snapshot holds the machine's devices, shares among them, so it can only\n * come back with the shares it was parked with: Cloud Hypervisor would resume\n * without a share that was added since, and Virtualization.framework refuses a\n * changed device list. The host restores with this list rather than the one it\n * was given, and a backend refuses a plan that disagrees with it.\n */\nconst SHARE_MANIFEST = 'shares.json'\n\nexport async function writeShareManifest(snapshotDir: string, shares: readonly DeskShare[]): Promise<void> {\n await writeFile(join(snapshotDir, SHARE_MANIFEST), `${shareManifest(shares)}\\n`, { mode: 0o600 })\n}\n\n/**\n * The shares recorded beside a snapshot. A snapshot with no record predates\n * shares, so it was taken with none. Paths are returned as recorded; whether\n * they still exist is the launch plan's to check.\n */\nexport async function readShareManifest(snapshotDir: string): Promise<DeskShare[]> {\n let text: string\n try {\n text = await readFile(join(snapshotDir, SHARE_MANIFEST), 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw error\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch {\n throw new DeskError(`${join(snapshotDir, SHARE_MANIFEST)} is not valid JSON.`)\n }\n const valid = Array.isArray(value) && value.every((entry: unknown) =>\n typeof entry === 'object' && entry !== null\n && typeof (entry as DeskShare).tag === 'string'\n && typeof (entry as DeskShare).path === 'string'\n && typeof (entry as DeskShare).readOnly === 'boolean')\n if (!valid) throw new DeskError(`${join(snapshotDir, SHARE_MANIFEST)} is not a list of shares.`)\n return (value as DeskShare[]).map(({ tag, path, readOnly }) => ({ tag, path, readOnly }))\n}\n\n/** Throws unless the snapshot was parked with exactly `shares`, in order. */\nexport async function assertShareManifest(snapshotDir: string, shares: readonly DeskShare[]): Promise<void> {\n const saved = shareManifest(await readShareManifest(snapshotDir))\n const wanted = shareManifest(shares)\n if (saved !== wanted) throw new DeskError(`the snapshot was taken with shares ${saved}, not ${wanted}`)\n}\n\nfunction shareManifest(shares: readonly DeskShare[]): string {\n return JSON.stringify(shares.map(({ tag, path, readOnly }) => ({ tag, path, readOnly })))\n}\n\nexport function defaultLauncher(\n command: string,\n args: readonly string[],\n options: { identity?: DeskLauncherIdentity },\n): ChildProcess {\n return spawn(command, [...args], {\n stdio: ['ignore', 'pipe', 'pipe'],\n uid: options.identity?.uid,\n gid: options.identity?.gid,\n })\n}\n\nexport function defaultConnect(socketPath: string): Duplex {\n return createConnection(socketPath)\n}\n\nexport function delay(ms: number): Promise<void> {\n return new Promise<void>((resolvePromise) => {\n const timer = setTimeout(resolvePromise, ms)\n timer.unref()\n })\n}\n\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"machine.js","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,2BAA2B,EAA+C,MAAM,WAAW,CAAA;AACpG,OAAO,EAAE,SAAS,EAA6C,MAAM,QAAQ,CAAA;AAC7E,OAAO,EACL,WAAW,EACX,YAAY,EACZ,qBAAqB,GAGtB,MAAM,YAAY,CAAA;AAEnB,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAA;AAChD,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAA;AAChD,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAA;AACjD,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAA;AACjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAA;AACjD,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,CAAA;AACnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAA;AAC1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAC1C,MAAM,oBAAoB,GAAG,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,UAAU,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;QAC5C,KAAK,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["/**\n * The guest channel every backend shares: the hybrid-vsock handshake, the\n * proof that a guest is really behind it, the reconnecting machine, and the\n * child-process plumbing around a VMM. Cloud Hypervisor and the\n * Virtualization.framework helper both expose the guest agent through a host\n * Unix socket with the same `CONNECT <port>` preamble, so everything from the\n * socket inwards is one implementation. Internal to the package.\n */\nimport { spawn, type ChildProcess } from 'node:child_process'\nimport { readFile, writeFile } from 'node:fs/promises'\nimport { createConnection } from 'node:net'\nimport { join } from 'node:path'\nimport { Buffer } from 'node:buffer'\nimport type { Duplex } from 'node:stream'\nimport { DeskRequestFateUnknownError, type DeskConnectionChange, type DeskMachine } from './backend'\nimport { DeskError, type DeskLauncherIdentity, type DeskShare } from './plan'\nimport {\n encodeFrame,\n FrameDecoder,\n parseHostBoundMessage,\n type GuestEventMessage,\n type HostBoundMessage,\n} from './protocol'\n\nexport const DEFAULT_REQUEST_TIMEOUT_MS = 30_000\nexport const DEFAULT_CONNECT_TIMEOUT_MS = 20_000\nexport const DEFAULT_CONNECT_RETRY_DELAY_MS = 100\nexport const DEFAULT_HANDSHAKE_TIMEOUT_MS = 5_000\nexport const DEFAULT_RECONNECT_WINDOW_MS = 30_000\nexport const DEFAULT_RECONNECT_RETRY_DELAY_MS = 250\n/**\n * How far the reconnect delay is allowed to double. A guest agent that systemd\n * is restarting is not helped by being hammered four times a second for the\n * whole window, and an unbounded doubling would spend most of the window\n * asleep after two failures.\n */\nexport const RECONNECT_BACKOFF_CEILING = 8\nexport const DEFAULT_KILL_GRACE_MS = 2_000\nconst HANDSHAKE_LINE_LIMIT = 128\n\n/**\n * The machine, and the small state machine that keeps it connected.\n *\n * A vsock channel is not a fact the host learns once at boot — the transport\n * can lie about being connected, and it can go away mid-lease for reasons that\n * have nothing to do with the desk being unusable: the guest agent restarts,\n * the socat bridge drops, a transient vsock error, the guest wedges for a\n * moment. Treating any of those as terminal stranded the desk for the rest of\n * its lease with a perfectly healthy guest behind it, answering every call\n * with \"no longer connected\". So a live connection is something this machine\n * RE-ESTABLISHES:\n *\n * live ──unexpected drop──▶ reconnecting ──confirmed guest──▶ live\n * │ │\n * │ └──window exhausted / VMM exited──▶ closed\n * └──shutdown(), VMM already exited, protocol violation───────────▶ closed\n *\n * `closed` is terminal. Nothing reconnects out of it, which is what makes\n * `shutdown()` and a dead VMM final rather than the start of a retry loop.\n *\n * What differs between hypervisors is only how the VM stops, parks, and\n * reaches guest ports, and those arrive as functions.\n */\nexport function createGuestMachine(options: {\n deskId: string\n exit: ExitWatcher\n stream: Duplex\n /** Re-establishes the channel; resolves only once a guest has answered. */\n reconnect: (abandoned: () => boolean) => Promise<Duplex>\n reconnectWindowMs: number\n now: () => number\n idFactory: () => string\n requestTimeoutMs: number\n /** Stop the VMM; resolves once its process has exited. */\n stop: () => Promise<void>\n /**\n * Pause, snapshot into `snapshotDir`, and stop the VMM. Called after the\n * guest channel has been closed. Must leave the VMM stopped on failure too.\n */\n park?: (snapshotDir: string) => Promise<void>\n pause?: () => Promise<void>\n resume?: () => Promise<void>\n /** Open a host-to-guest TCP stream, for backends with no routable guest. */\n connect?: (port: number) => Promise<Duplex>\n}): DeskMachine {\n const { deskId, exit, now, idFactory, requestTimeoutMs, reconnectWindowMs } = options\n const pending = new Map<\n string,\n { resolve: (result: unknown) => void; reject: (error: Error) => void; timer: NodeJS.Timeout }\n >()\n // Listeners live on the machine rather than on the socket, so a reconnect\n // re-points the data path at the new stream and every subscriber keeps\n // working without re-registering.\n const listeners = new Set<(event: GuestEventMessage) => void>()\n const watchers = new Set<(change: DeskConnectionChange) => void>()\n let stream = options.stream\n let state: 'live' | 'reconnecting' | 'closed' = 'live'\n let reconnects = 0\n let reconnecting: Promise<void> | null = null\n let paused = false\n let deferredDrop: { reason: string; at: number } | null = null\n\n function failAll(error: Error): void {\n for (const entry of pending.values()) {\n clearTimeout(entry.timer)\n entry.reject(error)\n }\n pending.clear()\n }\n\n function announce(change: DeskConnectionChange): void {\n for (const watcher of [...watchers]) watcher(change)\n }\n\n function close(error: DeskError, intentional: boolean): void {\n if (state === 'closed') return\n state = 'closed'\n failAll(error)\n stream.destroy()\n // A desk the consumer asked to stop is not news; one that stopped on its\n // own is the thing an operator needs to be told about.\n if (!intentional) announce({ state: 'lost', deskId, reason: error.message })\n }\n\n function attach(next: Duplex): void {\n stream = next\n // Each connection decodes with its OWN decoder: a frame the drop cut in\n // half must never be completed by the first bytes of its replacement.\n const decoder = new FrameDecoder()\n const current = () => stream === next && state !== 'closed'\n const onData = (chunk: Buffer): void => {\n if (!current()) return\n let values: unknown[]\n try {\n values = decoder.push(chunk)\n } catch (error) {\n close(\n new DeskError(`Guest agent protocol violation on desk ${deskId}: ${errorMessage(error)}`),\n false,\n )\n return\n }\n for (const value of values) {\n let message: HostBoundMessage\n try {\n message = parseHostBoundMessage(value)\n } catch (error) {\n close(\n new DeskError(`Guest agent sent a malformed message on desk ${deskId}: ${errorMessage(error)}`),\n false,\n )\n return\n }\n if ('id' in message) {\n const entry = pending.get(message.id)\n if (!entry) continue\n pending.delete(message.id)\n clearTimeout(entry.timer)\n if (message.ok) entry.resolve(message.result)\n else entry.reject(new DeskError(`Guest agent error on desk ${deskId}: ${message.error}`))\n } else {\n for (const listener of [...listeners]) listener(message)\n }\n }\n }\n next.on('data', onData)\n next.once('close', () => {\n drop(next, `the guest agent connection closed on desk ${deskId}`)\n })\n next.once('error', (error: Error) => {\n drop(next, `the guest agent connection failed on desk ${deskId}: ${error.message}`)\n })\n }\n\n function drop(from: Duplex, reason: string): void {\n if (state !== 'live' || from !== stream) return\n from.destroy()\n if (exit.done) {\n // A dead VMM is not a connection problem. There is no guest to get back\n // to, and retrying against it forever only delays the fresh boot the\n // desk actually needs.\n close(new DeskError(`Desk ${deskId} is no longer connected: the VMM exited (${reason}).`), false)\n return\n }\n state = 'reconnecting'\n const lostAt = now()\n // In-flight requests CANNOT be silently retried. Each of their frames\n // already reached the guest, and whether the guest ran it before the\n // channel went away is not knowable from here: an `exec` may have sent\n // mail, a `click` may have landed. Replaying a side-effecting operation to\n // paper over a blip is the wrong kind of resilience, so every one of them\n // is told its fate is unknown and the caller decides.\n failAll(\n new DeskRequestFateUnknownError(\n `Desk ${deskId} lost its guest agent connection while this request was in flight `\n + `(${reason}); the guest may or may not have run it.`,\n ),\n )\n if (paused) deferredDrop = { reason, at: lostAt }\n else reconnecting = restore(reason, lostAt)\n }\n\n /** Always resolves: callers await it to learn the outcome, not to be thrown at. */\n async function restore(reason: string, lostAt: number): Promise<void> {\n let next: Duplex\n try {\n next = await options.reconnect(() => state !== 'reconnecting')\n } catch (error) {\n close(\n new DeskError(\n `Desk ${deskId} lost its guest agent connection and could not get it back: ${errorMessage(error)}`,\n ),\n false,\n )\n return\n }\n if (state !== 'reconnecting') {\n // shutdown() won the race while the replacement socket was coming up.\n next.destroy()\n return\n }\n attach(next)\n state = 'live'\n reconnects += 1\n announce({ state: 'reconnected', deskId, reason, downtimeMs: now() - lostAt, reconnects })\n }\n\n attach(options.stream)\n\n const machine: DeskMachine = {\n deskId,\n async request(command, requestOptions = {}) {\n // A call that lands mid-reconnect waits for it rather than failing on\n // the spot: the guest is usually back within seconds, and telling a\n // caller a desk is gone when it is about to be fine is the bug this\n // machine exists to end. The wait is bounded by the same window the\n // reconnect itself is.\n if (paused) throw new DeskError(`Desk ${deskId} is paused; resume it first.`)\n const waitUntil = now() + reconnectWindowMs\n while (state === 'reconnecting') {\n const attempt = reconnecting\n if (!attempt || now() >= waitUntil) break\n await attempt\n }\n if (paused) throw new DeskError(`Desk ${deskId} is paused; resume it first.`)\n if (state !== 'live') {\n // This one never left the host, so — unlike a request that was in\n // flight when the channel dropped — repeating it is safe.\n throw new DeskError(`Desk ${deskId} is no longer connected.`)\n }\n const id = idFactory()\n const timeoutMs = requestOptions.timeoutMs ?? requestTimeoutMs\n const target = stream\n return await new Promise<unknown>((resolvePromise, rejectPromise) => {\n const timer = setTimeout(() => {\n pending.delete(id)\n rejectPromise(new DeskError(`Guest request ${command.op} timed out on desk ${deskId}.`))\n }, timeoutMs)\n timer.unref()\n pending.set(id, { resolve: resolvePromise, reject: rejectPromise, timer })\n target.write(encodeFrame({ ...command, id }))\n })\n },\n subscribe(listener) {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n },\n onConnectionChange(listener) {\n watchers.add(listener)\n return () => {\n watchers.delete(listener)\n }\n },\n async shutdown() {\n // Terminal by construction: `closed` is the state the reconnect loop\n // checks, so an explicit shutdown can never be followed by a reconnect.\n close(new DeskError(`Desk ${deskId} is shutting down.`), true)\n await options.stop()\n },\n }\n if (options.pause && options.resume) {\n const pause = options.pause\n const resume = options.resume\n machine.pause = async () => {\n if (paused) return\n if (state !== 'live') throw new DeskError(`Desk ${deskId} is not connected.`)\n paused = true\n failAll(new DeskRequestFateUnknownError(`Desk ${deskId} paused with a request in flight; its fate is unknown.`))\n // On failure the VMM state may be unknown; retain the fence until resume succeeds.\n await pause()\n }\n machine.resume = async () => {\n if (!paused) return\n await resume()\n paused = false\n if (deferredDrop && state === 'reconnecting') {\n const drop = deferredDrop\n deferredDrop = null\n reconnecting = restore(drop.reason, drop.at)\n }\n }\n }\n if (options.park) {\n const park = options.park\n machine.park = async (snapshotDir: string) => {\n // Close the guest channel FIRST. Pausing a VM strands whatever was in\n // flight on the vsock, and a reconnect attempt against a paused guest\n // would burn the whole reconnect window before giving up — so the channel\n // is made terminal before the VM stops answering, exactly as shutdown\n // does it.\n close(new DeskError(`Desk ${deskId} is being parked.`), true)\n await park(snapshotDir)\n }\n }\n if (options.connect) {\n const connect = options.connect\n machine.connect = async (port: number) => {\n if (paused) throw new DeskError(`Desk ${deskId} is paused; resume it first.`)\n if (state === 'closed') throw new DeskError(`Desk ${deskId} is no longer connected.`)\n const connection = await connect(port)\n if ((state as string) === 'closed') { connection.destroy(); throw new DeskError(`Desk ${deskId} is no longer connected.`) }\n return connection\n }\n }\n return machine\n}\n\nexport interface ExitWatcher {\n done: boolean\n promise: Promise<void>\n}\n\n/**\n * Read a child's output and keep only the last few kilobytes.\n *\n * This is not for logging — it is load-bearing. A child spawned with its\n * streams as PIPES blocks once a pipe nobody reads fills, after about 64KB.\n * Cloud Hypervisor logs while it runs, so an unread pipe freezes the guest\n * partway through boot: the process is alive, the disk is untouched, and the\n * guest agent never reaches vsock. Every symptom points at the image and none\n * of them are its fault.\n *\n * Draining costs nothing and buys the tail of what the process said, which is\n * the difference between \"the VMM exited\" and knowing why. `streams` names the\n * pipes to drain: a helper that speaks a protocol on stdout drains only stderr.\n */\nexport function drainOutput(\n child: ChildProcess,\n limit = 8 * 1024,\n streams: readonly ('stdout' | 'stderr')[] = ['stdout', 'stderr'],\n): { tail: () => string } {\n let buffered = ''\n const absorb = (chunk: unknown) => {\n buffered += String(chunk)\n if (buffered.length > limit) buffered = buffered.slice(buffered.length - limit)\n }\n for (const name of streams) {\n const pipe = child[name]\n pipe?.on('data', absorb)\n // A pipe that errors must not take the process down with it.\n pipe?.on('error', () => undefined)\n }\n return { tail: () => buffered.trim() }\n}\n\nexport function watchExit(child: ChildProcess): ExitWatcher {\n const watcher: ExitWatcher = { done: false, promise: Promise.resolve() }\n watcher.promise = new Promise<void>((resolvePromise) => {\n const settle = () => {\n watcher.done = true\n resolvePromise()\n }\n child.once('exit', settle)\n child.once('error', settle)\n })\n return watcher\n}\n\nexport async function terminate(child: ChildProcess, exit: ExitWatcher, killGraceMs: number): Promise<void> {\n if (exit.done) return\n child.kill('SIGTERM')\n const forceKill = setTimeout(() => {\n if (!exit.done) child.kill('SIGKILL')\n }, killGraceMs)\n forceKill.unref()\n await exit.promise\n clearTimeout(forceKill)\n}\n\nexport function runToCompletion(child: ChildProcess, label: string): Promise<void> {\n return new Promise<void>((resolvePromise, rejectPromise) => {\n let stderr = ''\n child.stderr?.on('data', (chunk) => {\n stderr += String(chunk)\n })\n child.once('error', (error) => {\n rejectPromise(new DeskError(`${label} failed to start: ${error.message}`))\n })\n child.once('exit', (code, signal) => {\n if (code === 0) {\n resolvePromise()\n return\n }\n const detail = stderr.trim()\n rejectPromise(\n new DeskError(\n `${label} exited with code ${code ?? 'unknown'}`\n + `${signal ? ` (${signal})` : ''}${detail ? `: ${detail}` : '.'}`,\n ),\n )\n })\n })\n}\n\n/**\n * Cloud Hypervisor exposes guest vsock ports through a host Unix socket with\n * a line-oriented preamble: the client writes `CONNECT <port>\\n` and the VMM\n * answers `OK <assigned>\\n` before the byte stream becomes the guest\n * connection. The VMM creates the socket during boot, so connection attempts\n * retry until the deadline. The Virtualization.framework helper speaks the\n * same preamble on its own socket.\n *\n * The same loop serves the first connection and every later reconnect, so a\n * reconnect gets `confirmGuest` too — a mid-lease reconnect that trusted the\n * banner would re-adopt exactly the hollow stream the boot path learned not to.\n */\nexport async function connectWithRetry(options: {\n connect: (socketPath: string) => Duplex\n now: () => number\n socketPath: string\n port: number\n timeoutMs: number\n retryDelayMs: number\n /** Ceiling the delay doubles toward; omitted keeps the delay constant. */\n maxRetryDelayMs?: number\n attemptTimeoutMs: number\n exited: ExitWatcher\n /** A dead VMM means something different at boot than it does mid-lease. */\n exitedMessage?: string\n /** Stops the loop early when the caller no longer wants the connection. */\n abandoned?: () => boolean\n}): Promise<Duplex> {\n const deadline = options.now() + options.timeoutMs\n let lastFailure = 'the guest agent never answered'\n let retryDelayMs = options.retryDelayMs\n while (options.now() <= deadline) {\n if (options.exited.done) {\n throw new DeskError(options.exitedMessage ?? 'The VMM exited before the guest agent came up.')\n }\n if (options.abandoned?.() === true) {\n throw new DeskError('the connection attempt was abandoned.')\n }\n try {\n const stream = await attemptHandshake(\n options.connect,\n options.socketPath,\n options.port,\n options.attemptTimeoutMs,\n )\n try {\n await confirmGuest(stream, options.attemptTimeoutMs)\n } catch (error) {\n stream.destroy()\n throw error\n }\n return stream\n } catch (error) {\n lastFailure = errorMessage(error)\n }\n await delay(retryDelayMs)\n if (options.maxRetryDelayMs !== undefined) {\n retryDelayMs = Math.min(retryDelayMs * 2, options.maxRetryDelayMs)\n }\n }\n throw new DeskError(\n `Timed out connecting to the guest agent at ${options.socketPath}: ${lastFailure}`,\n )\n}\n\n/**\n * Prove a guest is behind the handshake by asking it something.\n *\n * Cloud Hypervisor answers `CONNECT <port>` with `OK` whether or not anything\n * in the guest is listening on that port, and only closes the socket a moment\n * later when it finds nobody there. A caller that trusts the banner therefore\n * \"connects\" to a guest that is still booting, gets a closed stream seconds\n * later, and — because a closed machine is not retried — leaves the desk dead\n * for as long as it is leased, with a healthy guest sitting behind it. So the\n * handshake is not the test; a reply is.\n */\nasync function confirmGuest(stream: Duplex, timeoutMs: number): Promise<void> {\n const decoder = new FrameDecoder()\n await new Promise<void>((resolvePromise, rejectPromise) => {\n let settled = false\n const finish = (error?: Error) => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n stream.off('data', onData)\n stream.off('close', onClose)\n stream.off('error', finish)\n if (error) rejectPromise(error)\n else resolvePromise()\n }\n const timer = setTimeout(\n () => finish(new DeskError('the guest agent did not answer the first request.')),\n timeoutMs,\n )\n timer.unref?.()\n const onClose = () =>\n finish(new DeskError('the connection closed before the guest agent answered.'))\n const onData = (chunk: Buffer) => {\n let values: unknown[]\n try {\n values = decoder.push(chunk)\n } catch (error) {\n finish(error instanceof Error ? error : new Error(String(error)))\n return\n }\n for (const value of values) {\n // Anything at all proves a guest is there; the reply is parsed for\n // real by the machine once it owns the stream.\n if (value && typeof value === 'object') {\n finish()\n return\n }\n }\n }\n stream.on('data', onData)\n stream.once('close', onClose)\n stream.once('error', finish)\n stream.write(encodeFrame({ id: 'hello', op: 'ping' }))\n })\n}\n\n/**\n * One handshake attempt, which MUST settle.\n *\n * Cloud Hypervisor accepts a connection on the vsock socket whether or not\n * anything in the guest is listening on the port, and when nothing is it may\n * answer nothing at all: no reply, no error, no close. Without a deadline of\n * its own this promise then never settles — and because the caller awaits it\n * inside the retry loop, the loop stops iterating, the overall deadline is\n * never re-checked, and the boot hangs forever rather than failing. That is\n * indistinguishable from a wedged host and it is why every attempt is bounded\n * here as well as in aggregate.\n *\n * A close before the reply line is a refusal: that is how a port with nothing\n * listening presents through Cloud Hypervisor, and the Virtualization.framework\n * helper presents a refused vsock or TCP port the same way.\n */\nexport function attemptHandshake(\n connect: (socketPath: string) => Duplex,\n socketPath: string,\n port: number,\n attemptTimeoutMs: number,\n): Promise<Duplex> {\n return new Promise<Duplex>((resolvePromise, rejectPromise) => {\n let stream: Duplex\n try {\n stream = connect(socketPath)\n } catch (error) {\n rejectPromise(error instanceof Error ? error : new Error(String(error)))\n return\n }\n let banner = ''\n let settled = false\n const timer = setTimeout(() => {\n fail(new DeskError('vsock handshake went unanswered.'))\n }, attemptTimeoutMs)\n // An unref'd timer must not hold the process open on its own.\n timer.unref?.()\n const fail = (error: Error) => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n stream.destroy()\n rejectPromise(error)\n }\n const onData = (chunk: Buffer) => {\n banner += chunk.toString('latin1')\n const newline = banner.indexOf('\\n')\n if (newline === -1) {\n if (banner.length > HANDSHAKE_LINE_LIMIT) {\n fail(new DeskError('vsock handshake reply exceeded the line limit.'))\n }\n return\n }\n const line = banner.slice(0, newline)\n const rest = banner.slice(newline + 1)\n stream.off('data', onData)\n stream.off('error', fail)\n if (!line.startsWith('OK ')) {\n fail(new DeskError(`vsock handshake was refused: ${line}`))\n return\n }\n settled = true\n clearTimeout(timer)\n if (rest.length > 0) stream.unshift(Buffer.from(rest, 'latin1'))\n resolvePromise(stream)\n }\n stream.on('data', onData)\n stream.once('error', fail)\n // A close before the banner is a refusal, not a hang.\n stream.once('close', () => fail(new DeskError('vsock handshake closed before a reply.')))\n stream.write(`CONNECT ${port}\\n`)\n })\n}\n\n/**\n * The shares a snapshot was taken with, kept beside it.\n *\n * A snapshot holds the machine's devices, shares among them, so it can only\n * come back with the shares it was parked with: Cloud Hypervisor would resume\n * without a share that was added since, and Virtualization.framework refuses a\n * changed device list. The host restores with this list rather than the one it\n * was given, and a backend refuses a plan that disagrees with it.\n */\nconst SHARE_MANIFEST = 'shares.json'\n\nexport async function writeShareManifest(snapshotDir: string, shares: readonly DeskShare[]): Promise<void> {\n await writeFile(join(snapshotDir, SHARE_MANIFEST), `${shareManifest(shares)}\\n`, { mode: 0o600 })\n}\n\n/**\n * The shares recorded beside a snapshot. A snapshot with no record predates\n * shares, so it was taken with none. Paths are returned as recorded; whether\n * they still exist is the launch plan's to check.\n */\nexport async function readShareManifest(snapshotDir: string): Promise<DeskShare[]> {\n let text: string\n try {\n text = await readFile(join(snapshotDir, SHARE_MANIFEST), 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw error\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch {\n throw new DeskError(`${join(snapshotDir, SHARE_MANIFEST)} is not valid JSON.`)\n }\n const valid = Array.isArray(value) && value.every((entry: unknown) =>\n typeof entry === 'object' && entry !== null\n && typeof (entry as DeskShare).tag === 'string'\n && typeof (entry as DeskShare).path === 'string'\n && typeof (entry as DeskShare).readOnly === 'boolean')\n if (!valid) throw new DeskError(`${join(snapshotDir, SHARE_MANIFEST)} is not a list of shares.`)\n return (value as DeskShare[]).map(({ tag, path, readOnly }) => ({ tag, path, readOnly }))\n}\n\n/** Throws unless the snapshot was parked with exactly `shares`, in order. */\nexport async function assertShareManifest(snapshotDir: string, shares: readonly DeskShare[]): Promise<void> {\n const saved = shareManifest(await readShareManifest(snapshotDir))\n const wanted = shareManifest(shares)\n if (saved !== wanted) throw new DeskError(`the snapshot was taken with shares ${saved}, not ${wanted}`)\n}\n\nfunction shareManifest(shares: readonly DeskShare[]): string {\n return JSON.stringify(shares.map(({ tag, path, readOnly }) => ({ tag, path, readOnly })))\n}\n\nexport function defaultLauncher(\n command: string,\n args: readonly string[],\n options: { identity?: DeskLauncherIdentity },\n): ChildProcess {\n return spawn(command, [...args], {\n stdio: ['ignore', 'pipe', 'pipe'],\n uid: options.identity?.uid,\n gid: options.identity?.gid,\n })\n}\n\nexport function defaultConnect(socketPath: string): Duplex {\n return createConnection(socketPath)\n}\n\nexport function delay(ms: number): Promise<void> {\n return new Promise<void>((resolvePromise) => {\n const timer = setTimeout(resolvePromise, ms)\n timer.unref()\n })\n}\n\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@braedonsaunders/appkit-desk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Per-agent Debian microVMs on Linux and macOS, with a framed guest-agent protocol, leases, snapshots, and governed networking.",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
package/plan.d.ts
CHANGED
|
@@ -83,6 +83,13 @@ export interface DeskShare {
|
|
|
83
83
|
* the share; running unconfined is not offered.
|
|
84
84
|
*/
|
|
85
85
|
export type DeskVirtiofsdSandbox = 'namespace' | 'chroot';
|
|
86
|
+
/** An immutable host image. The caller must retain its bytes and path for every snapshot. */
|
|
87
|
+
export interface DeskReadOnlyAttachment {
|
|
88
|
+
path: string;
|
|
89
|
+
/** SHA-256 of the immutable image, used as snapshot identity. */
|
|
90
|
+
sha256: string;
|
|
91
|
+
kind: 'block' | 'pmem';
|
|
92
|
+
}
|
|
86
93
|
export interface DeskLaunchPlanOptions {
|
|
87
94
|
deskId: string;
|
|
88
95
|
/** Defaults to `cloud-hypervisor`. */
|
|
@@ -106,6 +113,8 @@ export interface DeskLaunchPlanOptions {
|
|
|
106
113
|
/** Absolute path of this desk's copy-on-write overlay (a raw reflink clone). */
|
|
107
114
|
overlayPath: string;
|
|
108
115
|
memoryMb?: number;
|
|
116
|
+
/** Cloud Hypervisor virtio-balloon with free-page reporting, size zero. */
|
|
117
|
+
freePageReporting?: boolean;
|
|
109
118
|
vcpus?: number;
|
|
110
119
|
/**
|
|
111
120
|
* Guest vsock context ID; must be unique among resident desks. Cloud
|
|
@@ -133,6 +142,8 @@ export interface DeskLaunchPlanOptions {
|
|
|
133
142
|
* same shares the desk was parked with; see the backends.
|
|
134
143
|
*/
|
|
135
144
|
shares?: readonly DeskShare[];
|
|
145
|
+
/** Additional immutable Cloud Hypervisor devices, in guest enumeration order. */
|
|
146
|
+
readOnlyAttachments?: readonly DeskReadOnlyAttachment[];
|
|
136
147
|
/**
|
|
137
148
|
* Cloud Hypervisor only: the `virtiofsd` binary (1.13 or later) that serves
|
|
138
149
|
* each share. Defaults to the first `virtiofsd` on `PATH`, then
|
|
@@ -159,6 +170,8 @@ export interface DeskLaunchPlanOptions {
|
|
|
159
170
|
* was promised to have kept.
|
|
160
171
|
*/
|
|
161
172
|
restore?: boolean;
|
|
173
|
+
/** Cloud Hypervisor copy-on-write restore; the source must remain unchanged while resident. */
|
|
174
|
+
memoryRestoreMode?: 'copyonwrite';
|
|
162
175
|
}
|
|
163
176
|
/** What every plan carries, whichever hypervisor runs it. */
|
|
164
177
|
export interface DeskLaunchPlanBase {
|
|
@@ -295,5 +308,7 @@ export declare function buildDeskLaunchPlan(options: DeskLaunchPlanOptions & {
|
|
|
295
308
|
hypervisor?: 'cloud-hypervisor';
|
|
296
309
|
}, dependencies?: DeskLaunchPlanDependencies): CloudHypervisorLaunchPlan;
|
|
297
310
|
export declare function buildDeskLaunchPlan(options: DeskLaunchPlanOptions, dependencies?: DeskLaunchPlanDependencies): DeskLaunchPlan;
|
|
311
|
+
/** Reject ambiguous Cloud Hypervisor key-value arguments and unpinned images. */
|
|
312
|
+
export declare function cleanAttachments(attachments: readonly DeskReadOnlyAttachment[] | undefined, pathExists: (path: string) => boolean): DeskReadOnlyAttachment[];
|
|
298
313
|
export declare function cleanLauncherIdentity(identity: DeskLauncherIdentity | undefined): DeskLauncherIdentity | undefined;
|
|
299
314
|
//# sourceMappingURL=plan.d.ts.map
|
package/plan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gBAAgB,8BAA8B,CAAA;AAC3D,eAAO,MAAM,gBAAgB,aAAa,CAAA;AAC1C,eAAO,MAAM,qBAAqB,sBAAsB,CAAA;AACxD,eAAO,MAAM,mBAAmB,qBAAqB,CAAA;AACrD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AACpC,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,sBAAsB,2BAA2B,CAAA;AAC9D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,2BAA2B,CAAA;AAC9D,eAAO,MAAM,yBAAyB,EAAE,oBAAkC,CAAA;AAC1E;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,cAAc,CAAA;AACnD,eAAO,MAAM,0BAA0B,aAAa,CAAA;AACpD,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAC1C,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAA2B,CAAA;AACvE,0EAA0E;AAC1E,eAAO,MAAM,YAAY,IAAI,CAAA;AAiB7B;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAkB,IAAI,EAAE,MAAM,CAAc;CAC7C;AAED,MAAM,WAAW,oBAAoB;IACnC,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAA;IACX,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;;GAIG;AACH,M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,EACjE,YAAY,CAAC,EAAE,0BAA0B,GACxC,wBAAwB,CAAA;AAC3B,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAAE,EACpE,YAAY,CAAC,EAAE,0BAA0B,GACxC,yBAAyB,CAAA;AAC5B,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,qBAAqB,EAC9B,YAAY,CAAC,EAAE,0BAA0B,GACxC,cAAc,CAAA;AA2QjB,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,SAAS,sBAAsB,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,sBAAsB,EAAE,CAS5J;AAkND,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,oBAAoB,GAAG,SAAS,GACzC,oBAAoB,GAAG,SAAS,CAUlC"}
|
package/plan.js
CHANGED
|
@@ -85,6 +85,9 @@ export function cleanDeskId(value) {
|
|
|
85
85
|
}
|
|
86
86
|
export function buildDeskLaunchPlan(options, dependencies = {}) {
|
|
87
87
|
const hypervisor = options.hypervisor ?? 'cloud-hypervisor';
|
|
88
|
+
if (options.memoryRestoreMode !== undefined && (options.memoryRestoreMode !== 'copyonwrite' || hypervisor !== 'cloud-hypervisor')) {
|
|
89
|
+
throw new DeskError('Copy-on-write restore requires Cloud Hypervisor.');
|
|
90
|
+
}
|
|
88
91
|
if (hypervisor === 'virtualization')
|
|
89
92
|
return buildVirtualizationPlan(options, dependencies);
|
|
90
93
|
if (hypervisor !== 'cloud-hypervisor') {
|
|
@@ -151,6 +154,7 @@ function buildCloudHypervisorPlan(options, dependencies) {
|
|
|
151
154
|
// guest instead of a missing snapshot out here.
|
|
152
155
|
throw new DeskError(`Desk ${deskId} has no snapshot to restore at ${snapshotDir}`);
|
|
153
156
|
}
|
|
157
|
+
const attachments = cleanAttachments(options.readOnlyAttachments, pathExists);
|
|
154
158
|
const shares = cloudHypervisorShares(cleanShares(options.shares, isDirectory), {
|
|
155
159
|
deskId,
|
|
156
160
|
runtimeDir,
|
|
@@ -185,8 +189,9 @@ function buildCloudHypervisorPlan(options, dependencies) {
|
|
|
185
189
|
// that died in that window would, on the next start, replay this memory
|
|
186
190
|
// against a disk that had moved on. That is corruption, not a stale cache.
|
|
187
191
|
//
|
|
188
|
-
//
|
|
189
|
-
//
|
|
192
|
+
// The guest comes back PAUSED; before it runs, the caller must make the
|
|
193
|
+
// snapshot unavailable for replay. File-backed restores keep their retired
|
|
194
|
+
// source unchanged until the VMM exits.
|
|
190
195
|
//
|
|
191
196
|
// The tap is reopened BY NAME from the snapshotted config. That is the detail
|
|
192
197
|
// that makes this possible at all: Cloud Hypervisor's `net_fds` restore
|
|
@@ -201,7 +206,7 @@ function buildCloudHypervisorPlan(options, dependencies) {
|
|
|
201
206
|
const args = restoring
|
|
202
207
|
? [
|
|
203
208
|
'--api-socket', apiSocketPath,
|
|
204
|
-
'--restore', `source_url=file://${snapshotDir},resume=false`,
|
|
209
|
+
'--restore', `source_url=file://${snapshotDir},resume=false${options.memoryRestoreMode === 'copyonwrite' ? ',memory_restore_mode=copyonwrite' : ''}`,
|
|
205
210
|
]
|
|
206
211
|
: [
|
|
207
212
|
'--api-socket', apiSocketPath,
|
|
@@ -212,10 +217,12 @@ function buildCloudHypervisorPlan(options, dependencies) {
|
|
|
212
217
|
'--cmdline', kernelCmdline,
|
|
213
218
|
// Be explicit that the disk is raw: CH deprecated image-format auto-detection
|
|
214
219
|
// and warns without image_type; there is never a qcow2 overlay here.
|
|
215
|
-
'--disk', `path=${overlayPath},image_type=raw`,
|
|
220
|
+
'--disk', `path=${overlayPath},image_type=raw`, ...attachments.filter(a => a.kind === 'block').map(a => `path=${a.path},readonly=on,image_type=raw`),
|
|
221
|
+
...attachments.filter(a => a.kind === 'pmem').flatMap(a => ['--pmem', `file=${a.path},discard_writes=on`]),
|
|
216
222
|
// vhost-user devices map guest RAM into their daemon, so it must be
|
|
217
223
|
// shared memory; a desk without shares keeps private memory.
|
|
218
224
|
'--memory', `size=${memoryMb}M${shares.length === 0 ? '' : ',shared=on'}`,
|
|
225
|
+
...(options.freePageReporting ? ['--balloon', 'size=0,free_page_reporting=on'] : []),
|
|
219
226
|
'--cpus', `boot=${vcpus}`,
|
|
220
227
|
'--vsock', `cid=${vsockCid},socket=${vsockSocketPath}`,
|
|
221
228
|
'--net', `tap=${tapDevice},mac=${macAddress}`,
|
|
@@ -252,6 +259,10 @@ function buildCloudHypervisorPlan(options, dependencies) {
|
|
|
252
259
|
*/
|
|
253
260
|
function buildVirtualizationPlan(options, dependencies) {
|
|
254
261
|
const pathExists = dependencies.pathExists ?? existsSync;
|
|
262
|
+
if (options.readOnlyAttachments?.length)
|
|
263
|
+
throw new DeskError('Read-only attachments require Cloud Hypervisor.');
|
|
264
|
+
if (options.freePageReporting)
|
|
265
|
+
throw new DeskError('Free-page reporting requires Cloud Hypervisor.');
|
|
255
266
|
const deskId = cleanDeskId(options.deskId);
|
|
256
267
|
if (options.tapDevice !== undefined) {
|
|
257
268
|
throw new DeskError('tapDevice applies to Cloud Hypervisor desks; a Virtualization.framework desk has no TAP.');
|
|
@@ -316,6 +327,21 @@ function buildVirtualizationPlan(options, dependencies) {
|
|
|
316
327
|
launcherIdentity: cleanLauncherIdentity(options.launcherIdentity),
|
|
317
328
|
};
|
|
318
329
|
}
|
|
330
|
+
/** Reject ambiguous Cloud Hypervisor key-value arguments and unpinned images. */
|
|
331
|
+
export function cleanAttachments(attachments, pathExists) {
|
|
332
|
+
if (attachments === undefined)
|
|
333
|
+
return [];
|
|
334
|
+
if (!Array.isArray(attachments))
|
|
335
|
+
throw new DeskError('readOnlyAttachments must be an array.');
|
|
336
|
+
return attachments.map((attachment, index) => {
|
|
337
|
+
if (!attachment || !['block', 'pmem'].includes(attachment.kind) || !/^[a-f0-9]{64}$/.test(attachment.sha256))
|
|
338
|
+
throw new DeskError(`Invalid readOnlyAttachments[${index}].`);
|
|
339
|
+
const path = absolutePath(attachment.path, `readOnlyAttachments[${index}].path`);
|
|
340
|
+
if (path.includes(',') || !pathExists(path))
|
|
341
|
+
throw new DeskError(`Invalid attachment path: ${path}`);
|
|
342
|
+
return { path, kind: attachment.kind, sha256: attachment.sha256 };
|
|
343
|
+
});
|
|
344
|
+
}
|
|
319
345
|
/** Validate shares as given: tags, absolute existing directories, explicit access. */
|
|
320
346
|
function cleanShares(shares, isDirectory) {
|
|
321
347
|
if (shares === undefined)
|