diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index 0de459116..119183cb4 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -801,6 +801,7 @@ dependencies = [ "async-recursion", "async-trait", "capctl", + "cfg-if 1.0.0", "cgroups-rs", "clap", "futures", diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index 8851798fd..b5a82f257 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -48,6 +48,7 @@ slog-scope = "4.1.2" slog-stdlog = "4.0.0" log = "0.4.11" +cfg-if = "1.0.0" prometheus = { version = "0.13.0", features = ["process"] } procfs = "0.12.0" anyhow = "1.0.32" diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 2d01b63ab..620163ee0 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -16,13 +16,12 @@ use std::str::FromStr; use std::sync::Arc; use tokio::sync::Mutex; -#[cfg(target_arch = "s390x")] -use crate::ccw; use crate::linux_abi::*; use crate::pci; use crate::sandbox::Sandbox; use crate::uevent::{wait_for_uevent, Uevent, UeventMatcher}; use anyhow::{anyhow, Context, Result}; +use cfg_if::cfg_if; use oci::{LinuxDeviceCgroup, LinuxResources, Spec}; use protocols::agent::Device; use tracing::instrument; @@ -54,6 +53,12 @@ pub const DRIVER_VFIO_TYPE: &str = "vfio"; pub const DRIVER_OVERLAYFS_TYPE: &str = "overlayfs"; pub const FS_TYPE_HUGETLB: &str = "hugetlbfs"; +cfg_if! { + if #[cfg(target_arch = "s390x")] { + use crate::ccw; + } +} + #[instrument] pub fn online_device(path: &str) -> Result<()> { fs::write(path, "1")?; diff --git a/src/agent/src/linux_abi.rs b/src/agent/src/linux_abi.rs index fbfb9b377..9df398d61 100644 --- a/src/agent/src/linux_abi.rs +++ b/src/agent/src/linux_abi.rs @@ -3,6 +3,8 @@ // SPDX-License-Identifier: Apache-2.0 // +use cfg_if::cfg_if; + /// Linux ABI related constants. #[cfg(target_arch = "aarch64")] @@ -64,8 +66,11 @@ pub fn create_pci_root_bus_path() -> String { ret } -#[cfg(target_arch = "s390x")] -pub const CCW_ROOT_BUS_PATH: &str = "/devices/css0"; +cfg_if! { + if #[cfg(target_arch = "s390x")] { + pub const CCW_ROOT_BUS_PATH: &str = "/devices/css0"; + } +} // From https://www.kernel.org/doc/Documentation/acpi/namespace.txt // The Linux kernel's core ACPI subsystem creates struct acpi_device diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index d8e9fc828..4ca89a9a1 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -20,6 +20,7 @@ extern crate scopeguard; extern crate slog; use anyhow::{anyhow, Context, Result}; +use cfg_if::cfg_if; use clap::{AppSettings, Parser}; use nix::fcntl::OFlag; use nix::sys::socket::{self, AddressFamily, SockFlag, SockType, VsockAddr}; @@ -34,8 +35,6 @@ use std::process::exit; use std::sync::Arc; use tracing::{instrument, span}; -#[cfg(target_arch = "s390x")] -mod ccw; mod config; mod console; mod device; @@ -74,6 +73,12 @@ use tokio::{ mod rpc; mod tracer; +cfg_if! { + if #[cfg(target_arch = "s390x")] { + mod ccw; + } +} + const NAME: &str = "kata-agent"; lazy_static! {