mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add valid FDs for TAP devices to 'VmConfig::preserved_fds'
In this way, valid FDs for TAP devices will be closed when the holding VmConfig instance is destroyed. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
@@ -2317,8 +2317,7 @@ impl DeviceManager {
|
|||||||
.map_err(DeviceManagerError::CreateVirtioNet)?,
|
.map_err(DeviceManagerError::CreateVirtioNet)?,
|
||||||
))
|
))
|
||||||
} else if let Some(fds) = &net_cfg.fds {
|
} else if let Some(fds) = &net_cfg.fds {
|
||||||
Arc::new(Mutex::new(
|
let net = virtio_devices::Net::from_tap_fds(
|
||||||
virtio_devices::Net::from_tap_fds(
|
|
||||||
id.clone(),
|
id.clone(),
|
||||||
fds,
|
fds,
|
||||||
Some(net_cfg.mac),
|
Some(net_cfg.mac),
|
||||||
@@ -2332,8 +2331,14 @@ impl DeviceManager {
|
|||||||
.map_err(DeviceManagerError::EventFd)?,
|
.map_err(DeviceManagerError::EventFd)?,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::CreateVirtioNet)?,
|
.map_err(DeviceManagerError::CreateVirtioNet)?;
|
||||||
))
|
|
||||||
|
// SAFETY: 'fds' are valid because TAP devices are created successfully
|
||||||
|
unsafe {
|
||||||
|
self.config.lock().unwrap().add_preserved_fds(fds.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
Arc::new(Mutex::new(net))
|
||||||
} else {
|
} else {
|
||||||
Arc::new(Mutex::new(
|
Arc::new(Mutex::new(
|
||||||
virtio_devices::Net::new(
|
virtio_devices::Net::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user