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; infix, what changes that, naming the setting, variable or command, and for a setting its value and where it was set.
- pub const Mount = struct[source][autodoc]¶
A line of
/proc/self/mountinfo: where the file system is mounted, its type, and its mount options.
- pub const JobRoot = struct[source][autodoc]¶
The allocation’s node-local mount that
jobRootchecked.
- pub const NodeLocal = struct[source][autodoc]¶
The site file’s node-local settings, each with where it was set, as
eb-local configshows it.
- pub const LockedWorkspace = struct[source][autodoc]¶
A newly created workspace directory and its held
.eb-local.lockdescriptor.
- pub const Capacity = struct[source][autodoc]¶
Capacity available to an unprivileged caller.
- pub const WorkspaceProbe = struct[source][autodoc]¶
Result of creating, writing, renaming, executing and removing one probe.
- pub const CancelLockResult = union(enum)[source][autodoc]¶
Outcome of acquiring a bounded exclusive lock with signal cancellation.
- pub const LockCancel = struct[source][autodoc]¶
Captures non-ignored termination signals while waiting on a contended lock so
acquireBoundedLockCancelaborts immediately and the caller can clean up.- 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.
Error sets¶
Functions¶
- pub fn describeError(e: anyerror) []const u8[source][autodoc]¶
Format
ewith its kernel errno when it maps tosys.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
pathlies on: the last entry (a later mount covers an earlier one) whose target ispathor a parent of it.
- pub fn canonical(a: Allocator, path: []const u8, cwd: []const u8) Allocator.Error![]const u8[source][autodoc]¶
pathmade absolute and normal asreadlink -mdoes. A symbolic link is resolved even when its target does not exist yet, solink/..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 whatreadlink -mprints, instead of being walked forever.
- pub fn under(path: []const u8, root: []const u8) bool[source][autodoc]¶
Whether
pathisrootor 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
pathand everything under it that is ondev. A mount point, whose device differs, is left in place, asrm --one-file-systemdoes. Symbolic links are removed, not followed.
- pub fn removeTree(a: Allocator, path: []const u8) (fsx.Error || Allocator.Error)!void[source][autodoc]¶
Remove
pathand everything under it on its own file system, asremoveTreeDevicedoes for the devicepathis 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_rootwhose.eb-local.lockand subdirectories exist and are locked beforeeb-local.XXXXXXXXbecomes visible toclean --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_resultis 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
erepresents an unsupportedflockoperation 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_pathwithout following symlinks and hold an exclusive lock viacommon.state.lockExclusivewith a bounded timeout. Whennotifyis true and another process holds the lock, prints one waiting line on stderr before waiting. Whenflockis unsupported (ENOLCK,ENOTSUP,EOPNOTSUPP,ENOSYS), prints one warning on stderr whennotifyis 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.canceledwhencancelis set while waiting on a contended lock viacommon.state.lockExclusiveCancel.
- pub fn acquireOptionalLock(path: []const u8) ?sys.fd_t[source][autodoc]¶
Acquire a non-blocking exclusive lock on
pathwithout 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
acquireBoundedLockoracquireOptionalLock. The descriptor is closed whateverLOCK_UNreturns; a failedLOCK_UNis then returned, as Python’sfcntl.flockraises it, withsys.last_errnoits errno.
- pub fn releaseLockAfterError(lock: *?sys.fd_t) void[source][autodoc]¶
releaseLockin cleanup after another failure. A failed release is dropped andsys.last_errnois 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]¶
eas thesys.Errora failed write returns, withlast_errnoset 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
EIOfor.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_errnoits 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.
Constants¶
Variables¶
- pub var test_flock_errno: ?linux.E = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_FLOCK_ERRNO, only in the test artifact, so a test can emulateENOLCKorEOPNOTSUPPfromflock.
- pub var test_release_errno: ?linux.E = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_RELEASE_ERRNO, only in the test artifact, and by unit tests, so theLOCK_UNof every release fails with that errno.
- pub var test_close_errno: ?linux.E = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_CLOSE_ERRNO, only in the test artifact, so eachcloseWrittenafter the firsttest_close_aftercloses its descriptor and then fails with that errno.testErrnorefuses EINTR, whichcloseWrittencounts as a success.
- pub var test_close_after: u32 = 0[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_CLOSE_AFTER: how many calls ofcloseWrittensucceed beforetest_close_errnoapplies.
- pub var test_close_count: ?u32 = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_CLOSE_COUNT: how many calls ofcloseWrittenfail oncetest_close_errnoapplies; the calls after them succeed. Null fails every one.
- pub var test_fsync_errno: ?linux.E = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_FSYNC_ERRNO, only in the test artifact, so eachfsyncWrittenafter the firsttest_fsync_afterfails with that errno without syncing.testErrnorefuses EINTR, whichfsyncWrittenwould retry without end.
- pub var test_fsync_after: u32 = 0[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_FSYNC_AFTER: how many calls offsyncWrittensucceed beforetest_fsync_errnoapplies.
- pub var test_fsync_count: ?u32 = null[source][autodoc]¶
Set in
mainfromEB_LOCAL_TEST_FSYNC_COUNT: how many calls offsyncWrittenfail oncetest_fsync_errnoapplies; the calls after them succeed. Null fails every one.
- pub var test_prefix_errno: ?linux.E = null[source][autodoc]¶
Set in
mainfromEB_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
mainfromEB_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
mainfromEB_LOCAL_TEST_REDACT_ERRNO. Replacing a log during redaction fails with this errno.