From 280d4fb245b7b1ca3c89f43606e3b19518ad3f26 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 30 Nov 2020 09:06:13 +0000 Subject: [PATCH] vmm: Include device tree in vm.info API The DeviceNode cannot be fully represented as it embeds a Rust style enum (i.e. with data) which is instead represented by a simple associative array. Fixes: #1167 Signed-off-by: Rob Bradford --- vmm/src/api/mod.rs | 2 ++ vmm/src/api/openapi/cloud-hypervisor.yaml | 22 ++++++++++++++++++++++ vmm/src/device_manager.rs | 4 ++++ vmm/src/lib.rs | 3 +++ vmm/src/vm.rs | 5 +++++ 5 files changed, 36 insertions(+) diff --git a/vmm/src/api/mod.rs b/vmm/src/api/mod.rs index 9684e3c46..6af762350 100644 --- a/vmm/src/api/mod.rs +++ b/vmm/src/api/mod.rs @@ -39,6 +39,7 @@ pub mod http_endpoint; use crate::config::{ DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig, }; +use crate::device_tree::DeviceTree; use crate::vm::{Error as VmError, VmState}; use micro_http::Body; use std::io; @@ -153,6 +154,7 @@ pub struct VmInfo { pub config: Arc>, pub state: VmState, pub memory_actual_size: u64, + pub device_tree: Option>>, } #[derive(Clone, Deserialize, Serialize)] diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 06a9bb3f5..dbadba734 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -363,8 +363,30 @@ components: memory_actual_size: type: integer format: int64 + device_tree: + type: object + additionalProperties: + $ref: '#/components/schemas/DeviceNode' description: Virtual Machine information + DeviceNode: + type: object + properties: + id: + type: string + resources: + type: array + items: + # Rust enum type (with data) which can't be better represented here + type: object + children: + type: array + items: + type: string + pci_bdf: + type: integer + format: int32 + VmCounters: type: object additionalProperties: diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 2c6482c08..783b19672 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3134,6 +3134,10 @@ impl DeviceManager { 0 } + + pub fn device_tree(&self) -> Arc> { + self.device_tree.clone() + } } #[cfg(feature = "acpi")] diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 7f3396828..769833869 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -484,10 +484,13 @@ impl Vmm { memory_actual_size -= vm.balloon_size(); } + let device_tree = self.vm.as_ref().map(|vm| vm.device_tree()); + Ok(VmInfo { config, state, memory_actual_size, + device_tree, }) } None => Err(VmError::VmNotCreated), diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 2751f6bd7..20c16dfdc 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -30,6 +30,7 @@ use crate::config::{ }; use crate::cpu; use crate::device_manager::{self, get_win_size, Console, DeviceManager, DeviceManagerError}; +use crate::device_tree::DeviceTree; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager}; use crate::migration::{get_vm_snapshot, url_to_path, VM_SNAPSHOT_FILE}; use crate::seccomp_filters::{get_seccomp_filter, Thread}; @@ -1717,6 +1718,10 @@ impl Vm { .unwrap() .dirty_memory_range_table() } + + pub fn device_tree(&self) -> Arc> { + self.device_manager.lock().unwrap().device_tree() + } } impl Pausable for Vm {