mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 05:16:47 +00:00
Rename SwornDisk
to MlsDisk
This commit is contained in:
parent
328ba47ccd
commit
c040df72b3
@ -311,7 +311,7 @@ impl<K: RecordKey<K>, V: RecordValue, D: BlockSet + 'static> TreeInner<K, V, D>
|
||||
|
||||
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<K: RecordKey<K>, V: RecordValue, D: BlockSet + 'static> TreeInner<K, V, D>
|
||||
|
||||
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<K: RecordKey<K>, V: RecordValue, D: BlockSet + 'static> TreeInner<K, V, D>
|
||||
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) {
|
||||
|
@ -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<BitMap>,
|
||||
@ -38,7 +38,7 @@ pub(super) struct AllocTable {
|
||||
num_free: CvarMutex<usize>,
|
||||
}
|
||||
|
||||
/// 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<D> {
|
||||
|
@ -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},
|
||||
|
@ -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<D: BlockSet> {
|
||||
/// MlsDisk.
|
||||
pub struct MlsDisk<D: BlockSet> {
|
||||
inner: Arc<DiskInner<D>>,
|
||||
}
|
||||
|
||||
/// Inner structures of `SwornDisk`.
|
||||
/// Inner structures of `MlsDisk`.
|
||||
struct DiskInner<D: BlockSet> {
|
||||
/// Block I/O request queue.
|
||||
bio_req_queue: BioReqQueue,
|
||||
@ -63,13 +63,13 @@ struct DiskInner<D: BlockSet> {
|
||||
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<D: BlockSet + 'static> aster_block::BlockDevice for SwornDisk<D> {
|
||||
impl<D: BlockSet + 'static> aster_block::BlockDevice for MlsDisk<D> {
|
||||
fn enqueue(
|
||||
&self,
|
||||
bio: aster_block::bio::SubmittedBio,
|
||||
@ -165,7 +165,7 @@ impl<D: BlockSet + 'static> aster_block::BlockDevice for SwornDisk<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BlockSet + 'static> SwornDisk<D> {
|
||||
impl<D: BlockSet + 'static> MlsDisk<D> {
|
||||
/// 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<D: BlockSet + 'static> SwornDisk<D> {
|
||||
// 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<D: BlockSet + 'static> SwornDisk<D> {
|
||||
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<D: BlockSet + 'static> SwornDisk<D> {
|
||||
}),
|
||||
};
|
||||
|
||||
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<D: BlockSet + 'static> SwornDisk<D> {
|
||||
}),
|
||||
};
|
||||
|
||||
info!("[SwornDisk] Opened successfully! {:?}", &opened_self);
|
||||
info!("[MlsDisk] Opened successfully! {:?}", &opened_self);
|
||||
Ok(opened_self)
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ impl<D: BlockSet + 'static> DiskInner<D> {
|
||||
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<D: BlockSet + 'static> DiskInner<D> {
|
||||
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<D: BlockSet + 'static> DiskInner<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BlockSet> Drop for SwornDisk<D> {
|
||||
impl<D: BlockSet> Drop for MlsDisk<D> {
|
||||
fn drop(&mut self) {
|
||||
self.inner.is_dropped.store(true, Ordering::Release);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: BlockSet + 'static> Debug for SwornDisk<D> {
|
||||
impl<D: BlockSet + 'static> Debug for MlsDisk<D> {
|
||||
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(())
|
@ -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;
|
||||
|
@ -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 _},
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user