Skip to content

Commit

Permalink
runtime-rs: move passfd_listener_addr attribute into Hypervisor
Browse files Browse the repository at this point in the history
Fixes: #6714

Signed-off-by: Zixuan Tan <tanzixuan.me@gmail.com>
  • Loading branch information
frezcirno committed Sep 13, 2023
1 parent 0ed4aea commit 0471f83
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
iter::FromIterator,
};

use anyhow::{Context, Ok, Result};
use anyhow::{anyhow, Context, Ok, Result};
use kata_types::capabilities::Capabilities;

use super::inner::DragonballInner;
Expand Down Expand Up @@ -76,6 +76,14 @@ impl DragonballInner {
))
}

pub(crate) async fn get_passfd_listener_addr(&self) -> Result<(String, u32)> {
if let Some(passfd_port) = self.passfd_listener_port {
Ok((get_vsock_path(&self.jailer_root), passfd_port))
} else {
Err(anyhow!("passfd io listener port not set"))
}
}

pub(crate) async fn get_hypervisor_metrics(&self) -> Result<String> {
info!(sl!(), "get hypervisor metrics");
self.vmm_instance.get_hypervisor_metrics()
Expand Down
5 changes: 5 additions & 0 deletions src/runtime-rs/crates/hypervisor/src/dragonball/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ impl Hypervisor for Dragonball {
let inner = self.inner.read().await;
inner.get_hypervisor_metrics().await
}

async fn get_passfd_listener_addr(&self) -> Result<(String, u32)> {
let inner = self.inner.read().await;
inner.get_passfd_listener_addr().await
}
}

#[async_trait]
Expand Down
1 change: 1 addition & 0 deletions src/runtime-rs/crates/hypervisor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ pub trait Hypervisor: std::fmt::Debug + Send + Sync {
async fn save_state(&self) -> Result<HypervisorState>;
async fn capabilities(&self) -> Result<Capabilities>;
async fn get_hypervisor_metrics(&self) -> Result<String>;
async fn get_passfd_listener_addr(&self) -> Result<(String, u32)>;
}
4 changes: 4 additions & 0 deletions src/runtime-rs/crates/hypervisor/src/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,8 @@ impl Hypervisor for Qemu {
let inner = self.inner.read().await;
inner.get_hypervisor_metrics().await
}

async fn get_passfd_listener_addr(&self) -> Result<(String, u32)> {
Err(anyhow::anyhow!("Not yet supported"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use kata_sys_util::k8s::update_ephemeral_storage_type;
use oci::{LinuxResources, Process as OCIProcess};
use resource::{ResourceManager, ResourceUpdateOp};
use tokio::sync::RwLock;
use url::Url;

use super::{
process::{Process, ProcessWatcher},
Expand Down Expand Up @@ -53,6 +52,7 @@ impl Container {
spec: oci::Spec,
agent: Arc<dyn Agent>,
resource_manager: Arc<ResourceManager>,
passfd_listener_addr: Option<(String, u32)>,
) -> Result<Self> {
let container_id = ContainerID::new(&config.container_id).context("new container id")?;
let logger = sl!().new(o!("container_id" => config.container_id.clone()));
Expand All @@ -71,26 +71,6 @@ impl Container {
.as_ref()
.and_then(|linux| linux.resources.clone());

let toml_config = resource_manager.config().await;
let passfd_listener_addr = if toml_config.runtime.use_passfd_io {
let agent_sock_addr = agent
.agent_sock_addr()
.await
.context("get agent sock addr")?;
let agent_sock_url = Url::parse(&agent_sock_addr).context("parse socket address")?;
if agent_sock_url.scheme() != "hvsock" {
return Err(anyhow!(
"passfd io is enabled, but agent sock url scheme is not hvsock"
));
}
Some((
agent_sock_url.path().to_owned(),
toml_config.runtime.passfd_listener_port,
))
} else {
None
};

Ok(Self {
pid,
container_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl ContainerManager for VirtContainerManager {
spec.clone(),
self.agent.clone(),
self.resource_manager.clone(),
self.hypervisor.get_passfd_listener_addr().await.ok(),
)
.await
.context("new container")?;
Expand Down

0 comments on commit 0471f83

Please sign in to comment.