disklayer_ram/
resolver.rsuse super::Error;
use super::RamDiskLayer;
use crate::LazyRamDiskLayer;
use disk_backend_resources::layer::RamDiskLayerHandle;
use disk_layered::resolve::ResolveDiskLayerParameters;
use disk_layered::resolve::ResolvedDiskLayer;
use vm_resource::ResolveResource;
use vm_resource::declare_static_resolver;
use vm_resource::kind::DiskLayerHandleKind;
pub struct RamDiskLayerResolver;
declare_static_resolver!(
RamDiskLayerResolver,
(DiskLayerHandleKind, RamDiskLayerHandle)
);
#[derive(Debug, Error)]
pub enum ResolveRamDiskError {
#[error("failed to create ram disk layer")]
Ram(#[source] Error),
}
impl ResolveResource<DiskLayerHandleKind, RamDiskLayerHandle> for RamDiskLayerResolver {
type Output = ResolvedDiskLayer;
type Error = ResolveRamDiskError;
fn resolve(
&self,
rsrc: RamDiskLayerHandle,
_input: ResolveDiskLayerParameters<'_>,
) -> Result<Self::Output, Self::Error> {
Ok(match rsrc.len {
Some(len) => {
ResolvedDiskLayer::new(RamDiskLayer::new(len).map_err(ResolveRamDiskError::Ram)?)
}
None => ResolvedDiskLayer::new(LazyRamDiskLayer::new()),
})
}
}