disk_backend/
resolve.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resolver-related definitions for disk resources.
5
6use crate::Disk;
7use crate::DiskIo;
8use crate::InvalidDisk;
9use vm_resource::CanResolveTo;
10use vm_resource::kind::DiskHandleKind;
11use vmcore::vm_task::VmTaskDriverSource;
12
13impl CanResolveTo<ResolvedDisk> for DiskHandleKind {
14    type Input<'a> = ResolveDiskParameters<'a>;
15}
16
17/// Parameters used when resolving a disk resource.
18#[derive(Copy, Clone)]
19pub struct ResolveDiskParameters<'a> {
20    /// Whether the disk is being opened for read-only use.
21    pub read_only: bool,
22    /// The task driver source for the VM.
23    pub driver_source: &'a VmTaskDriverSource,
24}
25
26/// A resolved [`Disk`].
27pub struct ResolvedDisk(pub Disk);
28
29impl ResolvedDisk {
30    /// Returns a resolved disk wrapping a backing object.
31    pub fn new<T: DiskIo>(disk: T) -> Result<Self, InvalidDisk> {
32        Ok(Self(Disk::new(disk)?))
33    }
34}