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}
22
23impl ResourceId<DiskLayerHandleKind> for RamDiskLayerHandle {
24    const ID: &'static str = "ram";
25}
26
27/// Handle for a disk layer backed by a full disk.
28#[derive(MeshPayload)]
29pub struct DiskLayerHandle(pub Resource<DiskHandleKind>);
30
31impl ResourceId<DiskLayerHandleKind> for DiskLayerHandle {
32    const ID: &'static str = "disk";
33}
34
35/// Parameters used when performing first-time init of `dbhd` files.
36#[derive(MeshPayload)]
37pub struct SqliteDiskLayerFormatParams {
38    /// Should the layer be considered logically read only (i.e: a cache layer)
39    pub logically_read_only: bool,
40    /// Desired layer size. If `None`, lazily selects a size only once after
41    /// being attached to an existing layer.
42    pub len: Option<u64>,
43}
44
45/// Sqlite disk layer handle.
46#[derive(MeshPayload)]
47pub struct SqliteDiskLayerHandle {
48    /// Path to `.dbhd` file
49    pub dbhd_path: String,
50
51    /// If this is provided, the dbhd will be (re)formatted with the provided
52    /// params.
53    pub format_dbhd: Option<SqliteDiskLayerFormatParams>,
54}
55
56impl ResourceId<DiskLayerHandleKind> for SqliteDiskLayerHandle {
57    const ID: &'static str = "sqlite";
58}
59
60/// A handle for a disk layer that automatically selects a dbhd file to use as a
61/// cache for lower layers.
62#[derive(MeshPayload)]
63pub struct SqliteAutoCacheDiskLayerHandle {
64    /// Path to the root directory for the cache.
65    pub cache_path: String,
66    /// The key to use to select the cache file. If `None`, use the next layer's
67    /// disk ID.
68    pub cache_key: Option<String>,
69}
70
71impl ResourceId<DiskLayerHandleKind> for SqliteAutoCacheDiskLayerHandle {
72    const ID: &'static str = "sqlite-autocache";
73}