mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-20 00:07:55 +00:00
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:
committed by
Fabiano Fidêncio
parent
f63ec50ba3
commit
d07b279bf1
@@ -11,7 +11,7 @@ use std::sync::Arc;
|
|||||||
use crate::storage::{common_storage_handler, new_device, StorageContext, StorageHandler};
|
use crate::storage::{common_storage_handler, new_device, StorageContext, StorageHandler};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use kata_types::device::{DRIVER_9P_TYPE, DRIVER_OVERLAYFS_TYPE, DRIVER_VIRTIOFS_TYPE};
|
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 protocols::agent::Storage;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
@@ -55,7 +55,15 @@ impl StorageHandler for OverlayfsHandler {
|
|||||||
.options
|
.options
|
||||||
.push(format!("workdir={}", work.to_string_lossy()));
|
.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)?;
|
let path = common_storage_handler(ctx.logger, &storage)?;
|
||||||
new_device(path)
|
new_device(path)
|
||||||
}
|
}
|
||||||
|
@@ -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
|
/// 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";
|
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
|
/// SANDBOX_BIND_MOUNTS_DIR is for sandbox bindmounts
|
||||||
pub const SANDBOX_BIND_MOUNTS_DIR: &str = "sandbox-mounts";
|
pub const SANDBOX_BIND_MOUNTS_DIR: &str = "sandbox-mounts";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user