scripts: add criu-move-mount and runc-action-add-mounts for restore-time bind mounts - #2
Merged
wangixt merged 2 commits intoMar 25, 2026
Conversation
…ime bind mounts
Add two new files for adding bind mounts into a container's mount
namespace during CRIU restore:
- criu-move-mount.c: C program that handles the complete workflow:
* Phase filtering (only acts during pre-resume)
* Reads mount rules from CRIU_ADD_MOUNTS environment variable
* Parses semicolon-separated mount rules with comma-separated fields
* Performs cross-namespace bind mounts using open_tree(OPEN_TREE_CLONE)
+ setns() + move_mount() (Linux 5.2+ new mount API)
* Supports recursive bind (rbind) and read-only (ro) options
* Handles multiple mount rules in a single invocation by switching
between host and container mount namespaces
- runc-action-add-mounts.sh: Thin wrapper script that locates and
exec's the criu-move-mount binary. Designed to be passed to CRIU as
--action-script.
Mount rules are specified exclusively via the CRIU_ADD_MOUNTS
environment variable using this format:
src=/host/path,dst=/container/path[,options=rbind:ro]
Multiple rules are separated by semicolons.
Co-authored-by: wangixt <wangixt@users.noreply.github.com>
Two changes to help diagnose failures: 1. Add file-based debug logging (default: /tmp/criu-move-mount.log). Every step (phase check, env read, open_tree, setns, move_mount) is logged with errno details. The log path can be overridden via CRIU_MOVE_MOUNT_LOG or disabled by setting it to empty. 2. Fix exit code: individual mount failures no longer cause a non-zero exit. This matches the original shell script's '|| true' behaviour and prevents a single bad rule from aborting the entire CRIU restore. Co-authored-by: wangixt <wangixt@users.noreply.github.com>
Owner
Author
|
add mount |
wangixt
marked this pull request as ready for review
March 25, 2026 07:34
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Add support for adding new bind mounts into a container's mount namespace during CRIU restore, using the Linux 5.2+ new mount API (
open_tree(OPEN_TREE_CLONE)+move_mount()).How
Two new files are introduced in
scripts/:criu-move-mount.cA C program that handles the complete workflow:
pre-resumeCRIU action phase (mount tree is restored, processes not yet resumed)CRIU_ADD_MOUNTSenvironment variable containing semicolon-separated mount rulesopen_tree(src, OPEN_TREE_CLONE)in the host mount namespace to clone the source mountsetns(container_mntns)to switch to the container's mount namespacemove_mount(treefd -> dst)to attach the cloned mount inside the containerremount(MS_RDONLY)for read-only mounts/tmp/criu-move-mount.logby default (configurable viaCRIU_MOVE_MOUNT_LOG, set to""to disable)|| truebehaviourrunc-action-add-mounts.shA thin wrapper script designed to be passed to CRIU as
--action-script. It locates andexecs thecriu-move-mountbinary. All logic resides in the C program.Mount rule format
Rules are specified exclusively via the
CRIU_ADD_MOUNTSenvironment variable:Example:
Debugging
Check
/tmp/criu-move-mount.log(or the path set viaCRIU_MOVE_MOUNT_LOG) for detailed logs including:Usage