mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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 <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
0cd87053ee
commit
ed27e93b81
@@ -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<Vec<i32>>,
|
||||
}
|
||||
|
||||
fn serialize_restorednetconfig_fds<S>(
|
||||
x: &Option<Vec<i32>>,
|
||||
s: S,
|
||||
) -> std::result::Result<S::Ok, S::Error>
|
||||
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<Option<Vec<i32>>, D::Error>
|
||||
|
||||
@@ -324,17 +324,13 @@ pub struct NetConfig {
|
||||
pub vhost_mode: VhostMode,
|
||||
#[serde(default)]
|
||||
pub id: Option<String>,
|
||||
// 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<Vec<i32>>,
|
||||
#[serde(default)]
|
||||
pub rate_limiter_config: Option<RateLimiterConfig>,
|
||||
@@ -372,19 +368,6 @@ pub fn default_netconfig_queue_size() -> u16 {
|
||||
DEFAULT_NET_QUEUE_SIZE
|
||||
}
|
||||
|
||||
fn serialize_netconfig_fds<S>(x: &Option<Vec<i32>>, s: S) -> Result<S::Ok, S::Error>
|
||||
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<Option<Vec<i32>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
|
||||
Reference in New Issue
Block a user