mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-02 05:34:46 +00:00
agent: create pci root Bus Path for arm64
port https://github.com/kata-containers/agent/pull/860 here. Fixes: #1059 Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
parent
43ec107d94
commit
6c2fc233e2
@ -21,6 +21,7 @@ signal-hook = "0.1.9"
|
||||
scan_fmt = "0.2.3"
|
||||
scopeguard = "1.0.0"
|
||||
regex = "1"
|
||||
|
||||
# slog:
|
||||
# - Dynamic keys required to allow HashMap keys to be slog::Serialized.
|
||||
# - The 'max_*' features allow changing the log level at runtime
|
||||
|
@ -5,8 +5,10 @@
|
||||
|
||||
/// Linux ABI related constants.
|
||||
|
||||
pub const SYSFS_DIR: &str = "/sys";
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use std::fs;
|
||||
|
||||
pub const SYSFS_DIR: &str = "/sys";
|
||||
pub const SYSFS_PCI_BUS_PREFIX: &str = "/sys/bus/pci/devices";
|
||||
pub const SYSFS_PCI_BUS_RESCAN_FILE: &str = "/sys/bus/pci/rescan";
|
||||
#[cfg(any(
|
||||
@ -15,9 +17,46 @@ pub const SYSFS_PCI_BUS_RESCAN_FILE: &str = "/sys/bus/pci/rescan";
|
||||
target_arch = "x86_64",
|
||||
target_arch = "x86"
|
||||
))]
|
||||
pub const PCI_ROOT_BUS_PATH: &str = "/devices/pci0000:00";
|
||||
pub fn create_pci_root_bus_path() -> String {
|
||||
String::from("/devices/pci0000:00")
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub const PCI_ROOT_BUS_PATH: &str = "/devices/platform/4010000000.pcie/pci0000:00";
|
||||
pub fn create_pci_root_bus_path() -> String {
|
||||
let ret = String::from("/devices/platform/4010000000.pcie/pci0000:00");
|
||||
|
||||
let mut sysfs_dir = String::from(SYSFS_DIR);
|
||||
let mut start_root_bus_path = String::from("/devices/platform/");
|
||||
let end_root_bus_path = String::from("/pci0000:00");
|
||||
|
||||
sysfs_dir.push_str(&start_root_bus_path);
|
||||
let entries = match fs::read_dir(sysfs_dir) {
|
||||
Ok(e) => e,
|
||||
Err(_) => return ret,
|
||||
};
|
||||
for entry in entries {
|
||||
let pathname = match entry {
|
||||
Ok(p) => p.path(),
|
||||
Err(_) => return ret,
|
||||
};
|
||||
let dir_name = match pathname.file_name() {
|
||||
Some(p) => p.to_str(),
|
||||
None => return ret,
|
||||
};
|
||||
let dir_name = match dir_name {
|
||||
Some(p) => p,
|
||||
None => return ret,
|
||||
};
|
||||
let dir_name = String::from(dir_name);
|
||||
if dir_name.ends_with(".pcie") {
|
||||
start_root_bus_path.push_str(&dir_name);
|
||||
start_root_bus_path.push_str(&end_root_bus_path);
|
||||
return start_root_bus_path;
|
||||
}
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub const SYSFS_CPU_ONLINE_PATH: &str = "/sys/devices/system/cpu";
|
||||
|
||||
|
@ -48,13 +48,16 @@ impl Uevent {
|
||||
|
||||
// Check whether this is a block device hot-add event.
|
||||
fn is_block_add_event(&self) -> bool {
|
||||
let pci_root_bus_path = create_pci_root_bus_path();
|
||||
self.action == U_EVENT_ACTION_ADD
|
||||
&& self.subsystem == "block"
|
||||
&& self.devpath.starts_with(PCI_ROOT_BUS_PATH)
|
||||
&& self.devpath.starts_with(&pci_root_bus_path)
|
||||
&& self.devname != ""
|
||||
}
|
||||
|
||||
fn handle_block_add_event(&self, sandbox: &Arc<Mutex<Sandbox>>) {
|
||||
let pci_root_bus_path = create_pci_root_bus_path();
|
||||
|
||||
// Keep the same lock order as device::get_device_name(), otherwise it may cause deadlock.
|
||||
let mut w = GLOBAL_DEVICE_WATCHER.lock().unwrap();
|
||||
let mut sb = sandbox.lock().unwrap();
|
||||
@ -69,7 +72,7 @@ impl Uevent {
|
||||
let empties: Vec<_> = w
|
||||
.iter()
|
||||
.filter(|(dev_addr, _)| {
|
||||
let pci_p = format!("{}/{}", PCI_ROOT_BUS_PATH, *dev_addr);
|
||||
let pci_p = format!("{}/{}", pci_root_bus_path, *dev_addr);
|
||||
|
||||
// blk block device
|
||||
devpath.starts_with(pci_p.as_str()) ||
|
||||
|
Loading…
Reference in New Issue
Block a user