Skip to content

Commit

Permalink
Switch to use nix::mount for overlayfs mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
miz060 committed Jan 14, 2025
1 parent a96690c commit 3d3fd4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
22 changes: 22 additions & 0 deletions src/overlay/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/overlay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"
clap = { version = "4.3.2", features = ["derive"] }
base64 = "0.21.2"
tempfile = "3.3.0"
nix = "0.24.2"
36 changes: 19 additions & 17 deletions src/overlay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn main() -> io::Result<()> {
unmounter.0.push(n);
}

// Mont the overlay if we have multiple layers, otherwise do a bind-mount.
// Mount the overlay if we have multiple layers, otherwise do a bind-mount.
let mp = std::fs::canonicalize(&args.directory)?;
if unmounter.0.len() == 1 {
let p = unmounter.1.path().join(unmounter.0.first().unwrap());
Expand All @@ -165,23 +165,25 @@ fn main() -> io::Result<()> {
let saved = std::env::current_dir()?;
set_current_dir(unmounter.1.path())?;

let status = Command::new("mount")
.arg("none")
.arg(&mp)
.args(&[
"-t",
"overlay",
"-o",
&format!("lowerdir={}", unmounter.0.join(":")),
])
.status()?;
if !status.success() {
return Err(Error::new(
let lowerdirs = unmounter.0.join(":");
let opts = format!("lowerdir={}", lowerdirs);

// Replace the mount(8) tool with nix::mount to address the limitation of FSCONFIG_SET_STRING,
// which has a 256-byte limit and cannot accommodate multiple lowerdir entries.
nix::mount::mount(
Some("overlay"),
&mp,
Some("overlay"),
nix::mount::MsFlags::empty(),
Some(opts.as_str()),
)
.map_err(|e| {
Error::new(
ErrorKind::Other,
format!("failed to mount overlay: {status}"),
));
}

format!("failed to mount overlay to {}: {}", mp.display(), e),
)
})?;
set_current_dir(saved)?;
}

Expand Down

0 comments on commit 3d3fd4c

Please sign in to comment.