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)]
32pub struct DiskWithReservationsHandle(pub Resource<DiskHandleKind>);
33
34impl ResourceId<DiskHandleKind> for DiskWithReservationsHandle {
35 const ID: &'static str = "prwrap";
36}
37
38#[derive(MeshPayload)]
40pub struct DelayDiskHandle {
41 pub disk: Resource<DiskHandleKind>,
43 pub delay: Cell<Duration>,
45}
46
47impl ResourceId<DiskHandleKind> for DelayDiskHandle {
48 const ID: &'static str = "delay";
49}
50
51#[derive(MeshPayload)]
53pub struct FixedVhd1DiskHandle(pub std::fs::File);
54
55impl ResourceId<DiskHandleKind> for FixedVhd1DiskHandle {
56 const ID: &'static str = "fixed_vhd1";
57}
58
59#[derive(MeshPayload)]
61pub struct StripedDiskHandle {
62 pub devices: Vec<Resource<DiskHandleKind>>,
64 pub chunk_size_in_bytes: Option<u32>,
66 pub logic_sector_count: Option<u64>,
68}
69
70impl ResourceId<DiskHandleKind> for StripedDiskHandle {
71 const ID: &'static str = "striped";
72}
73
74#[derive(MeshPayload)]
83pub struct AutoFormattedDiskHandle {
84 pub disk: Resource<DiskHandleKind>,
86 pub guid: [u8; 16],
88}
89
90impl ResourceId<DiskHandleKind> for AutoFormattedDiskHandle {
91 const ID: &'static str = "ntfsfmt";
92}
93
94#[derive(MeshPayload)]
98pub struct BlobDiskHandle {
99 pub url: String,
101 pub format: BlobDiskFormat,
103}
104
105impl ResourceId<DiskHandleKind> for BlobDiskHandle {
106 const ID: &'static str = "blob";
107}
108
109#[derive(MeshPayload)]
111pub enum BlobDiskFormat {
112 Flat,
114 FixedVhd1,
116}
117
118#[derive(MeshPayload)]
120pub struct LayeredDiskHandle {
121 pub layers: Vec<DiskLayerDescription>,
123}
124
125impl LayeredDiskHandle {
126 pub fn single_layer(layer: impl IntoResource<DiskLayerHandleKind>) -> Self {
128 Self {
129 layers: vec![layer.into_resource().into()],
130 }
131 }
132}
133
134impl ResourceId<DiskHandleKind> for LayeredDiskHandle {
135 const ID: &'static str = "layered";
136}
137
138#[derive(MeshPayload)]
140pub struct DiskLayerDescription {
141 pub layer: Resource<DiskLayerHandleKind>,
143 pub read_cache: bool,
145 pub write_through: bool,
147}
148
149impl From<Resource<DiskLayerHandleKind>> for DiskLayerDescription {
150 fn from(layer: Resource<DiskLayerHandleKind>) -> Self {
151 Self {
152 layer,
153 read_cache: false,
154 write_through: false,
155 }
156 }
157}