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 StripedDiskHandle {
75 pub devices: Vec<Resource<DiskHandleKind>>,
77 pub chunk_size_in_bytes: Option<u32>,
79 pub logic_sector_count: Option<u64>,
81}
82
83impl ResourceId<DiskHandleKind> for StripedDiskHandle {
84 const ID: &'static str = "striped";
85}
86
87#[derive(MeshPayload)]
96pub struct AutoFormattedDiskHandle {
97 pub disk: Resource<DiskHandleKind>,
99 pub guid: [u8; 16],
101}
102
103impl ResourceId<DiskHandleKind> for AutoFormattedDiskHandle {
104 const ID: &'static str = "ntfsfmt";
105}
106
107#[derive(MeshPayload)]
111pub struct BlobDiskHandle {
112 pub url: String,
114 pub format: BlobDiskFormat,
116}
117
118impl ResourceId<DiskHandleKind> for BlobDiskHandle {
119 const ID: &'static str = "blob";
120}
121
122#[derive(MeshPayload)]
124pub enum BlobDiskFormat {
125 Flat,
127 FixedVhd1,
129}
130
131#[derive(MeshPayload)]
133pub struct LayeredDiskHandle {
134 pub layers: Vec<DiskLayerDescription>,
136}
137
138impl LayeredDiskHandle {
139 pub fn single_layer(layer: impl IntoResource<DiskLayerHandleKind>) -> Self {
141 Self {
142 layers: vec![layer.into_resource().into()],
143 }
144 }
145}
146
147impl ResourceId<DiskHandleKind> for LayeredDiskHandle {
148 const ID: &'static str = "layered";
149}
150
151#[derive(MeshPayload)]
153pub struct DiskLayerDescription {
154 pub layer: Resource<DiskLayerHandleKind>,
156 pub read_cache: bool,
158 pub write_through: bool,
160}
161
162impl From<Resource<DiskLayerHandleKind>> for DiskLayerDescription {
163 fn from(layer: Resource<DiskLayerHandleKind>) -> Self {
164 Self {
165 layer,
166 read_cache: false,
167 write_through: false,
168 }
169 }
170}