Skip to content

Commit

Permalink
Add crucible-mem backend
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmooney committed Jan 11, 2024
1 parent e523726 commit 0cba3d1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bin/propolis-standalone/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn block_backend(
(be, creg)
}
"crucible" => create_crucible_backend(be, opts, log),
"crucible-mem" => create_crucible_mem_backend(be, opts, log),
"mem-async" => {
let parsed: MemAsyncConfig = opt_deser(&be.options).unwrap();

Expand Down Expand Up @@ -256,6 +257,25 @@ fn create_crucible_backend(
(be, creg)
}

#[cfg(feature = "crucible")]
fn create_crucible_mem_backend(
be: &propolis_standalone_config::BlockDevice,
opts: block::BackendOpts,
log: &slog::Logger,
) -> (Arc<dyn block::Backend>, ChildRegister) {
#[derive(Deserialize)]
struct CrucibleMemConfig {
size: u64,
}
let parsed: CrucibleMemConfig = opt_deser(&be.options).unwrap();

let be = block::CrucibleBackend::create_mem(parsed.size, opts, log.clone())
.unwrap();
let creg =
ChildRegister::new(&be, Some(be.get_uuid().unwrap().to_string()));
(be, creg)
}

#[cfg(not(feature = "crucible"))]
fn create_crucible_backend(
_be: &propolis_standalone_config::BlockDevice,
Expand All @@ -267,3 +287,15 @@ fn create_crucible_backend(
order to use the crucible block backend"
);
}

#[cfg(not(feature = "crucible"))]
fn create_crucible_mem_backend(
_be: &propolis_standalone_config::BlockDevice,
_opts: block::BackendOpts,
_log: &slog::Logger,
) -> (Arc<dyn block::Backend>, ChildRegister) {
panic!(
"Rebuild propolis-standalone with 'crucible' feature enabled in \
order to use the crucible-mem block backend"
);
}
39 changes: 39 additions & 0 deletions lib/propolis/src/block/crucible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,45 @@ impl CrucibleBackend {
}))
}

/// Create Crucible backend using the in-memory volume backend, rather than
/// "real" Crucible downstairs instances.
pub fn create_mem(
size: u64,
opts: block::BackendOpts,
log: slog::Logger,
) -> io::Result<Arc<Self>> {
let rt = tokio::runtime::Handle::current();
rt.block_on(async move {
let block_size = opts.block_size.ok_or_else(|| {
CrucibleError::GenericError(
"block_size is required parameter".into(),
)
})? as u64;
// Allocate and construct the volume.
let mem_disk = Arc::new(crucible::InMemoryBlockIO::new(
Uuid::new_v4(),
block_size,
size as usize,
));
let mut volume = Volume::new(block_size, log);
volume.add_subvolume(mem_disk).await?;

Ok(Arc::new(CrucibleBackend {
state: Arc::new(WorkerState {
attachment: block::backend::Attachment::new(),
volume,
info: block::DeviceInfo {
block_size: block_size as u32,
total_size: size / block_size,
read_only: opts.read_only.unwrap_or(false),
},
skip_flush: opts.skip_flush.unwrap_or(false),
}),
}))
})
.map_err(CrucibleError::into)
}

// Communicate to Nexus that we can remove the read only parent for
// the given volume id.
async fn remove_read_only_parent(
Expand Down

0 comments on commit 0cba3d1

Please sign in to comment.