]> git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MonOpRequest.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / 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
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2015 Red Hat <contact@redhat.com>
7 * Copyright (C) 2015 SUSE LINUX GmbH
8 *
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.
13 */
14
15 #ifndef MON_OPREQUEST_H_
16 #define MON_OPREQUEST_H_
17 #include <iosfwd>
18 #include <stdint.h>
19
20 #include "common/TrackedOp.h"
21 #include "mon/Session.h"
22 #include "msg/Message.h"
23
24 struct MonOpRequest : public TrackedOp {
25 friend class OpTracker;
26
27 void mark_dispatch() {
28 mark_event("monitor_dispatch");
29 }
30 void mark_wait_for_quorum() {
31 mark_event("wait_for_quorum");
32 }
33 void mark_zap() {
34 mark_event("monitor_zap");
35 }
36 void mark_forwarded() {
37 mark_event("forwarded");
38 forwarded_to_leader = true;
39 }
40
41 void mark_svc_event(const string &service, const string &event) {
42 string s = service;
43 s.append(":").append(event);
44 mark_event(s);
45 }
46
47 void mark_logmon_event(const string &event) {
48 mark_svc_event("logm", event);
49 }
50 void mark_osdmon_event(const string &event) {
51 mark_svc_event("osdmap", event);
52 }
53 void mark_pgmon_event(const string &event) {
54 mark_svc_event("pgmap", event);
55 }
56 void mark_mdsmon_event(const string &event) {
57 mark_svc_event("mdsmap", event);
58 }
59 void mark_authmon_event(const string &event) {
60 mark_svc_event("auth", event);
61 }
62 void mark_paxos_event(const string &event) {
63 mark_svc_event("paxos", event);
64 }
65
66
67 enum op_type_t {
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
74 };
75
76 MonOpRequest(const MonOpRequest &other) = delete;
77 MonOpRequest & operator = (const MonOpRequest &other) = delete;
78
79 private:
80 Message *request;
81 utime_t dequeued_time;
82 RefCountedPtr session;
83 ConnectionRef con;
84 bool forwarded_to_leader;
85 op_type_t op_type;
86
87 MonOpRequest(Message *req, OpTracker *tracker) :
88 TrackedOp(tracker,
89 req->get_recv_stamp().is_zero() ?
90 ceph_clock_now() : req->get_recv_stamp()),
91 request(req),
92 con(NULL),
93 forwarded_to_leader(false),
94 op_type(OP_TYPE_NONE)
95 {
96 if (req) {
97 con = req->get_connection();
98 if (con) {
99 session = con->get_priv();
100 }
101 }
102 }
103
104 void _dump(Formatter *f) const override {
105 {
106 f->open_array_section("events");
107 std::lock_guard l(lock);
108 for (auto& i : events) {
109 f->dump_object("event", i);
110 }
111 f->close_section();
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);
117 f->close_section();
118 }
119 }
120
121 protected:
122 void _dump_op_descriptor_unlocked(ostream& stream) const override {
123 get_req()->print(stream);
124 }
125
126 public:
127 ~MonOpRequest() override {
128 request->put();
129 }
130
131 MonSession *get_session() const {
132 return static_cast<MonSession*>(session.get());
133 }
134
135 template<class T>
136 T *get_req() const { return static_cast<T*>(request); }
137
138 Message *get_req() const { return get_req<Message>(); }
139
140 int get_req_type() const {
141 if (!request)
142 return 0;
143 return request->get_type();
144 }
145
146 ConnectionRef get_connection() { return con; }
147
148 void set_session(MonSession *s) {
149 session.reset(s);
150 }
151
152 bool is_src_mon() const {
153 return (con && con->get_peer_type() & CEPH_ENTITY_TYPE_MON);
154 }
155
156 typedef boost::intrusive_ptr<MonOpRequest> Ref;
157
158 void set_op_type(op_type_t t) {
159 op_type = t;
160 }
161 void set_type_service() {
162 set_op_type(OP_TYPE_SERVICE);
163 }
164 void set_type_monitor() {
165 set_op_type(OP_TYPE_MONITOR);
166 }
167 void set_type_paxos() {
168 set_op_type(OP_TYPE_PAXOS);
169 }
170 void set_type_election() {
171 set_op_type(OP_TYPE_ELECTION);
172 }
173 void set_type_command() {
174 set_op_type(OP_TYPE_COMMAND);
175 }
176
177 op_type_t get_op_type() {
178 return op_type;
179 }
180
181 bool is_type_service() {
182 return (get_op_type() == OP_TYPE_SERVICE);
183 }
184 bool is_type_monitor() {
185 return (get_op_type() == OP_TYPE_MONITOR);
186 }
187 bool is_type_paxos() {
188 return (get_op_type() == OP_TYPE_PAXOS);
189 }
190 bool is_type_election() {
191 return (get_op_type() == OP_TYPE_ELECTION);
192 }
193 bool is_type_command() {
194 return (get_op_type() == OP_TYPE_COMMAND);
195 }
196 };
197
198 typedef MonOpRequest::Ref MonOpRequestRef;
199
200 struct C_MonOp : public Context
201 {
202 MonOpRequestRef op;
203
204 explicit C_MonOp(MonOpRequestRef o) :
205 op(o) { }
206
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");
214 }
215 _finish(r);
216 }
217
218 void mark_op_event(const string &event) {
219 if (op)
220 op->mark_event(event);
221 }
222
223 virtual void _finish(int r) = 0;
224 };
225
226 #endif /* MON_OPREQUEST_H_ */