virtio_resources/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! VM resource definitions for virtio devices.
5//!
6//! Device-specific definitions are here to avoid needing to pull in a device
7//! implementation crate just to construct the device's config.
8
9#![expect(missing_docs)]
10#![forbid(unsafe_code)]
11
12use mesh::MeshPayload;
13use vm_resource::Resource;
14use vm_resource::ResourceId;
15use vm_resource::kind::PciDeviceHandleKind;
16use vm_resource::kind::VirtioDeviceHandle;
17
18/// A resource for mapping a virtio device as a PCI device.
19#[derive(MeshPayload)]
20pub struct VirtioPciDeviceHandle(pub Resource<VirtioDeviceHandle>);
21
22impl ResourceId<PciDeviceHandleKind> for VirtioPciDeviceHandle {
23    const ID: &'static str = "virtio";
24}
25
26pub mod p9 {
27    use mesh::MeshPayload;
28    use vm_resource::ResourceId;
29    use vm_resource::kind::VirtioDeviceHandle;
30
31    #[derive(MeshPayload)]
32    pub struct VirtioPlan9Handle {
33        pub tag: String,
34        pub root_path: String,
35        pub debug: bool,
36    }
37
38    impl ResourceId<VirtioDeviceHandle> for VirtioPlan9Handle {
39        const ID: &'static str = "virtio-9p";
40    }
41}
42
43pub mod fs {
44    use mesh::MeshPayload;
45    use vm_resource::ResourceId;
46    use vm_resource::kind::VirtioDeviceHandle;
47
48    #[derive(MeshPayload)]
49    pub struct VirtioFsHandle {
50        pub tag: String,
51        pub fs: VirtioFsBackend,
52    }
53
54    #[derive(MeshPayload)]
55    pub enum VirtioFsBackend {
56        HostFs {
57            root_path: String,
58            mount_options: String,
59        },
60        SectionFs {
61            root_path: String,
62        },
63    }
64
65    impl ResourceId<VirtioDeviceHandle> for VirtioFsHandle {
66        const ID: &'static str = "virtiofs";
67    }
68}
69
70pub mod pmem {
71    use mesh::MeshPayload;
72    use vm_resource::ResourceId;
73    use vm_resource::kind::VirtioDeviceHandle;
74
75    #[derive(MeshPayload)]
76    pub struct VirtioPmemHandle {
77        pub path: String,
78    }
79
80    impl ResourceId<VirtioDeviceHandle> for VirtioPmemHandle {
81        const ID: &'static str = "virtio-pmem";
82    }
83}
84
85pub mod net {
86    use mesh::MeshPayload;
87    use net_backend_resources::mac_address::MacAddress;
88    use vm_resource::Resource;
89    use vm_resource::ResourceId;
90    use vm_resource::kind::NetEndpointHandleKind;
91    use vm_resource::kind::VirtioDeviceHandle;
92
93    #[derive(MeshPayload)]
94    pub struct VirtioNetHandle {
95        pub max_queues: Option<u16>,
96        pub mac_address: MacAddress,
97        pub endpoint: Resource<NetEndpointHandleKind>,
98    }
99
100    impl ResourceId<VirtioDeviceHandle> for VirtioNetHandle {
101        const ID: &'static str = "virtio-net";
102    }
103}