#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub enum RcuGracePeriodConfiguration
{
Ordinary,
Expedited,
Normal,
}
impl RcuGracePeriodConfiguration
{
pub fn get(sys_path: &SysPath) -> io::Result<Self>
{
let rcu_expedited_file_path = Self::rcu_expedited_file_path(sys_path);
let rcu_normal_file_path = Self::rcu_normal_file_path(sys_path);
let expedited = rcu_expedited_file_path.read_zero_or_one_bool()?;
let normal = rcu_normal_file_path.read_zero_or_one_bool()?;
use self::RcuGracePeriodConfiguration::*;
match (expedited, normal)
{
(false, false) => Ok(Ordinary),
(true, false) => Ok(Expedited),
(false, true) => Ok(Normal),
_ => Err(io_error_other("expedited and normal should not both be true"))
}
}
pub fn set(self, sys_path: &SysPath) -> io::Result<()>
{
assert_effective_user_id_is_root("write to /sys/kernel/rcu_expedited and /sys/kernel/rcu_normal");
use self::RcuGracePeriodConfiguration::*;
let (expedited, normal) = match self
{
Ordinary => (false, false),
Expedited => (true, false),
Normal => (false, true),
};
let rcu_expedited_file_path = Self::rcu_expedited_file_path(sys_path);
let rcu_normal_file_path = Self::rcu_normal_file_path(sys_path);
if rcu_expedited_file_path.exists() && rcu_normal_file_path.exists()
{
rcu_expedited_file_path.write_value(expedited)?;
rcu_normal_file_path.write_value(normal)?;
}
Ok(())
}
#[inline(always)]
fn rcu_expedited_file_path(sys_path: &SysPath) -> PathBuf
{
sys_path.kernel_file_path("rcu_expedited")
}
#[inline(always)]
fn rcu_normal_file_path(sys_path: &SysPath) -> PathBuf
{
sys_path.kernel_file_path("rcu_normal")
}
}