-
Notifications
You must be signed in to change notification settings - Fork 268
Mounts: Change single file mounts to a different approach #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Single File Mounts | ||
|
|
||
| In Containerization, what is analogous to bind mounts goes over virtiofs. virtiofs can only | ||
| share directories, not individual files. To support mounting a single file from the host into | ||
| a container, Containerization shares the file's parent directory via virtiofs and then bind | ||
| mounts the specific file to its final destination inside the container. | ||
|
|
||
| ## How it works | ||
|
|
||
| 1. **Detection**: During mount preparation, each virtiofs mount source is stat'd. If it's a | ||
| regular file (not a directory), it enters the single-file mount path. Symlinks are | ||
| resolved to the real file first. | ||
|
|
||
| 2. **Parent directory share**: The file's parent directory is shared via virtiofs into the | ||
| guest VM. If multiple single-file mounts reference files in the same parent directory, | ||
| only one virtiofs share is created. | ||
|
|
||
| 3. **Guest holding mount**: After the VM starts, the parent directory share is mounted to a | ||
| holding location in the guest. | ||
|
|
||
| 4. **Bind mount**: When the container starts, a bind mount is created from | ||
| the holding location to the requested destination path inside the container. | ||
|
|
||
| ### Example | ||
|
|
||
| Mounting `/Users/dev/config/app.toml` to `/etc/app.toml` in the container: | ||
|
|
||
| ``` | ||
| Host: /Users/dev/config/ (shared via virtiofs) | ||
| Guest VM: /temporary/holding/spot/ (virtiofs mount of parent dir) | ||
| Container: /etc/app.toml (bind mount of /temporary/holding/spot/app.toml) | ||
| ``` | ||
|
|
||
| ## Trade-offs | ||
|
|
||
| Sharing the parent directory means that sibling files in that directory are visible to the | ||
| guest VM at the holding mount point under `/run`. The bind mount into the container only | ||
| exposes the specific file requested, but the full parent directory contents are accessible | ||
| from inside the VM itself. This is a deliberate trade-off for reliability. Prior attempts | ||
| at supporting single file mounts using temporary directories with hardlinks were fragile | ||
| across filesystem boundaries and with certain host filesystem configurations. | ||
|
|
||
| ## Alternatives to single file mounts | ||
|
|
||
| If exposing the parent directory to the guest VM is not acceptable for your use case, you | ||
| can avoid single-file mounts entirely: | ||
|
|
||
| - **Mount the whole directory**: Instead of mounting a single file, mount the directory that | ||
| contains it. This is functionally equivalent (the directory is shared either way) but makes | ||
| the behavior explicit and gives the container access to the full directory at the | ||
| destination path. | ||
|
|
||
| - **Stage files into a dedicated directory**: Copy or link the files you need into a | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy or hard link? |
||
| dedicated directory on the host and mount that directory instead. This gives you full | ||
| control over what is visible to the guest. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the comment back about this path being a dummy value?