From 0fabfa336d94baa98a1115acdd7a24977b6ab4c6 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Mon, 4 Dec 2023 15:40:28 +0800 Subject: [PATCH] runtime-rs: bring support for legacy vsock device. Bring support for legacy vsock and add Vsock to the ResourceConfig enum type, and add the processing flow of the Vsock device to the prepare_before_start_vm function. Fixes: #8474 Signed-off-by: alex.lyn --- src/runtime-rs/crates/resource/src/lib.rs | 3 ++- src/runtime-rs/crates/resource/src/manager_inner.rs | 5 +++++ .../crates/runtimes/virt_container/src/sandbox.rs | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/runtime-rs/crates/resource/src/lib.rs b/src/runtime-rs/crates/resource/src/lib.rs index f7df9b687b..3a7524da9c 100644 --- a/src/runtime-rs/crates/resource/src/lib.rs +++ b/src/runtime-rs/crates/resource/src/lib.rs @@ -17,7 +17,7 @@ pub mod manager; mod manager_inner; pub mod network; pub mod resource_persist; -use hypervisor::{BlockConfig, HybridVsockConfig}; +use hypervisor::{BlockConfig, HybridVsockConfig, VsockConfig}; use network::NetworkConfig; pub mod rootfs; pub mod share_fs; @@ -33,6 +33,7 @@ pub enum ResourceConfig { ShareFs(SharedFsInfo), VmRootfs(BlockConfig), HybridVsock(HybridVsockConfig), + Vsock(VsockConfig), } #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/src/runtime-rs/crates/resource/src/manager_inner.rs b/src/runtime-rs/crates/resource/src/manager_inner.rs index 2ee6a5a054..592b2f5d4f 100644 --- a/src/runtime-rs/crates/resource/src/manager_inner.rs +++ b/src/runtime-rs/crates/resource/src/manager_inner.rs @@ -134,6 +134,11 @@ impl ResourceManagerInner { .await .context("do handle hybrid-vsock device failed.")?; } + ResourceConfig::Vsock(v) => { + do_handle_device(&self.device_manager, &DeviceConfig::VsockCfg(v)) + .await + .context("do handle vsock device failed.")?; + } }; } diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index b1b18021e9..e103f18d70 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -14,6 +14,7 @@ use async_trait::async_trait; use common::message::{Action, Message}; use common::{Sandbox, SandboxNetworkEnv}; use containerd_shim_protos::events::task::TaskOOM; +use hypervisor::VsockConfig; use hypervisor::{dragonball::Dragonball, BlockConfig, Hypervisor, HYPERVISOR_DRAGONBALL}; use hypervisor::{utils::get_hvsock_path, HybridVsockConfig, DEFAULT_GUEST_VSOCK_CID}; use kata_sys_util::hooks::HookStates; @@ -28,6 +29,7 @@ use tracing::instrument; use crate::health_check::HealthCheck; pub(crate) const VIRTCONTAINER: &str = "virt_container"; + pub struct SandboxRestoreArgs { pub sid: String, pub toml_config: TomlConfig, @@ -224,6 +226,7 @@ impl VirtSandbox { async fn prepare_vm_socket_config(&self) -> Result { // It will check the hypervisor's capabilities to see if it supports hybrid-vsock. + // If it does not, it'll assume that it only supports legacy vsock. let vm_socket = if self .hypervisor .capabilities() @@ -236,7 +239,10 @@ impl VirtSandbox { uds_path: get_hvsock_path(&self.sid), }) } else { - return Err(anyhow!("unsupported vm socket")); + // Qemu uses the vsock device model. + ResourceConfig::Vsock(VsockConfig { + guest_cid: libc::VMADDR_CID_ANY, + }) }; Ok(vm_socket)