From 526c91c3b8a373c8a8c04c76f078d1018e3cf5a1 Mon Sep 17 00:00:00 2001 From: Vandana Varakantham Date: Mon, 25 Sep 2023 09:52:01 +0000 Subject: [PATCH 1/2] feat(eventing): rebuild events Signed-off-by: Vandana Varakantham --- io-engine/src/eventing/mod.rs | 1 + io-engine/src/eventing/replica_events.rs | 29 ++++++++++++++++++++++++ io-engine/src/grpc/v1/replica.rs | 4 ++++ io-engine/src/lvs/lvs_lvol.rs | 5 +++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 io-engine/src/eventing/replica_events.rs diff --git a/io-engine/src/eventing/mod.rs b/io-engine/src/eventing/mod.rs index 4ddf7f818..4e73225f8 100644 --- a/io-engine/src/eventing/mod.rs +++ b/io-engine/src/eventing/mod.rs @@ -1,5 +1,6 @@ pub(crate) mod nexus_events; mod pool_events; +mod replica_events; use events_api::event::{EventAction, EventMessage, EventMeta}; /// Event trait definition for creating events. diff --git a/io-engine/src/eventing/replica_events.rs b/io-engine/src/eventing/replica_events.rs new file mode 100644 index 000000000..583baa12c --- /dev/null +++ b/io-engine/src/eventing/replica_events.rs @@ -0,0 +1,29 @@ +use events_api::event::{ + EventAction, + EventCategory, + EventMessage, + EventMeta, + EventSource, +}; + +use crate::{ + core::{logical_volume::LogicalVolume, MayastorEnvironment}, + eventing::Event, + lvs::Lvol, +}; + +// Pool event messages from Lvs data. +impl Event for Lvol { + fn event(&self, event_action: EventAction) -> EventMessage { + let event_source = EventSource::new( + MayastorEnvironment::global_or_default().node_name, + ) + .add_replica_data(&self.pool_name()); + EventMessage { + category: EventCategory::Replica as i32, + action: event_action as i32, + target: self.name(), + metadata: Some(EventMeta::from_source(event_source)), + } + } +} diff --git a/io-engine/src/grpc/v1/replica.rs b/io-engine/src/grpc/v1/replica.rs index 82b937558..a542a1f74 100644 --- a/io-engine/src/grpc/v1/replica.rs +++ b/io-engine/src/grpc/v1/replica.rs @@ -11,10 +11,12 @@ use crate::{ UntypedBdev, UpdateProps, }, + eventing::Event, grpc::{rpc_submit, GrpcClientContext, GrpcResult, Serializer}, lvs::{Error as LvsError, Lvol, LvolSpaceUsage, Lvs, LvsLvol}, }; use ::function_name::named; +use events_api::event::EventAction; use futures::FutureExt; use mayastor_api::v1::replica::*; use nix::errno::Errno; @@ -207,6 +209,7 @@ impl ReplicaRpc for ReplicaService { match Pin::new(&mut lvol).share_nvmf(Some(props)).await { Ok(s) => { debug!("created and shared {:?} as {}", lvol, s); + lvol.event(EventAction::Create).generate(); Ok(Replica::from(lvol)) } Err(e) => { @@ -222,6 +225,7 @@ impl ReplicaRpc for ReplicaService { } Ok(lvol) => { debug!("created lvol {:?}", lvol); + lvol.event(EventAction::Create).generate(); Ok(Replica::from(lvol)) } Err(e) => Err(e), diff --git a/io-engine/src/lvs/lvs_lvol.rs b/io-engine/src/lvs/lvs_lvol.rs index 60ce65c53..8c42bb968 100644 --- a/io-engine/src/lvs/lvs_lvol.rs +++ b/io-engine/src/lvs/lvs_lvol.rs @@ -1,6 +1,7 @@ use async_trait::async_trait; use byte_unit::Byte; use chrono::Utc; +use events_api::event::EventAction; use futures::channel::oneshot; use nix::errno::Errno; use pin_utils::core_reexport::fmt::Formatter; @@ -52,6 +53,7 @@ use crate::{ UntypedBdev, UpdateProps, }, + eventing::Event, ffihelper::{ cb_arg, done_cb, @@ -1007,7 +1009,8 @@ impl LvsLvol for Lvol { async fn destroy_replica(mut self) -> Result { let snapshot_lvol = self.is_snapshot_clone(); let name = self.name(); - self.destroy().await?; + self.clone().destroy().await?; + self.event(EventAction::Delete).generate(); // If destroy replica is a snapshot clone and it is the last // clone from the snapshot, destroy the snapshot From 838e8ef2c1717fe71adee9f670f10c419a374457 Mon Sep 17 00:00:00 2001 From: Vandana Varakantham Date: Mon, 25 Sep 2023 09:53:08 +0000 Subject: [PATCH 2/2] feat(eventing): replica events Signed-off-by: Vandana Varakantham --- io-engine/src/eventing/nexus_events.rs | 2 +- io-engine/src/eventing/replica_events.rs | 13 +++++++++---- io-engine/src/grpc/v1/replica.rs | 4 ---- io-engine/src/lvs/lvs_lvol.rs | 5 +++-- io-engine/src/lvs/lvs_store.rs | 1 + utils/io-engine-dependencies | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/io-engine/src/eventing/nexus_events.rs b/io-engine/src/eventing/nexus_events.rs index 1cf09ced2..0e2e992c6 100644 --- a/io-engine/src/eventing/nexus_events.rs +++ b/io-engine/src/eventing/nexus_events.rs @@ -29,7 +29,7 @@ impl EventMetaGen for RebuildJob { let event_source = EventSource::new( MayastorEnvironment::global_or_default().node_name, ) - .add_rebuild_data( + .with_rebuild_data( rebuild_status, self.src_uri(), self.dst_uri(), diff --git a/io-engine/src/eventing/replica_events.rs b/io-engine/src/eventing/replica_events.rs index 583baa12c..4d842bb52 100644 --- a/io-engine/src/eventing/replica_events.rs +++ b/io-engine/src/eventing/replica_events.rs @@ -9,20 +9,25 @@ use events_api::event::{ use crate::{ core::{logical_volume::LogicalVolume, MayastorEnvironment}, eventing::Event, - lvs::Lvol, + lvs::lvs_lvol::{Lvol, LvsLvol}, }; -// Pool event messages from Lvs data. +// Replica event messages from Lvol data. impl Event for Lvol { fn event(&self, event_action: EventAction) -> EventMessage { let event_source = EventSource::new( MayastorEnvironment::global_or_default().node_name, ) - .add_replica_data(&self.pool_name()); + .with_replica_data( + self.lvs().name(), + &self.lvs().uuid(), + &self.name(), + ); + EventMessage { category: EventCategory::Replica as i32, action: event_action as i32, - target: self.name(), + target: self.uuid(), metadata: Some(EventMeta::from_source(event_source)), } } diff --git a/io-engine/src/grpc/v1/replica.rs b/io-engine/src/grpc/v1/replica.rs index a542a1f74..82b937558 100644 --- a/io-engine/src/grpc/v1/replica.rs +++ b/io-engine/src/grpc/v1/replica.rs @@ -11,12 +11,10 @@ use crate::{ UntypedBdev, UpdateProps, }, - eventing::Event, grpc::{rpc_submit, GrpcClientContext, GrpcResult, Serializer}, lvs::{Error as LvsError, Lvol, LvolSpaceUsage, Lvs, LvsLvol}, }; use ::function_name::named; -use events_api::event::EventAction; use futures::FutureExt; use mayastor_api::v1::replica::*; use nix::errno::Errno; @@ -209,7 +207,6 @@ impl ReplicaRpc for ReplicaService { match Pin::new(&mut lvol).share_nvmf(Some(props)).await { Ok(s) => { debug!("created and shared {:?} as {}", lvol, s); - lvol.event(EventAction::Create).generate(); Ok(Replica::from(lvol)) } Err(e) => { @@ -225,7 +222,6 @@ impl ReplicaRpc for ReplicaService { } Ok(lvol) => { debug!("created lvol {:?}", lvol); - lvol.event(EventAction::Create).generate(); Ok(Replica::from(lvol)) } Err(e) => Err(e), diff --git a/io-engine/src/lvs/lvs_lvol.rs b/io-engine/src/lvs/lvs_lvol.rs index 8c42bb968..900322061 100644 --- a/io-engine/src/lvs/lvs_lvol.rs +++ b/io-engine/src/lvs/lvs_lvol.rs @@ -824,6 +824,7 @@ impl LvsLvol for Lvol { } /// Destroy the lvol. async fn destroy(mut self) -> Result { + let event = self.event(EventAction::Delete); extern "C" fn destroy_cb(sender: *mut c_void, errno: i32) { let sender = unsafe { Box::from_raw(sender as *mut oneshot::Sender) }; @@ -860,6 +861,7 @@ impl LvsLvol for Lvol { } info!("destroyed lvol {}", name); + event.generate(); Ok(name) } @@ -1009,8 +1011,7 @@ impl LvsLvol for Lvol { async fn destroy_replica(mut self) -> Result { let snapshot_lvol = self.is_snapshot_clone(); let name = self.name(); - self.clone().destroy().await?; - self.event(EventAction::Delete).generate(); + self.destroy().await?; // If destroy replica is a snapshot clone and it is the last // clone from the snapshot, destroy the snapshot diff --git a/io-engine/src/lvs/lvs_store.rs b/io-engine/src/lvs/lvs_store.rs index 5a3d4bb10..a0fd3e88a 100644 --- a/io-engine/src/lvs/lvs_store.rs +++ b/io-engine/src/lvs/lvs_store.rs @@ -877,6 +877,7 @@ impl Lvs { } info!("{:?}: created", lvol); + lvol.event(EventAction::Create).generate(); Ok(lvol) } diff --git a/utils/io-engine-dependencies b/utils/io-engine-dependencies index 517096238..236918d70 160000 --- a/utils/io-engine-dependencies +++ b/utils/io-engine-dependencies @@ -1 +1 @@ -Subproject commit 51709623872153e13851f2628bed6e5e4b77b7c1 +Subproject commit 236918d70b137cc0f434af031ae9358c0a54c21e