From 04be02efb7b7ddc0af90a00fdc0e955a539315e7 Mon Sep 17 00:00:00 2001 From: Qingsong Chen Date: Fri, 10 Jan 2025 03:15:59 +0000 Subject: [PATCH] Add init_component for mlsdisk --- Cargo.lock | 1 + kernel/comps/mlsdisk/Cargo.toml | 1 + kernel/comps/mlsdisk/src/lib.rs | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7c8992d1..48e8b02e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,7 @@ dependencies = [ "aes-gcm", "aster-block", "bittle", + "component", "ctr", "hashbrown 0.14.5", "inherit-methods-macro", diff --git a/kernel/comps/mlsdisk/Cargo.toml b/kernel/comps/mlsdisk/Cargo.toml index c74d48c4..d9c52141 100644 --- a/kernel/comps/mlsdisk/Cargo.toml +++ b/kernel/comps/mlsdisk/Cargo.toml @@ -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 diff --git a/kernel/comps/mlsdisk/src/lib.rs b/kernel/comps/mlsdisk/src/lib.rs index 6f61770a..54a7790e 100644 --- a/kernel/comps/mlsdisk/src/lib.rs +++ b/kernel/comps/mlsdisk/src/lib.rs @@ -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,