Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmm: support readonly option of volume #158

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions vmm/sandbox/src/container/handler/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use containerd_sandbox::{
Sandbox,
};
use log::debug;
use vmm_common::{storage::ANNOTATION_KEY_STORAGE, DEV_SHM, STORAGE_FILE_PREFIX};
use vmm_common::{
storage::{Storage, ANNOTATION_KEY_STORAGE},
DEV_SHM, STORAGE_FILE_PREFIX,
};

use crate::{
container::handler::Handler, sandbox::KuasarSandbox, storage::mount::is_bind_shm,
Expand Down Expand Up @@ -55,14 +58,18 @@ where
let rootfs = &container.data.rootfs;

let mut handled_mounts = vec![];
let mut storages = vec![];
let mut storages: Vec<&Storage> = vec![];

for mut m in mounts {
if let Some(storage) = sandbox.storages.iter().find(|x| x.is_for_mount(&m)) {
debug!("found storage {:?} for mount {:?}", storage, m);
m.source.clone_from(&storage.mount_point);
m.options = vec!["bind".to_string()];
if storage.need_guest_handle {
m.options.push("bind".to_string());
if storage.need_guest_handle
&& !storages
.iter()
.any(|s| s.host_source == storage.host_source && s.r#type == storage.r#type)
{
storages.push(storage);
}
}
Expand Down
28 changes: 24 additions & 4 deletions vmm/sandbox/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
};

let mut storage = Storage {
host_source: source.clone(),
host_source: m.source.clone(),
r#type: m.r#type.clone(),
id: id.to_string(),
device_id: Some(device_id.to_string()),
Expand Down Expand Up @@ -161,6 +161,13 @@ where
} else {
m.source.clone()
};

let options = if m.options.contains(&"ro".to_string()) {
vec!["ro".to_string()]
} else {
vec![]
};

let host_dest = format!("{}/{}", self.get_sandbox_shared_path(), &storage_id);
debug!("bind mount storage for mount {:?}, dest: {}", m, &host_dest);
let source_path = Path::new(&*source);
Expand Down Expand Up @@ -188,7 +195,7 @@ where
driver: "".to_string(),
driver_options: vec![],
fstype: "bind".to_string(),
options: vec![],
options,
mount_point: format!("{}/{}", KUASAR_STATE_DIR, &storage_id),
};

Expand All @@ -209,6 +216,13 @@ where
m
)));
}

let options = if m.options.contains(&"ro".to_string()) {
vec!["ro".to_string()]
} else {
vec![]
};

let host_dest = format!("{}/{}", self.get_sandbox_shared_path(), &storage_id);
debug!("overlay mount storage for {:?}, dest: {}", m, &host_dest);
tokio::fs::create_dir_all(&host_dest).await?;
Expand All @@ -226,7 +240,7 @@ where
driver: "".to_string(),
driver_options: vec![],
fstype: "bind".to_string(),
options: vec![],
options,
mount_point: format!("{}/{}", KUASAR_STATE_DIR, &storage_id),
};

Expand All @@ -242,6 +256,12 @@ where
m: &Mount,
mount_info: &MountInfo,
) -> Result<()> {
let options = if m.options.contains(&"ro".to_string()) {
vec!["ro".to_string()]
} else {
vec![]
};

let mut storage = Storage {
host_source: m.source.clone(),
r#type: m.r#type.clone(),
Expand All @@ -253,7 +273,7 @@ where
driver: DRIVEREPHEMERALTYPE.to_string(),
driver_options: vec![],
fstype: "tmpfs".to_string(),
options: vec![],
options,
mount_point: format!("{}{}", KUASAR_GUEST_SHARE_DIR, storage_id),
};
// only handle size option because other options may not supported in guest
Expand Down
2 changes: 1 addition & 1 deletion vmm/sandbox/src/storage/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn get_file_type<P: AsRef<Path>>(path: P) -> Result<FileType> {
let real_path = match tokio::fs::canonicalize(path).await {
Ok(rp) => rp,
Err(e) => {
return Err(e.into());
return Err(anyhow!("get file type {}", e).into());
}
};

Expand Down
Loading