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
+2 -1
View File
@@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0
//
use std::collections::HashSet;
use std::net::IpAddr;
use std::path::{Path, PathBuf};
#[cfg(feature = "fw_cfg")]
@@ -1065,7 +1066,7 @@ pub struct VmConfig {
// causes the FDs to be closed early. This allows management software to
// gracefully clean up resources (e.g., libvirt closes tap devices).
#[serde(skip)]
pub preserved_fds: Option<Vec<i32>>,
pub preserved_fds: Option<HashSet<i32>>,
#[serde(default)]
pub landlock_enable: bool,
pub landlock_rules: Option<Box<[LandlockConfig]>>,