agent: switch to new device subsystem

Switch to new device subsystem to handle various devices in kata-agent.

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
This commit is contained in:
ChengyuZhu6 2024-08-27 06:44:12 +08:00
parent df55f37dfe
commit 75816d17f1
3 changed files with 13 additions and 19 deletions

View File

@ -1,9 +0,0 @@
// Copyright (c) 2019 Ant Financial
//
// SPDX-License-Identifier: Apache-2.0
//
// Convenience function to obtain the scope logger.
fn sl() -> slog::Logger {
slog_scope::logger().new(o!("subsystem" => "device"))
}

View File

@ -56,9 +56,9 @@ use nix::unistd::{self, Pid};
use rustjail::process::ProcessOperations; use rustjail::process::ProcessOperations;
use crate::cdh; use crate::cdh;
use crate::device::{ use crate::device::block_device_handler::get_virtio_blk_pci_device_name;
add_devices, get_virtio_blk_pci_device_name, update_env_pci, wait_for_net_interface, use crate::device::network_device_handler::wait_for_net_interface;
}; use crate::device::{add_devices, update_env_pci};
use crate::features::get_build_features; use crate::features::get_build_features;
use crate::image::KATA_IMAGE_WORK_DIR; use crate::image::KATA_IMAGE_WORK_DIR;
use crate::linux_abi::*; use crate::linux_abi::*;
@ -222,7 +222,7 @@ impl AgentService {
// updates the devices listed in the OCI spec, so that they actually // updates the devices listed in the OCI spec, so that they actually
// match real devices inside the VM. This step is necessary since we // match real devices inside the VM. This step is necessary since we
// cannot predict everything from the caller. // cannot predict everything from the caller.
add_devices(&req.devices, &mut oci, &self.sandbox).await?; add_devices(&sl(), &req.devices, &mut oci, &self.sandbox).await?;
let process = oci let process = oci
.process_mut() .process_mut()

View File

@ -19,14 +19,17 @@ use kata_types::mount::StorageDevice;
use protocols::agent::Storage; use protocols::agent::Storage;
use tracing::instrument; use tracing::instrument;
use crate::device::{ #[cfg(target_arch = "s390x")]
get_scsi_device_name, get_virtio_blk_pci_device_name, get_virtio_mmio_device_name, use crate::ccw;
wait_for_pmem_device, #[cfg(target_arch = "s390x")]
use crate::device::block_device_handler::get_virtio_blk_ccw_device_name;
use crate::device::block_device_handler::{
get_virtio_blk_mmio_device_name, get_virtio_blk_pci_device_name,
}; };
use crate::device::nvdimm_device_handler::wait_for_pmem_device;
use crate::device::scsi_device_handler::get_scsi_device_name;
use crate::pci; use crate::pci;
use crate::storage::{common_storage_handler, new_device, StorageContext, StorageHandler}; use crate::storage::{common_storage_handler, new_device, StorageContext, StorageHandler};
#[cfg(target_arch = "s390x")]
use crate::{ccw, device::get_virtio_blk_ccw_device_name};
#[derive(Debug)] #[derive(Debug)]
pub struct VirtioBlkMmioHandler {} pub struct VirtioBlkMmioHandler {}
@ -45,7 +48,7 @@ impl StorageHandler for VirtioBlkMmioHandler {
ctx: &mut StorageContext, ctx: &mut StorageContext,
) -> Result<Arc<dyn StorageDevice>> { ) -> Result<Arc<dyn StorageDevice>> {
if !Path::new(&storage.source).exists() { if !Path::new(&storage.source).exists() {
get_virtio_mmio_device_name(ctx.sandbox, &storage.source) get_virtio_blk_mmio_device_name(ctx.sandbox, &storage.source)
.await .await
.context("failed to get mmio device name")?; .context("failed to get mmio device name")?;
} }