From 7e1c8c9f72be1629a4e28fb5de122f95daed6f2d Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Fri, 5 Jun 2015 16:22:46 +0100 Subject: [PATCH] mon/mon_types.h: add C_MonOp abstract class To be used by monitor contexts relying on MonOpRequest, so that we can easily track the lifespan of an event. Signed-off-by: Joao Eduardo Luis --- src/mon/mon_types.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/mon/mon_types.h b/src/mon/mon_types.h index 4fa97d3a80bc..a720075dae78 100644 --- a/src/mon/mon_types.h +++ b/src/mon/mon_types.h @@ -18,6 +18,8 @@ #include "include/utime.h" #include "include/util.h" #include "common/Formatter.h" +#include "include/Context.h" +#include "mon/MonOpRequest.h" #define PAXOS_PGMAP 0 // before osd, for pg kick to behave #define PAXOS_MDSMAP 1 @@ -206,4 +208,30 @@ static inline ostream& operator<<(ostream& out, const ScrubResult& r) { /// for information like os, kernel, hostname, memory info, cpu model. typedef map Metadata; +struct C_MonOp : public Context +{ + MonOpRequestRef op; + + C_MonOp(MonOpRequestRef o) : + op(o) { } + + void finish(int r) { + if (op && r == -ECANCELED) { + op->mark_event("callback canceled"); + } else if (op && r == -EAGAIN) { + op->mark_event("callback retry"); + } else if (op && r == 0) { + op->mark_event("callback finished"); + } + _finish(r); + } + + void mark_op_event(const string &event) { + if (op) + op->mark_event(event); + } + + virtual void _finish(int r) = 0; +}; + #endif -- 2.47.3