From ed27e93b8103fb51cc8ddf03f7ec3b1b14781c20 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Thu, 19 Jun 2025 18:26:04 +0200 Subject: [PATCH] vmm: remove special serialization of network FDs Deserializing values as `-1` makes sense to prevent errors, so let's keep it. However, serializing them differently adds confusion. For example, a `ch-remote info` call should not report `-1` but the actual FDs. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- vmm/src/config.rs | 27 ++------------------------- vmm/src/vm_config.rs | 21 ++------------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 1d8979210..af89539f0 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -2205,40 +2205,17 @@ pub struct RestoredNetConfig { pub id: String, #[serde(default)] pub num_fds: usize, - // Special (de)serialize handling: + // Special deserialize handling: // A serialize-deserialize cycle typically happens across processes. // Therefore, we don't serialize FDs, and whatever value is here after // deserialization is invalid. // // Valid FDs are transmitted via a different channel (SCM_RIGHTS message) // and will be populated into this struct on the destination VMM eventually. - #[serde( - default, - serialize_with = "serialize_restorednetconfig_fds", - deserialize_with = "deserialize_restorednetconfig_fds" - )] + #[serde(default, deserialize_with = "deserialize_restorednetconfig_fds")] pub fds: Option>, } -fn serialize_restorednetconfig_fds( - x: &Option>, - s: S, -) -> std::result::Result -where - S: serde::Serializer, -{ - if let Some(x) = x { - // If the live-migration path is used properly, new FDs are passed as - // SCM_RIGHTS message. So, we don't get them from the serialized JSON - // anyway. - debug!("FDs in 'RestoredNetConfig' won't be serialized as they are most likely invalid after deserialization. Serializing them as -1."); - let invalid_fds = vec![-1; x.len()]; - s.serialize_some(&invalid_fds) - } else { - s.serialize_none() - } -} - fn deserialize_restorednetconfig_fds<'de, D>( d: D, ) -> std::result::Result>, D::Error> diff --git a/vmm/src/vm_config.rs b/vmm/src/vm_config.rs index 49e3e9596..7021f9e9c 100644 --- a/vmm/src/vm_config.rs +++ b/vmm/src/vm_config.rs @@ -324,17 +324,13 @@ pub struct NetConfig { pub vhost_mode: VhostMode, #[serde(default)] pub id: Option, - // Special (de)serialize handling: + // Special deserialize handling: // Therefore, we don't serialize FDs, and whatever value is here after // deserialization is invalid. // // Valid FDs are transmitted via a different channel (SCM_RIGHTS message) // and will be populated into this struct on the destination VMM eventually. - #[serde( - default, - serialize_with = "serialize_netconfig_fds", - deserialize_with = "deserialize_netconfig_fds" - )] + #[serde(default, deserialize_with = "deserialize_netconfig_fds")] pub fds: Option>, #[serde(default)] pub rate_limiter_config: Option, @@ -372,19 +368,6 @@ pub fn default_netconfig_queue_size() -> u16 { DEFAULT_NET_QUEUE_SIZE } -fn serialize_netconfig_fds(x: &Option>, s: S) -> Result -where - S: serde::Serializer, -{ - if let Some(x) = x { - debug!("FDs in 'NetConfig' won't be serialized as they are most likely invalid after deserialization; using -1."); - let invalid_fds = vec![-1; x.len()]; - s.serialize_some(&invalid_fds) - } else { - s.serialize_none() - } -} - fn deserialize_netconfig_fds<'de, D>(d: D) -> Result>, D::Error> where D: serde::Deserializer<'de>,