disk_backend_resources/layer.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Disk layer resources.
5
6use mesh::MeshPayload;
7use vm_resource::Resource;
8use vm_resource::ResourceId;
9use vm_resource::kind::DiskHandleKind;
10use vm_resource::kind::DiskLayerHandleKind;
11
12/// RAM disk layer handle.
13///
14/// FUTURE: allocate shared memory here so that the disk can be migrated between
15/// processes.
16#[derive(MeshPayload)]
17pub struct RamDiskLayerHandle {
18 /// The size of the layer. If `None`, the layer will be the same size as the
19 /// lower disk.
20 pub len: Option<u64>,
21 /// The sector size in bytes. If `None`, uses the lower layer's sector
22 /// size, or 512 if there is no lower layer.
23 pub sector_size: Option<u32>,
24}
25
26impl ResourceId<DiskLayerHandleKind> for RamDiskLayerHandle {
27 const ID: &'static str = "ram";
28}
29
30/// Handle for a disk layer backed by a full disk.
31#[derive(MeshPayload)]
32pub struct DiskLayerHandle(pub Resource<DiskHandleKind>);
33
34impl ResourceId<DiskLayerHandleKind> for DiskLayerHandle {
35 const ID: &'static str = "disk";
36}
37
38/// Parameters used when performing first-time init of `dbhd` files.
39#[derive(MeshPayload)]
40pub struct SqliteDiskLayerFormatParams {
41 /// Should the layer be considered logically read only (i.e: a cache layer)
42 pub logically_read_only: bool,
43 /// Desired layer size. If `None`, lazily selects a size only once after
44 /// being attached to an existing layer.
45 pub len: Option<u64>,
46}
47
48/// Sqlite disk layer handle.
49#[derive(MeshPayload)]
50pub struct SqliteDiskLayerHandle {
51 /// Path to `.dbhd` file
52 pub dbhd_path: String,
53
54 /// If this is provided, the dbhd will be (re)formatted with the provided
55 /// params.
56 pub format_dbhd: Option<SqliteDiskLayerFormatParams>,
57}
58
59impl ResourceId<DiskLayerHandleKind> for SqliteDiskLayerHandle {
60 const ID: &'static str = "sqlite";
61}
62
63/// A handle for a disk layer that automatically selects a dbhd file to use as a
64/// cache for lower layers.
65#[derive(MeshPayload)]
66pub struct SqliteAutoCacheDiskLayerHandle {
67 /// Path to the root directory for the cache.
68 pub cache_path: String,
69 /// The key to use to select the cache file. If `None`, use the next layer's
70 /// disk ID.
71 pub cache_key: Option<String>,
72}
73
74impl ResourceId<DiskLayerHandleKind> for SqliteAutoCacheDiskLayerHandle {
75 const ID: &'static str = "sqlite-autocache";
76}