From e838cd7d8dc26f669b3848293914c682e2ffeea4 Mon Sep 17 00:00:00 2001 From: Manuel Huber Date: Tue, 26 May 2026 18:33:30 +0000 Subject: [PATCH] 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//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 Signed-off-by: Manuel Huber --- src/agent/src/storage/multi_layer_erofs.rs | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/agent/src/storage/multi_layer_erofs.rs b/src/agent/src/storage/multi_layer_erofs.rs index 088fd4edf1..60d078ac8a 100644 --- a/src/agent/src/storage/multi_layer_erofs.rs +++ b/src/agent/src/storage/multi_layer_erofs.rs @@ -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,