mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 02:55:45 +00:00
vmm: Add support for creating virtio-watchdog
The watchdog device is created through the "--watchdog" parameter. At most a single watchdog can be created per VM. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
d2c7645731
commit
885ee9567b
@ -236,6 +236,13 @@ fn create_app<'a, 'b>(
|
|||||||
.min_values(1)
|
.min_values(1)
|
||||||
.group("vm-config"),
|
.group("vm-config"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("watchdog")
|
||||||
|
.long("watchdog")
|
||||||
|
.help("Enable virtio-watchdog")
|
||||||
|
.takes_value(false)
|
||||||
|
.group("vm-config"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("v")
|
Arg::with_name("v")
|
||||||
.short("v")
|
.short("v")
|
||||||
@ -593,6 +600,7 @@ mod unit_tests {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
sgx_epc: None,
|
sgx_epc: None,
|
||||||
numa: None,
|
numa: None,
|
||||||
|
watchdog: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
aver_eq!(tb, expected_vm_config, result_vm_config);
|
aver_eq!(tb, expected_vm_config, result_vm_config);
|
||||||
|
@ -439,6 +439,9 @@ components:
|
|||||||
iommu:
|
iommu:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
watchdog:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
description: Virtual machine configuration
|
description: Virtual machine configuration
|
||||||
|
|
||||||
CpuTopology:
|
CpuTopology:
|
||||||
|
@ -193,6 +193,7 @@ pub struct VmParams<'a> {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub sgx_epc: Option<Vec<&'a str>>,
|
pub sgx_epc: Option<Vec<&'a str>>,
|
||||||
pub numa: Option<Vec<&'a str>>,
|
pub numa: Option<Vec<&'a str>>,
|
||||||
|
pub watchdog: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VmParams<'a> {
|
impl<'a> VmParams<'a> {
|
||||||
@ -218,6 +219,7 @@ impl<'a> VmParams<'a> {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
let sgx_epc: Option<Vec<&str>> = args.values_of("sgx-epc").map(|x| x.collect());
|
let sgx_epc: Option<Vec<&str>> = args.values_of("sgx-epc").map(|x| x.collect());
|
||||||
let numa: Option<Vec<&str>> = args.values_of("numa").map(|x| x.collect());
|
let numa: Option<Vec<&str>> = args.values_of("numa").map(|x| x.collect());
|
||||||
|
let watchdog = args.is_present("watchdog");
|
||||||
|
|
||||||
VmParams {
|
VmParams {
|
||||||
cpus,
|
cpus,
|
||||||
@ -238,6 +240,7 @@ impl<'a> VmParams<'a> {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
sgx_epc,
|
sgx_epc,
|
||||||
numa,
|
numa,
|
||||||
|
watchdog,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1401,6 +1404,8 @@ pub struct VmConfig {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub sgx_epc: Option<Vec<SgxEpcConfig>>,
|
pub sgx_epc: Option<Vec<SgxEpcConfig>>,
|
||||||
pub numa: Option<Vec<NumaConfig>>,
|
pub numa: Option<Vec<NumaConfig>>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub watchdog: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VmConfig {
|
impl VmConfig {
|
||||||
@ -1608,6 +1613,7 @@ impl VmConfig {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
sgx_epc,
|
sgx_epc,
|
||||||
numa,
|
numa,
|
||||||
|
watchdog: vm_params.watchdog,
|
||||||
};
|
};
|
||||||
config.validate().map_err(Error::Validation)?;
|
config.validate().map_err(Error::Validation)?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
@ -2187,6 +2193,7 @@ mod tests {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
sgx_epc: None,
|
sgx_epc: None,
|
||||||
numa: None,
|
numa: None,
|
||||||
|
watchdog: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(valid_config.validate().is_ok());
|
assert!(valid_config.validate().is_ok());
|
||||||
|
@ -110,6 +110,7 @@ const NET_DEVICE_NAME_PREFIX: &str = "_net";
|
|||||||
const PMEM_DEVICE_NAME_PREFIX: &str = "_pmem";
|
const PMEM_DEVICE_NAME_PREFIX: &str = "_pmem";
|
||||||
const RNG_DEVICE_NAME: &str = "_rng";
|
const RNG_DEVICE_NAME: &str = "_rng";
|
||||||
const VSOCK_DEVICE_NAME_PREFIX: &str = "_vsock";
|
const VSOCK_DEVICE_NAME_PREFIX: &str = "_vsock";
|
||||||
|
const WATCHDOG_DEVICE_NAME: &str = "_watchdog";
|
||||||
|
|
||||||
const IOMMU_DEVICE_NAME: &str = "_iommu";
|
const IOMMU_DEVICE_NAME: &str = "_iommu";
|
||||||
|
|
||||||
@ -166,6 +167,9 @@ pub enum DeviceManagerError {
|
|||||||
/// Cannot create virtio-balloon device
|
/// Cannot create virtio-balloon device
|
||||||
CreateVirtioBalloon(io::Error),
|
CreateVirtioBalloon(io::Error),
|
||||||
|
|
||||||
|
/// Cannot create virtio-watchdog device
|
||||||
|
CreateVirtioWatchdog(io::Error),
|
||||||
|
|
||||||
/// Failed parsing disk image format
|
/// Failed parsing disk image format
|
||||||
DetectImageType(qcow::Error),
|
DetectImageType(qcow::Error),
|
||||||
|
|
||||||
@ -765,8 +769,6 @@ pub struct DeviceManager {
|
|||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
|
|
||||||
// Reset event
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
reset_evt: EventFd,
|
reset_evt: EventFd,
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
@ -787,7 +789,7 @@ impl DeviceManager {
|
|||||||
config: Arc<Mutex<VmConfig>>,
|
config: Arc<Mutex<VmConfig>>,
|
||||||
memory_manager: Arc<Mutex<MemoryManager>>,
|
memory_manager: Arc<Mutex<MemoryManager>>,
|
||||||
_exit_evt: &EventFd,
|
_exit_evt: &EventFd,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(unused_variables))] reset_evt: &EventFd,
|
reset_evt: &EventFd,
|
||||||
vmm_path: PathBuf,
|
vmm_path: PathBuf,
|
||||||
seccomp_action: SeccompAction,
|
seccomp_action: SeccompAction,
|
||||||
#[cfg(feature = "acpi")] numa_nodes: NumaNodes,
|
#[cfg(feature = "acpi")] numa_nodes: NumaNodes,
|
||||||
@ -842,7 +844,6 @@ impl DeviceManager {
|
|||||||
device_tree,
|
device_tree,
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
exit_evt: _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
exit_evt: _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
id_to_dev_info: HashMap::new(),
|
id_to_dev_info: HashMap::new(),
|
||||||
@ -1563,6 +1564,9 @@ impl DeviceManager {
|
|||||||
// Add virtio-balloon if required
|
// Add virtio-balloon if required
|
||||||
devices.append(&mut self.make_virtio_balloon_devices()?);
|
devices.append(&mut self.make_virtio_balloon_devices()?);
|
||||||
|
|
||||||
|
// Add virtio-watchdog device
|
||||||
|
devices.append(&mut self.make_virtio_watchdog_devices()?);
|
||||||
|
|
||||||
Ok(devices)
|
Ok(devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2468,6 +2472,39 @@ impl DeviceManager {
|
|||||||
Ok(devices)
|
Ok(devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_virtio_watchdog_devices(
|
||||||
|
&mut self,
|
||||||
|
) -> DeviceManagerResult<Vec<(VirtioDeviceArc, bool, String)>> {
|
||||||
|
let mut devices = Vec::new();
|
||||||
|
|
||||||
|
if !self.config.lock().unwrap().watchdog {
|
||||||
|
return Ok(devices);
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = String::from(WATCHDOG_DEVICE_NAME);
|
||||||
|
|
||||||
|
let virtio_watchdog_device = Arc::new(Mutex::new(
|
||||||
|
virtio_devices::Watchdog::new(
|
||||||
|
id.clone(),
|
||||||
|
self.reset_evt.try_clone().unwrap(),
|
||||||
|
self.seccomp_action.clone(),
|
||||||
|
)
|
||||||
|
.map_err(DeviceManagerError::CreateVirtioWatchdog)?,
|
||||||
|
));
|
||||||
|
devices.push((
|
||||||
|
Arc::clone(&virtio_watchdog_device) as VirtioDeviceArc,
|
||||||
|
false,
|
||||||
|
id.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
|
self.device_tree
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.insert(id.clone(), device_node!(id, virtio_watchdog_device));
|
||||||
|
|
||||||
|
Ok(devices)
|
||||||
|
}
|
||||||
|
|
||||||
fn next_device_name(&mut self, prefix: &str) -> DeviceManagerResult<String> {
|
fn next_device_name(&mut self, prefix: &str) -> DeviceManagerResult<String> {
|
||||||
let start_id = self.device_id_cnt;
|
let start_id = self.device_id_cnt;
|
||||||
loop {
|
loop {
|
||||||
|
@ -367,6 +367,8 @@ fn vmm_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
|
|||||||
allow_syscall(libc::SYS_stat),
|
allow_syscall(libc::SYS_stat),
|
||||||
allow_syscall(libc::SYS_statx),
|
allow_syscall(libc::SYS_statx),
|
||||||
allow_syscall(libc::SYS_tgkill),
|
allow_syscall(libc::SYS_tgkill),
|
||||||
|
allow_syscall(libc::SYS_timerfd_create),
|
||||||
|
allow_syscall(libc::SYS_timerfd_settime),
|
||||||
allow_syscall(libc::SYS_tkill),
|
allow_syscall(libc::SYS_tkill),
|
||||||
allow_syscall_if(
|
allow_syscall_if(
|
||||||
libc::SYS_umask,
|
libc::SYS_umask,
|
||||||
@ -459,6 +461,8 @@ fn vcpu_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
|
|||||||
allow_syscall(libc::SYS_stat),
|
allow_syscall(libc::SYS_stat),
|
||||||
allow_syscall(libc::SYS_statx),
|
allow_syscall(libc::SYS_statx),
|
||||||
allow_syscall(libc::SYS_tgkill),
|
allow_syscall(libc::SYS_tgkill),
|
||||||
|
allow_syscall(libc::SYS_timerfd_create),
|
||||||
|
allow_syscall(libc::SYS_timerfd_settime),
|
||||||
allow_syscall(libc::SYS_tkill),
|
allow_syscall(libc::SYS_tkill),
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
allow_syscall(libc::SYS_unlink),
|
allow_syscall(libc::SYS_unlink),
|
||||||
|
Loading…
Reference in New Issue
Block a user