From 7b7f426a3f5d1838cedc3dc9520035edb2cc6995 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 11 Feb 2022 12:07:21 +1100 Subject: [PATCH] device: Keep host to VM PCI mapping persistently add_devices() generates a mapping of host to guest PCI addresses which is used to update some environment variables for the workload. Currently it just does this locally, but it turns out we're going to need the same map again in order to correct environment variables for processes exec-ed into the existing container. Move the map to the sandbox structure so we can keep it around for those later uses. Signed-off-by: David Gibson --- src/agent/src/device.rs | 4 ++-- src/agent/src/sandbox.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 813c4d569..ad181141c 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -765,7 +765,6 @@ pub async fn add_devices( sandbox: &Arc>, ) -> Result<()> { let mut dev_updates = HashMap::<&str, DevUpdate>::with_capacity(devices.len()); - let mut pci_updates = HashMap::::new(); for device in devices.iter() { let update = add_device(device, sandbox).await?; @@ -780,8 +779,9 @@ pub async fn add_devices( )); } + let mut sb = sandbox.lock().await; for (host, guest) in update.pci { - if let Some(other_guest) = pci_updates.insert(host, guest) { + if let Some(other_guest) = sb.pcimap.insert(host, guest) { return Err(anyhow!( "Conflicting guest address for host device {} ({} versus {})", host, diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 4dfb2eda5..3edbe7ea0 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -8,6 +8,7 @@ use crate::mount::{get_mount_fs_type, remove_mounts, TYPE_ROOTFS}; use crate::namespace::Namespace; use crate::netlink::Handle; use crate::network::Network; +use crate::pci; use crate::uevent::{Uevent, UeventMatcher}; use crate::watcher::BindWatcher; use anyhow::{anyhow, Context, Result}; @@ -56,6 +57,7 @@ pub struct Sandbox { pub event_rx: Arc>>, pub event_tx: Option>, pub bind_watcher: BindWatcher, + pub pcimap: HashMap, } impl Sandbox { @@ -88,6 +90,7 @@ impl Sandbox { event_rx, event_tx: Some(tx), bind_watcher: BindWatcher::new(), + pcimap: HashMap::new(), }) }