Skip to content

Conversation

@dcantah
Copy link
Contributor

@dcantah dcantah commented Jan 22, 2026

Fixes #79

This adds support for single file (virtiofs based) mounts to the two main container types. This is transparent, and doesn't need to be setup by a user, so there is no visible API change. Virtiofs does not support single file mounts today, and it would be less than ideal from a security standpoint to just expose the parent directory of the file to the vm and then bind mount in the file, so we chose the following:

  1. Create a temp directory the container types will manage.
  2. Hardlink in the file we want.
  3. Share that tempdir into the vm.
  4. Finally bind mount in the file into the container.

The main goal I wanted for this is to leave the logic out of the VirtualMachineInstance. I really want this to just be a little dance the container types do, and leave the vm out of it. Because of that, most of the logic is shoved in a new FileMountContext type that does the dirty tricks of rewriting what the user asked for to be a bind mount from a temporary holding spot we'll use in the guest for these temp directories.

One of the downsides to this is today the tempdirs are solely on the main volume, so cross volume will need to copy the file to the tempdir, so writes won't get written back.

This adds support for single file (virtiofs based) mounts
to the two main container types. This is transparent, and
doesn't need to be setup by a user, so there is no visible
API change. Virtiofs does not support single file mounts today,
and it would be less than ideal from a security standpoint to
just expose the parent directory of the file to the vm and then
bind mount in the file, so we chose the following:

1. Create a temp directory the container types will manage.
2. Hardlink in the file we want.
3. Share that tempdir into the vm.
4. Finally bind mount in the file into the container.

The main goal I wanted for this is to leave the logic out of the
`VirtualMachineInstance`. I really want this to just be a little dance
the container types do, and leave the vm out of it. Because of that,
most of the logic is shoved in a new `FileMountContext` type that
does the dirty tricks of rewriting what the user asked for to be
a bind mount from a temporary holding spot we'll use in the guest
for these temp directories.

One of the downsides to this is today the tempdirs are solely on the
main volume, so cross volume will need to copy the file to the
tempdir, so writes won't get written back.

Co-authored-by: Dean Coulstock <d_coulstock@apple.com>
Co-authored-by: Jaewon Hur <hurjaewon@snu.ac.kr>
@dcantah dcantah force-pushed the support-single-file-mounts branch from fe68317 to 62a0614 Compare January 22, 2026 23:19
try FileManager.default.linkItem(at: resolvedSource, to: destURL)
} catch {
// Hardlink failed. Fall back to copy
try FileManager.default.copyItem(at: resolvedSource, to: destURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want our documentation on Mount to state that the caller is responsible for determining whether cross-filesystem mounts are present.

For "caller == container" we'd want to warn the user in the case that their single file mount won't actually propagate guest writes through to the host file.

@dcantah dcantah merged commit 1a01741 into apple:main Jan 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single file mount support

2 participants