forked from ChrisMacNaughton/bynar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1761eaf
commit 5772575
Showing
3 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,96 @@ | ||
extern crate serde_json; | ||
|
||
use std::io::Result; | ||
use std::process::Command; | ||
|
||
|
||
|
||
/// Retrieve the error logs from the nvme device | ||
pub fn get_error_log(dev: &Path) -> Result<String>{ | ||
let out = Command::new("nvme").args(&["error-log", &dev.to_string_lossy(), "-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
} | ||
|
||
/// Retrieve the firmware logs from the nvme device | ||
pub fn get_firmware_log(dev: &Path) -> Result<String>{ | ||
let out = Command::new("nvme").args(&["fw-log", &dev.to_string_lossy(), "-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
} | ||
|
||
/// Retrieve the smart logs from the nvme device | ||
pub fn get_smart_log(dev: &Path) -> Result<String>{ | ||
let out = Command::new("nvme").args(&["smart-log", &dev.to_string_lossy(), "-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
} | ||
|
||
// Format an nvme block device | ||
pub fn format(dev: &Path) -> Result<()>{ | ||
let out = Command::new("nvme").args(&["format", &dev.to_string_lossy()]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn list_nvme_namespaces(dev: &Path) -> Result<Vec<String>>{ | ||
let out = Command::new("nvme").args(&["list-ns", &device.to_string_lossy(), "-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
|
||
} | ||
|
||
/// List the nvme controllers on the host | ||
pub fn list_nvme_controllers() -> Result<Vec<String>>{ | ||
let out = Command::new("nvme-list").args(&["-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
} | ||
|
||
/// List the nvme devices on the host | ||
pub fn list_nvme_devices()->Result<Vec<String>>{ | ||
let out = Command::new("nvme-list").args(&["-o", "json"]).output() | ||
if !out.status.success() { | ||
return Err(::std::io::Error::new( | ||
::std::io::ErrorKind::NotFound, | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)); | ||
} | ||
let deserialized: Vec<String> = serde_json::from_str(&s)?; | ||
Ok(deserialized) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters