mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
agent: Correct mount point creation
mount_storage() first makes sure the mount point for the storage volume exists. It uses fs::create_dir_all() in the case of 9p or virtiofs volumes otherwise ensure_destination_exists(). But.. ensure_destination_exists() boils down to an fs::create_dir_all() in most cases anyway. The only case it doesn't is for a bind fstype, where it creates a file instead of a directory. But, that's not correct anyway because we need to create either a file or a directory depending on the source of the bind mount, which ensure_destination_exists() doesn't know. The 9p/virtiofs paths also check if the mountpoint exists before calling fs::create_dir_all(), which is unnecessary (fs::create_dir_all already handles that case). mount_storage() does have the information to know what we need to create, so have it explicitly call ensure_destination_file_exists() for the bind mount to a non-directory case, and fs::create_dir_all() in all other cases. fixes #2390 Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
08d7aebc28
commit
64aa562355
@ -439,17 +439,14 @@ fn mount_storage(logger: &Logger, storage: &Storage) -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match storage.fstype.as_str() {
|
||||
DRIVER_9P_TYPE | DRIVER_VIRTIOFS_TYPE => {
|
||||
let dest_path = Path::new(storage.mount_point.as_str());
|
||||
if !dest_path.exists() {
|
||||
fs::create_dir_all(dest_path).context("Create mount destination failed")?;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
ensure_destination_exists(storage.mount_point.as_str(), storage.fstype.as_str())?;
|
||||
}
|
||||
let mount_path = Path::new(&storage.mount_point);
|
||||
let src_path = Path::new(&storage.source);
|
||||
if storage.fstype == "bind" && !src_path.is_dir() {
|
||||
ensure_destination_file_exists(mount_path)
|
||||
} else {
|
||||
fs::create_dir_all(mount_path).map_err(anyhow::Error::from)
|
||||
}
|
||||
.context("Could not create mountpoint")?;
|
||||
|
||||
let options_vec = storage.options.to_vec();
|
||||
let options_vec = options_vec.iter().map(String::as_str).collect();
|
||||
|
Loading…
Reference in New Issue
Block a user