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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-11-30 09:06:13 +00:00 committed by Samuel Ortiz
parent 15f0451c34
commit 280d4fb245
5 changed files with 36 additions and 0 deletions

View File

@ -39,6 +39,7 @@ pub mod http_endpoint;
use crate::config::{ use crate::config::{
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig, DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
}; };
use crate::device_tree::DeviceTree;
use crate::vm::{Error as VmError, VmState}; use crate::vm::{Error as VmError, VmState};
use micro_http::Body; use micro_http::Body;
use std::io; use std::io;
@ -153,6 +154,7 @@ pub struct VmInfo {
pub config: Arc<Mutex<VmConfig>>, pub config: Arc<Mutex<VmConfig>>,
pub state: VmState, pub state: VmState,
pub memory_actual_size: u64, pub memory_actual_size: u64,
pub device_tree: Option<Arc<Mutex<DeviceTree>>>,
} }
#[derive(Clone, Deserialize, Serialize)] #[derive(Clone, Deserialize, Serialize)]

View File

@ -363,8 +363,30 @@ components:
memory_actual_size: memory_actual_size:
type: integer type: integer
format: int64 format: int64
device_tree:
type: object
additionalProperties:
$ref: '#/components/schemas/DeviceNode'
description: Virtual Machine information 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: VmCounters:
type: object type: object
additionalProperties: additionalProperties:

View File

@ -3134,6 +3134,10 @@ impl DeviceManager {
0 0
} }
pub fn device_tree(&self) -> Arc<Mutex<DeviceTree>> {
self.device_tree.clone()
}
} }
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]

View File

@ -484,10 +484,13 @@ impl Vmm {
memory_actual_size -= vm.balloon_size(); memory_actual_size -= vm.balloon_size();
} }
let device_tree = self.vm.as_ref().map(|vm| vm.device_tree());
Ok(VmInfo { Ok(VmInfo {
config, config,
state, state,
memory_actual_size, memory_actual_size,
device_tree,
}) })
} }
None => Err(VmError::VmNotCreated), None => Err(VmError::VmNotCreated),

View File

@ -30,6 +30,7 @@ use crate::config::{
}; };
use crate::cpu; use crate::cpu;
use crate::device_manager::{self, get_win_size, Console, DeviceManager, DeviceManagerError}; 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::memory_manager::{Error as MemoryManagerError, MemoryManager};
use crate::migration::{get_vm_snapshot, url_to_path, VM_SNAPSHOT_FILE}; use crate::migration::{get_vm_snapshot, url_to_path, VM_SNAPSHOT_FILE};
use crate::seccomp_filters::{get_seccomp_filter, Thread}; use crate::seccomp_filters::{get_seccomp_filter, Thread};
@ -1717,6 +1718,10 @@ impl Vm {
.unwrap() .unwrap()
.dirty_memory_range_table() .dirty_memory_range_table()
} }
pub fn device_tree(&self) -> Arc<Mutex<DeviceTree>> {
self.device_manager.lock().unwrap().device_tree()
}
} }
impl Pausable for Vm { impl Pausable for Vm {