Commit Graph
503 Commits
Author SHA1 Message Date
jwhur b770cd2a02 Add stat RPC (#614)
Add `Stat` RPC to vminitd.

`Stat` RPC is used to stat file system objects in the VM. It accepts the
path to the object (resolved against VM root) and returns the stat
result.
2026-04-27 14:44:33 -07:00
Michael Crosby 59f599eed5 allow filter of descriptors on push (#703)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-04-27 16:57:20 -04:00
Danny Canter 46c8fd3269 LinuxContainer/LinuxPod: Expose withVirtualMachineInstance (#701) 2026-04-27 12:17:12 -07:00
Danny Canter 0891bf399d OCI: Change hook to hooks (#702) 2026-04-27 11:47:36 -07:00
Dmitry Kovba 41ffd07f3e Add a default route to the first interface only (#697)
Adds a default route to the first interface only.
2026-04-23 11:05:25 -04:00
Dmitry Kovba bbea928c9e Add a public constructor to HTTP2ConnectBufferingHandler.swift (#695)
Adds a public constructor to `HTTP2ConnectBufferingHandler.swift`. This
is a follow-up to https://github.com/apple/containerization/pull/694.
2026-04-21 15:57:25 -07:00
Aditya Ramani 7874529578 Make HTTP2ConnectBufferingHandler public temporarily (#694)
Make the `HTTP2ConnectBufferingHandler` class public temporarily so that
consumers of the containerization package may reuse it for other grpc
clients.
2026-04-21 15:29:37 -07:00
J Logan f1ee6f8b73 Adds journal modes to EXT4.Formatter. (#689)
- Closes #671.
- Adds optional journal parameter to `EXT4.Formatter.init()`, with nil
default specifying the current no-journal filesystem configuration.
Otherwise the parameter value contains the journal size and mode.
- `minDiskSize` parameter for formatter init specifies the minimum
usable capacity of the resulting filesystem. The resulting disk image
grows past this value to accommodate the filesystem on-disk structures,
including the journal if specified.
2026-04-21 12:25:09 -07:00
J Logan 325d33a881 Update to use static SDK 6.3.0. (#691)
- Setting 6.3 in the .swift-version is pulling in 6.3.1 but we can't go
there until there is a docker image for it, or Linux build breaks.
Alternatively we'd need to have different Swift SDKs for Linux musl
build vs macOS.
2026-04-19 08:49:46 -07:00
Danny Canter fdd66283ce Epoll: Unit tests (#688)
Now that we can run this project on linux, lets add some unit tests for
the surfaces that don't..

This additionally changes delete to throw in most cases. I don't really
see how masking these errors is ideal.
2026-04-16 15:33:54 -07:00
Danny Canter 0f4c8cf592 Make unit tests runnable on Linux (#686)
Closes #606

This lets the unit tests be runnable on linux. The change:

- Adds a linux-test makefile target so we can run the unit tests locally
- Fixes up some test code to work on Linux (mostly ifdefs)
- Runs the unit tests in CI now
2026-04-15 16:58:03 -07:00
Danny Canter 8908ffc5d1 EXT4: Rework Ptr (#687) 2026-04-14 20:17:46 -07:00
Danny Canter c0f8fb423a ContainerizationOCI: dedupe platform normalizing logic (#683)
We had a couple spots we were using this logic, probably better to shove
it in a function. The other thing this fixes is today .current was only
checking for arm64 which on a linux host uname with return aarch64, so
we'll fatalError trying to use it today..
2026-04-14 14:27:14 -04:00
Danny Canter 47518e0738 LinuxContainer: Give 1 vcpu of overhead for guest (#684) 2026-04-14 00:19:40 -07:00
jwhur de58d1dd09 Set memory.low for vminitd to avoid kernel reclaiming its memory (#682)
Sets `memory.low` for `vminitd` cgroup to make kernel avoid reclaiming
its memory under high memory pressure. Even if the container process
runs in memory cgroup, consuming lots of page cache can lead to
reclaiming `vminitd`'s page cache memory , which hangs the `vminitd`.
Setting `memory.low` makes kernel avoid reclaiming `vminitd`'s page so
that we can guarantee the proper `vminitd` operation under high memory
pressure.
2026-04-13 18:42:28 -07:00
Danny Canter 833b07f4f5 vminitd (client): Turn off idle timeout (#680)
Closes: #678

There's no reason to have an idle timeout per connection as users may
use this library in many different ways. The grpc lib defaults to a 30
min idle timeout which could be trivially reached if instead of waiting
on the init process, you were waiting on a bunch of execs. NIO under the
hood asserts on ebadfs (which is good, but bad for this scenario..), so
lets turn off the timeout altogether.
2026-04-13 00:15:37 -07:00
J LoganandDanny Canter 9d870451e8 Upgrade vminitd API to use grpc-swift-2. (#578) (#669)
- Closes #51. Again.
- No real notable API changes. The largest change code-wise is in
Vminitd. The connection loop is set up immediately in the new API by
calling runConnections() on the client, and this blocks until either the
task it's running on is cancelled or beginGracefulShutdown is called.
Because of this, either we'd have to modify our API to have
VirtualMachineAgent implementations call some run() method, or we just
put runConnections in an internal task on Vminitd. This change uses the
latter approach as it's simpler.
- Updated dependencies to pick up latest protobuf and grpc-swift-2
fixes.
- ClientBootstrap.withConnectedSocket(fd).wait() registers the vsock fd
with epoll/kqueue immediately. vminitd sends its HTTP/2 SETTINGS frame
right away upon accepting the connection, so those bytes can arrive on
the fd — and be read by NIO — before the gRPC pipeline is installed.
With a bare pipeline, NIO has nowhere to send the bytes and discards
them.
- Buffer until ClientConnectionHandler is in the pipeline so it can
process the SETTINGS frame and fire .ready, then schedule delivery of
the buffered data with assumeIsolatedUnsafeUnchecked().execute.
- To help produce more accurate merged logs, defines a
`StderrLogHandler` in the vminitd Application.swift that writes
timestamps to the boot log with millisecond precision and format
identical to that of the log files created using the `--log-root` arg on
`container`.
- Updates hawkeye to latest version (v6.5.1).
- In vminitd, use the Server event loop group for the gRPC server.

Co-authored-by: Danny Canter <danny_canter@apple.com>
2026-04-12 22:11:03 -07:00
Danny Canter 57f623d7f7 Start converting libraries to use FoundationEssentials (#676)
This helps on binary size if we can successfully get all Foundation
imports out of our dep chain. It seems Foundation brings in a 30MiB ICU
blob, which bloats vmexec and vminitd.
2026-04-10 19:58:41 -07:00
Dmitry Kovba 8c53f4d526 Restore a configurable block size in the EXT4 formatter (#679)
Restores a configurable block size in the EXT4 formatter. 

https://github.com/apple/containerization/pull/662 resolved a conflict
between the hardcoded log block size and a user-provided block size, but
removed the later. This PR restores the configurable block size without
creating the conflict.
2026-04-10 14:04:20 -07:00
Danny Canter ceee3a67ba vminitd: Lower nio event loop group threads to 1 (#677) 2026-04-10 10:47:22 -07:00
Dmitry Kovba 250546f185 Fix the hardlink count decrement threshold and unlink cleanup (#610)
- Fixes a hardlink count decrement threshold
- Fixes unlinking not freeing the first inode

Resolves the failing added tests:

```
✘ Test hardlinkLinksCount() recorded an issue at TestEXT4Format+Link.swift:43:9: Expectation failed: try EXT4.EXT4Reader(blockDevice: afterUnlink).stat("/original").inode.linksCount == 1
✘ Test hardlinkLinksCount() failed after 0.016 seconds with 1 issue.
```

```
✘ Test unlinkFirstInodeFreesInode() recorded an issue at TestEXT4Format+Link.swift:58:9: Expectation failed: try EXT4.EXT4Reader(blockDevice: path).superBlock.freeInodesCount == EXT4.EXT4Reader(blockDevice: emptyPath).superBlock.freeInodesCount
✘ Test unlinkFirstInodeFreesInode() failed after 0.014 seconds with 1 issue.
```
2026-04-09 15:28:35 -04:00
Dmitry Kovba 2c4012e4e8 Derive the block size from the log block size (#662)
Derives the block size from the log block size.
2026-04-09 15:26:23 -04:00
Danny Canter 6f7e7f98ba makefile: Add goal to build the project in a linux container (#674)
Today our CI builds all of the linux code we have with musl and libc to
ensure everything is silky smooth. We should have a way to do the same
locally. This adds a new macOS only goal that spins up a container
(requires `container` to be installed) that builds an image with our
deps (libarchive and compression libs) and then builds the project. It
supports supplying whatever libc (musl or glibc) to verify they both
work.
2026-04-09 12:19:34 -07:00
Dmitry Kovba 3a84f98821 Fix the xattr read loop bounds (#658)
Fixes the `xattr` read loop bounds. Resolves the failing added tests:

> ✘ Test lastXattrNotDroppedAtBufferBoundary() recorded an issue at
TestEXT4ExtendedAttributes.swift:72:13: Expectation failed: (attrs.count
→ 0) == 1
> ✘ Test lastXattrNotDroppedAtBufferBoundary() failed after 0.001
seconds with 1 issue.

> Swift/Array.swift:430: Fatal error: Array index is out of range
2026-04-09 14:09:55 -04:00
Dmitry Kovba b2be8dec67 Remove the incorrect check for visited inodes (#659)
Removes the incorrect check for visited inodes. Fixes the added failing
tests:

> ✘ Test sameAbsoluteSymlinkFollowedTwice() recorded an issue at
TestEXT4Reader+IO.swift:502:6: Caught error: symlink loop while
resolving: target/../symlink/file.txt
> ✘ Test sameAbsoluteSymlinkFollowedTwice() failed after 0.009 seconds
with 1 issue.

> ✘ Test sameRelativeSymlinkFollowedTwice() recorded an issue at
TestEXT4Reader+IO.swift:516:6: Caught error: symlink loop while
resolving: ../target/../symlink/file.txt
> ✘ Test sameRelativeSymlinkFollowedTwice() failed after 0.010 seconds
with 1 issue.
2026-04-09 14:09:07 -04:00
Dmitry Kovba d8ec470b39 Throw an error for non-ASCII xattr names (#657)
Throws an error for non-ASCII xattr names on read instead of crashing at
force-unwrapping.
2026-04-09 13:59:24 -04:00
Dmitry Kovba 757885052b Crash instead of silently truncate on a type overflow (#663)
Crash instead of silently truncate on a type overflow. This change has
no real effect and only improves the code quality.
2026-04-09 13:56:19 -04:00
Dmitry Kovba 74ac944790 Match the byte order in the EXT4 reader to how the EXT4 formatter writes data (#664)
Matches the byte order in the EXT4 reader to how the EXT4 formatter
writes data.
2026-04-09 13:55:27 -04:00
Danny Canter 8451a8427d Single file mounts: Add/fix up some comments (#675) 2026-04-09 10:21:07 -07:00
Dmitry Kovba adce496396 Trim null bytes from the symlink target string (#618)
Trims null bytes from the symlink target string.
2026-04-09 13:19:51 -04:00
Dmitry Kovba 340c31d1d9 EXT4: Fix the construction of the path (#666)
Fixes the construction of the path and removed unnecessary code. Fixes
the added failing test:

> ✘ Test fileTreeNodePathWithAbsoluteRoot() recorded an issue at
TestEXT4Reader+IO.swift:600:9: Expectation failed: (dirPtr.pointee.path
→ /) == (FilePath("/dir") → /dir)
> ✘ Test fileTreeNodePathWithAbsoluteRoot() recorded an issue at
TestEXT4Reader+IO.swift:601:9: Expectation failed: (filePtr.pointee.path
→ /) == (FilePath("/dir/file") → /dir/file)
> ✘ Test fileTreeNodePathWithAbsoluteRoot() failed after 0.001 seconds
with 2 issues.
2026-04-08 22:32:38 -07:00
Danny Canter ab89983c56 Mounts: Change single file mounts to a different approach (#665)
Related to https://github.com/apple/container/issues/1251

Change to sharing in the parent directory, and then bind mounting in the
file into the container. This has the unfortunate reality of being less
secure, but the current approach is burdended by a couple things,
namely:

1. You can't share in files that are on a different volume
2. There is a Virtualization bug that causes spurious errors when trying
to open the file.

I've added a doc to go over the approach we've taken, and some
workarounds if the approach is not satisfactory.
2026-04-08 22:01:13 -07:00
Danny Canter c2552ca399 Epoll: Rework epoll type (#619) 2026-04-08 21:59:41 -07:00
Dmitry Kovba f6e7099cf1 Fix the minimum disk size check comparing bytes to blocks (#670)
Fixes the minimum disk size check comparing bytes to blocks and reduces
the code duplication.
2026-04-08 20:43:59 -07:00
Dmitry Kovba bc287a0f1c Fix the SuperBlock reserved block count field names (#668)
Fixes the `SuperBlock` reserved block count field names.
2026-04-08 20:11:50 -07:00
Dmitry Kovba 4c5c731a99 Fix typos in the code and comments (#673)
Fixes typos in the code and comments.
2026-04-08 20:11:41 -07:00
Dmitry Kovba 50560a33cb Remove unused, duplicated, and outdated private methods (#667)
Removes unused, duplicated, and outdated private methods.
2026-04-08 14:45:18 -07:00
Dmitry Kovba 744a7174c6 Remove not used code in the EXT4 formatter (#656)
Removes not used code in the EXT4 formatter.
2026-04-08 14:45:02 -07:00
Raj 636715513c Add multi-reference push to ImageStore (#661) 2026-04-07 16:41:58 -07:00
Danny Canter 997d5a4b08 Actions: Add Linux build step (#654)
Related to https://github.com/apple/containerization/issues/606

To make sure the project (and many linux specific libraries) builds on
linux lets add a linux step to build for both musl and glibc. Eventually
this will run unit tests as well. This change needs a bit more libc
agnostic-ifying work to make sure things work for both libcs.
2026-04-07 15:13:12 -07:00
Danny Canter 1a91899b63 Cgroup2: Map OCI spec unlimited sentinel values to "max" (#620) 2026-04-06 21:53:37 -07:00
Danny Canter 83943ed715 vminitd: Make everything libc agnostic (#655)
Remove the last (as far as I can see..) of the musl specific imports we
had.
2026-04-06 18:34:48 -07:00
Danny Canter a1038a9841 make default goal compile on Linux (#648)
To be able to test vminitd/vmexec/linux specific packages on ci it'd be
a heck of a lot easier if `make` just worked. This should be the last
bit needed. The default goal currently compiles just fine after the
linux specific `make deps` is ran. Next in line would be adding decent
unit tests/actually getting ci setup for the linux bits.
2026-04-06 11:13:16 -07:00
Danny Canter 367c136705 VirtualMachineInstance: Make default impls public (#651) 2026-04-06 10:34:32 -07:00
Dmitry Kovba 56916452e9 Fix the uid/gid truncation to 16 bits (#636)
Fixes the uid/gid truncation to 16 bits.
2026-04-03 19:07:30 -07:00
Dmitry Kovba 33afe9974f Remove the unreachable partial last block group handling in the EXT4 formatter (#640)
Fixes the last block group handling in the EXT4 formatter.
2026-04-03 19:07:17 -07:00
Dmitry Kovba 0273d0dcff Fix a force-unwrap crash on the last leaf of an extent tree (#639)
Fixes a force-unwrap crash on the last leaf of an extent tree:

> ContainerizationEXT4/EXT4+Formatter.swift:1148: Fatal error:
Unexpectedly found nil while unwrapping an Optional value
2026-04-03 19:06:50 -07:00
Dmitry Kovba 587339ae63 Add a guard against an empty range in the EXT4 formatter (#641)
Adds a guard against an empty range in the EXT4 formatter to prevent a
possible crash:

> Swift/arm64e-apple-macos.swiftinterface:6314: Fatal error: Range
requires lowerBound <= upperBound
2026-04-03 19:06:22 -07:00
Dmitry Kovba 586385fb15 Remove not used code which had a buffer overread (#629)
Removes not used `FilePath.init?(Data)` which had a buffer overread. It
used `String(cString:)` which reads until `\0`, but `Data` is not
null-terminated.
2026-04-03 17:07:43 -04:00
Dmitry Kovba b36c63c0b1 Skip deleted directory entries instead of breaking (#637)
Skips deleted directory entries instead of breaking.
2026-04-03 17:06:47 -04:00