]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MonOpRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Red Hat <contact@redhat.com>
7 * Copyright (C) 2015 SUSE LINUX GmbH
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
15 #ifndef MON_OPREQUEST_H_
16 #define MON_OPREQUEST_H_
20 #include "common/TrackedOp.h"
21 #include "mon/Session.h"
22 #include "msg/Message.h"
24 struct MonOpRequest
: public TrackedOp
{
25 friend class OpTracker
;
27 void mark_dispatch() {
28 mark_event("monitor_dispatch");
30 void mark_wait_for_quorum() {
31 mark_event("wait_for_quorum");
34 mark_event("monitor_zap");
36 void mark_forwarded() {
37 mark_event("forwarded");
38 forwarded_to_leader
= true;
41 void mark_svc_event(const string
&service
, const string
&event
) {
43 s
.append(":").append(event
);
47 void mark_logmon_event(const string
&event
) {
48 mark_svc_event("logm", event
);
50 void mark_osdmon_event(const string
&event
) {
51 mark_svc_event("osdmap", event
);
53 void mark_pgmon_event(const string
&event
) {
54 mark_svc_event("pgmap", event
);
56 void mark_mdsmon_event(const string
&event
) {
57 mark_svc_event("mdsmap", event
);
59 void mark_authmon_event(const string
&event
) {
60 mark_svc_event("auth", event
);
62 void mark_paxos_event(const string
&event
) {
63 mark_svc_event("paxos", event
);
68 OP_TYPE_NONE
= 0, ///< no type defined (default)
69 OP_TYPE_SERVICE
, ///< belongs to a Paxos Service or similar
70 OP_TYPE_MONITOR
, ///< belongs to the Monitor class
71 OP_TYPE_ELECTION
, ///< belongs to the Elector class
72 OP_TYPE_PAXOS
, ///< refers to Paxos messages
73 OP_TYPE_COMMAND
, ///< is a command
76 MonOpRequest(const MonOpRequest
&other
) = delete;
77 MonOpRequest
& operator = (const MonOpRequest
&other
) = delete;
81 utime_t dequeued_time
;
82 RefCountedPtr session
;
84 bool forwarded_to_leader
;
87 MonOpRequest(Message
*req
, OpTracker
*tracker
) :
89 req
->get_recv_stamp().is_zero() ?
90 ceph_clock_now() : req
->get_recv_stamp()),
93 forwarded_to_leader(false),
97 con
= req
->get_connection();
99 session
= con
->get_priv();
104 void _dump(Formatter
*f
) const override
{
106 f
->open_array_section("events");
107 std::lock_guard
l(lock
);
108 for (auto& i
: events
) {
109 f
->dump_object("event", i
);
112 f
->open_object_section("info");
113 f
->dump_int("seq", seq
);
114 f
->dump_bool("src_is_mon", is_src_mon());
115 f
->dump_stream("source") << request
->get_source_inst();
116 f
->dump_bool("forwarded_to_leader", forwarded_to_leader
);
122 void _dump_op_descriptor_unlocked(ostream
& stream
) const override
{
123 get_req()->print(stream
);
127 ~MonOpRequest() override
{
131 MonSession
*get_session() const {
132 return static_cast<MonSession
*>(session
.get());
136 T
*get_req() const { return static_cast<T
*>(request
); }
138 Message
*get_req() const { return get_req
<Message
>(); }
140 int get_req_type() const {
143 return request
->get_type();
146 ConnectionRef
get_connection() { return con
; }
148 void set_session(MonSession
*s
) {
152 bool is_src_mon() const {
153 return (con
&& con
->get_peer_type() & CEPH_ENTITY_TYPE_MON
);
156 typedef boost::intrusive_ptr
<MonOpRequest
> Ref
;
158 void set_op_type(op_type_t t
) {
161 void set_type_service() {
162 set_op_type(OP_TYPE_SERVICE
);
164 void set_type_monitor() {
165 set_op_type(OP_TYPE_MONITOR
);
167 void set_type_paxos() {
168 set_op_type(OP_TYPE_PAXOS
);
170 void set_type_election() {
171 set_op_type(OP_TYPE_ELECTION
);
173 void set_type_command() {
174 set_op_type(OP_TYPE_COMMAND
);
177 op_type_t
get_op_type() {
181 bool is_type_service() {
182 return (get_op_type() == OP_TYPE_SERVICE
);
184 bool is_type_monitor() {
185 return (get_op_type() == OP_TYPE_MONITOR
);
187 bool is_type_paxos() {
188 return (get_op_type() == OP_TYPE_PAXOS
);
190 bool is_type_election() {
191 return (get_op_type() == OP_TYPE_ELECTION
);
193 bool is_type_command() {
194 return (get_op_type() == OP_TYPE_COMMAND
);
198 typedef MonOpRequest::Ref MonOpRequestRef
;
200 struct C_MonOp
: public Context
204 explicit C_MonOp(MonOpRequestRef o
) :
207 void finish(int r
) override
{
208 if (op
&& r
== -ECANCELED
) {
209 op
->mark_event("callback canceled");
210 } else if (op
&& r
== -EAGAIN
) {
211 op
->mark_event("callback retry");
212 } else if (op
&& r
== 0) {
213 op
->mark_event("callback finished");
218 void mark_op_event(const string
&event
) {
220 op
->mark_event(event
);
223 virtual void _finish(int r
) = 0;
226 #endif /* MON_OPREQUEST_H_ */