From c040df72b391748d82133ca2dd554608813d6c74 Mon Sep 17 00:00:00 2001 From: Qingsong Chen Date: Fri, 10 Jan 2025 02:27:50 +0000 Subject: [PATCH] Rename `SwornDisk` to `MlsDisk` --- .../mlsdisk/src/layers/4-lsm/tx_lsm_tree.rs | 6 +- .../mlsdisk/src/layers/5-disk/block_alloc.rs | 6 +- .../mlsdisk/src/layers/5-disk/data_buf.rs | 2 +- .../5-disk/{sworndisk.rs => mlsdisk.rs} | 56 +++++++++---------- kernel/comps/mlsdisk/src/layers/5-disk/mod.rs | 22 ++++---- kernel/comps/mlsdisk/src/lib.rs | 2 +- kernel/comps/mlsdisk/src/util/lazy_delete.rs | 2 +- 7 files changed, 48 insertions(+), 48 deletions(-) rename kernel/comps/mlsdisk/src/layers/5-disk/{sworndisk.rs => mlsdisk.rs} (94%) diff --git a/kernel/comps/mlsdisk/src/layers/4-lsm/tx_lsm_tree.rs b/kernel/comps/mlsdisk/src/layers/4-lsm/tx_lsm_tree.rs index 28daf37ad..2ef8d44a1 100644 --- a/kernel/comps/mlsdisk/src/layers/4-lsm/tx_lsm_tree.rs +++ b/kernel/comps/mlsdisk/src/layers/4-lsm/tx_lsm_tree.rs @@ -311,7 +311,7 @@ impl, V: RecordValue, D: BlockSet + 'static> TreeInner recov_self.do_migration_tx()?; - debug!("[SwornDisk TxLsmTree] Recovery completed: {recov_self:?}"); + debug!("[MlsDisk TxLsmTree] Recovery completed: {recov_self:?}"); Ok(recov_self) } @@ -539,7 +539,7 @@ impl, V: RecordValue, D: BlockSet + 'static> TreeInner self.sst_manager.write().insert(new_sst, LsmLevel::L0); - debug!("[SwornDisk TxLsmTree] Minor Compaction completed: {self:?}"); + debug!("[MlsDisk TxLsmTree] Minor Compaction completed: {self:?}"); Ok(()) } @@ -638,7 +638,7 @@ impl, V: RecordValue, D: BlockSet + 'static> TreeInner deleted_ssts.into_iter(), ); - debug!("[SwornDisk TxLsmTree] Major Compaction completed: {self:?}"); + debug!("[MlsDisk TxLsmTree] Major Compaction completed: {self:?}"); // Continue to do major compaction if necessary if self.sst_manager.read().require_major_compaction(to_level) { diff --git a/kernel/comps/mlsdisk/src/layers/5-disk/block_alloc.rs b/kernel/comps/mlsdisk/src/layers/5-disk/block_alloc.rs index a8b2ac2c1..a2ef0333f 100644 --- a/kernel/comps/mlsdisk/src/layers/5-disk/block_alloc.rs +++ b/kernel/comps/mlsdisk/src/layers/5-disk/block_alloc.rs @@ -11,7 +11,7 @@ use core::{ use ostd_pod::Pod; use serde::{Deserialize, Serialize}; -use super::sworndisk::Hba; +use super::mlsdisk::Hba; use crate::{ layers::{ bio::{BlockSet, Buf, BufRef, BID_SIZE}, @@ -27,7 +27,7 @@ const BUCKET_BLOCK_VALIDITY_TABLE: &str = "BVT"; /// The bucket name of block alloc/dealloc log. const BUCKET_BLOCK_ALLOC_LOG: &str = "BAL"; -/// Block validity table. Global allocator for `SwornDisk`, +/// Block validity table. Global allocator for `MlsDisk`, /// which manages validities of user data blocks. pub(super) struct AllocTable { bitmap: Mutex, @@ -38,7 +38,7 @@ pub(super) struct AllocTable { num_free: CvarMutex, } -/// Per-TX block allocator in `SwornDisk`, recording validities +/// Per-TX block allocator in `MlsDisk`, recording validities /// of user data blocks within each TX. All metadata will be stored in /// `TxLog`s of bucket `BAL` during TX for durability and recovery purpose. pub(super) struct BlockAlloc { diff --git a/kernel/comps/mlsdisk/src/layers/5-disk/data_buf.rs b/kernel/comps/mlsdisk/src/layers/5-disk/data_buf.rs index 35bfb11c1..1089249b0 100644 --- a/kernel/comps/mlsdisk/src/layers/5-disk/data_buf.rs +++ b/kernel/comps/mlsdisk/src/layers/5-disk/data_buf.rs @@ -3,7 +3,7 @@ //! Data buffering. use core::ops::RangeInclusive; -use super::sworndisk::RecordKey; +use super::mlsdisk::RecordKey; use crate::{ layers::bio::{BufMut, BufRef}, os::{BTreeMap, Condvar, CvarMutex, Mutex}, diff --git a/kernel/comps/mlsdisk/src/layers/5-disk/sworndisk.rs b/kernel/comps/mlsdisk/src/layers/5-disk/mlsdisk.rs similarity index 94% rename from kernel/comps/mlsdisk/src/layers/5-disk/sworndisk.rs rename to kernel/comps/mlsdisk/src/layers/5-disk/mlsdisk.rs index ac426131a..414c8dc35 100644 --- a/kernel/comps/mlsdisk/src/layers/5-disk/sworndisk.rs +++ b/kernel/comps/mlsdisk/src/layers/5-disk/mlsdisk.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -//! SwornDisk as a block device. +//! MlsDisk as a block device. //! //! API: submit_bio(), submit_bio_sync(), create(), open(), //! read(), readv(), write(), writev(), sync(). @@ -42,12 +42,12 @@ pub type Lba = BlockId; /// Host Block Address. pub type Hba = BlockId; -/// SwornDisk. -pub struct SwornDisk { +/// MlsDisk. +pub struct MlsDisk { inner: Arc>, } -/// Inner structures of `SwornDisk`. +/// Inner structures of `MlsDisk`. struct DiskInner { /// Block I/O request queue. bio_req_queue: BioReqQueue, @@ -63,13 +63,13 @@ struct DiskInner { data_buf: DataBuf, /// Root encryption key. root_key: Key, - /// Whether `SwornDisk` is dropped. + /// Whether `MlsDisk` is dropped. is_dropped: AtomicBool, /// Scope lock for control write and sync operation. write_sync_region: RwLock<()>, } -impl aster_block::BlockDevice for SwornDisk { +impl aster_block::BlockDevice for MlsDisk { fn enqueue( &self, bio: aster_block::bio::SubmittedBio, @@ -165,7 +165,7 @@ impl aster_block::BlockDevice for SwornDisk { } } -impl SwornDisk { +impl MlsDisk { /// Read a specified number of blocks at a logical block address on the device. /// The block contents will be read into a single contiguous buffer. pub fn read(&self, lba: Lba, buf: BufMut) -> Result<()> { @@ -202,7 +202,7 @@ impl SwornDisk { // TODO: Error handling the sync operation self.inner.sync().unwrap(); - trace!("[SwornDisk] Sync completed. {self:?}"); + trace!("[MlsDisk] Sync completed. {self:?}"); Ok(()) } @@ -211,7 +211,7 @@ impl SwornDisk { self.inner.user_data_disk.nblocks() } - /// Creates a new `SwornDisk` on the given disk, with the root encryption key. + /// Creates a new `MlsDisk` on the given disk, with the root encryption key. pub fn create( disk: D, root_key: Key, @@ -257,12 +257,12 @@ impl SwornDisk { }), }; - info!("[SwornDisk] Created successfully! {:?}", &new_self); + info!("[MlsDisk] Created successfully! {:?}", &new_self); // XXX: Would `disk::drop()` bring unexpected behavior? Ok(new_self) } - /// Opens the `SwornDisk` on the given disk, with the root encryption key. + /// Opens the `MlsDisk` on the given disk, with the root encryption key. pub fn open( disk: D, root_key: Key, @@ -309,7 +309,7 @@ impl SwornDisk { }), }; - info!("[SwornDisk] Opened successfully! {:?}", &opened_self); + info!("[MlsDisk] Opened successfully! {:?}", &opened_self); Ok(opened_self) } @@ -360,7 +360,7 @@ impl DiskInner { if let Err(e) = &res && e.errno() == NotFound { - warn!("[SwornDisk] read contains empty read on lba {lba}"); + warn!("[MlsDisk] read contains empty read on lba {lba}"); return Ok(()); } res @@ -375,7 +375,7 @@ impl DiskInner { if let Err(e) = &res && e.errno() == NotFound { - warn!("[SwornDisk] readv contains empty read on lba {lba}"); + warn!("[MlsDisk] readv contains empty read on lba {lba}"); return Ok(()); } res @@ -622,15 +622,15 @@ impl DiskInner { } } -impl Drop for SwornDisk { +impl Drop for MlsDisk { fn drop(&mut self) { self.inner.is_dropped.store(true, Ordering::Release); } } -impl Debug for SwornDisk { +impl Debug for MlsDisk { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("SwornDisk") + f.debug_struct("MlsDisk") .field("user_data_nblocks", &self.inner.user_data_disk.nblocks()) .field("logical_block_table", &self.inner.logical_block_table) .finish() @@ -835,12 +835,12 @@ mod tests { use crate::layers::{bio::MemDisk, disk::bio::BioReqBuilder}; #[test] - fn sworndisk_fns() -> Result<()> { + fn mlsdisk_fns() -> Result<()> { let nblocks = 64 * 1024; let mem_disk = MemDisk::create(nblocks)?; let root_key = Key::random(); - // Create a new `SwornDisk` then do some writes - let sworndisk = SwornDisk::create(mem_disk.clone(), root_key, None)?; + // Create a new `MlsDisk` then do some writes + let mlsdisk = MlsDisk::create(mem_disk.clone(), root_key, None)?; let num_rw = 1024; // Submit a write block I/O request @@ -854,23 +854,23 @@ mod tests { .addr(0 as BlockId) .bufs(bufs) .build(); - sworndisk.submit_bio_sync(bio_req)?; + mlsdisk.submit_bio_sync(bio_req)?; - // Sync the `SwornDisk` then do some reads - sworndisk.submit_bio_sync(BioReqBuilder::new(BioType::Sync).build())?; + // Sync the `MlsDisk` then do some reads + mlsdisk.submit_bio_sync(BioReqBuilder::new(BioType::Sync).build())?; let mut rbuf = Buf::alloc(1)?; for i in 0..num_rw { - sworndisk.read(i as Lba, rbuf.as_mut())?; + mlsdisk.read(i as Lba, rbuf.as_mut())?; assert_eq!(rbuf.as_slice()[0], i as u8); } - // Open the closed `SwornDisk` then test its data's existence - drop(sworndisk); + // Open the closed `MlsDisk` then test its data's existence + drop(mlsdisk); thread::spawn(move || -> Result<()> { - let opened_sworndisk = SwornDisk::open(mem_disk, root_key, None)?; + let opened_mlsdisk = MlsDisk::open(mem_disk, root_key, None)?; let mut rbuf = Buf::alloc(2)?; - opened_sworndisk.read(5 as Lba, rbuf.as_mut())?; + opened_mlsdisk.read(5 as Lba, rbuf.as_mut())?; assert_eq!(rbuf.as_slice()[0], 5u8); assert_eq!(rbuf.as_slice()[4096], 6u8); Ok(()) diff --git a/kernel/comps/mlsdisk/src/layers/5-disk/mod.rs b/kernel/comps/mlsdisk/src/layers/5-disk/mod.rs index ff6852c2e..9d923092a 100644 --- a/kernel/comps/mlsdisk/src/layers/5-disk/mod.rs +++ b/kernel/comps/mlsdisk/src/layers/5-disk/mod.rs @@ -2,33 +2,33 @@ //! The layer of secure virtual disk. //! -//! `SwornDisk` provides three block I/O interfaces, `read()`, `write()` and `sync()`. -//! `SwornDisk` protects a logical block of user data using authenticated encryption. +//! `MlsDisk` provides three block I/O interfaces, `read()`, `write()` and `sync()`. +//! `MlsDisk` protects a logical block of user data using authenticated encryption. //! The metadata of the encrypted logical blocks are inserted into a secure index `TxLsmTree`. //! -//! `SwornDisk`'s backed untrusted host disk space is managed in `BlockAlloc`. Block reclamation can be +//! `MlsDisk`'s backed untrusted host disk space is managed in `BlockAlloc`. Block reclamation can be //! delayed to user-defined callbacks on `TxLsmTree`. -//! `SwornDisk` supports buffering written logical blocks. +//! `MlsDisk` supports buffering written logical blocks. //! //! # Usage Example //! -//! Write, sync then read blocks from `SwornDisk`. +//! Write, sync then read blocks from `MlsDisk`. //! //! ``` //! let nblocks = 1024; //! let mem_disk = MemDisk::create(nblocks)?; //! let root_key = Key::random(); -//! let sworndisk = SwornDisk::create(mem_disk.clone(), root_key)?; +//! let mlsdisk = MlsDisk::create(mem_disk.clone(), root_key)?; //! //! let num_rw = 128; //! let mut rw_buf = Buf::alloc(1)?; //! for i in 0..num_rw { //! rw_buf.as_mut_slice().fill(i as u8); -//! sworndisk.write(i as Lba, rw_buf.as_ref())?; +//! mlsdisk.write(i as Lba, rw_buf.as_ref())?; //! } -//! sworndisk.sync()?; +//! mlsdisk.sync()?; //! for i in 0..num_rw { -//! sworndisk.read(i as Lba, rw_buf.as_mut())?; +//! mlsdisk.read(i as Lba, rw_buf.as_mut())?; //! assert_eq!(rw_buf.as_slice()[0], i as u8); //! } //! ``` @@ -36,6 +36,6 @@ mod bio; mod block_alloc; mod data_buf; -mod sworndisk; +mod mlsdisk; -pub use self::sworndisk::SwornDisk; +pub use self::mlsdisk::MlsDisk; diff --git a/kernel/comps/mlsdisk/src/lib.rs b/kernel/comps/mlsdisk/src/lib.rs index 30499e508..2f8472c33 100644 --- a/kernel/comps/mlsdisk/src/lib.rs +++ b/kernel/comps/mlsdisk/src/lib.rs @@ -20,7 +20,7 @@ pub use self::{ error::{Errno, Error}, layers::{ bio::{BlockId, BlockSet, Buf, BufMut, BufRef, BLOCK_SIZE}, - disk::SwornDisk, + disk::MlsDisk, }, os::{Aead, AeadIv, AeadKey, AeadMac, Rng}, util::{Aead as _, RandomInit, Rng as _}, diff --git a/kernel/comps/mlsdisk/src/util/lazy_delete.rs b/kernel/comps/mlsdisk/src/util/lazy_delete.rs index f15fdcd8a..f2d6d281e 100644 --- a/kernel/comps/mlsdisk/src/util/lazy_delete.rs +++ b/kernel/comps/mlsdisk/src/util/lazy_delete.rs @@ -27,7 +27,7 @@ use crate::prelude::*; /// Here is a simple example. /// /// ``` -/// use sworndisk_v2::lazy_delete::*; +/// use crate::util::LazyDelete; /// /// let lazy_delete_u32 = LazyDelete::new(123_u32, |obj| { /// println!("the real deletion happens in this closure");