agent: compact EROFS overlay lowerdirs

Use kata_types::mount::Mount for the final multi-layer EROFS
overlay mount instead of calling baremount() directly.

The mount helper detects overlay option strings close to the kernel
mount data limit. When lowerdir entries share a common parent, it
changes into that directory and rewrites lowerdir to relative paths.
That avoids repeating the same long prefix for every layer.

Multi-layer EROFS images can have many lower layers under
/run/kata-containers/<cid>/multi-layer. Passing the raw absolute
lowerdir list can exceed the mount option buffer and fail the final
overlay mount, even after all layer devices mounted successfully.

Reuse the helper so this path follows Kata's normal overlay mount
handling, including lowerdir compaction before mount(2).

Assisted-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Manuel Huber <manuelh@nvidia.com>
This commit is contained in:
Manuel Huber
2026-05-26 18:33:30 +00:00
parent d75a91ee09
commit e838cd7d8d

View File

@@ -26,7 +26,7 @@ use crate::mount::baremount;
use crate::sandbox::Sandbox;
use crate::storage::{StorageContext, StorageHandler};
use anyhow::{anyhow, Context, Result};
use kata_sys_util::mount::create_mount_destination;
use kata_sys_util::mount::{create_mount_destination, Mounter};
use kata_types::device::{DRIVER_BLK_PCI_TYPE, DRIVER_SCSI_TYPE};
use kata_types::mount::StorageDevice;
use protocols::agent::Storage;
@@ -313,22 +313,21 @@ pub async fn handle_multi_layer_erofs_group(
)
.context("failed to create overlay mount destination")?;
let overlay_options = format!(
"upperdir={},lowerdir={},workdir={}",
upperdir.display(),
lowerdir,
workdir.display()
);
let overlay_mount = kata_types::mount::Mount {
source: OVERLAY_TYPE.to_string(),
destination: PathBuf::from(&ext4.mount_point),
fs_type: OVERLAY_TYPE.to_string(),
options: vec![
format!("upperdir={}", upperdir.display()),
format!("lowerdir={}", lowerdir),
format!("workdir={}", workdir.display()),
],
..Default::default()
};
baremount(
Path::new(OVERLAY_TYPE),
Path::new(&ext4.mount_point),
OVERLAY_TYPE,
nix::mount::MsFlags::empty(),
&overlay_options,
&logger,
)
.context("failed to mount overlay")?;
overlay_mount
.mount(Path::new(&ext4.mount_point))
.context("failed to mount overlay")?;
info!(
logger,