@nosana/node 1.1.84 → 1.1.85-rc

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.
Files changed (180) hide show
  1. package/dist/.env +2 -1
  2. package/dist/package.json +1 -1
  3. package/dist/packages/job-runtime/src/host/HostClient.d.ts +20 -4
  4. package/dist/packages/job-runtime/src/host/HostClient.js +35 -2
  5. package/dist/packages/job-runtime/src/host/contract.d.ts +27 -7
  6. package/dist/packages/job-runtime/src/host/contract.js +43 -7
  7. package/dist/packages/job-runtime/src/runtime/runJob.d.ts +8 -5
  8. package/dist/packages/job-runtime/src/runtime/runJob.js +44 -17
  9. package/dist/packages/vm-orchestrator/src/CidRegistry.d.ts +67 -0
  10. package/dist/packages/vm-orchestrator/src/CidRegistry.js +168 -0
  11. package/dist/packages/vm-orchestrator/src/GpuPool.d.ts +27 -0
  12. package/dist/packages/vm-orchestrator/src/GpuPool.js +41 -0
  13. package/dist/packages/vm-orchestrator/src/Hypervisor.d.ts +66 -0
  14. package/dist/packages/vm-orchestrator/src/Hypervisor.js +7 -0
  15. package/dist/packages/vm-orchestrator/src/QemuHypervisor.d.ts +62 -0
  16. package/dist/packages/vm-orchestrator/src/QemuHypervisor.js +185 -0
  17. package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.d.ts +61 -0
  18. package/dist/packages/vm-orchestrator/src/QemuHypervisorConfig.js +37 -0
  19. package/dist/packages/vm-orchestrator/src/QemuVmInstance.d.ts +37 -0
  20. package/dist/packages/vm-orchestrator/src/QemuVmInstance.js +44 -0
  21. package/dist/packages/vm-orchestrator/src/QmpClient.d.ts +43 -0
  22. package/dist/packages/vm-orchestrator/src/QmpClient.js +103 -0
  23. package/dist/packages/vm-orchestrator/src/VmSpec.d.ts +21 -0
  24. package/dist/packages/vm-orchestrator/src/VmSpec.js +30 -0
  25. package/dist/packages/vm-orchestrator/src/VmStateManager.d.ts +16 -0
  26. package/dist/packages/vm-orchestrator/src/VmStateManager.js +30 -0
  27. package/dist/packages/vm-orchestrator/src/bootAttempt.d.ts +31 -0
  28. package/dist/packages/vm-orchestrator/src/bootAttempt.js +193 -0
  29. package/dist/packages/vm-orchestrator/src/bootErrors.d.ts +33 -0
  30. package/dist/packages/vm-orchestrator/src/bootErrors.js +67 -0
  31. package/dist/packages/vm-orchestrator/src/buildCloudInit.d.ts +33 -0
  32. package/dist/packages/vm-orchestrator/src/buildCloudInit.js +55 -0
  33. package/dist/packages/vm-orchestrator/src/buildQemuArgs.d.ts +33 -0
  34. package/dist/packages/vm-orchestrator/src/buildQemuArgs.js +127 -0
  35. package/dist/packages/vm-orchestrator/src/diskSizing.d.ts +18 -0
  36. package/dist/packages/vm-orchestrator/src/diskSizing.js +41 -0
  37. package/dist/packages/vm-orchestrator/src/firmware.d.ts +5 -0
  38. package/dist/packages/vm-orchestrator/src/firmware.js +18 -0
  39. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.d.ts +22 -0
  40. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.js +33 -0
  41. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.d.ts +3 -0
  42. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.js +17 -0
  43. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.d.ts +9 -0
  44. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.js +17 -0
  45. package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.d.ts +6 -0
  46. package/dist/packages/vm-orchestrator/src/hostAccess/gpuProblems.js +42 -0
  47. package/dist/packages/vm-orchestrator/src/hostAccess/index.d.ts +1 -0
  48. package/dist/packages/vm-orchestrator/src/hostAccess/index.js +1 -0
  49. package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.d.ts +6 -0
  50. package/dist/packages/vm-orchestrator/src/hostAccess/memlockProblems.js +18 -0
  51. package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.d.ts +7 -0
  52. package/dist/packages/vm-orchestrator/src/hostAccess/workRootProblems.js +30 -0
  53. package/dist/packages/vm-orchestrator/src/hostDevices.d.ts +12 -0
  54. package/dist/packages/vm-orchestrator/src/hostDevices.js +12 -0
  55. package/dist/packages/vm-orchestrator/src/hostTools.d.ts +25 -0
  56. package/dist/packages/vm-orchestrator/src/hostTools.js +39 -0
  57. package/dist/packages/vm-orchestrator/src/imageCache.d.ts +25 -0
  58. package/dist/packages/vm-orchestrator/src/imageCache.js +73 -0
  59. package/dist/packages/vm-orchestrator/src/imageDownload.d.ts +31 -0
  60. package/dist/packages/vm-orchestrator/src/imageDownload.js +85 -0
  61. package/dist/packages/vm-orchestrator/src/index.d.ts +19 -0
  62. package/dist/packages/vm-orchestrator/src/index.js +15 -0
  63. package/dist/packages/vm-orchestrator/src/memlockLimit.d.ts +5 -0
  64. package/dist/packages/vm-orchestrator/src/memlockLimit.js +23 -0
  65. package/dist/packages/vm-orchestrator/src/nvidiaHolders.d.ts +11 -0
  66. package/dist/packages/vm-orchestrator/src/nvidiaHolders.js +74 -0
  67. package/dist/packages/vm-orchestrator/src/pciNuma.d.ts +7 -0
  68. package/dist/packages/vm-orchestrator/src/pciNuma.js +18 -0
  69. package/dist/packages/vm-orchestrator/src/pciSysfs.d.ts +21 -0
  70. package/dist/packages/vm-orchestrator/src/pciSysfs.js +47 -0
  71. package/dist/packages/vm-orchestrator/src/processes.d.ts +37 -0
  72. package/dist/packages/vm-orchestrator/src/processes.js +102 -0
  73. package/dist/packages/vm-orchestrator/src/sockets.d.ts +21 -0
  74. package/dist/packages/vm-orchestrator/src/sockets.js +58 -0
  75. package/dist/packages/vm-orchestrator/src/sweepVmImageCache.d.ts +19 -0
  76. package/dist/packages/vm-orchestrator/src/sweepVmImageCache.js +132 -0
  77. package/dist/packages/vm-orchestrator/src/util.d.ts +14 -0
  78. package/dist/packages/vm-orchestrator/src/util.js +33 -0
  79. package/dist/packages/vm-orchestrator/src/vfioBinding.d.ts +27 -0
  80. package/dist/packages/vm-orchestrator/src/vfioBinding.js +163 -0
  81. package/dist/packages/vm-orchestrator/src/vmImageResolver.d.ts +20 -0
  82. package/dist/packages/vm-orchestrator/src/vmImageResolver.js +62 -0
  83. package/dist/packages/vm-orchestrator/src/vsockBridge.d.ts +20 -0
  84. package/dist/packages/vm-orchestrator/src/vsockBridge.js +27 -0
  85. package/dist/packages/vm-orchestrator/src/workDirs.d.ts +49 -0
  86. package/dist/packages/vm-orchestrator/src/workDirs.js +79 -0
  87. package/dist/src/NodeManager/configs/configs.d.ts +4 -0
  88. package/dist/src/NodeManager/configs/configs.js +3 -0
  89. package/dist/src/NodeManager/db/index.d.ts +10 -0
  90. package/dist/src/NodeManager/db/index.js +4 -0
  91. package/dist/src/NodeManager/monitoring/log/NodeLog.d.ts +2 -0
  92. package/dist/src/NodeManager/monitoring/log/NodeLog.js +21 -0
  93. package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.d.ts +8 -0
  94. package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.js +29 -5
  95. package/dist/src/NodeManager/monitoring/log/vmSetupLog.d.ts +11 -0
  96. package/dist/src/NodeManager/monitoring/log/vmSetupLog.js +33 -0
  97. package/dist/src/NodeManager/node/Node.d.ts +2 -0
  98. package/dist/src/NodeManager/node/Node.js +12 -5
  99. package/dist/src/NodeManager/node/job/ContainerJobRuntime.d.ts +141 -0
  100. package/dist/src/NodeManager/node/job/ContainerJobRuntime.js +419 -0
  101. package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.d.ts +74 -0
  102. package/dist/src/NodeManager/node/job/JobRuntimeEnvironment.js +1 -0
  103. package/dist/src/NodeManager/node/job/JobRuntimeHost.d.ts +6 -2
  104. package/dist/src/NodeManager/node/job/JobRuntimeHost.js +13 -2
  105. package/dist/src/NodeManager/node/job/JobRuntimeSession.d.ts +12 -9
  106. package/dist/src/NodeManager/node/job/JobRuntimeSession.js +42 -71
  107. package/dist/src/NodeManager/node/job/VmJobRuntime.d.ts +109 -0
  108. package/dist/src/NodeManager/node/job/VmJobRuntime.js +258 -0
  109. package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.d.ts +33 -0
  110. package/dist/src/NodeManager/node/job/VmJobRuntimeConfig.js +1 -0
  111. package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.d.ts +41 -0
  112. package/dist/src/NodeManager/node/job/buildJobRuntimeEnv.js +25 -0
  113. package/dist/src/NodeManager/node/job/followFile.d.ts +14 -0
  114. package/dist/src/NodeManager/node/job/followFile.js +57 -0
  115. package/dist/src/NodeManager/node/job/jobHandler.d.ts +3 -3
  116. package/dist/src/NodeManager/node/job/jobHandler.js +7 -7
  117. package/dist/src/NodeManager/node/job/keepFailedConsole.d.ts +7 -0
  118. package/dist/src/NodeManager/node/job/keepFailedConsole.js +52 -0
  119. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.d.ts +50 -0
  120. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.js +117 -0
  121. package/dist/src/NodeManager/node/market/benchmark.d.ts +3 -3
  122. package/dist/src/NodeManager/node/market/benchmark.js +3 -3
  123. package/dist/src/NodeManager/node/market/marketHandler.d.ts +3 -3
  124. package/dist/src/NodeManager/node/market/marketHandler.js +3 -3
  125. package/dist/src/NodeManager/node/resource/resourceManager.d.ts +1 -1
  126. package/dist/src/NodeManager/node/resource/resourceManager.js +1 -1
  127. package/dist/src/NodeManager/provider/Provider.d.ts +3 -121
  128. package/dist/src/NodeManager/provider/Provider.js +3 -369
  129. package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.d.ts +14 -0
  130. package/dist/src/NodeManager/provider/vmHost/VmNodeOptions.js +1 -0
  131. package/dist/src/NodeManager/provider/vmHost/capacity.d.ts +16 -0
  132. package/dist/src/NodeManager/provider/vmHost/capacity.js +47 -0
  133. package/dist/src/NodeManager/provider/vmHost/gpus.d.ts +19 -0
  134. package/dist/src/NodeManager/provider/vmHost/gpus.js +83 -0
  135. package/dist/src/NodeManager/provider/vmHost/index.d.ts +5 -0
  136. package/dist/src/NodeManager/provider/vmHost/index.js +4 -0
  137. package/dist/src/NodeManager/provider/vmHost/readVmSpec.d.ts +11 -0
  138. package/dist/src/NodeManager/provider/vmHost/readVmSpec.js +22 -0
  139. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.d.ts +27 -0
  140. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.js +25 -0
  141. package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.d.ts +6 -0
  142. package/dist/src/NodeManager/provider/vmHost/setup/fileOwnership.js +22 -0
  143. package/dist/src/NodeManager/provider/vmHost/setup/hostUser.d.ts +15 -0
  144. package/dist/src/NodeManager/provider/vmHost/setup/hostUser.js +25 -0
  145. package/dist/src/NodeManager/provider/vmHost/setup/index.d.ts +2 -0
  146. package/dist/src/NodeManager/provider/vmHost/setup/index.js +2 -0
  147. package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.d.ts +6 -0
  148. package/dist/src/NodeManager/provider/vmHost/setup/memlockLimits.js +12 -0
  149. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.d.ts +17 -0
  150. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.js +90 -0
  151. package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.d.ts +5 -0
  152. package/dist/src/NodeManager/provider/vmHost/setup/sudoCaller.js +35 -0
  153. package/dist/src/NodeManager/provider/vmHost/vmHostEnv.d.ts +20 -0
  154. package/dist/src/NodeManager/provider/vmHost/vmHostEnv.js +24 -0
  155. package/dist/src/NodeManager/provider/vmHost/workRoot.d.ts +14 -0
  156. package/dist/src/NodeManager/provider/vmHost/workRoot.js +84 -0
  157. package/dist/src/NodeManager/repository/NodeRepository.d.ts +12 -2
  158. package/dist/src/NodeManager/repository/NodeRepository.js +21 -1
  159. package/dist/src/cli/commands/prune/command.js +2 -1
  160. package/dist/src/cli/commands/run/action.d.ts +2 -2
  161. package/dist/src/cli/commands/run/action.js +15 -34
  162. package/dist/src/cli/commands/run/command.js +7 -2
  163. package/dist/src/cli/commands/sharedOptions/--config.d.ts +2 -0
  164. package/dist/src/cli/commands/sharedOptions/--config.js +2 -0
  165. package/dist/src/cli/commands/sharedOptions/--environment.d.ts +6 -0
  166. package/dist/src/cli/commands/sharedOptions/--environment.js +6 -0
  167. package/dist/src/cli/commands/sharedOptions/--gpu.js +5 -2
  168. package/dist/src/cli/commands/sharedOptions/--node-limits.d.ts +9 -0
  169. package/dist/src/cli/commands/sharedOptions/--node-limits.js +24 -0
  170. package/dist/src/cli/commands/sharedOptions/index.d.ts +3 -0
  171. package/dist/src/cli/commands/sharedOptions/index.js +3 -0
  172. package/dist/src/cli/commands/start/command.js +7 -2
  173. package/dist/src/cli/commands/vm-setup/action.d.ts +10 -0
  174. package/dist/src/cli/commands/vm-setup/action.js +14 -0
  175. package/dist/src/cli/commands/vm-setup/command.d.ts +3 -0
  176. package/dist/src/cli/commands/vm-setup/command.js +11 -0
  177. package/dist/src/cli/createNosanaCli.d.ts +1 -0
  178. package/dist/src/cli/createNosanaCli.js +4 -1
  179. package/npm-shrinkwrap.json +10 -2
  180. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ import { execFileSync } from 'child_process';
2
+ import { readPciNumaNode } from './pciNuma.js';
3
+ /** QEMU's x86-64 system emulator: the VM itself. */
4
+ export const QEMU_BINARY = 'qemu-system-x86_64';
5
+ /** Creates and resizes the qcow2 overlays, and reads their backing files. */
6
+ export const QEMU_IMG_BINARY = 'qemu-img';
7
+ /** Bridges the guest's vsock connections to the node's `host.sock`. */
8
+ export const SOCAT_BINARY = 'socat';
9
+ /** Packs the cloud-init NoCloud seed ISO. */
10
+ export const ISO_BINARY = 'genisoimage';
11
+ /** Pins a VM to its GPU's NUMA node; needed only when that GPU has one. */
12
+ export const NUMA_TOOL = 'numactl';
13
+ /** The host binaries every VM needs. */
14
+ const VM_HOST_TOOLS = [QEMU_BINARY, QEMU_IMG_BINARY, SOCAT_BINARY, ISO_BINARY];
15
+ /**
16
+ * The host binaries a VM of `spec` needs: QEMU's tools, and numactl when its first GPU is on
17
+ * a NUMA node (the boot pins the VM there), so a node can refuse to start without them.
18
+ */
19
+ export function requiredHostTools(spec, readNumaNode = readPciNumaNode) {
20
+ const [gpu] = spec.gpus;
21
+ const isPinned = gpu !== undefined && readNumaNode(gpu) !== undefined;
22
+ return isPinned ? [...VM_HOST_TOOLS, NUMA_TOOL] : [...VM_HOST_TOOLS];
23
+ }
24
+ /**
25
+ * Whether the host's QEMU can pass GPUs through as the VMs do, by its iommufd backend
26
+ * (QEMU 9.0 or newer): its list of creatable objects names `iommufd`. False when QEMU cannot
27
+ * run.
28
+ */
29
+ export function qemuSupportsIommufd(run = runSync) {
30
+ try {
31
+ return /^\s*iommufd\s*$/m.test(run(QEMU_BINARY, ['-object', 'help']));
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ }
37
+ function runSync(command, args) {
38
+ return execFileSync(command, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
39
+ }
@@ -0,0 +1,25 @@
1
+ /** The image cache's directory name (the node puts it under its work root). */
2
+ export declare const VM_IMAGE_CACHE_DIR = "nosana-vm-images";
3
+ /** Disk-image file extensions a cached VM image carries. */
4
+ export declare const DISK_IMAGE_PATTERN: RegExp;
5
+ /** Frees an image lock. */
6
+ export type ReleaseLock = () => Promise<void>;
7
+ /** The cache dir name of an image reference: the reference, made a safe file name. */
8
+ export declare function cacheDirName(ref: string): string;
9
+ /** Where an image downloaded from `url` is cached. */
10
+ export declare function cachedImagePath(cacheDir: string, url: string): string;
11
+ /** The lock file of a cached image. */
12
+ export declare function imageLockPath(imagePath: string): string;
13
+ /**
14
+ * Take the lock for one cached image (`<file>.lock`), waiting while another
15
+ * process holds it. The resolver holds it while downloading, the hypervisor
16
+ * while creating an overlay over the image, and the cache sweep while deleting
17
+ * it. Resolves to the function that releases it.
18
+ */
19
+ export declare function lockVmImage(imagePath: string): Promise<ReleaseLock>;
20
+ /**
21
+ * Try once to take a lock file: created exclusively, holding our pid. A lock
22
+ * whose owner has died (a crashed download) is taken over. Resolves to the
23
+ * function that releases it, or undefined while someone else holds it.
24
+ */
25
+ export declare function tryLockFile(lockPath: string): Promise<ReleaseLock | undefined>;
@@ -0,0 +1,73 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { isPidAlive } from './processes.js';
4
+ import { describeError, sleep } from './util.js';
5
+ /** The image cache's directory name (the node puts it under its work root). */
6
+ export const VM_IMAGE_CACHE_DIR = 'nosana-vm-images';
7
+ /** Disk-image file extensions a cached VM image carries. */
8
+ export const DISK_IMAGE_PATTERN = /\.(qcow2|img|raw)$/i;
9
+ /** How often a waiting process re-checks another's image lock. */
10
+ const LOCK_POLL_MS = 1000;
11
+ /** A lock file with no readable owner yet is only abandoned after this long. */
12
+ const LOCK_UNOWNED_GRACE_MS = 10_000;
13
+ /** The cache dir name of an image reference: the reference, made a safe file name. */
14
+ export function cacheDirName(ref) {
15
+ return ref.replace(/[^a-zA-Z0-9._-]/g, '_');
16
+ }
17
+ /** Where an image downloaded from `url` is cached. */
18
+ export function cachedImagePath(cacheDir, url) {
19
+ const fileName = path.basename(new URL(url).pathname) || 'disk.img';
20
+ return path.join(cacheDir, cacheDirName(url), fileName);
21
+ }
22
+ /** The lock file of a cached image. */
23
+ export function imageLockPath(imagePath) {
24
+ return `${imagePath}.lock`;
25
+ }
26
+ /**
27
+ * Take the lock for one cached image (`<file>.lock`), waiting while another
28
+ * process holds it. The resolver holds it while downloading, the hypervisor
29
+ * while creating an overlay over the image, and the cache sweep while deleting
30
+ * it. Resolves to the function that releases it.
31
+ */
32
+ export async function lockVmImage(imagePath) {
33
+ for (;;) {
34
+ const release = await tryLockFile(imageLockPath(imagePath));
35
+ if (release)
36
+ return release;
37
+ await sleep(LOCK_POLL_MS);
38
+ }
39
+ }
40
+ /**
41
+ * Try once to take a lock file: created exclusively, holding our pid. A lock
42
+ * whose owner has died (a crashed download) is taken over. Resolves to the
43
+ * function that releases it, or undefined while someone else holds it.
44
+ */
45
+ export async function tryLockFile(lockPath) {
46
+ for (;;) {
47
+ if (await createLockFile(lockPath))
48
+ return () => fs.rm(lockPath, { force: true });
49
+ if (!(await isLockAbandoned(lockPath)))
50
+ return undefined;
51
+ await fs.rm(lockPath, { force: true });
52
+ }
53
+ }
54
+ /** Create the lock file holding our pid; false when it exists already. */
55
+ async function createLockFile(lockPath) {
56
+ try {
57
+ await fs.writeFile(lockPath, String(process.pid), { flag: 'wx' });
58
+ return true;
59
+ }
60
+ catch (error) {
61
+ if (describeError(error).code === 'EEXIST')
62
+ return false;
63
+ throw error;
64
+ }
65
+ }
66
+ /** Is the lock's owner dead, or has it held an unreadable lock past the grace period? */
67
+ async function isLockAbandoned(lockPath) {
68
+ const owner = Number((await fs.readFile(lockPath, 'utf8').catch(() => '')).trim());
69
+ if (owner)
70
+ return !isPidAlive(owner);
71
+ const changedMs = (await fs.stat(lockPath).catch(() => null))?.mtimeMs ?? 0;
72
+ return Date.now() - changedMs > LOCK_UNOWNED_GRACE_MS;
73
+ }
@@ -0,0 +1,31 @@
1
+ /** Download a URL to a file. Injectable for tests. */
2
+ export type DownloadLike = (url: string, dest: string) => Promise<void>;
3
+ /** Fetch the sha256 published for an image, undefined when none is. Injectable for tests. */
4
+ export type FetchChecksumLike = (url: string) => Promise<string | undefined>;
5
+ /** Download a URL to a file over HTTP(S). */
6
+ export declare function downloadToFile(url: string, dest: string): Promise<void>;
7
+ /**
8
+ * Fetch the sha256 hex published alongside an image as `<url>.sha256`. Returns
9
+ * undefined when none is published (404 / network error) so unverified upstream
10
+ * URLs still resolve. Accepts both a bare digest and `sha256sum` output
11
+ * (`<hex> <name>`).
12
+ */
13
+ export declare function fetchPublishedSha256(url: string): Promise<string | undefined>;
14
+ /** The sha256 hex of a file's contents. */
15
+ export declare function sha256File(filePath: string): Promise<string>;
16
+ /** The sidecar file a cached image's verified sha256 is recorded in. */
17
+ export declare function digestPath(imagePath: string): string;
18
+ /**
19
+ * The sha256 recorded for a cached image at download time. Falls back to
20
+ * hashing the file when none was recorded (a node warmed by an older
21
+ * resolver), so it still detects a same-URL re-publish.
22
+ */
23
+ export declare function cachedDigest(imagePath: string): Promise<string>;
24
+ /**
25
+ * Download `url` to `imagePath`: to a temp path of our own first, published
26
+ * into the cache only once complete and (when `expected` is given) verified,
27
+ * so a partial or tampered file is never served as a cache hit, and a broken
28
+ * lock costs a duplicate download, never a clobber. The verified digest is
29
+ * recorded so the next resolve detects a re-publish without re-hashing.
30
+ */
31
+ export declare function downloadVerified(download: DownloadLike, url: string, imagePath: string, expected: string | undefined): Promise<void>;
@@ -0,0 +1,85 @@
1
+ import { createHash } from 'crypto';
2
+ import { createReadStream, createWriteStream } from 'fs';
3
+ import fs from 'fs/promises';
4
+ import { Readable } from 'stream';
5
+ import { pipeline } from 'stream/promises';
6
+ const SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
7
+ /** Download a URL to a file over HTTP(S). */
8
+ export async function downloadToFile(url, dest) {
9
+ const res = await fetch(url);
10
+ if (!res.ok || !res.body) {
11
+ throw new Error(`failed to download '${url}': HTTP ${res.status}`);
12
+ }
13
+ await pipeline(Readable.fromWeb(res.body), createWriteStream(dest));
14
+ }
15
+ /**
16
+ * Fetch the sha256 hex published alongside an image as `<url>.sha256`. Returns
17
+ * undefined when none is published (404 / network error) so unverified upstream
18
+ * URLs still resolve. Accepts both a bare digest and `sha256sum` output
19
+ * (`<hex> <name>`).
20
+ */
21
+ export async function fetchPublishedSha256(url) {
22
+ let res;
23
+ try {
24
+ res = await fetch(`${url}.sha256`);
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ if (!res.ok)
30
+ return undefined;
31
+ const digest = (await res.text()).trim().split(/\s+/)[0]?.toLowerCase();
32
+ return digest && SHA256_HEX_PATTERN.test(digest) ? digest : undefined;
33
+ }
34
+ /** The sha256 hex of a file's contents. */
35
+ export function sha256File(filePath) {
36
+ return new Promise((resolve, reject) => {
37
+ const hash = createHash('sha256');
38
+ const stream = createReadStream(filePath);
39
+ stream.on('error', reject);
40
+ stream.on('data', (chunk) => hash.update(chunk));
41
+ stream.on('end', () => resolve(hash.digest('hex')));
42
+ });
43
+ }
44
+ /** The sidecar file a cached image's verified sha256 is recorded in. */
45
+ export function digestPath(imagePath) {
46
+ return `${imagePath}.sha256`;
47
+ }
48
+ /**
49
+ * The sha256 recorded for a cached image at download time. Falls back to
50
+ * hashing the file when none was recorded (a node warmed by an older
51
+ * resolver), so it still detects a same-URL re-publish.
52
+ */
53
+ export async function cachedDigest(imagePath) {
54
+ const recorded = await fs.readFile(digestPath(imagePath), 'utf8').catch(() => '');
55
+ if (SHA256_HEX_PATTERN.test(recorded.trim()))
56
+ return recorded.trim();
57
+ return sha256File(imagePath);
58
+ }
59
+ /**
60
+ * Download `url` to `imagePath`: to a temp path of our own first, published
61
+ * into the cache only once complete and (when `expected` is given) verified,
62
+ * so a partial or tampered file is never served as a cache hit, and a broken
63
+ * lock costs a duplicate download, never a clobber. The verified digest is
64
+ * recorded so the next resolve detects a re-publish without re-hashing.
65
+ */
66
+ export async function downloadVerified(download, url, imagePath, expected) {
67
+ const tmpPath = `${imagePath}.part.${process.pid}`;
68
+ try {
69
+ await download(url, tmpPath);
70
+ if (expected)
71
+ await verifySha256(url, tmpPath, expected);
72
+ await fs.rename(tmpPath, imagePath);
73
+ }
74
+ finally {
75
+ await fs.rm(tmpPath, { force: true }).catch(() => undefined);
76
+ }
77
+ if (expected)
78
+ await fs.writeFile(digestPath(imagePath), expected).catch(() => undefined);
79
+ }
80
+ async function verifySha256(url, filePath, expected) {
81
+ const actual = await sha256File(filePath);
82
+ if (actual !== expected) {
83
+ throw new Error(`checksum mismatch for '${url}': expected ${expected}, got ${actual}`);
84
+ }
85
+ }
@@ -0,0 +1,19 @@
1
+ export { QemuHypervisor } from './QemuHypervisor.js';
2
+ export type { QemuHypervisorConfig, QemuHypervisorOptions, QemuHypervisorSystem, } from './QemuHypervisorConfig.js';
3
+ export { VmNotRunningError } from './Hypervisor.js';
4
+ export type { Hypervisor, VmInstance, VmRecord, BootOptions } from './Hypervisor.js';
5
+ export { HOST_VSOCK_PORT_BASE } from './vsockBridge.js';
6
+ export { qemuSupportsIommufd, requiredHostTools } from './hostTools.js';
7
+ export { findVmHostAccessProblems } from './hostAccess/index.js';
8
+ export { bindGpusToVfio } from './vfioBinding.js';
9
+ export { IOMMUFD_DEVICE, KVM_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
10
+ export { missingVfioNodeMessage, readVfioDeviceNodes } from './pciSysfs.js';
11
+ export { removeWorkDir, WORK_DIR_PREFIX, OVERLAY_FILE, VM_CONSOLE_LOG } from './workDirs.js';
12
+ export { JOB_RUNTIME_GUEST_PORT } from './buildQemuArgs.js';
13
+ export { waitAtMost, sleep } from './util.js';
14
+ export { parseMemoryToMiB } from './VmSpec.js';
15
+ export type { VmSpec } from './VmSpec.js';
16
+ export { createVmImageResolver } from './vmImageResolver.js';
17
+ export type { VmImageResolverOptions } from './vmImageResolver.js';
18
+ export { sweepVmImageCache } from './sweepVmImageCache.js';
19
+ export { VM_IMAGE_CACHE_DIR } from './imageCache.js';
@@ -0,0 +1,15 @@
1
+ export { QemuHypervisor } from './QemuHypervisor.js';
2
+ export { VmNotRunningError } from './Hypervisor.js';
3
+ export { HOST_VSOCK_PORT_BASE } from './vsockBridge.js';
4
+ export { qemuSupportsIommufd, requiredHostTools } from './hostTools.js';
5
+ export { findVmHostAccessProblems } from './hostAccess/index.js';
6
+ export { bindGpusToVfio } from './vfioBinding.js';
7
+ export { IOMMUFD_DEVICE, KVM_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
8
+ export { missingVfioNodeMessage, readVfioDeviceNodes } from './pciSysfs.js';
9
+ export { removeWorkDir, WORK_DIR_PREFIX, OVERLAY_FILE, VM_CONSOLE_LOG } from './workDirs.js';
10
+ export { JOB_RUNTIME_GUEST_PORT } from './buildQemuArgs.js';
11
+ export { waitAtMost, sleep } from './util.js';
12
+ export { parseMemoryToMiB } from './VmSpec.js';
13
+ export { createVmImageResolver } from './vmImageResolver.js';
14
+ export { sweepVmImageCache } from './sweepVmImageCache.js';
15
+ export { VM_IMAGE_CACHE_DIR } from './imageCache.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The soft locked-memory limit, in bytes, of a `/proc/<pid>/limits` file: Infinity when
3
+ * unlimited, undefined when the file cannot be read.
4
+ */
5
+ export declare function readMemlockLimit(limitsFile?: string): number | undefined;
@@ -0,0 +1,23 @@
1
+ import fs from 'fs';
2
+ /** This process's resource limits. */
3
+ const PROC_SELF_LIMITS = '/proc/self/limits';
4
+ const MEMLOCK_ROW = 'Max locked memory';
5
+ /**
6
+ * The soft locked-memory limit, in bytes, of a `/proc/<pid>/limits` file: Infinity when
7
+ * unlimited, undefined when the file cannot be read.
8
+ */
9
+ export function readMemlockLimit(limitsFile = PROC_SELF_LIMITS) {
10
+ let limits;
11
+ try {
12
+ limits = fs.readFileSync(limitsFile, 'utf8');
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ const row = limits.split('\n').find((line) => line.startsWith(MEMLOCK_ROW));
18
+ const soft = row?.slice(MEMLOCK_ROW.length).trim().split(/\s+/)[0];
19
+ if (soft === 'unlimited')
20
+ return Infinity;
21
+ const bytes = Number(soft);
22
+ return soft && Number.isFinite(bytes) ? bytes : undefined;
23
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The processes holding an NVIDIA GPU's device file (`/dev/nvidia<minor>`) open, as
3
+ * `<pid> (<command>)`: what would block taking the GPU from the nvidia driver. None when the
4
+ * driver does not describe the GPU.
5
+ */
6
+ export declare function findNvidiaHolders(bdf: string, procRoot?: string): Promise<string[]>;
7
+ /**
8
+ * Turns persistence mode off for one GPU, so the persistence daemon closes its device; best
9
+ * effort, as a host without the daemon or nvidia-smi has nothing to release.
10
+ */
11
+ export declare function releaseNvidiaPersistence(bdf: string): Promise<void>;
@@ -0,0 +1,74 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { runToCompletion } from './processes.js';
4
+ /** Where, under procfs, the nvidia driver describes each GPU it drives. */
5
+ const NVIDIA_PROC_GPUS = 'driver/nvidia/gpus';
6
+ /** The `Device Minor` line of a GPU's description: its `/dev/nvidia<minor>`. */
7
+ const DEVICE_MINOR_RE = /^Device Minor:\s*(\d+)/m;
8
+ /**
9
+ * The processes holding an NVIDIA GPU's device file (`/dev/nvidia<minor>`) open, as
10
+ * `<pid> (<command>)`: what would block taking the GPU from the nvidia driver. None when the
11
+ * driver does not describe the GPU.
12
+ */
13
+ export async function findNvidiaHolders(bdf, procRoot = '/proc') {
14
+ const minor = await readDeviceMinor(bdf, procRoot);
15
+ if (minor === undefined)
16
+ return [];
17
+ const deviceFile = `/dev/nvidia${minor}`;
18
+ const pids = (await fs.readdir(procRoot)).filter((entry) => /^\d+$/.test(entry));
19
+ const holders = await Promise.all(pids.map((pid) => describeIfHolding(pid, deviceFile, procRoot)));
20
+ return holders.filter((holder) => holder !== undefined);
21
+ }
22
+ /**
23
+ * Turns persistence mode off for one GPU, so the persistence daemon closes its device; best
24
+ * effort, as a host without the daemon or nvidia-smi has nothing to release.
25
+ */
26
+ export async function releaseNvidiaPersistence(bdf) {
27
+ try {
28
+ await runToCompletion('nvidia-smi', ['-i', toNvidiaBusId(bdf), '-pm', '0']);
29
+ }
30
+ catch {
31
+ // No nvidia-smi, or persistence already off: nothing holds the GPU for it.
32
+ }
33
+ }
34
+ /** A sysfs BDF (`0000:01:00.0`) in nvidia-smi's 8-digit-domain form (`00000000:01:00.0`). */
35
+ function toNvidiaBusId(bdf) {
36
+ const [domain, ...rest] = bdf.split(':');
37
+ return [domain.padStart(8, '0'), ...rest].join(':');
38
+ }
39
+ async function readDeviceMinor(bdf, procRoot) {
40
+ try {
41
+ const informationFile = path.join(procRoot, NVIDIA_PROC_GPUS, bdf, 'information');
42
+ const information = await fs.readFile(informationFile, 'utf8');
43
+ const match = DEVICE_MINOR_RE.exec(information);
44
+ return match ? Number(match[1]) : undefined;
45
+ }
46
+ catch {
47
+ return undefined;
48
+ }
49
+ }
50
+ /** `<pid> (<command>)` when the process has `deviceFile` open; undefined otherwise. */
51
+ async function describeIfHolding(pid, deviceFile, procRoot) {
52
+ const fdDir = path.join(procRoot, pid, 'fd');
53
+ let fds;
54
+ try {
55
+ fds = await fs.readdir(fdDir);
56
+ }
57
+ catch {
58
+ return undefined; // gone, or not ours to read
59
+ }
60
+ for (const fd of fds) {
61
+ const target = await fs.readlink(path.join(fdDir, fd)).catch(() => undefined);
62
+ if (target === deviceFile)
63
+ return `${pid} (${await readCommand(pid, procRoot)})`;
64
+ }
65
+ return undefined;
66
+ }
67
+ async function readCommand(pid, procRoot) {
68
+ try {
69
+ return (await fs.readFile(path.join(procRoot, pid, 'comm'), 'utf8')).trim();
70
+ }
71
+ catch {
72
+ return 'unknown';
73
+ }
74
+ }
@@ -0,0 +1,7 @@
1
+ /** Reads the NUMA node of a PCI device. Injectable for tests. */
2
+ export type PciNumaNodeReader = (bdf: string) => number | undefined;
3
+ /**
4
+ * The NUMA node a PCI device is on, from sysfs; undefined on a single-node host (-1) or one
5
+ * that does not say.
6
+ */
7
+ export declare function readPciNumaNode(bdf: string, devicesDir?: string): number | undefined;
@@ -0,0 +1,18 @@
1
+ import { readFileSync } from 'fs';
2
+ import path from 'path';
3
+ import { SYSFS_PCI_ROOT } from './hostDevices.js';
4
+ /** Where sysfs lists PCI devices. */
5
+ const SYSFS_PCI_DEVICES = path.join(SYSFS_PCI_ROOT, 'devices');
6
+ /**
7
+ * The NUMA node a PCI device is on, from sysfs; undefined on a single-node host (-1) or one
8
+ * that does not say.
9
+ */
10
+ export function readPciNumaNode(bdf, devicesDir = SYSFS_PCI_DEVICES) {
11
+ try {
12
+ const node = Number(readFileSync(`${devicesDir}/${bdf}/numa_node`, 'utf8').trim());
13
+ return Number.isInteger(node) && node >= 0 ? node : undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
@@ -0,0 +1,21 @@
1
+ /** A PCI device and the driver it is bound to; none when undefined. */
2
+ interface PciFunction {
3
+ device: string;
4
+ driver?: string;
5
+ }
6
+ /** The driver a PCI device is bound to; undefined when it has none. */
7
+ export declare function readPciDriver(pciRoot: string, device: string): string | undefined;
8
+ /** The PCI slot of a device: its BDF without the function (`0000:01:00.0` → `0000:01:00`). */
9
+ export declare function pciSlot(bdf: string): string;
10
+ /** Whether a device is a function of that slot. */
11
+ export declare function isInSlot(device: string, slot: string): boolean;
12
+ /** Every function of the GPU's PCI slot (the GPU and its HDMI audio), in BDF order. */
13
+ export declare function readSlotFunctions(pciRoot: string, gpu: string): PciFunction[];
14
+ /**
15
+ * The paths of a vfio-pci device's VFIO nodes (`<vfioDevicesDir>/vfioN`), as sysfs names them
16
+ * under its `vfio-dev`. None for a device off vfio-pci, or on a kernel without VFIO cdev.
17
+ */
18
+ export declare function readVfioDeviceNodes(pciRoot: string, vfioDevicesDir: string, device: string): string[];
19
+ /** Why a vfio-pci GPU has no VFIO node: the kernel lacks what iommufd passthrough opens. */
20
+ export declare function missingVfioNodeMessage(gpu: string): string;
21
+ export {};
@@ -0,0 +1,47 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ /** The driver a PCI device is bound to; undefined when it has none. */
4
+ export function readPciDriver(pciRoot, device) {
5
+ try {
6
+ return path.basename(fs.readlinkSync(path.join(pciRoot, 'devices', device, 'driver')));
7
+ }
8
+ catch {
9
+ return undefined;
10
+ }
11
+ }
12
+ /** The PCI slot of a device: its BDF without the function (`0000:01:00.0` → `0000:01:00`). */
13
+ export function pciSlot(bdf) {
14
+ return bdf.slice(0, bdf.lastIndexOf('.'));
15
+ }
16
+ /** Whether a device is a function of that slot. */
17
+ export function isInSlot(device, slot) {
18
+ return device.startsWith(`${slot}.`);
19
+ }
20
+ /** Every function of the GPU's PCI slot (the GPU and its HDMI audio), in BDF order. */
21
+ export function readSlotFunctions(pciRoot, gpu) {
22
+ const slot = pciSlot(gpu);
23
+ return readDirNames(path.join(pciRoot, 'devices'))
24
+ .filter((device) => isInSlot(device, slot))
25
+ .sort()
26
+ .map((device) => ({ device, driver: readPciDriver(pciRoot, device) }));
27
+ }
28
+ /**
29
+ * The paths of a vfio-pci device's VFIO nodes (`<vfioDevicesDir>/vfioN`), as sysfs names them
30
+ * under its `vfio-dev`. None for a device off vfio-pci, or on a kernel without VFIO cdev.
31
+ */
32
+ export function readVfioDeviceNodes(pciRoot, vfioDevicesDir, device) {
33
+ return readDirNames(path.join(pciRoot, 'devices', device, 'vfio-dev')).map((name) => path.join(vfioDevicesDir, name));
34
+ }
35
+ /** Why a vfio-pci GPU has no VFIO node: the kernel lacks what iommufd passthrough opens. */
36
+ export function missingVfioNodeMessage(gpu) {
37
+ return (`GPU ${gpu} has no VFIO device node: QEMU's iommufd passthrough needs a kernel with ` +
38
+ 'VFIO cdev support (CONFIG_VFIO_DEVICE_CDEV, Linux 6.6 or newer)');
39
+ }
40
+ function readDirNames(dir) {
41
+ try {
42
+ return fs.readdirSync(dir);
43
+ }
44
+ catch {
45
+ return [];
46
+ }
47
+ }
@@ -0,0 +1,37 @@
1
+ import { type ChildProcess, type SpawnOptions } from 'child_process';
2
+ /** Spawn a process (QEMU, socat). Injectable so tests don't launch a real hypervisor. */
3
+ export type SpawnLike = (command: string, args: string[], options: SpawnOptions) => ChildProcess;
4
+ /** Run a process to completion (qemu-img, the ISO tool). Injectable for tests. */
5
+ export type RunLike = (command: string, args: string[]) => Promise<void>;
6
+ /** Run a process to completion, resolving with its stdout (`qemu-img info`). */
7
+ export type RunForOutput = (command: string, args: string[]) => Promise<string>;
8
+ /** Signal a process (a negative pid: its process group). Injectable for tests. */
9
+ export type KillLike = (pid: number, signal: NodeJS.Signals) => void;
10
+ /** Run a process to completion; rejects when it fails. */
11
+ export declare function runToCompletion(command: string, args: string[]): Promise<void>;
12
+ /** Run a process to completion and resolve with its stdout. */
13
+ export declare function runForOutput(command: string, args: string[]): Promise<string>;
14
+ /** Signal a real process. */
15
+ export declare function killPid(pid: number, signal: NodeJS.Signals): void;
16
+ /** Is a process with this pid alive? EPERM means "alive, just not ours". */
17
+ export declare function isPidAlive(pid: number): boolean;
18
+ /**
19
+ * Spawn a process that outlives this one: its own session (`detached`, so no
20
+ * signal to the node's process group or terminal reaches it), its output
21
+ * appended to `logPath`, and not keeping this process's event loop alive. The
22
+ * log is opened and closed synchronously so the child's 'error' event cannot
23
+ * fire before the caller listens for it.
24
+ */
25
+ export declare function spawnDetached(spawn: SpawnLike, command: string, args: string[], logPath: string): ChildProcess;
26
+ /** SIGKILL a process; one already gone is not an error. */
27
+ export declare function killProcess(kill: KillLike, pid: number): void;
28
+ /** SIGKILL a detached process with the children it forked (its process group). */
29
+ export declare function killProcessGroup(kill: KillLike, pid: number): void;
30
+ /** Has a child this process spawned exited (been reaped)? */
31
+ export declare function hasExited(child: ChildProcess): boolean;
32
+ /** Resolves with a child's exit code once it has exited (been reaped). */
33
+ export declare function childExit(child: ChildProcess): Promise<number | null>;
34
+ /** Read a pid's command line (Linux procfs); undefined when unknowable. */
35
+ export declare function procCmdline(pid: number | string): Promise<string | undefined>;
36
+ /** Every process's command line (Linux procfs); undefined when /proc cannot be listed. */
37
+ export declare function procCommandLines(): Promise<string[] | undefined>;
@@ -0,0 +1,102 @@
1
+ import { execFile } from 'child_process';
2
+ import { once } from 'events';
3
+ import { closeSync, openSync } from 'fs';
4
+ import fs from 'fs/promises';
5
+ import { promisify } from 'util';
6
+ import { describeError } from './util.js';
7
+ const execFileAsync = promisify(execFile);
8
+ /** Run a process to completion; rejects when it fails. */
9
+ export async function runToCompletion(command, args) {
10
+ await execFileAsync(command, args);
11
+ }
12
+ /** Run a process to completion and resolve with its stdout. */
13
+ export async function runForOutput(command, args) {
14
+ return (await execFileAsync(command, args)).stdout;
15
+ }
16
+ /** Signal a real process. */
17
+ export function killPid(pid, signal) {
18
+ process.kill(pid, signal);
19
+ }
20
+ /** Is a process with this pid alive? EPERM means "alive, just not ours". */
21
+ export function isPidAlive(pid) {
22
+ try {
23
+ process.kill(pid, 0);
24
+ return true;
25
+ }
26
+ catch (error) {
27
+ return describeError(error).code === 'EPERM';
28
+ }
29
+ }
30
+ /**
31
+ * Spawn a process that outlives this one: its own session (`detached`, so no
32
+ * signal to the node's process group or terminal reaches it), its output
33
+ * appended to `logPath`, and not keeping this process's event loop alive. The
34
+ * log is opened and closed synchronously so the child's 'error' event cannot
35
+ * fire before the caller listens for it.
36
+ */
37
+ export function spawnDetached(spawn, command, args, logPath) {
38
+ const fd = openSync(logPath, 'a');
39
+ try {
40
+ const child = spawn(command, args, { detached: true, stdio: ['ignore', fd, fd] });
41
+ child.unref();
42
+ return child;
43
+ }
44
+ finally {
45
+ closeSync(fd);
46
+ }
47
+ }
48
+ /** SIGKILL a process; one already gone is not an error. */
49
+ export function killProcess(kill, pid) {
50
+ try {
51
+ kill(pid, 'SIGKILL');
52
+ }
53
+ catch {
54
+ // already gone
55
+ }
56
+ }
57
+ /** SIGKILL a detached process with the children it forked (its process group). */
58
+ export function killProcessGroup(kill, pid) {
59
+ try {
60
+ kill(-pid, 'SIGKILL');
61
+ }
62
+ catch {
63
+ killProcess(kill, pid);
64
+ }
65
+ }
66
+ /** Has a child this process spawned exited (been reaped)? */
67
+ export function hasExited(child) {
68
+ return child.exitCode != null || child.signalCode != null;
69
+ }
70
+ /** Resolves with a child's exit code once it has exited (been reaped). */
71
+ export async function childExit(child) {
72
+ if (hasExited(child))
73
+ return child.exitCode;
74
+ const [code] = await once(child, 'exit');
75
+ return code;
76
+ }
77
+ /** Read a pid's command line (Linux procfs); undefined when unknowable. */
78
+ export async function procCmdline(pid) {
79
+ try {
80
+ const raw = await fs.readFile(`/proc/${pid}/cmdline`, 'utf8');
81
+ return raw.replaceAll('\0', ' ');
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ }
87
+ /** Every process's command line (Linux procfs); undefined when /proc cannot be listed. */
88
+ export async function procCommandLines() {
89
+ const pids = await listPids();
90
+ if (!pids)
91
+ return undefined;
92
+ const lines = await Promise.all(pids.map(procCmdline));
93
+ return lines.filter((line) => line !== undefined);
94
+ }
95
+ async function listPids() {
96
+ try {
97
+ return (await fs.readdir('/proc')).filter((entry) => /^\d+$/.test(entry));
98
+ }
99
+ catch {
100
+ return undefined;
101
+ }
102
+ }