agent:storage: Add directory creation support

Implementing directory creation logic in the OverlayfsHandler to process
driver options with the KATA_VOLUME_OVERLAYFS_CREATE_DIR prefix

Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
This commit is contained in:
ChengyuZhu6
2025-04-21 19:11:32 +08:00
committed by Fabiano Fidêncio
parent f63ec50ba3
commit d07b279bf1
2 changed files with 14 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ use std::sync::Arc;
use crate::storage::{common_storage_handler, new_device, StorageContext, StorageHandler};
use anyhow::{anyhow, Context, Result};
use kata_types::device::{DRIVER_9P_TYPE, DRIVER_OVERLAYFS_TYPE, DRIVER_VIRTIOFS_TYPE};
use kata_types::mount::StorageDevice;
use kata_types::mount::{StorageDevice, KATA_VOLUME_OVERLAYFS_CREATE_DIR};
use protocols::agent::Storage;
use tracing::instrument;
@@ -55,7 +55,15 @@ impl StorageHandler for OverlayfsHandler {
.options
.push(format!("workdir={}", work.to_string_lossy()));
}
let overlay_create_dir_prefix = &(KATA_VOLUME_OVERLAYFS_CREATE_DIR.to_string() + "=");
for driver_option in &storage.driver_options {
if let Some(dir) = driver_option
.as_str()
.strip_prefix(overlay_create_dir_prefix)
{
fs::create_dir_all(dir).context("Failed to create directory")?;
}
}
let path = common_storage_handler(ctx.logger, &storage)?;
new_device(path)
}

View File

@@ -34,6 +34,10 @@ pub const KATA_MOUNT_OPTION_FS_GID: &str = "fsgid";
/// KATA_DIRECT_VOLUME_ROOT_PATH is the root path used for concatenating with the direct-volume mount info file path
pub const KATA_DIRECT_VOLUME_ROOT_PATH: &str = "/run/kata-containers/shared/direct-volumes";
/// Key to indentify directory creation in `Storage.driver_options`.
pub const KATA_VOLUME_OVERLAYFS_CREATE_DIR: &str =
"io.katacontainers.volume.overlayfs.create_directory";
/// SANDBOX_BIND_MOUNTS_DIR is for sandbox bindmounts
pub const SANDBOX_BIND_MOUNTS_DIR: &str = "sandbox-mounts";