mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-06 06:31:31 +00:00
hypha: implement basic container init
This commit is contained in:
48
hypha/src/container/init.rs
Normal file
48
hypha/src/container/init.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use crate::error::Result;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use sys_mount::{FilesystemType, Mount, MountFlags};
|
||||
|
||||
const IMAGE_BLOCK_DEVICE_PATH: &str = "/dev/xvda";
|
||||
const CONFIG_BLOCK_DEVICE_PATH: &str = "/dev/xvdb";
|
||||
|
||||
const IMAGE_MOUNT_PATH: &str = "/image";
|
||||
const CONFIG_MOUNT_PATH: &str = "/config";
|
||||
|
||||
pub struct ContainerInit {}
|
||||
|
||||
impl Default for ContainerInit {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ContainerInit {
|
||||
pub fn new() -> ContainerInit {
|
||||
ContainerInit {}
|
||||
}
|
||||
|
||||
pub fn init(&mut self) -> Result<()> {
|
||||
self.prepare_mounts()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepare_mounts(&mut self) -> Result<()> {
|
||||
let image_mount_path = Path::new(IMAGE_MOUNT_PATH);
|
||||
let config_mount_path = Path::new(CONFIG_MOUNT_PATH);
|
||||
self.mount_squashfs(Path::new(IMAGE_BLOCK_DEVICE_PATH), image_mount_path)?;
|
||||
self.mount_squashfs(Path::new(CONFIG_BLOCK_DEVICE_PATH), config_mount_path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mount_squashfs(&mut self, from: &Path, to: &Path) -> Result<()> {
|
||||
if !to.is_dir() {
|
||||
fs::create_dir(to)?;
|
||||
}
|
||||
Mount::builder()
|
||||
.fstype(FilesystemType::Manual("squashfs"))
|
||||
.flags(MountFlags::RDONLY)
|
||||
.mount(from, to)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
|
||||
pub mod init;
|
||||
|
Reference in New Issue
Block a user