diff --git a/io-engine/src/eventing/host_events.rs b/io-engine/src/eventing/host_events.rs index e0b548b78d..fb7603ddd4 100644 --- a/io-engine/src/eventing/host_events.rs +++ b/io-engine/src/eventing/host_events.rs @@ -7,18 +7,49 @@ use events_api::event::{ }; use crate::{ - core::MayastorEnvironment, + bdev::Nexus, + core::{LogicalVolume, MayastorEnvironment}, eventing::{EventMetaGen, EventWithMeta}, + lvs::Lvol, subsys::NvmfSubsystem, }; use spdk_rs::NvmfController; +/// A trait definition to include target details in host events meta data +pub(crate) trait HostTargetMeta { + /// Add target detaails to host event meta + fn host_target_meta(&self, meta: EventMeta) -> EventMeta; +} + +impl<'n> HostTargetMeta for Nexus<'n> { + fn host_target_meta(&self, mut meta: EventMeta) -> EventMeta { + if let Some(source) = meta.source { + let event_source = + source.with_host_target_data("nexus", &self.uuid().to_string()); + meta.source = Some(event_source); + } + meta + } +} + +impl HostTargetMeta for Lvol { + fn host_target_meta(&self, mut meta: EventMeta) -> EventMeta { + if let Some(source) = meta.source { + let event_source = + source.with_host_target_data("replica", &self.uuid()); + meta.source = Some(event_source); + } + meta + } +} + impl EventMetaGen for NvmfSubsystem { fn meta(&self) -> EventMeta { + let nqn = self.get_nqn(); let event_source = EventSource::new( MayastorEnvironment::global_or_default().node_name, ) - .with_subsystem_data(&self.get_nqn()); + .with_subsystem_data(&nqn); EventMeta::from_source(event_source) } diff --git a/io-engine/src/eventing/mod.rs b/io-engine/src/eventing/mod.rs index 3c823a5dca..de8cd5ab28 100644 --- a/io-engine/src/eventing/mod.rs +++ b/io-engine/src/eventing/mod.rs @@ -1,4 +1,4 @@ -mod host_events; +pub(crate) mod host_events; mod nexus_child_events; pub(crate) mod nexus_events; mod pool_events; diff --git a/io-engine/src/subsys/nvmf/subsystem.rs b/io-engine/src/subsys/nvmf/subsystem.rs index e716dfd4c9..e913580b20 100644 --- a/io-engine/src/subsys/nvmf/subsystem.rs +++ b/io-engine/src/subsys/nvmf/subsystem.rs @@ -64,7 +64,7 @@ use crate::{ bdev::{nexus::NEXUS_MODULE_NAME, nvmx::NVME_CONTROLLERS, Nexus}, constants::{NVME_CONTROLLER_MODEL_ID, NVME_NQN_PREFIX}, core::{Bdev, Reactors, UntypedBdev}, - eventing::{EventMetaGen, EventWithMeta}, + eventing::{host_events::HostTargetMeta, EventMetaGen, EventWithMeta}, ffihelper::{cb_arg, done_cb, AsStr, FfiResult, IntoCString}, lvs::Lvol, subsys::{ @@ -73,7 +73,6 @@ use crate::{ Config, }, }; - use events_api::event::EventAction; /// TODO @@ -256,9 +255,15 @@ impl NvmfSubsystem { ); } + let event_meta = match nqn_tgt { + NqnTarget::Nexus(n) => n.host_target_meta(s.meta()), + NqnTarget::Replica(ref r) => r.host_target_meta(s.meta()), + NqnTarget::None => s.meta(), + }; + match event { NvmfSubsystemEvent::HostConnect(c) => { - c.event(EventAction::NvmeConnect, s.meta()).generate(); + c.event(EventAction::NvmeConnect, event_meta).generate(); match nqn_tgt { NqnTarget::Nexus(n) => s.host_connect_nexus(c, n), @@ -267,7 +272,7 @@ impl NvmfSubsystem { } } NvmfSubsystemEvent::HostDisconnect(c) => { - c.event(EventAction::NvmeDisconnect, s.meta()).generate(); + c.event(EventAction::NvmeDisconnect, event_meta).generate(); match nqn_tgt { NqnTarget::Nexus(n) => s.host_disconnect_nexus(c, n), @@ -276,7 +281,7 @@ impl NvmfSubsystem { } } NvmfSubsystemEvent::HostKeepAliveTimeout(c) => { - c.event(EventAction::NvmeKeepAliveTimeout, s.meta()) + c.event(EventAction::NvmeKeepAliveTimeout, event_meta) .generate(); match nqn_tgt {