mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: config: Extend 'VmConfig' with 'preserved_fds'
Preserved FDs are the ones that share the same life-time as its holding VmConfig instance, such as FDs for creating TAP devices. Preserved FDs will stay open as long as the holding VmConfig instance is valid, and will be closed when the holding VmConfig instance is destroyed. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
@@ -2093,11 +2093,27 @@ impl VmConfig {
|
||||
gdb,
|
||||
platform,
|
||||
tpm,
|
||||
preserved_fds: None,
|
||||
};
|
||||
config.validate().map_err(Error::Validation)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// To use this safely, the caller must guarantee that the input
|
||||
/// fds are all valid.
|
||||
pub unsafe fn add_preserved_fds(&mut self, mut fds: Vec<i32>) {
|
||||
if fds.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(preserved_fds) = &self.preserved_fds {
|
||||
fds.append(&mut preserved_fds.clone());
|
||||
}
|
||||
|
||||
self.preserved_fds = Some(fds);
|
||||
}
|
||||
|
||||
#[cfg(feature = "tdx")]
|
||||
pub fn is_tdx_enabled(&self) -> bool {
|
||||
self.platform.as_ref().map(|p| p.tdx).unwrap_or(false)
|
||||
@@ -2714,6 +2730,7 @@ mod tests {
|
||||
gdb: false,
|
||||
platform: None,
|
||||
tpm: None,
|
||||
preserved_fds: None,
|
||||
};
|
||||
|
||||
assert!(valid_config.validate().is_ok());
|
||||
|
||||
Reference in New Issue
Block a user