eb-local.storage

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

Where a build may write: the allocation’s own node-local mount, and a durable installation prefix that is neither node-local nor shared scratch. Mounts are read from /proc/self/mountinfo.

Types

pub const Refusal = struct[source][autodoc]

Why a path was refused: in message, what was refused and why, as one clause; in fix, what changes that, naming the setting, variable or command, and for a setting its value and where it was set.

message: []const u8 = ""[source]
fix: []const u8 = ""[source]
pub const Mount = struct[source][autodoc]

A line of /proc/self/mountinfo: where the file system is mounted, its type, and its mount options.

target: []const u8[source]
fstype: []const u8[source]
options: []const u8[source]
pub const JobRoot = struct[source][autodoc]

The allocation’s node-local mount that jobRoot checked.

path: []const u8[source]
pub const NodeLocal = struct[source][autodoc]

The site file’s node-local settings, each with where it was set, as eb-local config shows it.

root: []const u8[source]
root_from: []const u8 = "default"[source]
mount: []const u8 = default_mount[source]
mount_from: []const u8 = "default"[source]
fstype: []const u8 = "xfs"[source]
fstype_from: []const u8 = "default"[source]
pub const LockedWorkspace = struct[source][autodoc]

A newly created workspace directory and its held .eb-local.lock descriptor.

path: []const u8[source]
lock: ?sys.fd_t[source]
pub const Capacity = struct[source][autodoc]

Capacity available to an unprivileged caller.

bytes: u64[source]
inodes: u64[source]

Free inodes; meaningful only while inodes_counted is true.

inodes_counted: bool = true[source]

False for a file system with no inode table to run out of. btrfs allocates inodes on demand and statfs reports zero total and zero free there, which is not a full file system.

pub fn exhausted(self: Capacity) bool[source][autodoc]

Whether nothing more can be written: no free bytes, or no free inodes on a file system that counts them.

pub const WorkspaceProbe = struct[source][autodoc]

Result of creating, writing, renaming, executing and removing one probe.

created: bool = false[source]
written: bool = false[source]
renamed: bool = false[source]
executed: bool = false[source]
removed: bool = false[source]
pub const LockResult = union(enum)[source][autodoc]

Outcome of acquiring a bounded exclusive lock.

held: sys.fd_t[source]
unlocked[source]
failed[source]
pub const CancelLockResult = union(enum)[source][autodoc]

Outcome of acquiring a bounded exclusive lock with signal cancellation.

held: sys.fd_t[source]
unlocked[source]
canceled[source]
failed[source]
pub const LockCancel = struct[source][autodoc]

Captures non-ignored termination signals while waiting on a contended lock so acquireBoundedLockCancel aborts immediately and the caller can clean up.

old: [lock_signals.len]linux.Sigaction[source]
pub fn hold() LockCancel[source][autodoc]

Install cancellation handlers for non-ignored termination signals.

pub fn release(lc: *const LockCancel) void[source][autodoc]

Restore the signal actions that were in effect before hold.

pub fn received(_: *const LockCancel) ?linux.SIG[source][autodoc]

Return the first guarded signal received since hold, or null.

pub fn flag(_: *const LockCancel) *const std.atomic.Value(bool)[source][autodoc]

Return the atomic cancellation flag observed by lockExclusiveCancel.

Error sets

pub const Error = error{Refused} || Allocator.Error[source][autodoc]

error.Refused when a path may not be used, with what and why in the Refusal.

Functions

pub fn describeError(e: anyerror) []const u8[source][autodoc]

Format e with its kernel errno when it maps to sys.Error, otherwise return the Zig error name.

pub fn mountOf(a: Allocator, mountinfo: []const u8, path: []const u8) Allocator.Error!?Mount[source][autodoc]

The mount path lies on: the last entry (a later mount covers an earlier one) whose target is path or a parent of it.

pub fn canonical(a: Allocator, path: []const u8, cwd: []const u8) Allocator.Error![]const u8[source][autodoc]

path made absolute and normal as readlink -m does. A symbolic link is resolved even when its target does not exist yet, so link/.. is the parent of the link’s target and a dangling link onto shared scratch is visible to the prefix check. A link cycle is kept as a literal component, which is what readlink -m prints, instead of being walked forever.

pub fn under(path: []const u8, root: []const u8) bool[source][autodoc]

Whether path is root or below it, compared by whole components; both are already canonical.

pub fn validMountPattern(p: []const u8) bool[source][autodoc]

A storage.node_local_mount: one file name of letters, digits, ‘.’, ‘_’, ‘-’, %u (the user) and %j (the job id). It must hold %j, so that each allocation has a mount of its own.

pub fn jobRoot( a: Allocator, nl: NodeLocal, job_id: []const u8, user: []const u8, mountinfo: []const u8, uid: linux.uid_t, r: *Refusal) Error!JobRoot[source][autodoc]

The allocation’s node-local mount: /, the mount name with the user and the job id filled in, an owned, writable, canonical directory that is its own mount of nl.fstype.

pub fn ownWorkspace(job_root: []const u8, path: []const u8, uid: linux.uid_t) bool[source][autodoc]

A workspace eb-local made: a real directory of the caller named eb-local.XXXXXXXX directly in the job mount.

pub fn removeTreeDevice(a: Allocator, path: []const u8, dev: u64) (fsx.Error || Allocator.Error)!void[source][autodoc]

Remove path and everything under it that is on dev. A mount point, whose device differs, is left in place, as rm --one-file-system does. Symbolic links are removed, not followed.

pub fn removeTree(a: Allocator, path: []const u8) (fsx.Error || Allocator.Error)!void[source][autodoc]

Remove path and everything under it on its own file system, as removeTreeDevice does for the device path is on.

pub fn makeWorkspace(a: Allocator, job_root: []const u8) (fsx.Error || Allocator.Error)![]const u8[source][autodoc]

A new eb-local.XXXXXXXX directory, mode 0700, in job_root.

pub fn makeLockedWorkspace(a: Allocator, job_root: []const u8, subdirs: []const []const u8) (fsx.Error || Allocator.Error)!LockedWorkspace[source][autodoc]

Create a workspace directory in job_root whose .eb-local.lock and subdirectories exist and are locked before eb-local.XXXXXXXX becomes visible to clean --workspaces.

pub fn capacity(path: []const u8) sys.Error!Capacity[source][autodoc]

Free bytes and inodes on the file system containing path.

pub fn hasMountOption(options: []const u8, wanted: []const u8) bool[source][autodoc]

Whether a mount option is present as one whole comma-separated word.

pub fn workspaceClass(path: []const u8, fstype: []const u8, shared_roots: []const []const u8) []const u8[source][autodoc]

Operational storage class for a workspace. Configured shared roots and network file systems are shared; other file systems are node-local.

pub fn probeWorkspace( io: std.Io, a: Allocator, path: []const u8, execute_result: ?bool) (fsx.Error || sys.Error || common.proc.Error || Allocator.Error)!WorkspaceProbe[source][autodoc]

Exercise the file operations a build workspace needs. execute_result is a test seam; null executes the renamed probe.

pub fn lockTimeoutMs(env: ?*const std.process.Environ.Map, err_msg: *[]const u8) ?u32[source][autodoc]

Resolve the lock wait timeout in milliseconds from EB_LOCAL_LOCK_TIMEOUT_MS.

pub fn flockUnsupported(e: sys.Error) bool[source][autodoc]

True when e represents an unsupported flock operation on this filesystem.

pub fn acquireBoundedLock(a: Allocator, lock_path: []const u8, timeout_ms: u32, notify: bool, err_msg: *[]const u8) LockResult[source][autodoc]

Open lock_path without following symlinks and hold an exclusive lock via common.state.lockExclusive with a bounded timeout. When notify is true and another process holds the lock, prints one waiting line on stderr before waiting. When flock is unsupported (ENOLCK, ENOTSUP, EOPNOTSUPP, ENOSYS), prints one warning on stderr when notify is true and returns .unlocked.

pub fn acquireBoundedLockCancel( a: Allocator, lock_path: []const u8, timeout_ms: u32, notify: bool, cancel: ?*const std.atomic.Value(bool), err_msg: *[]const u8) CancelLockResult[source][autodoc]

Like acquireBoundedLock, also returning .canceled when cancel is set while waiting on a contended lock via common.state.lockExclusiveCancel.

pub fn acquireOptionalLock(path: []const u8) ?sys.fd_t[source][autodoc]

Acquire a non-blocking exclusive lock on path without printing errors, returning null when it cannot be opened or locked.

pub fn releaseLock(lock: *?sys.fd_t) sys.Error!void[source][autodoc]

Release a lock descriptor returned by acquireBoundedLock or acquireOptionalLock. The descriptor is closed whatever LOCK_UN returns; a failed LOCK_UN is then returned, as Python’s fcntl.flock raises it, with sys.last_errno its errno.

pub fn releaseLockAfterError(lock: *?sys.fd_t) void[source][autodoc]

releaseLock in cleanup after another failure. A failed release is dropped and sys.last_errno is put back, so the earlier failure’s errno is the one its message describes.

pub fn takeWriteErrno() ?linux.E[source][autodoc]

The next EB_LOCAL_TEST_WRITE_ERRNO, or null. A release build cannot see it.

pub fn injectedSysError(e: linux.E) sys.Error[source][autodoc]

e as the sys.Error a failed write returns, with last_errno set so the message names that errno.

pub fn testErrno(name: []const u8) ?linux.E[source][autodoc]

The errno a close or fsync hook names, as EIO for .IO. Null for a name that is not an errno and for EINTR, which neither call reports.

pub fn closeWritten(fd: sys.fd_t) sys.Error!void[source][autodoc]

Close a descriptor this process wrote a file through. A failed close is returned, with sys.last_errno its errno, because NFS and some quota setups report a lost write only there. Linux frees the descriptor whatever close returns, so it is not closed again, and EINTR is not an error.

pub fn fsyncWritten(fd: sys.fd_t) sys.Error!void[source][autodoc]

fsync(2) of a file this process wrote, or of the directory that names it. A failure is returned, with sys.last_errno its errno.

pub fn tryLockFree(path: []const u8) bool[source][autodoc]

True when path is absent, unlocked, or on a filesystem without flock. A probe lock whose release fails counts as held, so clean keeps it.

Constants

pub const default_mount = "%u.%j"[source][autodoc]

storage.node_local_mount unless the site sets it: the user, a dot and the job id.

pub const default_lock_timeout_ms: u32 = 300_000[source][autodoc]

Default milliseconds to wait on a contended flock lock.

Variables

pub var test_flock_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_FLOCK_ERRNO, only in the test artifact, so a test can emulate ENOLCK or EOPNOTSUPP from flock.

pub var test_release_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_RELEASE_ERRNO, only in the test artifact, and by unit tests, so the LOCK_UN of every release fails with that errno.

pub var test_close_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_CLOSE_ERRNO, only in the test artifact, so each closeWritten after the first test_close_after closes its descriptor and then fails with that errno. testErrno refuses EINTR, which closeWritten counts as a success.

pub var test_close_after: u32 = 0[source][autodoc]

Set in main from EB_LOCAL_TEST_CLOSE_AFTER: how many calls of closeWritten succeed before test_close_errno applies.

pub var test_close_count: ?u32 = null[source][autodoc]

Set in main from EB_LOCAL_TEST_CLOSE_COUNT: how many calls of closeWritten fail once test_close_errno applies; the calls after them succeed. Null fails every one.

pub var test_fsync_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_FSYNC_ERRNO, only in the test artifact, so each fsyncWritten after the first test_fsync_after fails with that errno without syncing. testErrno refuses EINTR, which fsyncWritten would retry without end.

pub var test_fsync_after: u32 = 0[source][autodoc]

Set in main from EB_LOCAL_TEST_FSYNC_AFTER: how many calls of fsyncWritten succeed before test_fsync_errno applies.

pub var test_fsync_count: ?u32 = null[source][autodoc]

Set in main from EB_LOCAL_TEST_FSYNC_COUNT: how many calls of fsyncWritten fail once test_fsync_errno applies; the calls after them succeed. Null fails every one.

pub var test_prefix_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_PREFIX_ERRNO, only in the test artifact. The prefix writability check fails with this errno.

pub var test_logs_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_LOGS_ERRNO. The logs-directory writability check fails with this errno.

pub var test_redact_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_REDACT_ERRNO. Replacing a log during redaction fails with this errno.

pub var test_workspace_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_WORKSPACE_ERRNO. Creating a directory inside a new workspace fails with this errno, and the workspace is removed.

pub var test_write_errno: ?linux.E = null[source][autodoc]

Set in main from EB_LOCAL_TEST_WRITE_ERRNO. The next durable write fails with this errno. One write, then it is clear.