mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 15:07:46 +00:00
agent: group Linux ABI constants into dedicated file
Group Linux ABI related constants into dedicated file for maintenance. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
parent
000bb8592d
commit
154c68eb93
@ -10,6 +10,7 @@ use std::os::unix::fs::MetadataExt;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{mpsc, Arc, Mutex};
|
use std::sync::{mpsc, Arc, Mutex};
|
||||||
|
|
||||||
|
use crate::linux_abi::*;
|
||||||
use crate::mount::{DRIVERBLKTYPE, DRIVERMMIOBLKTYPE, DRIVERNVDIMMTYPE, DRIVERSCSITYPE};
|
use crate::mount::{DRIVERBLKTYPE, DRIVERMMIOBLKTYPE, DRIVERNVDIMMTYPE, DRIVERSCSITYPE};
|
||||||
use crate::sandbox::Sandbox;
|
use crate::sandbox::Sandbox;
|
||||||
use crate::{AGENT_CONFIG, GLOBAL_DEVICE_WATCHER};
|
use crate::{AGENT_CONFIG, GLOBAL_DEVICE_WATCHER};
|
||||||
@ -24,34 +25,6 @@ macro_rules! sl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "s390x"
|
|
||||||
))]
|
|
||||||
pub const ROOT_BUS_PATH: &str = "/devices/pci0000:00";
|
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub const ROOT_BUS_PATH: &str = "/devices/platform/4010000000.pcie/pci0000:00";
|
|
||||||
|
|
||||||
pub const SYSFS_DIR: &str = "/sys";
|
|
||||||
|
|
||||||
const SYS_BUS_PREFIX: &str = "/sys/bus/pci/devices";
|
|
||||||
const PCI_BUS_RESCAN_FILE: &str = "/sys/bus/pci/rescan";
|
|
||||||
const SYSTEM_DEV_PATH: &str = "/dev";
|
|
||||||
|
|
||||||
// SCSI const
|
|
||||||
|
|
||||||
// Here in "0:0", the first number is the SCSI host number because
|
|
||||||
// only one SCSI controller has been plugged, while the second number
|
|
||||||
// is always 0.
|
|
||||||
pub const SCSI_HOST_CHANNEL: &str = "0:0:";
|
|
||||||
const SYS_CLASS_PREFIX: &str = "/sys/class";
|
|
||||||
const SCSI_DISK_PREFIX: &str = "/sys/class/scsi_disk/0:0:";
|
|
||||||
pub const SCSI_BLOCK_SUFFIX: &str = "block";
|
|
||||||
const SCSI_DISK_SUFFIX: &str = "/device/block";
|
|
||||||
const SCSI_HOST_PATH: &str = "/sys/class/scsi_host";
|
|
||||||
|
|
||||||
// DeviceHandler is the type of callback to be defined to handle every type of device driver.
|
// DeviceHandler is the type of callback to be defined to handle every type of device driver.
|
||||||
type DeviceHandler = fn(&Device, &mut Spec, &Arc<Mutex<Sandbox>>) -> Result<()>;
|
type DeviceHandler = fn(&Device, &mut Spec, &Arc<Mutex<Sandbox>>) -> Result<()>;
|
||||||
|
|
||||||
@ -69,7 +42,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn rescan_pci_bus() -> Result<()> {
|
pub fn rescan_pci_bus() -> Result<()> {
|
||||||
online_device(PCI_BUS_RESCAN_FILE)
|
online_device(SYSFS_PCI_BUS_RESCAN_FILE)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn online_device(path: &str) -> Result<()> {
|
pub fn online_device(path: &str) -> Result<()> {
|
||||||
@ -100,7 +73,7 @@ fn get_pci_device_address(pci_id: &str) -> Result<String> {
|
|||||||
let pci_bridge_addr = format!("0000:00:{}.0", bridge_id);
|
let pci_bridge_addr = format!("0000:00:{}.0", bridge_id);
|
||||||
|
|
||||||
// Find out the bus exposed by bridge
|
// Find out the bus exposed by bridge
|
||||||
let bridge_bus_path = format!("{}/{}/pci_bus/", SYS_BUS_PREFIX, pci_bridge_addr);
|
let bridge_bus_path = format!("{}/{}/pci_bus/", SYSFS_PCI_BUS_PREFIX, pci_bridge_addr);
|
||||||
|
|
||||||
let files_slice: Vec<_> = fs::read_dir(&bridge_bus_path)
|
let files_slice: Vec<_> = fs::read_dir(&bridge_bus_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -199,9 +172,14 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> {
|
|||||||
// Channel is always 0 because we have only one SCSI controller.
|
// Channel is always 0 because we have only one SCSI controller.
|
||||||
let scan_data = format!("0 {} {}", tokens[0], tokens[1]);
|
let scan_data = format!("0 {} {}", tokens[0], tokens[1]);
|
||||||
|
|
||||||
for entry in fs::read_dir(SCSI_HOST_PATH)? {
|
for entry in fs::read_dir(SYSFS_SCSI_HOST_PATH)? {
|
||||||
let host = entry?.file_name();
|
let host = entry?.file_name();
|
||||||
let scan_path = format!("{}/{}/{}", SCSI_HOST_PATH, host.to_str().unwrap(), "scan");
|
let scan_path = format!(
|
||||||
|
"{}/{}/{}",
|
||||||
|
SYSFS_SCSI_HOST_PATH,
|
||||||
|
host.to_str().unwrap(),
|
||||||
|
"scan"
|
||||||
|
);
|
||||||
|
|
||||||
fs::write(scan_path, &scan_data)?;
|
fs::write(scan_path, &scan_data)?;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ use nix::unistd::{self, Pid};
|
|||||||
use rustjail::process::ProcessOperations;
|
use rustjail::process::ProcessOperations;
|
||||||
|
|
||||||
use crate::device::{add_devices, rescan_pci_bus};
|
use crate::device::{add_devices, rescan_pci_bus};
|
||||||
|
use crate::linux_abi::*;
|
||||||
use crate::mount::{add_storages, remove_mounts, STORAGEHANDLERLIST};
|
use crate::mount::{add_storages, remove_mounts, STORAGEHANDLERLIST};
|
||||||
use crate::namespace::{NSTYPEIPC, NSTYPEPID, NSTYPEUTS};
|
use crate::namespace::{NSTYPEIPC, NSTYPEPID, NSTYPEUTS};
|
||||||
use crate::netlink::{RtnlHandle, NETLINK_ROUTE};
|
use crate::netlink::{RtnlHandle, NETLINK_ROUTE};
|
||||||
@ -53,9 +54,6 @@ use std::io::{BufRead, BufReader};
|
|||||||
use std::os::unix::fs::FileExt;
|
use std::os::unix::fs::FileExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
const SYSFS_MEMORY_BLOCK_SIZE_PATH: &str = "/sys/devices/system/memory/block_size_bytes";
|
|
||||||
const SYSFS_MEMORY_HOTPLUG_PROBE_PATH: &str = "/sys/devices/system/memory/probe";
|
|
||||||
pub const SYSFS_MEMORY_ONLINE_PATH: &str = "/sys/devices/system/memory";
|
|
||||||
const CONTAINER_BASE: &str = "/run/kata-containers";
|
const CONTAINER_BASE: &str = "/run/kata-containers";
|
||||||
|
|
||||||
// Convenience macro to obtain the scope logger
|
// Convenience macro to obtain the scope logger
|
||||||
|
50
src/agent/src/linux_abi.rs
Normal file
50
src/agent/src/linux_abi.rs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) 2019 Ant Financial
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
/// Linux ABI related constants.
|
||||||
|
|
||||||
|
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(
|
||||||
|
target_arch = "powerpc64le",
|
||||||
|
target_arch = "s390x",
|
||||||
|
target_arch = "x86_64",
|
||||||
|
target_arch = "x86"
|
||||||
|
))]
|
||||||
|
pub const PCI_ROOT_BUS_PATH: &str = "/devices/pci0000:00";
|
||||||
|
#[cfg(target_arch = "arm")]
|
||||||
|
pub const PCI_ROOT_BUS_PATH: &str = "/devices/platform/4010000000.pcie/pci0000:00";
|
||||||
|
|
||||||
|
pub const SYSFS_CPU_ONLINE_PATH: &str = "/sys/devices/system/cpu";
|
||||||
|
|
||||||
|
pub const SYSFS_MEMORY_BLOCK_SIZE_PATH: &str = "/sys/devices/system/memory/block_size_bytes";
|
||||||
|
pub const SYSFS_MEMORY_HOTPLUG_PROBE_PATH: &str = "/sys/devices/system/memory/probe";
|
||||||
|
pub const SYSFS_MEMORY_ONLINE_PATH: &str = "/sys/devices/system/memory";
|
||||||
|
|
||||||
|
// Here in "0:0", the first number is the SCSI host number because
|
||||||
|
// only one SCSI controller has been plugged, while the second number
|
||||||
|
// is always 0.
|
||||||
|
pub const SCSI_HOST_CHANNEL: &str = "0:0:";
|
||||||
|
pub const SCSI_BLOCK_SUFFIX: &str = "block";
|
||||||
|
pub const SYSFS_SCSI_HOST_PATH: &str = "/sys/class/scsi_host";
|
||||||
|
|
||||||
|
pub const SYSFS_CGROUPPATH: &str = "/sys/fs/cgroup";
|
||||||
|
pub const SYSFS_ONLINE_FILE: &str = "online";
|
||||||
|
|
||||||
|
pub const PROC_MOUNTSTATS: &str = "/proc/self/mountstats";
|
||||||
|
pub const PROC_CGROUPS: &str = "/proc/cgroups";
|
||||||
|
|
||||||
|
pub const SYSTEM_DEV_PATH: &str = "/dev";
|
||||||
|
|
||||||
|
// Linux UEvent related consts.
|
||||||
|
pub const U_EVENT_ACTION: &str = "ACTION";
|
||||||
|
pub const U_EVENT_ACTION_ADD: &str = "add";
|
||||||
|
pub const U_EVENT_DEV_PATH: &str = "DEVPATH";
|
||||||
|
pub const U_EVENT_SUB_SYSTEM: &str = "SUBSYSTEM";
|
||||||
|
pub const U_EVENT_SEQ_NUM: &str = "SEQNUM";
|
||||||
|
pub const U_EVENT_DEV_NAME: &str = "DEVNAME";
|
||||||
|
pub const U_EVENT_INTERFACE: &str = "INTERFACE";
|
@ -44,6 +44,7 @@ use unistd::Pid;
|
|||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod device;
|
mod device;
|
||||||
|
mod linux_abi;
|
||||||
mod logging;
|
mod logging;
|
||||||
mod mount;
|
mod mount;
|
||||||
mod namespace;
|
mod namespace;
|
||||||
|
@ -23,28 +23,22 @@ use std::fs::File;
|
|||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
use crate::device::{get_pci_device_name, get_scsi_device_name, online_device};
|
use crate::device::{get_pci_device_name, get_scsi_device_name, online_device};
|
||||||
|
use crate::linux_abi::*;
|
||||||
use crate::protocols::agent::Storage;
|
use crate::protocols::agent::Storage;
|
||||||
use crate::Sandbox;
|
use crate::Sandbox;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
|
|
||||||
const DRIVER9PTYPE: &str = "9p";
|
pub const DRIVER9PTYPE: &str = "9p";
|
||||||
const DRIVERVIRTIOFSTYPE: &str = "virtio-fs";
|
pub const DRIVERVIRTIOFSTYPE: &str = "virtio-fs";
|
||||||
pub const DRIVERBLKTYPE: &str = "blk";
|
pub const DRIVERBLKTYPE: &str = "blk";
|
||||||
pub const DRIVERMMIOBLKTYPE: &str = "mmioblk";
|
pub const DRIVERMMIOBLKTYPE: &str = "mmioblk";
|
||||||
pub const DRIVERSCSITYPE: &str = "scsi";
|
pub const DRIVERSCSITYPE: &str = "scsi";
|
||||||
pub const DRIVERNVDIMMTYPE: &str = "nvdimm";
|
pub const DRIVERNVDIMMTYPE: &str = "nvdimm";
|
||||||
const DRIVEREPHEMERALTYPE: &str = "ephemeral";
|
pub const DRIVEREPHEMERALTYPE: &str = "ephemeral";
|
||||||
const DRIVERLOCALTYPE: &str = "local";
|
pub const DRIVERLOCALTYPE: &str = "local";
|
||||||
|
|
||||||
pub const TYPEROOTFS: &str = "rootfs";
|
pub const TYPEROOTFS: &str = "rootfs";
|
||||||
|
|
||||||
pub const PROCMOUNTSTATS: &str = "/proc/self/mountstats";
|
|
||||||
|
|
||||||
const ROOTBUSPATH: &str = "/devices/pci0000:00";
|
|
||||||
|
|
||||||
const CGROUPPATH: &str = "/sys/fs/cgroup";
|
|
||||||
const PROCCGROUPS: &str = "/proc/cgroups";
|
|
||||||
|
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref FLAGS: HashMap<&'static str, (bool, MsFlags)> = {
|
pub static ref FLAGS: HashMap<&'static str, (bool, MsFlags)> = {
|
||||||
@ -509,7 +503,7 @@ pub fn general_mount(logger: &Logger) -> Result<()> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_mount_fs_type(mount_point: &str) -> Result<String> {
|
pub fn get_mount_fs_type(mount_point: &str) -> Result<String> {
|
||||||
get_mount_fs_type_from_file(PROCMOUNTSTATS, mount_point)
|
get_mount_fs_type_from_file(PROC_MOUNTSTATS, mount_point)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_mount_fs_type returns the FS type corresponding to the passed mount point and
|
// get_mount_fs_type returns the FS type corresponding to the passed mount point and
|
||||||
@ -553,7 +547,7 @@ pub fn get_cgroup_mounts(logger: &Logger, cg_path: &str) -> Result<Vec<INIT_MOUN
|
|||||||
let mut cg_mounts: Vec<INIT_MOUNT> = vec![INIT_MOUNT {
|
let mut cg_mounts: Vec<INIT_MOUNT> = vec![INIT_MOUNT {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@ -613,7 +607,7 @@ pub fn get_cgroup_mounts(logger: &Logger, cg_path: &str) -> Result<Vec<INIT_MOUN
|
|||||||
cg_mounts.push(INIT_MOUNT {
|
cg_mounts.push(INIT_MOUNT {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -623,7 +617,7 @@ pub fn get_cgroup_mounts(logger: &Logger, cg_path: &str) -> Result<Vec<INIT_MOUN
|
|||||||
pub fn cgroups_mount(logger: &Logger) -> Result<()> {
|
pub fn cgroups_mount(logger: &Logger) -> Result<()> {
|
||||||
let logger = logger.new(o!("subsystem" => "mount"));
|
let logger = logger.new(o!("subsystem" => "mount"));
|
||||||
|
|
||||||
let cgroups = get_cgroup_mounts(&logger, PROCCGROUPS)?;
|
let cgroups = get_cgroup_mounts(&logger, PROC_CGROUPS)?;
|
||||||
|
|
||||||
for cg in cgroups.iter() {
|
for cg in cgroups.iter() {
|
||||||
mount_to_rootfs(&logger, cg)?;
|
mount_to_rootfs(&logger, cg)?;
|
||||||
@ -1103,14 +1097,14 @@ mod tests {
|
|||||||
let first_mount = INIT_MOUNT {
|
let first_mount = INIT_MOUNT {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["nosuid", "nodev", "noexec", "mode=755"],
|
||||||
};
|
};
|
||||||
|
|
||||||
let last_mount = INIT_MOUNT {
|
let last_mount = INIT_MOUNT {
|
||||||
fstype: "tmpfs",
|
fstype: "tmpfs",
|
||||||
src: "tmpfs",
|
src: "tmpfs",
|
||||||
dest: CGROUPPATH,
|
dest: SYSFS_CGROUPPATH,
|
||||||
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//use crate::container::Container;
|
//use crate::container::Container;
|
||||||
|
use crate::linux_abi::*;
|
||||||
use crate::mount::{get_mount_fs_type, remove_mounts, TYPEROOTFS};
|
use crate::mount::{get_mount_fs_type, remove_mounts, TYPEROOTFS};
|
||||||
use crate::namespace::Namespace;
|
use crate::namespace::Namespace;
|
||||||
use crate::netlink::{RtnlHandle, NETLINK_ROUTE};
|
use crate::netlink::{RtnlHandle, NETLINK_ROUTE};
|
||||||
@ -220,10 +221,6 @@ impl Sandbox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const CPU_ONLINE_PATH: &str = "/sys/devices/system/cpu";
|
|
||||||
pub const MEMORY_ONLINE_PATH: &str = "/sys/devices/system/memory";
|
|
||||||
pub const ONLINE_FILE: &str = "online";
|
|
||||||
|
|
||||||
fn online_resources(logger: &Logger, path: &str, pattern: &str, num: i32) -> Result<i32> {
|
fn online_resources(logger: &Logger, path: &str, pattern: &str, num: i32) -> Result<i32> {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let re = Regex::new(pattern)?;
|
let re = Regex::new(pattern)?;
|
||||||
@ -235,7 +232,7 @@ fn online_resources(logger: &Logger, path: &str, pattern: &str, num: i32) -> Res
|
|||||||
let p = entry.path();
|
let p = entry.path();
|
||||||
|
|
||||||
if re.is_match(name) {
|
if re.is_match(name) {
|
||||||
let file = format!("{}/{}", p.to_str().unwrap(), ONLINE_FILE);
|
let file = format!("{}/{}", p.to_str().unwrap(), SYSFS_ONLINE_FILE);
|
||||||
info!(logger, "{}", file.as_str());
|
info!(logger, "{}", file.as_str());
|
||||||
let c = fs::read_to_string(file.as_str())?;
|
let c = fs::read_to_string(file.as_str())?;
|
||||||
|
|
||||||
@ -258,10 +255,10 @@ fn online_resources(logger: &Logger, path: &str, pattern: &str, num: i32) -> Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn online_cpus(logger: &Logger, num: i32) -> Result<i32> {
|
fn online_cpus(logger: &Logger, num: i32) -> Result<i32> {
|
||||||
online_resources(logger, CPU_ONLINE_PATH, r"cpu[0-9]+", num)
|
online_resources(logger, SYSFS_CPU_ONLINE_PATH, r"cpu[0-9]+", num)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn online_memory(logger: &Logger) -> Result<()> {
|
fn online_memory(logger: &Logger) -> Result<()> {
|
||||||
online_resources(logger, MEMORY_ONLINE_PATH, r"memory[0-9]+", -1)?;
|
online_resources(logger, SYSFS_MEMORY_ONLINE_PATH, r"memory[0-9]+", -1)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
use crate::device::{online_device, ROOT_BUS_PATH, SCSI_BLOCK_SUFFIX, SYSFS_DIR};
|
use crate::device::online_device;
|
||||||
use crate::grpc::SYSFS_MEMORY_ONLINE_PATH;
|
use crate::linux_abi::*;
|
||||||
use crate::netlink::{RtnlHandle, NETLINK_UEVENT};
|
use crate::netlink::{RtnlHandle, NETLINK_UEVENT};
|
||||||
use crate::sandbox::Sandbox;
|
use crate::sandbox::Sandbox;
|
||||||
use crate::GLOBAL_DEVICE_WATCHER;
|
use crate::GLOBAL_DEVICE_WATCHER;
|
||||||
@ -12,14 +12,6 @@ use slog::Logger;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
pub const U_EVENT_ACTION: &str = "ACTION";
|
|
||||||
pub const U_EVENT_ACTION_ADD: &str = "add";
|
|
||||||
pub const U_EVENT_DEV_PATH: &str = "DEVPATH";
|
|
||||||
pub const U_EVENT_SUB_SYSTEM: &str = "SUBSYSTEM";
|
|
||||||
pub const U_EVENT_SEQ_NUM: &str = "SEQNUM";
|
|
||||||
pub const U_EVENT_DEV_NAME: &str = "DEVNAME";
|
|
||||||
pub const U_EVENT_INTERFACE: &str = "INTERFACE";
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Uevent {
|
struct Uevent {
|
||||||
action: String,
|
action: String,
|
||||||
@ -58,7 +50,7 @@ impl Uevent {
|
|||||||
fn is_block_add_event(&self) -> bool {
|
fn is_block_add_event(&self) -> bool {
|
||||||
self.action == U_EVENT_ACTION_ADD
|
self.action == U_EVENT_ACTION_ADD
|
||||||
&& self.subsystem == "block"
|
&& self.subsystem == "block"
|
||||||
&& self.devpath.starts_with(ROOT_BUS_PATH)
|
&& self.devpath.starts_with(PCI_ROOT_BUS_PATH)
|
||||||
&& self.devname != ""
|
&& self.devname != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +69,7 @@ impl Uevent {
|
|||||||
let empties: Vec<_> = w
|
let empties: Vec<_> = w
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(dev_addr, _)| {
|
.filter(|(dev_addr, _)| {
|
||||||
let pci_p = format!("{}/{}", ROOT_BUS_PATH, *dev_addr);
|
let pci_p = format!("{}/{}", PCI_ROOT_BUS_PATH, *dev_addr);
|
||||||
|
|
||||||
// blk block device
|
// blk block device
|
||||||
devpath.starts_with(pci_p.as_str()) ||
|
devpath.starts_with(pci_p.as_str()) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user