From f4982130e16ae5add3d5c119d5e522f3d0aed001 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 5 Nov 2021 16:04:20 +1100 Subject: [PATCH] agent/device: Check for conflicting device updates For each device in the OCI spec we need to update it to reflect the guest rather than the host. We do this with additional device information provided by the runtime. There should only be one update for each device though, if there are multiple, something has gone horribly wrong. Detect and report this situation, for safety. Signed-off-by: David Gibson --- src/agent/src/device.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 66ee9d9fa..a8c49ecd9 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -745,7 +745,15 @@ pub async fn add_devices( for device in devices.iter() { let update = add_device(device, sandbox).await?; if let Some(dev_update) = update.dev { - dev_updates.insert(&device.container_path, dev_update); + if dev_updates + .insert(&device.container_path, dev_update) + .is_some() + { + return Err(anyhow!( + "Conflicting device updates for {}", + &device.container_path + )); + } } }