Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
bc090fa9b2 | |||
86cf230f21 | |||
fefcbe4373 | |||
f7c9605f26 | |||
f4374459dd | |||
89be5b3542 | |||
8209da3b21 |
2 changed files with 13 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "phenix"
|
||||
description = "Utility to restart PCIe devices when link is lost."
|
||||
version = "0.1.4"
|
||||
version = "0.2.1"
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository="https://code.edgarpierre.fr/edpibu/phenix"
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -1,13 +1,20 @@
|
|||
#![feature(file_buffered)]
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::io::Write;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
|
||||
fn main() {
|
||||
println!("Reading kernel messages...");
|
||||
|
||||
let kmsg_file = File::open_buffered("/dev/kmsg").expect("Failed to open /dev/kmsg");
|
||||
let mut kmsg_file =
|
||||
File::open_buffered(env::var("PHENIX_KMSG").unwrap_or(String::from("/dev/kmsg")))
|
||||
.expect("Failed to open /dev/kmsg");
|
||||
|
||||
|
||||
kmsg_file.seek(SeekFrom::End(0)).expect("Failed to seek to end");
|
||||
let lines = kmsg_file.lines();
|
||||
for line in lines {
|
||||
match line {
|
||||
|
@ -23,8 +30,9 @@ fn manage_line(line: String) {
|
|||
println!("PCIe link lost {prefix}");
|
||||
|
||||
let id = line.splitn(3, " ").nth(1);
|
||||
if let Some(id) = id {
|
||||
reset_device(id);
|
||||
match id {
|
||||
Some(id) => reset_device(id),
|
||||
None => println!("No device id found in message {line}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +41,7 @@ fn manage_line(line: String) {
|
|||
fn reset_device(id: &str) {
|
||||
println!("Resetting {id}");
|
||||
echo1(rm_file_path(&id));
|
||||
println!("Removed device {id}");
|
||||
echo1(String::from("/sys/bus/pci/rescan"));
|
||||
println!("Rescanned PCI bus");
|
||||
}
|
||||
|
@ -44,7 +53,6 @@ fn echo1(path: String) {
|
|||
Ok(mut file) => {
|
||||
file.write_all(b"1")
|
||||
.expect("Failed to write to remove file");
|
||||
println!("Removed device {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue