mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
bugfix: add get_ns_path API for Hypervisor
For external hypervisors(qemu, cloud-hypervisor, ...), the ns they launch vm in is different from internal hypervisor(dragonball). And when we doing CreateContainer hook, we will rely on the netns path. So we add a get_ns_path API. Fixes: #6442 Signed-off-by: Yushuo <y-shuo@linux.alibaba.com>
This commit is contained in:
parent
fef268a7de
commit
e029988bc2
@ -473,7 +473,20 @@ impl CloudHypervisorInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_vmm_master_tid(&self) -> Result<u32> {
|
pub(crate) async fn get_vmm_master_tid(&self) -> Result<u32> {
|
||||||
todo!()
|
if let Some(pid) = self.pid {
|
||||||
|
Ok(pid)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("could not get vmm master tid"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
if let Some(pid) = self.pid {
|
||||||
|
let ns_path = format!("/proc/{}/ns", pid);
|
||||||
|
Ok(ns_path)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("could not get ns path"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn check(&self) -> Result<()> {
|
pub(crate) async fn check(&self) -> Result<()> {
|
||||||
|
@ -123,6 +123,11 @@ impl Hypervisor for CloudHypervisor {
|
|||||||
inner.get_vmm_master_tid().await
|
inner.get_vmm_master_tid().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
let inner = self.inner.read().await;
|
||||||
|
inner.get_ns_path().await
|
||||||
|
}
|
||||||
|
|
||||||
async fn check(&self) -> Result<()> {
|
async fn check(&self) -> Result<()> {
|
||||||
let inner = self.inner.read().await;
|
let inner = self.inner.read().await;
|
||||||
inner.check().await
|
inner.check().await
|
||||||
|
@ -132,6 +132,11 @@ impl DragonballInner {
|
|||||||
Ok(master_tid)
|
Ok(master_tid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
let ns_path = self.vmm_instance.get_ns_path();
|
||||||
|
Ok(ns_path)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn check(&self) -> Result<()> {
|
pub(crate) async fn check(&self) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,11 @@ impl Hypervisor for Dragonball {
|
|||||||
inner.get_vmm_master_tid().await
|
inner.get_vmm_master_tid().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
let inner = self.inner.read().await;
|
||||||
|
inner.get_ns_path().await
|
||||||
|
}
|
||||||
|
|
||||||
async fn check(&self) -> Result<()> {
|
async fn check(&self) -> Result<()> {
|
||||||
let inner = self.inner.read().await;
|
let inner = self.inner.read().await;
|
||||||
inner.check().await
|
inner.check().await
|
||||||
|
@ -81,6 +81,13 @@ impl VmmInstance {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_ns_path(&self) -> String {
|
||||||
|
let info_binding = self.vmm_shared_info.clone();
|
||||||
|
let info = info_binding.read().unwrap();
|
||||||
|
let result = format!("/proc/{}/task/{}/ns", info.pid, info.master_tid);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_vcpu_tids(&self) -> Vec<(u8, u32)> {
|
pub fn get_vcpu_tids(&self) -> Vec<(u8, u32)> {
|
||||||
let info = self.vmm_shared_info.clone();
|
let info = self.vmm_shared_info.clone();
|
||||||
let result = info.read().unwrap().tids.clone();
|
let result = info.read().unwrap().tids.clone();
|
||||||
|
@ -88,6 +88,7 @@ pub trait Hypervisor: Send + Sync {
|
|||||||
async fn get_thread_ids(&self) -> Result<VcpuThreadIds>;
|
async fn get_thread_ids(&self) -> Result<VcpuThreadIds>;
|
||||||
async fn get_pids(&self) -> Result<Vec<u32>>;
|
async fn get_pids(&self) -> Result<Vec<u32>>;
|
||||||
async fn get_vmm_master_tid(&self) -> Result<u32>;
|
async fn get_vmm_master_tid(&self) -> Result<u32>;
|
||||||
|
async fn get_ns_path(&self) -> Result<String>;
|
||||||
async fn cleanup(&self) -> Result<()>;
|
async fn cleanup(&self) -> Result<()>;
|
||||||
async fn check(&self) -> Result<()>;
|
async fn check(&self) -> Result<()>;
|
||||||
async fn get_jailer_root(&self) -> Result<String>;
|
async fn get_jailer_root(&self) -> Result<String>;
|
||||||
|
@ -94,6 +94,11 @@ impl QemuInner {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
info!(sl!(), "QemuInner::get_ns_path()");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn cleanup(&self) -> Result<()> {
|
pub(crate) async fn cleanup(&self) -> Result<()> {
|
||||||
info!(sl!(), "QemuInner::cleanup()");
|
info!(sl!(), "QemuInner::cleanup()");
|
||||||
todo!()
|
todo!()
|
||||||
|
@ -108,6 +108,11 @@ impl Hypervisor for Qemu {
|
|||||||
inner.get_vmm_master_tid().await
|
inner.get_vmm_master_tid().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_ns_path(&self) -> Result<String> {
|
||||||
|
let inner = self.inner.read().await;
|
||||||
|
inner.get_ns_path().await
|
||||||
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
let inner = self.inner.read().await;
|
let inner = self.inner.read().await;
|
||||||
inner.cleanup().await
|
inner.cleanup().await
|
||||||
|
@ -73,7 +73,8 @@ impl ContainerManager for VirtContainerManager {
|
|||||||
// * should be run after the vm is started, before container is created, and after CreateRuntime Hooks
|
// * should be run after the vm is started, before container is created, and after CreateRuntime Hooks
|
||||||
// * spec details: https://github.com/opencontainers/runtime-spec/blob/c1662686cff159595277b79322d0272f5182941b/config.md#createcontainer-hooks
|
// * spec details: https://github.com/opencontainers/runtime-spec/blob/c1662686cff159595277b79322d0272f5182941b/config.md#createcontainer-hooks
|
||||||
let vmm_master_tid = self.hypervisor.get_vmm_master_tid().await?;
|
let vmm_master_tid = self.hypervisor.get_vmm_master_tid().await?;
|
||||||
let vmm_netns_path = format!("/proc/{}/task/{}/ns/{}", self.pid, vmm_master_tid, "net");
|
let vmm_ns_path = self.hypervisor.get_ns_path().await?;
|
||||||
|
let vmm_netns_path = format!("{}/{}", vmm_ns_path, "net");
|
||||||
let state = oci::State {
|
let state = oci::State {
|
||||||
version: spec.version.clone(),
|
version: spec.version.clone(),
|
||||||
id: config.container_id.clone(),
|
id: config.container_id.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user