#[derive(Default, Debug, Clone, Eq, PartialEq)]
#[derive(Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct GlobalLinuxModuleConfiguration
{
pub modprobe_executable_path: Option<PathBuf>,
pub linux_kernel_modules_to_unload: IndexSet<LinuxKernelModuleName>,
pub linux_kernel_modules_to_load: IndexSet<LinuxKernelModuleName>,
pub linux_kernel_module_parameters: GlobalLinuxModuleParametersConfiguration,
pub disable_module_loading_and_unloading_until_reboot: bool,
}
impl GlobalLinuxModuleConfiguration
{
#[inline(always)]
pub fn configure(&self, sys_path: &SysPath, proc_path: &ProcPath) -> Result<(), GlobalLinuxModuleConfigurationError>
{
use self::GlobalLinuxModuleConfigurationError::*;
set_value(proc_path, LinuxKernelModuleName::set_modprobe_executable_path, self.modprobe_executable_path.as_ref(), CouldNotChangeModprobeExecutablePath)?;
let potentially_have_modules_to_unload = !self.linux_kernel_modules_to_unload.is_empty();
let potentially_have_modules_to_load = !self.linux_kernel_modules_to_load.is_empty();
if potentially_have_modules_to_unload || potentially_have_modules_to_load
{
if !self.linux_kernel_modules_to_unload.is_disjoint(&self.linux_kernel_modules_to_load)
{
return Err(ReloadingLinuxKernelModulesIsUnsupported)
}
let loaded_modules = LinuxKernelModulesList::parse(proc_path)?;
if LinuxKernelModuleName::is_module_loading_and_unloading_disabled(proc_path)
{
if loaded_modules.contains_any_of(self.linux_kernel_modules_to_unload.iter())
{
return Err(CouldNotUnloadLinuxKernelModuleBecauseModuleUnloadingIsDisabled)
}
if loaded_modules.does_not_contain_all_of(self.linux_kernel_modules_to_load.iter())
{
return Err(CouldNotLoadLinuxKernelModuleBecauseModuleLoadingIsDisabled)
}
}
else
{
for linux_kernel_module_to_unload in self.linux_kernel_modules_to_unload.iter()
{
let _unloaded = linux_kernel_module_to_unload.unload_linux_kernel_module().map_err(|cause| CouldNotUnloadLinuxKernelModule(cause))?;
}
if let Some(modprobe_path) = LinuxKernelModuleName::modprobe_executable_path(proc_path)
{
for linux_kernel_module_to_load in self.linux_kernel_modules_to_load.iter()
{
linux_kernel_module_to_load.load_linux_kernel_module_using_modprobe(&modprobe_path)?
}
}
}
}
self.linux_kernel_module_parameters.configure(sys_path)?;
set_value_once(proc_path, LinuxKernelModuleName::disable_module_loading_and_unloading_until_reboot, self.disable_module_loading_and_unloading_until_reboot, CouldNotDisableModuleLoadingAndUnloadingUntilNextReboot)
}
}