src/tools/disks/smart.rs - get_smart_data: use &Disk instead of &str

So that we can query other device infos easily (model, vendor, ..)
This commit is contained in:
Dietmar Maurer 2020-06-06 08:23:59 +02:00
parent 1278aeec36
commit 059b7a252e
1 changed files with 8 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use anyhow::{format_err, Error}; use anyhow::{bail, format_err, Error};
use ::serde::{Deserialize, Serialize}; use ::serde::{Deserialize, Serialize};
use proxmox::api::api; use proxmox::api::api;
@ -72,7 +72,7 @@ pub struct SmartData {
/// Read smartctl data for a disk (/dev/XXX). /// Read smartctl data for a disk (/dev/XXX).
pub fn get_smart_data( pub fn get_smart_data(
disk: &str, disk: &super::Disk,
health_only: bool, health_only: bool,
) -> Result<SmartData, Error> { ) -> Result<SmartData, Error> {
@ -81,7 +81,12 @@ pub fn get_smart_data(
let mut command = std::process::Command::new(SMARTCTL_BIN_PATH); let mut command = std::process::Command::new(SMARTCTL_BIN_PATH);
command.arg("-H"); command.arg("-H");
if !health_only { command.args(&["-A", "-j"]); } if !health_only { command.args(&["-A", "-j"]); }
command.arg(disk);
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 = command.output() let output = command.output()
.map_err(|err| format_err!("failed to execute '{}' - {}", SMARTCTL_BIN_PATH, err))?; .map_err(|err| format_err!("failed to execute '{}' - {}", SMARTCTL_BIN_PATH, err))?;