diff --git a/exts/devmaster/src/lib/builtin/kmod.rs b/exts/devmaster/src/lib/builtin/kmod.rs index ac73d1bb5f4912046b1573eab7bb7b0b0debe7a1..cf718d41c2f8a07257afb44c64c3e5f2a3f08800 100644 --- a/exts/devmaster/src/lib/builtin/kmod.rs +++ b/exts/devmaster/src/lib/builtin/kmod.rs @@ -24,14 +24,14 @@ use std::rc::Rc; /// kmod builtin command pub(crate) struct Kmod { /// kmod struct - kernel_module: Rc>, + kernel_module: Option>>, } impl Kmod { /// create Kmod pub(crate) fn new() -> Kmod { Kmod { - kernel_module: Rc::new(RefCell::new(kmod_rs::LibKmod::new())), + kernel_module: kmod_rs::LibKmod::new().map(|inner| Rc::new(RefCell::new(inner))), } } } @@ -53,7 +53,8 @@ impl Builtin for Kmod { ) -> Result { let device = exec_unit.get_device(); - if self.kernel_module.borrow().is_ctx_null() { + if self.kernel_module.is_none() { + log::error!("Kmod context is not loaded."); return Ok(true); } @@ -72,6 +73,8 @@ impl Builtin for Kmod { if !modalias.is_empty() { if let Err(e) = self .kernel_module + .as_ref() + .unwrap() .borrow_mut() .module_load_and_warn(&modalias, false) { @@ -82,6 +85,8 @@ impl Builtin for Kmod { for i in 2..argc { if let Err(e) = self .kernel_module + .as_ref() + .unwrap() .borrow_mut() .module_load_and_warn(&argv[i as usize], false) { @@ -94,7 +99,13 @@ impl Builtin for Kmod { /// builtin init function fn init(&self) { - if let Err(e) = self.kernel_module.borrow_mut().load_resources() { + if let Err(e) = self + .kernel_module + .as_ref() + .unwrap() + .borrow_mut() + .load_resources() + { log::error!("Load resources failed! {}", e); } } @@ -105,6 +116,8 @@ impl Builtin for Kmod { /// check whether builtin command should reload fn should_reload(&self) -> bool { self.kernel_module + .as_ref() + .unwrap() .borrow_mut() .validate_resources() .map_or(false, |e| { diff --git a/exts/devmaster/src/lib/builtin/path_id.rs b/exts/devmaster/src/lib/builtin/path_id.rs index ecd730f8bf28e8e7a96d62ccaa52102a01138660..303b752888b7a1cd6012709bb14e6b74713a757c 100644 --- a/exts/devmaster/src/lib/builtin/path_id.rs +++ b/exts/devmaster/src/lib/builtin/path_id.rs @@ -390,7 +390,7 @@ impl PathId { Err(_) => return None, }; - let sas_address = match asadev.get_sysattr_value("asa_address") { + let sas_address = match asadev.get_sysattr_value("sas_address") { Ok(addr) => addr, Err(_) => return None, }; @@ -430,7 +430,7 @@ impl PathId { Err(_) => return None, }; - let target = match sessiondev.get_sysattr_value("asa_address") { + let target = match sessiondev.get_sysattr_value("sas_address") { Ok(port) => port, Err(_) => return None, }; diff --git a/libs/kmod_rs/src/lib.rs b/libs/kmod_rs/src/lib.rs index d0efabc5f72e876c285b6ae5b2e2d346f038090e..f95cd32a5fa668e7433000b7ccb6b438423a7884 100644 --- a/libs/kmod_rs/src/lib.rs +++ b/libs/kmod_rs/src/lib.rs @@ -73,21 +73,20 @@ impl Drop for LibKmod { } } -impl Default for LibKmod { - fn default() -> Self { - Self::new() - } -} - impl LibKmod { /// Create libkmod - pub fn new() -> LibKmod { + pub fn new() -> Option { let c = unsafe { kmod_sys::kmod_new(std::ptr::null(), std::ptr::null()) }; - LibKmod { + + if c.is_null() { + return None; + } + + Some(LibKmod { ctx: c, kmod_list_head: ptr::null::() as *mut kmod_sys::kmod_list, module: ptr::null::() as *mut kmod_sys::kmod_module, - } + }) } /// Create KmodListIter with internal members