let manager = DiskManage::new();
let disk = manager.disk_by_name(&disk)?;
- get_smart_data(&disk, healthonly)
+ if let Some(path) = disk.device_path() {
+ get_smart_data(path, healthonly)
+ } else {
+ bail!("disk {:?} has no node in /dev", disk.syspath());
+ }
}
#[api(
lvm_devices: &HashSet<u64>,
zfs_devices: &HashSet<u64>,
file_system_devices: &HashSet<u64>,
+ lsblk_infos: &[LsblkInfo],
) -> Vec<PartitionInfo> {
- let lsblk_infos = get_lsblk_info().ok();
partitions
.values()
.map(|disk| {
let mounted = disk.is_mounted().unwrap_or(false);
let mut filesystem = None;
- if let (Some(devpath), Some(infos)) = (devpath.as_ref(), lsblk_infos.as_ref()) {
- for info in infos.iter().filter(|i| i.path.eq(devpath)) {
+ if let Some(devpath) = devpath.as_ref() {
+ for info in lsblk_infos.iter().filter(|i| i.path.eq(devpath)) {
used = match info.partition_type.as_deref() {
Some("21686148-6449-6e6f-744e-656564454649") => PartitionUsageType::BIOS,
Some("c12a7328-f81f-11d2-ba4b-00a0c93ec93b") => PartitionUsageType::EFI,
// fixme: ceph journals/volumes
let mut result = HashMap::new();
+ let mut device_paths = Vec::new();
for item in proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)?
{
.map(|p| p.to_owned())
.map(|p| p.to_string_lossy().to_string());
+ device_paths.push((name.clone(), devpath.clone()));
+
let wwn = disk.wwn().map(|s| s.to_string_lossy().into_owned());
let partitions: Option<Vec<PartitionInfo>> = if include_partitions {
&lvm_devices,
&zfs_devices,
&file_system_devices,
+ &lsblk_info,
))
})
} else {
-use std::collections::{HashMap, HashSet};
use std::sync::LazyLock;
+use std::{collections::{HashMap, HashSet}, path::Path};
use ::serde::{Deserialize, Serialize};
-use anyhow::{bail, Error};
+use anyhow::Error;
use proxmox_schema::api;
}
/// Read smartctl data for a disk (/dev/XXX).
-pub fn get_smart_data(disk: &super::Disk, health_only: bool) -> Result<SmartData, Error> {
+pub fn get_smart_data(disk_path: &Path, health_only: bool) -> Result<SmartData, Error> {
const SMARTCTL_BIN_PATH: &str = "smartctl";
let mut command = std::process::Command::new(SMARTCTL_BIN_PATH);
command.args(["-A", "-j"]);
}
- let disk_path = match disk.device_path() {
- Some(path) => path,
- None => bail!("disk {:?} has no node in /dev", disk.syspath()),
- };
command.arg(disk_path);
let output = proxmox_sys::command::run_command(
///
/// The set is indexed by using the unix raw device number (dev_t is u64)
pub fn zfs_devices(lsblk_info: &[LsblkInfo], pool: Option<String>) -> Result<HashSet<u64>, Error> {
- let list = zpool_list(pool, true)?;
+ let list = zpool_list(pool.as_ref(), true)?;
let mut device_set = HashSet::new();
for entry in list {
device_set.insert(meta.rdev());
}
}
-
- for info in lsblk_info.iter() {
- if let Some(partition_type) = &info.partition_type {
- if ZFS_UUIDS.contains(partition_type.as_str()) {
- let meta = std::fs::metadata(&info.path)?;
- device_set.insert(meta.rdev());
+ if pool.is_none() {
+ for info in lsblk_info.iter() {
+ if let Some(partition_type) = &info.partition_type {
+ if ZFS_UUIDS.contains(partition_type.as_str()) {
+ let meta = std::fs::metadata(&info.path)?;
+ device_set.insert(meta.rdev());
+ }
}
}
}
///
/// Devices are only included when run with verbose flags
/// set. Without, device lists are empty.
-pub fn zpool_list(pool: Option<String>, verbose: bool) -> Result<Vec<ZFSPoolInfo>, Error> {
+pub fn zpool_list(pool: Option<&String>, verbose: bool) -> Result<Vec<ZFSPoolInfo>, Error> {
// Note: zpools list verbose output can include entries for 'special', 'cache' and 'logs'
// and maybe other things.