diff --git a/core/coms/mount/src/comm.rs b/core/coms/mount/src/comm.rs index d0068d869f3b90ee6a17f67f0baba8a25aa7b6b2..be8a1bdd43a321a482367b434c793fcb79d4663a 100644 --- a/core/coms/mount/src/comm.rs +++ b/core/coms/mount/src/comm.rs @@ -15,6 +15,8 @@ //! * Get the attributes of the unit object //! * Call relation: mount_ unit->mount_ mng->mount_ comm +use crate::rentry::SectionMount; + use super::rentry::{MountRe, MountState}; use core::rel::Reliability; use core::unit::{UmIf, UnitBase}; @@ -60,6 +62,16 @@ impl MountUnitComm { self.owner().map_or_else(|| "None".to_string(), |u| u.id()) } + pub(super) fn rentry_conf_insert(&self, mount: &SectionMount) { + if let Some(u) = self.owner() { + self.rentry().conf_insert(&u.id(), mount) + } + } + + pub(super) fn rentry_conf_get(&self) -> Option { + self.owner().map(|u| self.rentry().conf_get(&u.id()))? + } + pub(super) fn rentry_mng_insert(&self, state: MountState) { self.rentry().mng_insert(&self.get_owner_id(), state) } diff --git a/core/coms/mount/src/config.rs b/core/coms/mount/src/config.rs index 074deaffed60261c7a3cd82312fb98470b9534da..15932c8978b181bac44badbaf1bf1fa3fdac82b4 100644 --- a/core/coms/mount/src/config.rs +++ b/core/coms/mount/src/config.rs @@ -10,9 +10,9 @@ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. // - -use core::error::Result; +#![allow(non_snake_case)] use core::unit::KillContext; +use core::{error::Result, rel::ReStation}; use std::{cell::RefCell, path::PathBuf, rc::Rc, str::FromStr}; use nix::sys::signal::Signal; @@ -21,11 +21,16 @@ use unit_parser::prelude::UnitConfig; use crate::{comm::MountUnitComm, rentry::SectionMount}; #[derive(UnitConfig, Default)] -#[allow(non_snake_case)] pub(super) struct MountConfigData { pub Mount: SectionMount, } +impl MountConfigData { + pub(self) fn new(Mount: SectionMount) -> MountConfigData { + MountConfigData { Mount } + } +} + #[allow(unused)] pub(super) struct MountConfig { // associated objects @@ -38,6 +43,26 @@ pub(super) struct MountConfig { mount_parameters_from_mountinfo: RefCell, } +impl ReStation for MountConfig { + // no input, no compensate + + // data + fn db_map(&self, reload: bool) { + if reload { + return; + } + if let Some(conf) = self.comm.rentry_conf_get() { + self.data.replace(MountConfigData::new(conf)); + } + } + + fn db_insert(&self) { + self.comm.rentry_conf_insert(&self.data.borrow().Mount); + } + + // reload: no external connections, no entry +} + #[derive(Clone)] pub(super) struct MountParameters { pub what: String, diff --git a/core/coms/mount/src/mng.rs b/core/coms/mount/src/mng.rs index 5d9842b13cb924c28b4c6ac10ca8b65bc2a2f5ea..de00ea5229dfbbcde9fab5835023211e9eaeca03 100644 --- a/core/coms/mount/src/mng.rs +++ b/core/coms/mount/src/mng.rs @@ -84,6 +84,16 @@ impl ReStation for MountMng { self.comm.rentry_mng_insert(self.state()); } + fn entry_coldplug(&self) { + // nothing to do. + } + + fn entry_clear(&self) { + if let Err(e) = self.disable_timer() { + log::error!("Failed to disable timer: {}", e); + } + } + // reload: no external connections, no entry } @@ -350,6 +360,12 @@ impl MountMng { Ok(0) } + pub(super) fn disable_timer(&self) -> Result { + let events = self.comm.um().events(); + events.del_source(self.timer())?; + Ok(0) + } + pub(super) fn dispatch_timer(&self) -> i32 { log::info!("Dispatch timeout event for {}", self.comm.get_owner_id()); match self.state() { @@ -755,6 +771,10 @@ impl Source for MountTimer { let data: u64 = unsafe { std::mem::transmute(self) }; data } + + fn description(&self) -> String { + String::from("MountTimer") + } } // #[cfg(test)] diff --git a/core/coms/mount/src/rentry.rs b/core/coms/mount/src/rentry.rs index d6142ef8f2c1317284c54d8849646a8517d2c856..db07447e787a1d318b799ea143967fc93e0db2f1 100644 --- a/core/coms/mount/src/rentry.rs +++ b/core/coms/mount/src/rentry.rs @@ -22,6 +22,7 @@ use std::{collections::HashMap, path::PathBuf, rc::Rc}; const RELI_DB_HMOUNT_MNG: &str = "mntmng"; const RELI_DB_HMOUNTM_FRAME: &str = "mntm-frame"; +const RELI_DB_HMOUNTM_CONFIG: &str = "mntconf"; const RELI_LAST_KEY: u32 = 0; // singleton //Mount contains two states: unmounted Dead and mounted Mounted. The corresponding unit status is inactive and active @@ -80,6 +81,19 @@ bitflags! { } } +#[derive(Clone, Debug, Serialize, Deserialize)] +struct MountReConf { + mount: SectionMount, +} + +impl MountReConf { + fn new(mount: &SectionMount) -> MountReConf { + MountReConf { + mount: mount.clone(), + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize)] struct MountReMng { state: MountState, @@ -99,6 +113,8 @@ pub(super) enum MountReFrame { struct MountReDb(ReDb); pub(super) struct MountRe { + conf: Rc>, // RELI_DB_ESERVICE_CONF; key: unit_id, data: config; + // database: multi-instance(N) mng: Rc>, // RELI_DB_HMOUNT_MNG; key: unit_id, data: state; @@ -110,11 +126,22 @@ impl MountRe { pub(super) fn new(relir: &Rc) -> MountRe { let mng = Rc::new(MountReDb(ReDb::new(relir, RELI_DB_HMOUNT_MNG))); let frame = Rc::new(MountReDb(ReDb::new(relir, RELI_DB_HMOUNTM_FRAME))); - let rentry = MountRe { mng, frame }; + let conf = Rc::new(MountReDb(ReDb::new(relir, RELI_DB_HMOUNTM_CONFIG))); + let rentry = MountRe { conf, mng, frame }; rentry.register(relir); rentry } + pub(super) fn conf_insert(&self, unit_id: &str, service: &SectionMount) { + let conf = MountReConf::new(service); + self.conf.0.insert(unit_id.to_string(), conf); + } + + pub(super) fn conf_get(&self, unit_id: &str) -> Option { + let conf = self.conf.0.get(&unit_id.to_string()); + conf.map(|c| c.mount) + } + pub(super) fn mng_insert(&self, unit_id: &str, state: MountState) { let mng = MountReMng::new(state); self.mng.0.insert(unit_id.to_string(), mng); @@ -192,7 +219,7 @@ impl ReDbTable for MountReDb { } } -#[derive(UnitSection, Default)] +#[derive(UnitSection, Default, Clone, Serialize, Deserialize, Debug)] #[allow(non_snake_case)] pub struct SectionMount { #[entry(default = String::new())] diff --git a/core/coms/mount/src/unit.rs b/core/coms/mount/src/unit.rs index 96ca094263ddfb89b7a79424f8ec7c49f9efe9aa..86b1fc55c06f8bfbdb1cb4ce43b6cd2f944ce89b 100644 --- a/core/coms/mount/src/unit.rs +++ b/core/coms/mount/src/unit.rs @@ -29,8 +29,8 @@ use std::rc::Rc; struct MountUnit { comm: Rc, - mng: Rc, config: Rc, + mng: Rc, exec_ctx: Rc, } @@ -39,22 +39,25 @@ impl ReStation for MountUnit { // data fn db_map(&self, reload: bool) { + self.config.db_map(reload); + if !reload { + self.parse().unwrap(); + } self.mng.db_map(reload); } fn db_insert(&self) { + self.config.db_insert(); self.mng.db_insert(); } // reload: no external connections, entry-only fn entry_coldplug(&self) { - // rebuild external connections, like: timer, ... - // do nothing now + self.mng.entry_coldplug(); } fn entry_clear(&self) { - // release external connection, like: timer, ... - // do nothing now + self.mng.entry_clear(); } } diff --git a/core/sysmaster/src/job/entry.rs b/core/sysmaster/src/job/entry.rs index c62878fd20f46881454d79d874503d6b5b284de6..164486c82e8ebdf5b74833a11c4464354a8c7121 100644 --- a/core/sysmaster/src/job/entry.rs +++ b/core/sysmaster/src/job/entry.rs @@ -149,6 +149,10 @@ impl Source for JobTimer { fn priority(&self) -> i8 { 0i8 } + + fn description(&self) -> String { + String::from("JobTimer") + } } #[derive(Clone)] diff --git a/core/sysmaster/src/manager/alive_timer.rs b/core/sysmaster/src/manager/alive_timer.rs index a325483afc62cc2151e0f52997d5acd3b45c03f5..35d24e6c88f943437edf0cdaf679c429923cb445 100644 --- a/core/sysmaster/src/manager/alive_timer.rs +++ b/core/sysmaster/src/manager/alive_timer.rs @@ -129,4 +129,8 @@ impl Source for AliveTimerData { let data: u64 = unsafe { std::mem::transmute(self) }; data } + + fn description(&self) -> String { + String::from("AliveTimer") + } } diff --git a/libs/event/src/events.rs b/libs/event/src/events.rs index 613a010a021c943646b8c407c941a60806ffc41e..1ef6afe00c3eef469629af845ae5529201c79896 100644 --- a/libs/event/src/events.rs +++ b/libs/event/src/events.rs @@ -515,16 +515,19 @@ impl EventsData { EventType::TimerRealtimeAlarm, EventType::TimerBoottimeAlarm, ] { - if let Some(next) = self.timer.next(&et) { - if self.timer.timerid(&et) >= next { - if !self.flush_timer(&et) { - return false; - } + let next = match self.timer.next(&et) { + None => continue, + Some(v) => v, + }; + if self.timer.timerid(&et) < next { + continue; + } + if !self.flush_timer(&et) { + return false; + } - while let Some(source) = self.timer.pop(&et) { - self.pending_push(source, 0); - } - } + while let Some(source) = self.timer.pop(&et) { + self.pending_push(source, 0); } } @@ -542,23 +545,26 @@ impl EventsData { EventType::TimerBoottimeAlarm, ] { self.timer.now(); - if let Some(next) = self.timer.next(&et) { - if self.timer.timerid(&et) >= next { - while let Some(source) = self.timer.pop(&et) { - self.pending_push(source, 0); - } - ret = true; - } else { - let new_value = self.timer.timer_stored(next); - let mut old_value = MaybeUninit::::zeroed(); - unsafe { - libc::timerfd_settime( - self.timerfd.get(&et).unwrap().as_raw_fd(), - libc::TFD_TIMER_ABSTIME, - &new_value, - old_value.as_mut_ptr(), - ); - } + let next = match self.timer.next(&et) { + None => continue, + Some(v) => v, + }; + + if self.timer.timerid(&et) >= next { + while let Some(source) = self.timer.pop(&et) { + self.pending_push(source, 0); + } + ret = true; + } else { + let new_value = self.timer.timer_stored(next); + let mut old_value = MaybeUninit::::zeroed(); + unsafe { + libc::timerfd_settime( + self.timerfd.get(&et).unwrap().as_raw_fd(), + libc::TFD_TIMER_ABSTIME, + &new_value, + old_value.as_mut_ptr(), + ); } } } diff --git a/libs/event/src/source.rs b/libs/event/src/source.rs index ed06ea90f59e854a2bec205ca12e1ef4655ccb71..b9d36a58888863ede8812a8ceadff7bb558a9a20 100644 --- a/libs/event/src/source.rs +++ b/libs/event/src/source.rs @@ -72,6 +72,11 @@ pub trait Source { /// The code of callback fn dispatch(&self, event: &Events) -> i32; + + /// The short description of this source + fn description(&self) -> String { + String::from("default") + } } // for HashSet diff --git a/libs/event/src/timer.rs b/libs/event/src/timer.rs index c5f020c22b517d4a90d98cd98bf25b4733f5ca59..bd2e4490e3dfad4320ef8c3d913ee0974a55870c 100644 --- a/libs/event/src/timer.rs +++ b/libs/event/src/timer.rs @@ -11,7 +11,6 @@ // See the Mulan PSL v2 for more details. use std::{ - cmp::Ordering, collections::{BinaryHeap, HashMap}, mem, rc::Rc, @@ -212,7 +211,7 @@ impl TimerInner { // let v = self.data.; let mut tmp = BinaryHeap::::new(); for clock_data in self.data.iter() { - if clock_data.source().cmp(&source) != Ordering::Equal { + if !clock_data.source().eq(&source) { tmp.push(clock_data.clone()); } }