vmm: Use HashSet for VmConfig::preserved_fds

Each VM reboot re-entered the VFIO/virtio-net add paths and re-appended
the same originating fds, leaving duplicates in preserved_fds and a
double-close hazard at final teardown. Switching to HashSet makes
add_preserved_fds idempotent.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
Assisted-by: Claude:Opus-4.7
This commit is contained in:
Bo Chen
2026-05-06 22:03:45 +00:00
committed by Rob Bradford
parent 5c25d82f59
commit 8fd8224ee3
3 changed files with 9 additions and 10 deletions

View File

@@ -4797,7 +4797,7 @@ impl DeviceManager {
debug!("Closing preserved FDs from virtio-net device: id={id}, fds={fds:?}");
for fd in fds {
config.preserved_fds.as_mut().unwrap().retain(|x| *x != fd);
config.preserved_fds.as_mut().unwrap().remove(&fd);
// SAFETY: We are closing the only remaining instance of this FD.
unsafe {
libc::close(fd);