disk_backend_resources/
lib.rs1#![forbid(unsafe_code)]
7
8pub mod layer;
9
10use mesh::Cell;
11use mesh::MeshPayload;
12use std::time::Duration;
13use vm_resource::IntoResource;
14use vm_resource::Resource;
15use vm_resource::ResourceId;
16use vm_resource::kind::DiskHandleKind;
17use vm_resource::kind::DiskLayerHandleKind;
18
19#[derive(MeshPayload)]
24pub struct FileDiskHandle(pub std::fs::File);
25
26impl ResourceId<DiskHandleKind> for FileDiskHandle {
27 const ID: &'static str = "file";
28}
29
30#[derive(MeshPayload)]
34pub struct BlockDeviceDiskHandle {
35 pub file: std::fs::File,
37}
38
39impl ResourceId<DiskHandleKind> for BlockDeviceDiskHandle {
40 const ID: &'static str = "block";
41}
42
43#[derive(MeshPayload)]
45pub struct DiskWithReservationsHandle(pub Resource<DiskHandleKind>);
46
47impl ResourceId<DiskHandleKind> for DiskWithReservationsHandle {
48 const ID: &'static str = "prwrap";
49}
50
51#[derive(MeshPayload)]
53pub struct DelayDiskHandle {
54 pub disk: Resource<DiskHandleKind>,
56 pub delay: Cell<Duration>,
58}
59
60impl ResourceId<DiskHandleKind> for DelayDiskHandle {
61 const ID: &'static str = "delay";
62}
63
64#[derive(MeshPayload)]
66pub struct FixedVhd1DiskHandle(pub std::fs::File);
67
68impl ResourceId<DiskHandleKind> for FixedVhd1DiskHandle {
69 const ID: &'static str = "fixed_vhd1";
70}
71
72#[derive(MeshPayload)]
74pub struct FlatVmdkDiskHandle {
75 pub files: Vec<std::fs::File>,
77 pub extents: Vec<FlatVmdkExtent>,
79}
80
81impl ResourceId<DiskHandleKind> for FlatVmdkDiskHandle {
82 const ID: &'static str = "vmdk_flat";
83}
84
85#[derive(MeshPayload)]
87pub struct FlatVmdkExtent {
88 pub file_index: u32,
90 pub access: VmdkExtentAccess,
92 pub sector_count: u64,
94 pub source_start_sector: u64,
96}
97
98#[derive(MeshPayload)]
100pub enum VmdkExtentAccess {
101 ReadWrite,
103 ReadOnly,
105}
106
107#[derive(MeshPayload)]
109pub struct StripedDiskHandle {
110 pub devices: Vec<Resource<DiskHandleKind>>,
112 pub chunk_size_in_bytes: Option<u32>,
114 pub logic_sector_count: Option<u64>,
116}
117
118impl ResourceId<DiskHandleKind> for StripedDiskHandle {
119 const ID: &'static str = "striped";
120}
121
122#[derive(MeshPayload)]
131pub struct AutoFormattedDiskHandle {
132 pub disk: Resource<DiskHandleKind>,
134 pub guid: [u8; 16],
136}
137
138impl ResourceId<DiskHandleKind> for AutoFormattedDiskHandle {
139 const ID: &'static str = "ntfsfmt";
140}
141
142#[derive(MeshPayload)]
146pub struct BlobDiskHandle {
147 pub url: String,
149 pub format: BlobDiskFormat,
151}
152
153impl ResourceId<DiskHandleKind> for BlobDiskHandle {
154 const ID: &'static str = "blob";
155}
156
157#[derive(MeshPayload)]
159pub enum BlobDiskFormat {
160 Flat,
162 FixedVhd1,
164}
165
166#[derive(MeshPayload)]
168pub struct LayeredDiskHandle {
169 pub layers: Vec<DiskLayerDescription>,
171}
172
173impl LayeredDiskHandle {
174 pub fn single_layer(layer: impl IntoResource<DiskLayerHandleKind>) -> Self {
176 Self {
177 layers: vec![layer.into_resource().into()],
178 }
179 }
180}
181
182impl ResourceId<DiskHandleKind> for LayeredDiskHandle {
183 const ID: &'static str = "layered";
184}
185
186#[derive(MeshPayload)]
188pub struct DiskLayerDescription {
189 pub layer: Resource<DiskLayerHandleKind>,
191 pub read_cache: bool,
193 pub write_through: bool,
195}
196
197impl From<Resource<DiskLayerHandleKind>> for DiskLayerDescription {
198 fn from(layer: Resource<DiskLayerHandleKind>) -> Self {
199 Self {
200 layer,
201 read_cache: false,
202 write_through: false,
203 }
204 }
205}