Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# that change it and for each release.
#
# The parts of `cargo xtask check` run at once, each in a job of its own, and
# "cargo xtask check" passes once they all have: that check and "cargo xtask
# "cargo xtask check" passes once they all have, and fctl for macOS has
# passed Clippy on a Mac: that check and "cargo xtask
# dev --smoke" are the ones main's ruleset requires (.github/rulesets). The
# jobs run xtask's binary, which .github/actions/xtask takes from a cache when
# nothing it is built from changed. On main, the Worker's release build runs
Expand Down Expand Up @@ -74,11 +75,23 @@ jobs:
- run: npm ci --no-audit --no-fund
- run: xtask check web

# fctl for macOS, which only the Release workflow built before: code for
# Linux alone (the firecracker driver's fallocate, O_PATH and nodev) broke
# v0.30.2's release. Clippy for the host's Mac, its tests included.
macos:
name: fctl on macOS
runs-on: macos-15
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/rust
- run: cargo clippy --locked -p fctl -p fctl-host --all-targets -- -D warnings

# A skipped job would count as passed, so this one runs when a part fails
# too (unless the run was cancelled), and fails unless they all passed.
check:
name: cargo xtask check
needs: [lint, test, web]
needs: [lint, test, web, macos]
if: ${{ !cancelled() }}
runs-on: ubuntu-24.04
timeout-minutes: 5
Expand All @@ -88,9 +101,11 @@ jobs:
LINT: ${{ needs.lint.result }}
TEST: ${{ needs.test.result }}
WEB: ${{ needs.web.result }}
MACOS: ${{ needs.macos.result }}
run: |
echo "lint: $LINT, test: $TEST, web: $WEB"
[ "$LINT" = success ] && [ "$TEST" = success ] && [ "$WEB" = success ]
echo "lint: $LINT, test: $TEST, web: $WEB, macos: $MACOS"
[ "$LINT" = success ] && [ "$TEST" = success ] && [ "$WEB" = success ] \
&& [ "$MACOS" = success ]

# Nothing else runs the control plane before it deploys: this applies the
# migrations to a fresh local D1, starts the Worker, bootstraps an owner,
Expand Down
17 changes: 8 additions & 9 deletions crates/fctl-host/src/docker_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! it ([`regroup`]).

use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

/// Where the docker CLI finds the daemon when `DOCKER_HOST` doesn't say.
pub const DEFAULT_SOCKET: &str = "/var/run/docker.sock";
Expand Down Expand Up @@ -362,23 +362,22 @@ pub fn status_groups(status: &str) -> Vec<u32> {
.collect()
}

/// Whether the socket at `path` refuses this process.
#[cfg(unix)]
fn denied(path: &Path) -> bool {
std::os::unix::net::UnixStream::connect(path)
.is_err_and(|e| e.kind() == std::io::ErrorKind::PermissionDenied)
}

#[cfg(target_os = "linux")]
mod linux {
use super::{Facts, REGROUPED, denied, exec_line};
use super::{Facts, REGROUPED, exec_line};
use nix::sys::signal::Signal;
use nix::unistd::{Gid, Group, User, getegid, getgroups, getppid, getuid};
use std::os::unix::fs::MetadataExt;
use std::os::unix::process::CommandExt;
use std::path::{Path, PathBuf};
use std::process::Stdio;

/// Whether the socket at `path` refuses this process.
fn denied(path: &Path) -> bool {
std::os::unix::net::UnixStream::connect(path)
.is_err_and(|e| e.kind() == std::io::ErrorKind::PermissionDenied)
}

/// How `sg` started this process, from [`REGROUPED`]: in its own place
/// (`InPlace`), or as its child, which it waits for (`Child`).
#[derive(Debug, PartialEq, Eq)]
Expand Down
28 changes: 21 additions & 7 deletions crates/fctl-host/src/driver/firecracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ async fn binary_version(firecracker: &Path) -> Result<String> {
/// Gives back the disk that the pages of zeros in the first `len` bytes of
/// the file at `path` take, which most of a VM's saved memory is.
fn punch_zeros(path: &Path, len: u64) -> Result<()> {
use nix::fcntl::{FallocateFlags, fallocate};
use std::os::unix::fs::FileExt;
const PAGE: usize = 4096;
let file = std::fs::OpenOptions::new()
Expand All @@ -304,12 +303,7 @@ fn punch_zeros(path: &Path, len: u64) -> Result<()> {
let (Ok(start), Ok(len)) = (i64::try_from(start), i64::try_from(end - start)) else {
return Ok(());
};
fallocate(
&file,
FallocateFlags::FALLOC_FL_PUNCH_HOLE | FallocateFlags::FALLOC_FL_KEEP_SIZE,
start,
len,
)
punch_hole(&file, start, len)
};
let mut buf = vec![0u8; 1 << 20];
let mut offset = 0u64;
Expand Down Expand Up @@ -340,6 +334,26 @@ fn punch_zeros(path: &Path, len: u64) -> Result<()> {
Ok(())
}

/// Gives back the disk under `len` bytes of `file` from `start`, keeping its
/// size.
#[cfg(target_os = "linux")]
fn punch_hole(file: &std::fs::File, start: i64, len: i64) -> nix::Result<()> {
use nix::fcntl::{FallocateFlags, fallocate};
fallocate(
file,
FallocateFlags::FALLOC_FL_PUNCH_HOLE | FallocateFlags::FALLOC_FL_KEEP_SIZE,
start,
len,
)
}

/// Firecracker runs only on Linux, which alone has `fallocate`: elsewhere
/// (fctl for macOS still builds this driver) the zeros stay.
#[cfg(not(target_os = "linux"))]
fn punch_hole(_file: &std::fs::File, _start: i64, _len: i64) -> nix::Result<()> {
Ok(())
}

impl FirecrackerDriver {
pub fn new(host: &HostConfig) -> Self {
let root = host.data_dir().join("firecracker");
Expand Down
29 changes: 24 additions & 5 deletions crates/fctl-host/src/driver/firecracker/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl Vm {
loop {
let opened = std::fs::OpenOptions::new()
.read(true)
.custom_flags(nix::libc::O_PATH | nix::libc::O_NOFOLLOW)
.custom_flags(O_PATH | nix::libc::O_NOFOLLOW)
.open(root.join(name));
match opened {
Ok(file) => {
Expand Down Expand Up @@ -1239,9 +1239,7 @@ pub fn jails_problem(jails: &Path) -> Option<String> {
while !at.exists() {
at = at.parent()?;
}
if nix::sys::statvfs::statvfs(at)
.is_ok_and(|v| v.flags().contains(nix::sys::statvfs::FsFlags::ST_NODEV))
{
if nodev(at) {
return Some(format!(
"the VMs' jails need a filesystem that allows device files, and {} is on one mounted nodev: move data_dir in host.toml, or set jailer = false in its [firecracker]",
jails.display()
Expand All @@ -1250,6 +1248,27 @@ pub fn jails_problem(jails: &Path) -> Option<String> {
None
}

/// Whether the filesystem `at` is on is mounted `nodev`.
#[cfg(target_os = "linux")]
fn nodev(at: &Path) -> bool {
nix::sys::statvfs::statvfs(at)
.is_ok_and(|v| v.flags().contains(nix::sys::statvfs::FsFlags::ST_NODEV))
}

/// Only Linux says (fctl for macOS still builds this driver, which never
/// runs there).
#[cfg(not(target_os = "linux"))]
fn nodev(_at: &Path) -> bool {
false
}

/// `O_PATH`, which only Linux has: elsewhere (fctl for macOS still builds
/// this driver, which never runs there) the files are opened without it.
#[cfg(target_os = "linux")]
const O_PATH: nix::libc::c_int = nix::libc::O_PATH;
#[cfg(not(target_os = "linux"))]
const O_PATH: nix::libc::c_int = 0;

/// The jails' lock, under which a jail's uid is picked and taken; other
/// processes' VMs (`fctl host image pull`'s) take it too.
fn lock_jails(jails: &Path) -> Result<JailsLock> {
Expand Down Expand Up @@ -1367,7 +1386,7 @@ fn take_out(root: &Path, uid: u32, name: &str, to: &Path) -> Result<()> {
use std::os::unix::fs::{MetadataExt, OpenOptionsExt, PermissionsExt};
let file = std::fs::OpenOptions::new()
.read(true)
.custom_flags(nix::libc::O_PATH | nix::libc::O_NOFOLLOW)
.custom_flags(O_PATH | nix::libc::O_NOFOLLOW)
.open(root.join(name))
.with_context(|| format!("opening the {name} Firecracker saved in the VM's jail"))?;
let meta = file.metadata()?;
Expand Down
10 changes: 10 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ instead: xtask's binary (`.github/actions/xtask`), which the jobs run as
which runs beside the checks for the deploy. Only `main` saves caches;
pull requests use `main`'s.

CI also runs Clippy over `fctl` and `fctl-host` on a Mac (the "fctl on
macOS" job), and `cargo xtask check` waits for it: the release builds fctl
for macOS, and code that only Linux has (`O_PATH`, `fallocate`, the
firecracker driver's) needs `#[cfg(target_os = "linux")]` there. To check
from Linux, `rustup target add aarch64-apple-darwin`, then `cargo clippy
-p fctl -p fctl-host --target aarch64-apple-darwin`; `ring`'s build script
needs a C compiler for macOS, such as zig's (`python3 -m ziglang cc -target
aarch64-macos`, without the `-arch` and `-mmacosx-version-min` flags cc
passes it) in `CC_aarch64_apple_darwin`.

The Standalone image workflow (`.github/workflows/standalone-image.yml`)
builds the standalone control plane's image, starts it and runs `cargo
xtask dev --smoke --server` against it, so the container, its migrations
Expand Down
Loading