Add init_component for mlsdisk

This commit is contained in:
Qingsong Chen
2025-01-10 03:15:59 +00:00
committed by Tate, Hongliang Tian
parent f6e040ec94
commit 04be02efb7
3 changed files with 18 additions and 1 deletions

1
Cargo.lock generated
View File

@ -151,6 +151,7 @@ dependencies = [
"aes-gcm",
"aster-block",
"bittle",
"component",
"ctr",
"hashbrown 0.14.5",
"inherit-methods-macro",

View File

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
inherit-methods-macro = {git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e"}
ostd-pod = { git = "https://github.com/asterinas/ostd-pod", rev = "c4644be", version = "0.1.1" }
component = { path = "../../libs/comp-sys/component" }
aster-block = { path = "../block" }
ostd = { path = "../../../ostd" }
# Enable `force-soft` feature to disable `AES-NI` and `CLMUL` intrinsics, ensuring that the implementation

View File

@ -16,7 +16,7 @@ mod util;
extern crate alloc;
use alloc::{sync::Arc, vec};
use alloc::{string::ToString, sync::Arc, vec};
use core::ops::Range;
use aster_block::{
@ -24,6 +24,7 @@ use aster_block::{
id::Sid,
BlockDevice, SECTOR_SIZE,
};
use component::{init_component, ComponentInitError};
use ostd::{mm::VmIo, prelude::*};
pub use self::{
@ -36,6 +37,20 @@ pub use self::{
util::{Aead as _, RandomInit, Rng as _},
};
#[init_component]
fn init() -> core::result::Result<(), ComponentInitError> {
// FIXME: add a virtio-blk-pci device in qemu and a image file.
let Some(device) = aster_block::get_device("raw_mlsdisk") else {
return Err(ComponentInitError::Unknown);
};
let raw_disk = RawDisk::new(device);
let root_key = AeadKey::random();
let device =
MlsDisk::create(raw_disk, root_key, None).map_err(|_| ComponentInitError::Unknown)?;
aster_block::register_device("mlsdisk".to_string(), Arc::new(device));
Ok(())
}
#[derive(Clone, Debug)]
struct RawDisk {
inner: Arc<dyn BlockDevice>,