# eb-local.vm ::::{zig:module} eb-local.vm :file: src/vm.zig :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig `eb-local __vm-run`: run a command under a virtual CPU that presents an EESSI CPU target. An internal helper, absent from `--help`. `--mode kvm` boots the host kernel under QEMU with KVM, a named CPU model per target and `enforce`; the guest's root is the host's, read-only over virtiofs, with /cvmfs and the build directories shared. `--mode tcg` runs the command in qemu user mode with `QEMU_CPU` set, for a target of another architecture. Before the command starts, the guest checks that EESSI archdetect, archspec, `gcc -march=native` (or `-mcpu=native`), the CPU vendor and /dev/fd all name the target, and the helper refuses when one does not. :::: ## Types ::::{zig:type} eb-local.vm.Mode :signature: pub const Mode = enum :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L36 The kind of virtual CPU: KVM for the host's architecture, qemu user mode for the other. :::{zig:field} eb-local.vm.Mode.kvm :signature: kvm :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L36 ::: :::{zig:field} eb-local.vm.Mode.tcg :signature: tcg :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L36 ::: :::: ::::{zig:type} eb-local.vm.Arch :signature: pub const Arch = enum :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L38 The CPU architectures a target can have. :::{zig:field} eb-local.vm.Arch.x86_64 :signature: x86_64 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L38 ::: :::{zig:field} eb-local.vm.Arch.aarch64 :signature: aarch64 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L38 ::: :::: ::::{zig:type} eb-local.vm.Target :signature: pub const Target = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L53 An EESSI CPU target, what each detector must call it, and the QEMU CPU that presents it. :::{zig:field} eb-local.vm.Target.name :signature: name: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L55 The EESSI software subdirectory. ::: :::{zig:field} eb-local.vm.Target.arch :signature: arch: Arch :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L56 ::: :::{zig:field} eb-local.vm.Target.vendor :signature: vendor: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L58 `vendor_id` on x86_64, `CPU implementer` on aarch64. ::: :::{zig:field} eb-local.vm.Target.archspec :signature: archspec: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L60 archspec's name for the CPU. ::: :::{zig:field} eb-local.vm.Target.gcc :signature: gcc: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L63 What `gcc -march=native` (x86_64) or `-mcpu=native` (aarch64) names, as space-separated alternatives. ::: :::{zig:field} eb-local.vm.Target.kvm :signature: kvm: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L65 The `-cpu` value, without `enforce`, under KVM. ::: :::{zig:field} eb-local.vm.Target.kvm_refusal :signature: kvm_refusal: []const u8 = "" :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L66 ::: :::{zig:field} eb-local.vm.Target.tcg :signature: tcg: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L68 The `-cpu` value in qemu user mode. ::: :::{zig:field} eb-local.vm.Target.tcg_refusal :signature: tcg_refusal: []const u8 = "" :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L69 ::: :::: ::::{zig:type} eb-local.vm.Plan :signature: pub const Plan = union(enum) :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L103 What a mode does for a target on a host: the QEMU CPU, or the reason it cannot. :::{zig:field} eb-local.vm.Plan.kvm :signature: kvm: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L105 The `-cpu` value, `enforce` included. ::: :::{zig:field} eb-local.vm.Plan.tcg :signature: tcg: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L107 The `QEMU_CPU` value. ::: :::{zig:field} eb-local.vm.Plan.refused :signature: refused: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L108 ::: :::: ::::{zig:type} eb-local.vm.Request :signature: pub const Request = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L128 A command line after `__vm-run`. :::{zig:field} eb-local.vm.Request.mode :signature: mode: Mode :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L129 ::: :::{zig:field} eb-local.vm.Request.target :signature: target: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L130 ::: :::{zig:field} eb-local.vm.Request.memory_mib :signature: memory_mib: u32 = 8192 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L131 ::: :::{zig:field} eb-local.vm.Request.cpus :signature: cpus: ?u32 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L132 ::: :::{zig:field} eb-local.vm.Request.share :signature: share: []const []const u8 = &.{} :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L133 ::: :::{zig:field} eb-local.vm.Request.share_ro :signature: share_ro: []const []const u8 = &.{} :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L134 ::: :::{zig:field} eb-local.vm.Request.allow_archspec_mismatch :signature: allow_archspec_mismatch: bool = false :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L135 ::: :::{zig:field} eb-local.vm.Request.command :signature: command: []const []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L136 ::: :::: ::::{zig:type} eb-local.vm.Parsed :signature: pub const Parsed = union(enum) :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L140 The result of `parseArgs`. :::{zig:field} eb-local.vm.Parsed.ok :signature: ok: Request :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L141 ::: :::{zig:field} eb-local.vm.Parsed.bad :signature: bad: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L143 The message for stderr. ::: :::: ::::{zig:type} eb-local.vm.Share :signature: pub const Share = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L210 One virtiofs share: a daemon serving `host`, a device tagged `tag`. :::{zig:field} eb-local.vm.Share.tag :signature: tag: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L211 ::: :::{zig:field} eb-local.vm.Share.host :signature: host: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L212 ::: :::{zig:field} eb-local.vm.Share.guest :signature: guest: []const u8 = "" :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L215 Where the guest mounts it; empty for the root and the job directory, which the kernel and the init mount. ::: :::{zig:field} eb-local.vm.Share.readonly :signature: readonly: bool = true :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L216 ::: :::{zig:field} eb-local.vm.Share.cache :signature: cache: []const u8 = "always" :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L217 ::: :::: ::::{zig:type} eb-local.vm.KvmConfig :signature: pub const KvmConfig = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L221 What the guest's kernel command line and QEMU need. :::{zig:field} eb-local.vm.KvmConfig.qemu :signature: qemu: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L222 ::: :::{zig:field} eb-local.vm.KvmConfig.cpu :signature: cpu: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L223 ::: :::{zig:field} eb-local.vm.KvmConfig.cpus :signature: cpus: u32 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L224 ::: :::{zig:field} eb-local.vm.KvmConfig.memory_mib :signature: memory_mib: u32 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L225 ::: :::{zig:field} eb-local.vm.KvmConfig.kernel :signature: kernel: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L226 ::: :::{zig:field} eb-local.vm.KvmConfig.rundir :signature: rundir: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L227 ::: :::{zig:field} eb-local.vm.KvmConfig.shares :signature: shares: []const Share :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L228 ::: :::: ::::{zig:type} eb-local.vm.Job :signature: pub const Job = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L361 The values the job script exports for the verification and the command. :::{zig:field} eb-local.vm.Job.dir :signature: dir: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L363 The job directory as the command sees it. ::: :::{zig:field} eb-local.vm.Job.cwd :signature: cwd: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L364 ::: :::{zig:field} eb-local.vm.Job.t :signature: t: *const Target :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L365 ::: :::{zig:field} eb-local.vm.Job.eessi_version :signature: eessi_version: []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L366 ::: :::{zig:field} eb-local.vm.Job.allow_archspec_mismatch :signature: allow_archspec_mismatch: bool :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L367 ::: :::{zig:field} eb-local.vm.Job.gcc_bin :signature: gcc_bin: []const u8 = "" :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L368 ::: :::{zig:field} eb-local.vm.Job.env :signature: env: []const [2][]const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L370 Name and value of every variable the command receives. ::: :::{zig:field} eb-local.vm.Job.command :signature: command: []const []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L371 ::: :::: ::::{zig:type} eb-local.vm.Outcome :signature: pub const Outcome = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L401 What the guest left in the job directory. :::{zig:field} eb-local.vm.Outcome.refused :signature: refused: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L403 The `refused` file, when the verification refused. ::: :::{zig:field} eb-local.vm.Outcome.status :signature: status: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L405 The `status` file, when the guest init wrote one. ::: :::: ## Functions :::{zig:function} eb-local.vm.find :signature: pub fn find(name: []const u8) ?*const Target :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L96 The target named `name`, an EESSI software subdirectory. ::: :::{zig:function} eb-local.vm.plan :signature: pub fn plan(a: Allocator, t: *const Target, mode: Mode, host: Arch) Allocator.Error!Plan :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L112 What `mode` does for target `t` on a `host`: the QEMU CPU, or why it cannot. ::: :::{zig:function} eb-local.vm.parseArgs :signature: pub fn parseArgs(a: Allocator, args: []const []const u8) Allocator.Error!Parsed :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L163 Parse `--mode kvm|tcg --cpu-target TARGET [--memory MiB] [--cpus N] [--share DIR] [--share-ro DIR] [--allow-archspec-mismatch] -- COMMAND...`. ::: :::{zig:function} eb-local.vm.socketPath :signature: pub fn socketPath(a: Allocator, rundir: []const u8, tag: []const u8) Allocator.Error![]u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L232 The vhost-user socket of share `tag` in the job directory. ::: :::{zig:function} eb-local.vm.kernelCmdline :signature: pub fn kernelCmdline(a: Allocator, rundir: []const u8) Allocator.Error![]u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L238 The kernel command line: the host root over virtiofs, read-only, and the init in the job directory. ::: :::{zig:function} eb-local.vm.qemuArgv :signature: pub fn qemuArgv(a: Allocator, cfg: KvmConfig) Allocator.Error![]const []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L244 The QEMU command line. The CPU is the named model with `enforce`; no argument names the host CPU. ::: :::{zig:function} eb-local.vm.virtiofsdArgv :signature: pub fn virtiofsdArgv(a: Allocator, virtiofsd: []const u8, rundir: []const u8, s: Share) Allocator.Error![]const []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L282 The virtiofsd command line for share `s`: no sandbox, read-only when the share is. ::: :::{zig:function} eb-local.vm.mountsFile :signature: pub fn mountsFile(a: Allocator, shares: []const Share, cvmfs_root: bool) Allocator.Error![]u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L295 The guest init's `mounts` file: one line per mount, parent paths first. ::: :::{zig:function} eb-local.vm.dedupePaths :signature: pub fn dedupePaths(a: Allocator, paths: []const []const u8) Allocator.Error![]const []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L308 Drop each path that lies inside another one in the list, and repeats; sorted shortest first so that a parent is mounted before its children would be. ::: :::{zig:function} eb-local.vm.envForwarded :signature: pub fn envForwarded(name: []const u8) bool :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L328 Environment variables the command receives in the guest. ::: :::{zig:function} eb-local.vm.shellQuote :signature: pub fn shellQuote(a: Allocator, s: []const u8) Allocator.Error![]u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L348 `s` in single quotes for a POSIX shell. ::: :::{zig:function} eb-local.vm.jobScript :signature: pub fn jobScript(a: Allocator, j: Job) Allocator.Error![]u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L375 The script the guest runs as the caller: the environment, the working directory, the CPU check, then the command. ::: :::{zig:function} eb-local.vm.exitStatus :signature: pub fn exitStatus(o: Outcome) u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L411 The helper's exit status for what the guest reported. A refusal is 126 whatever else exists; a command's own status passes through; no report is a VM failure. ::: :::{zig:function} eb-local.vm.termStatus :signature: pub fn termStatus(raw: u32) u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L421 The status of a process the helper waited for: its exit code, or 128 plus the signal. ::: :::{zig:function} eb-local.vm.run :signature: pub fn run(a: Allocator, env: *const std.process.Environ.Map, cwd: []const u8, args: []const []const u8) u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L563 Run `request` and return the helper's exit status. ::: ## Constants :::{zig:constant} eb-local.vm.status_refused :signature: pub const status_refused: u8 = 2 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L28 Refused before anything started: usage, an unknown target, a target this mode cannot present, or a missing tool. ::: :::{zig:constant} eb-local.vm.status_failed :signature: pub const status_failed: u8 = 125 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L30 The VM or emulator failed, so the command did not report a status. ::: :::{zig:constant} eb-local.vm.status_unverified :signature: pub const status_unverified: u8 = 126 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L33 The guest checked the CPU view and it does not name the target; the command did not run. ::: :::{zig:constant} eb-local.vm.host_arch :signature: pub const host_arch: Arch = ... :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L41 The architecture this binary runs on. ::: :::{zig:constant} eb-local.vm.targets :signature: pub const targets = ... :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L80 Every target `__vm-run` knows. QEMU's EPYC-Milan lacks vaes and vpclmulqdq, which a real Milan has and EESSI archdetect requires for amd/zen3 (its spec line is "avx2 fma vaes"), so the zen3 line adds both. ::: :::{zig:constant} eb-local.vm.writable_vars :signature: pub const writable_vars = ... :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/vm.zig#L341 The variables whose values name directories the command writes. :::