Skip to content

Commit

Permalink
Trace logging for detecting links
Browse files Browse the repository at this point in the history
  • Loading branch information
nokyan committed Feb 21, 2025
1 parent 30e4da9 commit e930cfa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/utils/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::utils::drive::{AtaSlot, UsbSlot};
use crate::utils::link::SataSpeed::{Sata150, Sata300, Sata600};
use crate::utils::units::convert_speed_bits_decimal_with_places;
use anyhow::{Context, Error, Result, anyhow, bail};
use log::trace;
use process_data::pci_slot::PciSlot;
use std::fmt::{Display, Formatter};
use std::path::Path;
Expand Down Expand Up @@ -69,10 +70,12 @@ impl LinkData<PcieLinkData> {

fn read_pcie_link_data<P: AsRef<Path>>(path: P) -> Result<Self> {
let path = path.as_ref();
trace!("Reading PCIe link data for {path:?}…");

let current_pcie_speed_raw = std::fs::read_to_string(path.join("current_link_speed"))
.map(|x| x.trim().to_string())
.context("Could not read current link speed")?;

let current_pcie_width_raw = std::fs::read_to_string(path.join("current_link_width"))
.map(|x| x.trim().to_string())
.context("Could not read current link width")?;
Expand All @@ -81,6 +84,7 @@ impl LinkData<PcieLinkData> {
let max_pcie_speed_raw = std::fs::read_to_string(path.join("max_link_speed"))
.map(|x| x.trim().to_string())
.context("Could not read max link speed");

let max_pcie_width_raw = std::fs::read_to_string(path.join("max_link_width"))
.map(|x| x.trim().to_string())
.context("Could not read max link width");
Expand Down Expand Up @@ -131,12 +135,15 @@ where

impl LinkData<SataSpeed> {
pub fn from_ata_slot(ata_slot: &AtaSlot) -> Result<Self> {
trace!("Reading ATA link data for {ata_slot:?}…");

let ata_link_path =
Path::new("/sys/class/ata_link").join(format!("link{}", ata_slot.ata_link));

let current_sata_speed_raw = std::fs::read_to_string(ata_link_path.join("sata_spd"))
.map(|x| x.trim().to_string())
.context("Could not read sata_spd")?;

let max_sata_speed_raw = std::fs::read_to_string(ata_link_path.join("sata_spd_max"))
.map(|x| x.trim().to_string())
.context("Could not read sata_spd_max");
Expand All @@ -151,6 +158,8 @@ impl LinkData<SataSpeed> {

impl LinkData<UsbSpeed> {
pub fn from_usb_slot(usb_slot: &UsbSlot) -> Result<Self> {
trace!("Reading USB link data for {usb_slot:?}…");

let usb_bus_path =
Path::new("/sys/bus/usb/devices/").join(format!("usb{}", usb_slot.usb_bus));

Expand Down

0 comments on commit e930cfa

Please sign in to comment.