diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index a6bf6b4ff2..83f624f98c 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -340,8 +340,33 @@ pub async fn update_ephemeral_mounts( async fn overlayfs_storage_handler( logger: &Logger, storage: &Storage, + cid: Option<&str>, _sandbox: Arc>, ) -> Result { + if storage + .options + .iter() + .any(|e| e == "io.katacontainers.fs-opt.overlay-rw") + { + let cid = cid.ok_or_else(|| anyhow!("No container id in rw overlay"))?; + let cpath = Path::new(crate::rpc::CONTAINER_BASE).join(cid); + let work = cpath.join("work"); + let upper = cpath.join("upper"); + + fs::create_dir_all(&work).context("Creating overlay work directory")?; + fs::create_dir_all(&upper).context("Creating overlay upper directory")?; + + let mut storage = storage.clone(); + storage.fstype = "overlay".into(); + storage + .options + .push(format!("upperdir={}", upper.to_string_lossy())); + storage + .options + .push(format!("workdir={}", work.to_string_lossy())); + return common_storage_handler(logger, &storage); + } + common_storage_handler(logger, storage) } @@ -869,7 +894,7 @@ pub async fn add_storages( ephemeral_storage_handler(&logger, &storage, sandbox.clone()).await } DRIVER_OVERLAYFS_TYPE => { - overlayfs_storage_handler(&logger, &storage, sandbox.clone()).await + overlayfs_storage_handler(&logger, &storage, cid.as_deref(), sandbox.clone()).await } DRIVER_MMIO_BLK_TYPE => { virtiommio_blk_storage_handler(&logger, &storage, sandbox.clone()).await diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 6c92eb774e..3b7f0a4720 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -84,7 +84,7 @@ use std::io::{BufRead, BufReader, Write}; use std::os::unix::fs::FileExt; use std::path::PathBuf; -const CONTAINER_BASE: &str = "/run/kata-containers"; +pub const CONTAINER_BASE: &str = "/run/kata-containers"; const MODPROBE_PATH: &str = "/sbin/modprobe"; /// the iptables seriers binaries could appear either in /sbin