eb-local.vm

module eb-local.vm  src/vm.zig[source][autodoc]

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

pub const Mode = enum[source][autodoc]

The kind of virtual CPU: KVM for the host’s architecture, qemu user mode for the other.

kvm[source]
tcg[source]
pub const Arch = enum[source][autodoc]

The CPU architectures a target can have.

x86_64[source]
aarch64[source]
pub const Target = struct[source][autodoc]

An EESSI CPU target, what each detector must call it, and the QEMU CPU that presents it.

name: []const u8[source]

The EESSI software subdirectory.

arch: Arch[source]
vendor: []const u8[source]

vendor_id on x86_64, CPU implementer on aarch64.

archspec: []const u8[source]

archspec’s name for the CPU.

gcc: []const u8[source]

What gcc -march=native (x86_64) or -mcpu=native (aarch64) names, as space-separated alternatives.

kvm: ?[]const u8 = null[source]

The -cpu value, without enforce, under KVM.

kvm_refusal: []const u8 = ""[source]
tcg: ?[]const u8 = null[source]

The -cpu value in qemu user mode.

tcg_refusal: []const u8 = ""[source]
pub const Plan = union(enum)[source][autodoc]

What a mode does for a target on a host: the QEMU CPU, or the reason it cannot.

kvm: []const u8[source]

The -cpu value, enforce included.

tcg: []const u8[source]

The QEMU_CPU value.

refused: []const u8[source]
pub const Request = struct[source][autodoc]

A command line after __vm-run.

mode: Mode[source]
target: []const u8[source]
memory_mib: u32 = 8192[source]
cpus: ?u32 = null[source]
share: []const []const u8 = &.{}[source]
share_ro: []const []const u8 = &.{}[source]
allow_archspec_mismatch: bool = false[source]
command: []const []const u8[source]
pub const Parsed = union(enum)[source][autodoc]

The result of parseArgs.

ok: Request[source]
bad: []const u8[source]

The message for stderr.

pub const Share = struct[source][autodoc]

One virtiofs share: a daemon serving host, a device tagged tag.

tag: []const u8[source]
host: []const u8[source]
guest: []const u8 = ""[source]

Where the guest mounts it; empty for the root and the job directory, which the kernel and the init mount.

readonly: bool = true[source]
cache: []const u8 = "always"[source]
pub const KvmConfig = struct[source][autodoc]

What the guest’s kernel command line and QEMU need.

qemu: []const u8[source]
cpu: []const u8[source]
cpus: u32[source]
memory_mib: u32[source]
kernel: []const u8[source]
rundir: []const u8[source]
shares: []const Share[source]
pub const Job = struct[source][autodoc]

The values the job script exports for the verification and the command.

dir: []const u8[source]

The job directory as the command sees it.

cwd: []const u8[source]
t: *const Target[source]
eessi_version: []const u8[source]
allow_archspec_mismatch: bool[source]
gcc_bin: []const u8 = ""[source]
env: []const [2][]const u8[source]

Name and value of every variable the command receives.

command: []const []const u8[source]
pub const Outcome = struct[source][autodoc]

What the guest left in the job directory.

refused: ?[]const u8 = null[source]

The refused file, when the verification refused.

status: ?[]const u8 = null[source]

The status file, when the guest init wrote one.

Functions

pub fn find(name: []const u8) ?*const Target[source][autodoc]

The target named name, an EESSI software subdirectory.

pub fn plan(a: Allocator, t: *const Target, mode: Mode, host: Arch) Allocator.Error!Plan[source][autodoc]

What mode does for target t on a host: the QEMU CPU, or why it cannot.

pub fn parseArgs(a: Allocator, args: []const []const u8) Allocator.Error!Parsed[source][autodoc]

Parse --mode kvm|tcg --cpu-target TARGET [--memory MiB] [--cpus N] [--share DIR] [--share-ro DIR] [--allow-archspec-mismatch] -- COMMAND....

pub fn socketPath(a: Allocator, rundir: []const u8, tag: []const u8) Allocator.Error![]u8[source][autodoc]

The vhost-user socket of share tag in the job directory.

pub fn kernelCmdline(a: Allocator, rundir: []const u8) Allocator.Error![]u8[source][autodoc]

The kernel command line: the host root over virtiofs, read-only, and the init in the job directory.

pub fn qemuArgv(a: Allocator, cfg: KvmConfig) Allocator.Error![]const []const u8[source][autodoc]

The QEMU command line. The CPU is the named model with enforce; no argument names the host CPU.

pub fn virtiofsdArgv(a: Allocator, virtiofsd: []const u8, rundir: []const u8, s: Share) Allocator.Error![]const []const u8[source][autodoc]

The virtiofsd command line for share s: no sandbox, read-only when the share is.

pub fn mountsFile(a: Allocator, shares: []const Share, cvmfs_root: bool) Allocator.Error![]u8[source][autodoc]

The guest init’s mounts file: one line per mount, parent paths first.

pub fn dedupePaths(a: Allocator, paths: []const []const u8) Allocator.Error![]const []const u8[source][autodoc]

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.

pub fn envForwarded(name: []const u8) bool[source][autodoc]

Environment variables the command receives in the guest.

pub fn shellQuote(a: Allocator, s: []const u8) Allocator.Error![]u8[source][autodoc]

s in single quotes for a POSIX shell.

pub fn jobScript(a: Allocator, j: Job) Allocator.Error![]u8[source][autodoc]

The script the guest runs as the caller: the environment, the working directory, the CPU check, then the command.

pub fn exitStatus(o: Outcome) u8[source][autodoc]

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.

pub fn termStatus(raw: u32) u8[source][autodoc]

The status of a process the helper waited for: its exit code, or 128 plus the signal.

pub fn run(a: Allocator, env: *const std.process.Environ.Map, cwd: []const u8, args: []const []const u8) u8[source][autodoc]

Run request and return the helper’s exit status.

Constants

pub const status_refused: u8 = 2[source][autodoc]

Refused before anything started: usage, an unknown target, a target this mode cannot present, or a missing tool.

pub const status_failed: u8 = 125[source][autodoc]

The VM or emulator failed, so the command did not report a status.

pub const status_unverified: u8 = 126[source][autodoc]

The guest checked the CPU view and it does not name the target; the command did not run.

pub const host_arch: Arch = ...[source][autodoc]

The architecture this binary runs on.

pub const targets = ...[source][autodoc]

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.

pub const writable_vars = ...[source][autodoc]

The variables whose values name directories the command writes.