disk_backend_resources/
lib.rs1#![forbid(unsafe_code)]
7
8pub mod layer;
9
10use mesh::MeshPayload;
11use vm_resource::IntoResource;
12use vm_resource::Resource;
13use vm_resource::ResourceId;
14use vm_resource::kind::DiskHandleKind;
15use vm_resource::kind::DiskLayerHandleKind;
16
17#[derive(MeshPayload)]
22pub struct FileDiskHandle(pub std::fs::File);
23
24impl ResourceId<DiskHandleKind> for FileDiskHandle {
25 const ID: &'static str = "file";
26}
27
28#[derive(MeshPayload)]
30pub struct DiskWithReservationsHandle(pub Resource<DiskHandleKind>);
31
32impl ResourceId<DiskHandleKind> for DiskWithReservationsHandle {
33 const ID: &'static str = "prwrap";
34}
35
36#[derive(MeshPayload)]
38pub struct FixedVhd1DiskHandle(pub std::fs::File);
39
40impl ResourceId<DiskHandleKind> for FixedVhd1DiskHandle {
41 const ID: &'static str = "fixed_vhd1";
42}
43
44#[derive(MeshPayload)]
46pub struct StripedDiskHandle {
47 pub devices: Vec<Resource<DiskHandleKind>>,
49 pub chunk_size_in_bytes: Option<u32>,
51 pub logic_sector_count: Option<u64>,
53}
54
55impl ResourceId<DiskHandleKind> for StripedDiskHandle {
56 const ID: &'static str = "striped";
57}
58
59#[derive(MeshPayload)]
68pub struct AutoFormattedDiskHandle {
69 pub disk: Resource<DiskHandleKind>,
71 pub guid: [u8; 16],
73}
74
75impl ResourceId<DiskHandleKind> for AutoFormattedDiskHandle {
76 const ID: &'static str = "ntfsfmt";
77}
78
79#[derive(MeshPayload)]
83pub struct BlobDiskHandle {
84 pub url: String,
86 pub format: BlobDiskFormat,
88}
89
90impl ResourceId<DiskHandleKind> for BlobDiskHandle {
91 const ID: &'static str = "blob";
92}
93
94#[derive(MeshPayload)]
96pub enum BlobDiskFormat {
97 Flat,
99 FixedVhd1,
101}
102
103#[derive(MeshPayload)]
105pub struct LayeredDiskHandle {
106 pub layers: Vec<DiskLayerDescription>,
108}
109
110impl LayeredDiskHandle {
111 pub fn single_layer(layer: impl IntoResource<DiskLayerHandleKind>) -> Self {
113 Self {
114 layers: vec![layer.into_resource().into()],
115 }
116 }
117}
118
119impl ResourceId<DiskHandleKind> for LayeredDiskHandle {
120 const ID: &'static str = "layered";
121}
122
123#[derive(MeshPayload)]
125pub struct DiskLayerDescription {
126 pub layer: Resource<DiskLayerHandleKind>,
128 pub read_cache: bool,
130 pub write_through: bool,
132}
133
134impl From<Resource<DiskLayerHandleKind>> for DiskLayerDescription {
135 fn from(layer: Resource<DiskLayerHandleKind>) -> Self {
136 Self {
137 layer,
138 read_cache: false,
139 write_through: false,
140 }
141 }
142}