virtio_p9/
resolver.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Defines the resource resolver for virtio-9p devices.
5
6use crate::VirtioPlan9Device;
7use plan9::Plan9FileSystem;
8use virtio::LegacyWrapper;
9use virtio::resolve::ResolvedVirtioDevice;
10use virtio::resolve::VirtioResolveInput;
11use virtio_resources::p9::VirtioPlan9Handle;
12use vm_resource::ResolveResource;
13use vm_resource::declare_static_resolver;
14use vm_resource::kind::VirtioDeviceHandle;
15
16/// Resolver for virtio-9p devices.
17pub struct VirtioPlan9Resolver;
18
19declare_static_resolver! {
20    VirtioPlan9Resolver,
21    (VirtioDeviceHandle, VirtioPlan9Handle),
22}
23
24impl ResolveResource<VirtioDeviceHandle, VirtioPlan9Handle> for VirtioPlan9Resolver {
25    type Output = ResolvedVirtioDevice;
26    type Error = anyhow::Error;
27
28    fn resolve(
29        &self,
30        resource: VirtioPlan9Handle,
31        input: VirtioResolveInput<'_>,
32    ) -> Result<Self::Output, Self::Error> {
33        let device = LegacyWrapper::new(
34            input.driver_source,
35            VirtioPlan9Device::new(
36                &resource.tag,
37                Plan9FileSystem::new(&resource.root_path, resource.debug)?,
38                input.guest_memory.clone(),
39            ),
40            input.guest_memory,
41        );
42        Ok(device.into())
43    }
44}