vmm: document + FD (de)serialization + warn -> debug

(1) The old messages are missing the "why" part. With this change, users
    of Cloud Hypervisor have somehow more context and people looking at
    the code perfectly know what's going on.

(2) Using warn! implies that the user should take action, but in this
    case, there’s nothing the user can do. If the API is used correctly
    and file descriptors are passed via an SCM_RIGHTS message over a
    UNIX domain socket, everything works as intended. In that case,
    there's no need to issue a warning — debug! is sufficient.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-06-19 18:41:16 +02:00
committed by Rob Bradford
parent 60efa1aa03
commit 0cd87053ee
2 changed files with 25 additions and 10 deletions
+9 -5
View File
@@ -324,6 +324,12 @@ pub struct NetConfig {
pub vhost_mode: VhostMode,
#[serde(default)]
pub id: Option<String>,
// Special (de)serialize 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",
@@ -371,9 +377,7 @@ where
S: serde::Serializer,
{
if let Some(x) = x {
warn!(
"'NetConfig' contains FDs that can't be serialized correctly. Serializing them as invalid FDs."
);
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 {
@@ -387,8 +391,8 @@ where
{
let invalid_fds: Option<Vec<i32>> = Option::deserialize(d)?;
if let Some(invalid_fds) = invalid_fds {
warn!(
"'NetConfig' contains FDs that can't be deserialized correctly. Deserializing them as invalid FDs."
debug!(
"FDs in 'NetConfig' won't be deserialized as they are most likely invalid now. Deserializing them as -1."
);
Ok(Some(vec![-1; invalid_fds.len()]))
} else {