From 75816d17f1c6affe3bb5b61375ca108daa2e4e32 Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Tue, 27 Aug 2024 06:44:12 +0800 Subject: [PATCH] agent: switch to new device subsystem Switch to new device subsystem to handle various devices in kata-agent. Signed-off-by: ChengyuZhu6 --- src/agent/src/device.rs | 9 --------- src/agent/src/rpc.rs | 8 ++++---- src/agent/src/storage/block_handler.rs | 15 +++++++++------ 3 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 src/agent/src/device.rs diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs deleted file mode 100644 index 69789cc2b1..0000000000 --- a/src/agent/src/device.rs +++ /dev/null @@ -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")) -} diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 57410463d7..9f13af0f04 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -56,9 +56,9 @@ use nix::unistd::{self, Pid}; use rustjail::process::ProcessOperations; use crate::cdh; -use crate::device::{ - add_devices, get_virtio_blk_pci_device_name, update_env_pci, wait_for_net_interface, -}; +use crate::device::block_device_handler::get_virtio_blk_pci_device_name; +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::image::KATA_IMAGE_WORK_DIR; use crate::linux_abi::*; @@ -222,7 +222,7 @@ impl AgentService { // updates the devices listed in the OCI spec, so that they actually // match real devices inside the VM. This step is necessary since we // 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 .process_mut() diff --git a/src/agent/src/storage/block_handler.rs b/src/agent/src/storage/block_handler.rs index 2cae2b2898..251a4dfff7 100644 --- a/src/agent/src/storage/block_handler.rs +++ b/src/agent/src/storage/block_handler.rs @@ -19,14 +19,17 @@ use kata_types::mount::StorageDevice; use protocols::agent::Storage; use tracing::instrument; -use crate::device::{ - get_scsi_device_name, get_virtio_blk_pci_device_name, get_virtio_mmio_device_name, - wait_for_pmem_device, +#[cfg(target_arch = "s390x")] +use crate::ccw; +#[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::storage::{common_storage_handler, new_device, StorageContext, StorageHandler}; -#[cfg(target_arch = "s390x")] -use crate::{ccw, device::get_virtio_blk_ccw_device_name}; #[derive(Debug)] pub struct VirtioBlkMmioHandler {} @@ -45,7 +48,7 @@ impl StorageHandler for VirtioBlkMmioHandler { ctx: &mut StorageContext, ) -> Result> { 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 .context("failed to get mmio device name")?; }