diff --git a/src/overlay/Cargo.lock b/src/overlay/Cargo.lock index d39139eff42b..f091ad441b36 100644 --- a/src/overlay/Cargo.lock +++ b/src/overlay/Cargo.lock @@ -209,6 +209,7 @@ version = "0.1.0" dependencies = [ "base64", "clap", + "nix", "tempfile", ] @@ -224,6 +225,27 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "memoffset", +] + [[package]] name = "once_cell" version = "1.18.0" diff --git a/src/overlay/Cargo.toml b/src/overlay/Cargo.toml index f610c1cfed3d..541cece1e8ed 100644 --- a/src/overlay/Cargo.toml +++ b/src/overlay/Cargo.toml @@ -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" \ No newline at end of file diff --git a/src/overlay/src/main.rs b/src/overlay/src/main.rs index c4605c0e84f0..e24284a0f179 100644 --- a/src/overlay/src/main.rs +++ b/src/overlay/src/main.rs @@ -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()); @@ -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)?; }