sysfs_class/
scsi_host.rs

1use crate::SysClass;
2use std::io::{self, Result};
3use std::path::{Path, PathBuf};
4
5/// Fetch and modify SCSI host parameters.
6#[derive(Clone)]
7pub struct ScsiHost {
8    path: PathBuf,
9}
10
11impl SysClass for ScsiHost {
12    fn class() -> &'static str {
13        "scsi_host"
14    }
15
16    unsafe fn from_path_unchecked(path: PathBuf) -> Self {
17        Self { path }
18    }
19
20    fn path(&self) -> &Path {
21        &self.path
22    }
23}
24
25impl ScsiHost {
26    method!(active_mod trim_file String);
27
28    method!(can_queue parse_file i32);
29
30    method!(host_busy parse_file u8);
31
32    method!(link_power_management_policy trim_file String);
33
34    /// Sets the power management profile for this SCSI host.
35    ///
36    /// Multiple profiles are given, and each profile is tried until one succeeds.
37    pub fn set_link_power_management_policy<'b>(
38        &self,
39        profiles: &[&'b str],
40    ) -> io::Result<&'b str> {
41        debug_assert!(
42            !profiles.is_empty(),
43            "at least one profile must be specified"
44        );
45
46        let mut last_result = Ok(());
47        let mut last_prof = "";
48
49        for prof in profiles {
50            last_result = self.write_file("link_power_management_policy", prof);
51            last_prof = prof;
52            if last_result.is_ok() {
53                break;
54            }
55        }
56
57        last_result.map(|_| last_prof)
58    }
59
60    method!(proc_name trim_file String);
61
62    method!(sg_tablesize parse_file i32);
63
64    method!(state trim_file String);
65
66    method!(supported_mode parse_file u8);
67
68    method!(use_blk_mq parse_file u8);
69}