mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 07:22:20 +00:00
runtime-rs: support linux device
support linux device in runtime-rs Fixes:#5375 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com> Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
fe9ec67644
commit
f16012a1eb
@ -76,10 +76,10 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_device(&mut self, device_config: &DeviceConfig) -> Result<String> {
|
pub async fn new_device(&mut self, device_config: &DeviceConfig) -> Result<String> {
|
||||||
let device_id = if let Some(dev) = self.find_device(&device_config).await {
|
let device_id = if let Some(dev) = self.find_device(device_config).await {
|
||||||
dev
|
dev
|
||||||
} else {
|
} else {
|
||||||
self.create_device(&device_config)
|
self.create_device(device_config)
|
||||||
.await
|
.await
|
||||||
.context("failed to create device")?
|
.context("failed to create device")?
|
||||||
};
|
};
|
||||||
|
@ -7,13 +7,14 @@
|
|||||||
use crate::network::NetworkConfig;
|
use crate::network::NetworkConfig;
|
||||||
use crate::resource_persist::ResourceState;
|
use crate::resource_persist::ResourceState;
|
||||||
use crate::{manager_inner::ResourceManagerInner, rootfs::Rootfs, volume::Volume, ResourceConfig};
|
use crate::{manager_inner::ResourceManagerInner, rootfs::Rootfs, volume::Volume, ResourceConfig};
|
||||||
|
use agent::types::Device;
|
||||||
use agent::{Agent, Storage};
|
use agent::{Agent, Storage};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use hypervisor::Hypervisor;
|
use hypervisor::Hypervisor;
|
||||||
use kata_types::config::TomlConfig;
|
use kata_types::config::TomlConfig;
|
||||||
use kata_types::mount::Mount;
|
use kata_types::mount::Mount;
|
||||||
use oci::LinuxResources;
|
use oci::{Linux, LinuxResources};
|
||||||
use persist::sandbox_persist::Persist;
|
use persist::sandbox_persist::Persist;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@ -93,6 +94,11 @@ impl ResourceManager {
|
|||||||
inner.handler_volumes(cid, spec).await
|
inner.handler_volumes(cid, spec).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn handler_devices(&self, cid: &str, linux: &Linux) -> Result<Vec<Device>> {
|
||||||
|
let inner = self.inner.read().await;
|
||||||
|
inner.handler_devices(cid, linux).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn dump(&self) {
|
pub async fn dump(&self) {
|
||||||
let inner = self.inner.read().await;
|
let inner = self.inner.read().await;
|
||||||
inner.dump().await
|
inner.dump().await
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::{sync::Arc, thread};
|
use std::{sync::Arc, thread, vec};
|
||||||
|
|
||||||
use crate::{network::NetworkConfig, resource_persist::ResourceState};
|
use crate::{network::NetworkConfig, resource_persist::ResourceState};
|
||||||
use agent::{Agent, Storage};
|
use agent::{types::Device, Agent, Storage};
|
||||||
use anyhow::{anyhow, Context, Ok, Result};
|
use anyhow::{anyhow, Context, Ok, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use hypervisor::{device::device_manager::DeviceManager, Hypervisor};
|
use hypervisor::{device::device_manager::DeviceManager, BlockConfig, DeviceConfig, Hypervisor};
|
||||||
use kata_types::config::TomlConfig;
|
use kata_types::config::TomlConfig;
|
||||||
use kata_types::mount::Mount;
|
use kata_types::mount::Mount;
|
||||||
use oci::LinuxResources;
|
use oci::{Linux, LinuxResources};
|
||||||
use persist::sandbox_persist::Persist;
|
use persist::sandbox_persist::Persist;
|
||||||
use tokio::{runtime, sync::RwLock};
|
use tokio::{runtime, sync::RwLock};
|
||||||
|
|
||||||
@ -246,6 +246,61 @@ impl ResourceManagerInner {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn handler_devices(&self, _cid: &str, linux: &Linux) -> Result<Vec<Device>> {
|
||||||
|
let mut devices = vec![];
|
||||||
|
for d in linux.devices.iter() {
|
||||||
|
match d.r#type.as_str() {
|
||||||
|
"b" => {
|
||||||
|
let device_info = DeviceConfig::Block(BlockConfig {
|
||||||
|
major: d.major,
|
||||||
|
minor: d.minor,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let device_id = self
|
||||||
|
.device_manager
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.new_device(&device_info)
|
||||||
|
.await
|
||||||
|
.context("failed to create deviec")?;
|
||||||
|
|
||||||
|
self.device_manager
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.try_add_device(&device_id)
|
||||||
|
.await
|
||||||
|
.context("failed to add deivce")?;
|
||||||
|
|
||||||
|
// get complete device information
|
||||||
|
let dev_info = self
|
||||||
|
.device_manager
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.get_device_info(&device_id)
|
||||||
|
.await
|
||||||
|
.context("failed to get device info")?;
|
||||||
|
|
||||||
|
// create agent device
|
||||||
|
if let DeviceConfig::Block(config) = dev_info {
|
||||||
|
let agent_device = Device {
|
||||||
|
id: device_id.clone(),
|
||||||
|
container_path: d.path.clone(),
|
||||||
|
field_type: config.driver_option,
|
||||||
|
vm_path: config.virt_path,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
devices.push(agent_device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// TODO enable other devices type
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(devices)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_cgroups(
|
pub async fn update_cgroups(
|
||||||
&self,
|
&self,
|
||||||
cid: &str,
|
cid: &str,
|
||||||
|
@ -140,7 +140,15 @@ impl Container {
|
|||||||
}
|
}
|
||||||
spec.mounts = oci_mounts;
|
spec.mounts = oci_mounts;
|
||||||
|
|
||||||
// TODO: handler device
|
let linux = spec
|
||||||
|
.linux
|
||||||
|
.as_ref()
|
||||||
|
.context("OCI spec missing linux field")?;
|
||||||
|
|
||||||
|
let devices_agent = self
|
||||||
|
.resource_manager
|
||||||
|
.handler_devices(&config.container_id, linux)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// update cgroups
|
// update cgroups
|
||||||
self.resource_manager
|
self.resource_manager
|
||||||
@ -158,6 +166,7 @@ impl Container {
|
|||||||
storages,
|
storages,
|
||||||
oci: Some(spec),
|
oci: Some(spec),
|
||||||
sandbox_pidns,
|
sandbox_pidns,
|
||||||
|
devices: devices_agent,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user