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 <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn
2023-12-04 15:40:28 +08:00
parent 6c08cf35d5
commit 0fabfa336d
3 changed files with 14 additions and 2 deletions

View File

@@ -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)]

View File

@@ -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.")?;
}
};
}

View File

@@ -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<ResourceConfig> {
// 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)