Skip to content

Commit ef402d3

Browse files
mayastor-borsdatacore-vvarakantham
mayastor-bors
andcommitted
Merge #1580
1580: feat(eventing): snapshot and clone events r=datacore-vvarakantham a=datacore-vvarakantham Added snapshot and clone create events. Co-authored-by: Vandana Varakantham <vandana.varakantham@datacore.com>
2 parents 271e01b + 17bf8db commit ef402d3

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use events_api::event::{
2+
EventAction,
3+
EventCategory,
4+
EventMessage,
5+
EventMeta,
6+
EventSource,
7+
};
8+
9+
use crate::{
10+
core::{snapshot::CloneParams, MayastorEnvironment},
11+
eventing::Event,
12+
};
13+
14+
impl Event for CloneParams {
15+
fn event(&self, event_action: EventAction) -> EventMessage {
16+
let event_source = EventSource::new(
17+
MayastorEnvironment::global_or_default().node_name,
18+
)
19+
.with_clone_data(
20+
self.source_uuid().unwrap_or_default(),
21+
self.clone_create_time().unwrap_or_default(),
22+
);
23+
24+
EventMessage {
25+
category: EventCategory::Clone as i32,
26+
action: event_action as i32,
27+
target: self.clone_uuid().unwrap_or_default(),
28+
metadata: Some(EventMeta::from_source(event_source)),
29+
}
30+
}
31+
}

io-engine/src/eventing/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
mod clone_events;
12
pub(crate) mod host_events;
23
pub(crate) mod io_engine_events;
34
mod nexus_child_events;
45
pub(crate) mod nexus_events;
56
mod pool_events;
67
pub(crate) mod replica_events;
8+
mod snapshot_events;
79
use events_api::event::{EventAction, EventMessage, EventMeta};
810

911
/// Event trait definition for creating events.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use events_api::event::{
2+
EventAction,
3+
EventCategory,
4+
EventMessage,
5+
EventMeta,
6+
EventSource,
7+
};
8+
9+
use crate::{
10+
core::{MayastorEnvironment, SnapshotDescriptor, SnapshotParams},
11+
eventing::Event,
12+
};
13+
14+
impl Event for SnapshotParams {
15+
fn event(&self, event_action: EventAction) -> EventMessage {
16+
let event_source = EventSource::new(
17+
MayastorEnvironment::global_or_default().node_name,
18+
)
19+
.with_snapshot_data(
20+
self.parent_id().unwrap_or_default(),
21+
self.create_time().unwrap_or_default(),
22+
self.entity_id().unwrap_or_default(),
23+
);
24+
25+
EventMessage {
26+
category: EventCategory::Snapshot as i32,
27+
action: event_action as i32,
28+
target: self.snapshot_uuid().unwrap_or_default(),
29+
metadata: Some(EventMeta::from_source(event_source)),
30+
}
31+
}
32+
}

io-engine/src/lvs/lvol_snapshot.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use crate::{
99
SnapshotXattrs,
1010
UntypedBdev,
1111
},
12+
eventing::Event,
1213
ffihelper::{cb_arg, IntoCString},
1314
lvs::{lvs_lvol::LvsLvol, Lvol},
1415
subsys::NvmfReq,
1516
};
1617
use async_trait::async_trait;
1718
use chrono::Utc;
19+
use events_api::event::EventAction;
1820
use futures::channel::oneshot;
1921
use nix::errno::Errno;
2022
use spdk_rs::libspdk::{
@@ -252,7 +254,10 @@ impl SnapshotOps for Lvol {
252254
let (error, lvol_ptr) =
253255
receiver.await.expect("Snapshot done callback disappeared");
254256
match error {
255-
0 => Ok(Lvol::from_inner_ptr(lvol_ptr)),
257+
0 => {
258+
snap_param.event(EventAction::Create).generate();
259+
Ok(Lvol::from_inner_ptr(lvol_ptr))
260+
}
256261
_ => Err(Error::SnapshotCreate {
257262
source: Errno::from_i32(error),
258263
msg: snap_param.name().unwrap(),
@@ -268,6 +273,7 @@ impl SnapshotOps for Lvol {
268273
unsafe {
269274
self.create_snapshot_inner(&snap_param, done_cb, done_cb_arg)?;
270275
}
276+
snap_param.event(EventAction::Create).generate();
271277
Ok(())
272278
}
273279

@@ -406,7 +412,10 @@ impl SnapshotOps for Lvol {
406412
.await
407413
.expect("Snapshot Clone done callback disappeared");
408414
match error {
409-
0 => Ok(Lvol::from_inner_ptr(lvol_ptr)),
415+
0 => {
416+
clone_param.event(EventAction::Create).generate();
417+
Ok(Lvol::from_inner_ptr(lvol_ptr))
418+
}
410419
_ => Err(Error::SnapshotCloneCreate {
411420
source: Errno::from_i32(error),
412421
msg: clone_param.clone_name().unwrap_or_default(),
@@ -573,6 +582,7 @@ impl SnapshotOps for Lvol {
573582
)
574583
.await?;
575584
}
585+
576586
Ok(())
577587
}
578588

0 commit comments

Comments
 (0)