]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_MESSAGE_H | |
16 | #define CEPH_MESSAGE_H | |
9f95a23c TL |
17 | |
18 | #include <cstdlib> | |
7c673cae | 19 | #include <ostream> |
11fdf7f2 | 20 | #include <string_view> |
7c673cae | 21 | |
7c673cae | 22 | #include <boost/intrusive/list.hpp> |
7c673cae | 23 | |
11fdf7f2 | 24 | #include "include/Context.h" |
7c673cae | 25 | #include "common/RefCountedObj.h" |
11fdf7f2 | 26 | #include "common/ThrottleInterface.h" |
7c673cae | 27 | #include "common/config.h" |
9f95a23c | 28 | #include "common/ref.h" |
11fdf7f2 TL |
29 | #include "common/debug.h" |
30 | #include "common/zipkin_trace.h" | |
31 | #include "include/ceph_assert.h" // Because intrusive_ptr clobbers our assert... | |
32 | #include "include/buffer.h" | |
33 | #include "include/types.h" | |
34 | #include "msg/Connection.h" | |
35 | #include "msg/MessageRef.h" | |
36 | #include "msg_types.h" | |
7c673cae | 37 | |
9f95a23c TL |
38 | #ifdef WITH_SEASTAR |
39 | # include "crimson/net/SocketConnection.h" | |
40 | #endif // WITH_SEASTAR | |
41 | ||
7c673cae FG |
42 | // monitor internal |
43 | #define MSG_MON_SCRUB 64 | |
44 | #define MSG_MON_ELECTION 65 | |
45 | #define MSG_MON_PAXOS 66 | |
46 | #define MSG_MON_PROBE 67 | |
47 | #define MSG_MON_JOIN 68 | |
48 | #define MSG_MON_SYNC 69 | |
49 | ||
50 | /* monitor <-> mon admin tool */ | |
51 | #define MSG_MON_COMMAND 50 | |
52 | #define MSG_MON_COMMAND_ACK 51 | |
53 | #define MSG_LOG 52 | |
54 | #define MSG_LOGACK 53 | |
55 | ||
56 | #define MSG_GETPOOLSTATS 58 | |
57 | #define MSG_GETPOOLSTATSREPLY 59 | |
58 | ||
59 | #define MSG_MON_GLOBAL_ID 60 | |
60 | ||
61 | #define MSG_ROUTE 47 | |
62 | #define MSG_FORWARD 46 | |
63 | ||
64 | #define MSG_PAXOS 40 | |
65 | ||
11fdf7f2 TL |
66 | #define MSG_CONFIG 62 |
67 | #define MSG_GET_CONFIG 63 | |
68 | ||
9f95a23c TL |
69 | #define MSG_MON_GET_PURGED_SNAPS 76 |
70 | #define MSG_MON_GET_PURGED_SNAPS_REPLY 77 | |
7c673cae FG |
71 | |
72 | // osd internal | |
73 | #define MSG_OSD_PING 70 | |
74 | #define MSG_OSD_BOOT 71 | |
75 | #define MSG_OSD_FAILURE 72 | |
76 | #define MSG_OSD_ALIVE 73 | |
77 | #define MSG_OSD_MARK_ME_DOWN 74 | |
78 | #define MSG_OSD_FULL 75 | |
9f95a23c | 79 | #define MSG_OSD_MARK_ME_DEAD 123 |
7c673cae | 80 | |
11fdf7f2 TL |
81 | // removed right after luminous |
82 | //#define MSG_OSD_SUBOP 76 | |
83 | //#define MSG_OSD_SUBOPREPLY 77 | |
7c673cae FG |
84 | |
85 | #define MSG_OSD_PGTEMP 78 | |
86 | ||
87 | #define MSG_OSD_BEACON 79 | |
88 | ||
89 | #define MSG_OSD_PG_NOTIFY 80 | |
9f95a23c | 90 | #define MSG_OSD_PG_NOTIFY2 130 |
7c673cae | 91 | #define MSG_OSD_PG_QUERY 81 |
9f95a23c | 92 | #define MSG_OSD_PG_QUERY2 131 |
7c673cae FG |
93 | #define MSG_OSD_PG_LOG 83 |
94 | #define MSG_OSD_PG_REMOVE 84 | |
95 | #define MSG_OSD_PG_INFO 85 | |
9f95a23c | 96 | #define MSG_OSD_PG_INFO2 132 |
7c673cae FG |
97 | #define MSG_OSD_PG_TRIM 86 |
98 | ||
99 | #define MSG_PGSTATS 87 | |
100 | #define MSG_PGSTATSACK 88 | |
101 | ||
102 | #define MSG_OSD_PG_CREATE 89 | |
103 | #define MSG_REMOVE_SNAPS 90 | |
104 | ||
105 | #define MSG_OSD_SCRUB 91 | |
106 | #define MSG_OSD_SCRUB_RESERVE 92 // previous PG_MISSING | |
107 | #define MSG_OSD_REP_SCRUB 93 | |
108 | ||
109 | #define MSG_OSD_PG_SCAN 94 | |
110 | #define MSG_OSD_PG_BACKFILL 95 | |
111 | #define MSG_OSD_PG_BACKFILL_REMOVE 96 | |
112 | ||
113 | #define MSG_COMMAND 97 | |
114 | #define MSG_COMMAND_REPLY 98 | |
115 | ||
116 | #define MSG_OSD_BACKFILL_RESERVE 99 | |
117 | #define MSG_OSD_RECOVERY_RESERVE 150 | |
c07f9fc5 | 118 | #define MSG_OSD_FORCE_RECOVERY 151 |
7c673cae FG |
119 | |
120 | #define MSG_OSD_PG_PUSH 105 | |
121 | #define MSG_OSD_PG_PULL 106 | |
122 | #define MSG_OSD_PG_PUSH_REPLY 107 | |
123 | ||
124 | #define MSG_OSD_EC_WRITE 108 | |
125 | #define MSG_OSD_EC_WRITE_REPLY 109 | |
126 | #define MSG_OSD_EC_READ 110 | |
127 | #define MSG_OSD_EC_READ_REPLY 111 | |
128 | ||
129 | #define MSG_OSD_REPOP 112 | |
130 | #define MSG_OSD_REPOPREPLY 113 | |
131 | #define MSG_OSD_PG_UPDATE_LOG_MISSING 114 | |
132 | #define MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY 115 | |
133 | ||
134 | #define MSG_OSD_PG_CREATED 116 | |
135 | #define MSG_OSD_REP_SCRUBMAP 117 | |
c07f9fc5 FG |
136 | #define MSG_OSD_PG_RECOVERY_DELETE 118 |
137 | #define MSG_OSD_PG_RECOVERY_DELETE_REPLY 119 | |
11fdf7f2 TL |
138 | #define MSG_OSD_PG_CREATE2 120 |
139 | #define MSG_OSD_SCRUB2 121 | |
140 | ||
141 | #define MSG_OSD_PG_READY_TO_MERGE 122 | |
7c673cae | 142 | |
9f95a23c TL |
143 | #define MSG_OSD_PG_LEASE 133 |
144 | #define MSG_OSD_PG_LEASE_ACK 134 | |
145 | ||
7c673cae FG |
146 | // *** MDS *** |
147 | ||
148 | #define MSG_MDS_BEACON 100 // to monitor | |
149 | #define MSG_MDS_SLAVE_REQUEST 101 | |
150 | #define MSG_MDS_TABLE_REQUEST 102 | |
151 | ||
152 | // 150 already in use (MSG_OSD_RECOVERY_RESERVE) | |
153 | ||
154 | #define MSG_MDS_RESOLVE 0x200 | |
155 | #define MSG_MDS_RESOLVEACK 0x201 | |
156 | #define MSG_MDS_CACHEREJOIN 0x202 | |
157 | #define MSG_MDS_DISCOVER 0x203 | |
158 | #define MSG_MDS_DISCOVERREPLY 0x204 | |
159 | #define MSG_MDS_INODEUPDATE 0x205 | |
160 | #define MSG_MDS_DIRUPDATE 0x206 | |
161 | #define MSG_MDS_CACHEEXPIRE 0x207 | |
162 | #define MSG_MDS_DENTRYUNLINK 0x208 | |
163 | #define MSG_MDS_FRAGMENTNOTIFY 0x209 | |
164 | #define MSG_MDS_OFFLOAD_TARGETS 0x20a | |
165 | #define MSG_MDS_DENTRYLINK 0x20c | |
166 | #define MSG_MDS_FINDINO 0x20d | |
167 | #define MSG_MDS_FINDINOREPLY 0x20e | |
168 | #define MSG_MDS_OPENINO 0x20f | |
169 | #define MSG_MDS_OPENINOREPLY 0x210 | |
11fdf7f2 | 170 | #define MSG_MDS_SNAPUPDATE 0x211 |
a8e16298 | 171 | #define MSG_MDS_FRAGMENTNOTIFYACK 0x212 |
7c673cae FG |
172 | #define MSG_MDS_LOCK 0x300 |
173 | #define MSG_MDS_INODEFILECAPS 0x301 | |
174 | ||
175 | #define MSG_MDS_EXPORTDIRDISCOVER 0x449 | |
176 | #define MSG_MDS_EXPORTDIRDISCOVERACK 0x450 | |
177 | #define MSG_MDS_EXPORTDIRCANCEL 0x451 | |
178 | #define MSG_MDS_EXPORTDIRPREP 0x452 | |
179 | #define MSG_MDS_EXPORTDIRPREPACK 0x453 | |
180 | #define MSG_MDS_EXPORTDIRWARNING 0x454 | |
181 | #define MSG_MDS_EXPORTDIRWARNINGACK 0x455 | |
182 | #define MSG_MDS_EXPORTDIR 0x456 | |
183 | #define MSG_MDS_EXPORTDIRACK 0x457 | |
184 | #define MSG_MDS_EXPORTDIRNOTIFY 0x458 | |
185 | #define MSG_MDS_EXPORTDIRNOTIFYACK 0x459 | |
186 | #define MSG_MDS_EXPORTDIRFINISH 0x460 | |
187 | ||
188 | #define MSG_MDS_EXPORTCAPS 0x470 | |
189 | #define MSG_MDS_EXPORTCAPSACK 0x471 | |
190 | #define MSG_MDS_GATHERCAPS 0x472 | |
191 | ||
192 | #define MSG_MDS_HEARTBEAT 0x500 // for mds load balancer | |
193 | ||
194 | // *** generic *** | |
195 | #define MSG_TIMECHECK 0x600 | |
196 | #define MSG_MON_HEALTH 0x601 | |
197 | ||
198 | // *** Message::encode() crcflags bits *** | |
199 | #define MSG_CRC_DATA (1 << 0) | |
200 | #define MSG_CRC_HEADER (1 << 1) | |
201 | #define MSG_CRC_ALL (MSG_CRC_DATA | MSG_CRC_HEADER) | |
202 | ||
7c673cae FG |
203 | |
204 | // Special | |
205 | #define MSG_NOP 0x607 | |
206 | ||
224ce89b | 207 | #define MSG_MON_HEALTH_CHECKS 0x608 |
11fdf7f2 | 208 | #define MSG_TIMECHECK2 0x609 |
224ce89b | 209 | |
7c673cae FG |
210 | // *** ceph-mgr <-> OSD/MDS daemons *** |
211 | #define MSG_MGR_OPEN 0x700 | |
212 | #define MSG_MGR_CONFIGURE 0x701 | |
213 | #define MSG_MGR_REPORT 0x702 | |
214 | ||
215 | // *** ceph-mgr <-> ceph-mon *** | |
216 | #define MSG_MGR_BEACON 0x703 | |
217 | ||
218 | // *** ceph-mon(MgrMonitor) -> OSD/MDS daemons *** | |
219 | #define MSG_MGR_MAP 0x704 | |
220 | ||
221 | // *** ceph-mon(MgrMonitor) -> ceph-mgr | |
222 | #define MSG_MGR_DIGEST 0x705 | |
31f18b77 FG |
223 | // *** cephmgr -> ceph-mon |
224 | #define MSG_MON_MGR_REPORT 0x706 | |
224ce89b | 225 | #define MSG_SERVICE_MAP 0x707 |
7c673cae | 226 | |
11fdf7f2 | 227 | #define MSG_MGR_CLOSE 0x708 |
9f95a23c TL |
228 | #define MSG_MGR_COMMAND 0x709 |
229 | #define MSG_MGR_COMMAND_REPLY 0x70a | |
11fdf7f2 | 230 | |
7c673cae FG |
231 | // ====================================================== |
232 | ||
233 | // abstract Message class | |
234 | ||
7c673cae | 235 | class Message : public RefCountedObject { |
9f95a23c TL |
236 | public: |
237 | #ifdef WITH_SEASTAR | |
238 | using ConnectionRef = crimson::net::ConnectionRef; | |
239 | #else | |
240 | using ConnectionRef = ::ConnectionRef; | |
241 | #endif // WITH_SEASTAR | |
242 | ||
7c673cae FG |
243 | protected: |
244 | ceph_msg_header header; // headerelope | |
245 | ceph_msg_footer footer; | |
9f95a23c TL |
246 | ceph::buffer::list payload; // "front" unaligned blob |
247 | ceph::buffer::list middle; // "middle" unaligned blob | |
248 | ceph::buffer::list data; // data payload (page-alignment will be preserved where possible) | |
7c673cae FG |
249 | |
250 | /* recv_stamp is set when the Messenger starts reading the | |
251 | * Message off the wire */ | |
252 | utime_t recv_stamp; | |
253 | /* dispatch_stamp is set when the Messenger starts calling dispatch() on | |
254 | * its endpoints */ | |
255 | utime_t dispatch_stamp; | |
256 | /* throttle_stamp is the point at which we got throttle */ | |
257 | utime_t throttle_stamp; | |
258 | /* time at which message was fully read */ | |
259 | utime_t recv_complete_stamp; | |
260 | ||
261 | ConnectionRef connection; | |
262 | ||
263 | uint32_t magic = 0; | |
264 | ||
9f95a23c | 265 | boost::intrusive::list_member_hook<> dispatch_q; |
7c673cae FG |
266 | |
267 | public: | |
268 | // zipkin tracing | |
269 | ZTracer::Trace trace; | |
9f95a23c TL |
270 | void encode_trace(ceph::buffer::list &bl, uint64_t features) const; |
271 | void decode_trace(ceph::buffer::list::const_iterator &p, bool create = false); | |
7c673cae FG |
272 | |
273 | class CompletionHook : public Context { | |
274 | protected: | |
275 | Message *m; | |
276 | friend class Message; | |
277 | public: | |
278 | explicit CompletionHook(Message *_m) : m(_m) {} | |
279 | virtual void set_message(Message *_m) { m = _m; } | |
280 | }; | |
281 | ||
9f95a23c TL |
282 | typedef boost::intrusive::list<Message, |
283 | boost::intrusive::member_hook< | |
284 | Message, | |
285 | boost::intrusive::list_member_hook<>, | |
286 | &Message::dispatch_q>> Queue; | |
7c673cae | 287 | |
9f95a23c | 288 | ceph::mono_time queue_start; |
7c673cae FG |
289 | protected: |
290 | CompletionHook* completion_hook = nullptr; // owned by Messenger | |
291 | ||
292 | // release our size in bytes back to this throttler when our payload | |
293 | // is adjusted or when we are destroyed. | |
11fdf7f2 | 294 | ThrottleInterface *byte_throttler = nullptr; |
7c673cae FG |
295 | |
296 | // release a count back to this throttler when we are destroyed | |
11fdf7f2 | 297 | ThrottleInterface *msg_throttler = nullptr; |
7c673cae FG |
298 | |
299 | // keep track of how big this message was when we reserved space in | |
300 | // the msgr dispatch_throttler, so that we can properly release it | |
301 | // later. this is necessary because messages can enter the dispatch | |
302 | // queue locally (not via read_message()), and those are not | |
303 | // currently throttled. | |
304 | uint64_t dispatch_throttle_size = 0; | |
305 | ||
306 | friend class Messenger; | |
307 | ||
308 | public: | |
309 | Message() { | |
310 | memset(&header, 0, sizeof(header)); | |
311 | memset(&footer, 0, sizeof(footer)); | |
312 | } | |
313 | Message(int t, int version=1, int compat_version=0) { | |
314 | memset(&header, 0, sizeof(header)); | |
315 | header.type = t; | |
316 | header.version = version; | |
317 | header.compat_version = compat_version; | |
318 | header.priority = 0; // undef | |
319 | header.data_off = 0; | |
320 | memset(&footer, 0, sizeof(footer)); | |
321 | } | |
322 | ||
323 | Message *get() { | |
324 | return static_cast<Message *>(RefCountedObject::get()); | |
325 | } | |
326 | ||
327 | protected: | |
328 | ~Message() override { | |
329 | if (byte_throttler) | |
330 | byte_throttler->put(payload.length() + middle.length() + data.length()); | |
331 | release_message_throttle(); | |
332 | trace.event("message destructed"); | |
333 | /* call completion hooks (if any) */ | |
334 | if (completion_hook) | |
335 | completion_hook->complete(0); | |
336 | } | |
337 | public: | |
338 | const ConnectionRef& get_connection() const { return connection; } | |
9f95a23c TL |
339 | void set_connection(ConnectionRef c) { |
340 | connection = std::move(c); | |
7c673cae FG |
341 | } |
342 | CompletionHook* get_completion_hook() { return completion_hook; } | |
343 | void set_completion_hook(CompletionHook *hook) { completion_hook = hook; } | |
11fdf7f2 TL |
344 | void set_byte_throttler(ThrottleInterface *t) { |
345 | byte_throttler = t; | |
346 | } | |
347 | void set_message_throttler(ThrottleInterface *t) { | |
348 | msg_throttler = t; | |
349 | } | |
7c673cae FG |
350 | |
351 | void set_dispatch_throttle_size(uint64_t s) { dispatch_throttle_size = s; } | |
352 | uint64_t get_dispatch_throttle_size() const { return dispatch_throttle_size; } | |
353 | ||
354 | const ceph_msg_header &get_header() const { return header; } | |
355 | ceph_msg_header &get_header() { return header; } | |
356 | void set_header(const ceph_msg_header &e) { header = e; } | |
357 | void set_footer(const ceph_msg_footer &e) { footer = e; } | |
358 | const ceph_msg_footer &get_footer() const { return footer; } | |
359 | ceph_msg_footer &get_footer() { return footer; } | |
360 | void set_src(const entity_name_t& src) { header.src = src; } | |
361 | ||
362 | uint32_t get_magic() const { return magic; } | |
363 | void set_magic(int _magic) { magic = _magic; } | |
364 | ||
365 | /* | |
366 | * If you use get_[data, middle, payload] you shouldn't | |
9f95a23c | 367 | * use it to change those ceph::buffer::lists unless you KNOW |
7c673cae FG |
368 | * there is no throttle being used. The other |
369 | * functions are throttling-aware as appropriate. | |
370 | */ | |
371 | ||
372 | void clear_payload() { | |
373 | if (byte_throttler) { | |
374 | byte_throttler->put(payload.length() + middle.length()); | |
375 | } | |
376 | payload.clear(); | |
377 | middle.clear(); | |
378 | } | |
379 | ||
380 | virtual void clear_buffers() {} | |
381 | void clear_data() { | |
382 | if (byte_throttler) | |
383 | byte_throttler->put(data.length()); | |
384 | data.clear(); | |
385 | clear_buffers(); // let subclass drop buffers as well | |
386 | } | |
387 | void release_message_throttle() { | |
388 | if (msg_throttler) | |
389 | msg_throttler->put(); | |
390 | msg_throttler = nullptr; | |
391 | } | |
392 | ||
393 | bool empty_payload() const { return payload.length() == 0; } | |
9f95a23c TL |
394 | ceph::buffer::list& get_payload() { return payload; } |
395 | const ceph::buffer::list& get_payload() const { return payload; } | |
396 | void set_payload(ceph::buffer::list& bl) { | |
7c673cae FG |
397 | if (byte_throttler) |
398 | byte_throttler->put(payload.length()); | |
9f95a23c | 399 | payload.claim(bl); |
7c673cae FG |
400 | if (byte_throttler) |
401 | byte_throttler->take(payload.length()); | |
402 | } | |
403 | ||
9f95a23c | 404 | void set_middle(ceph::buffer::list& bl) { |
7c673cae FG |
405 | if (byte_throttler) |
406 | byte_throttler->put(middle.length()); | |
9f95a23c | 407 | middle.claim(bl); |
7c673cae FG |
408 | if (byte_throttler) |
409 | byte_throttler->take(middle.length()); | |
410 | } | |
9f95a23c | 411 | ceph::buffer::list& get_middle() { return middle; } |
7c673cae | 412 | |
9f95a23c | 413 | void set_data(const ceph::buffer::list &bl) { |
7c673cae FG |
414 | if (byte_throttler) |
415 | byte_throttler->put(data.length()); | |
416 | data.share(bl); | |
417 | if (byte_throttler) | |
418 | byte_throttler->take(data.length()); | |
419 | } | |
420 | ||
9f95a23c TL |
421 | const ceph::buffer::list& get_data() const { return data; } |
422 | ceph::buffer::list& get_data() { return data; } | |
423 | void claim_data(ceph::buffer::list& bl) { | |
7c673cae FG |
424 | if (byte_throttler) |
425 | byte_throttler->put(data.length()); | |
9f95a23c | 426 | bl.claim(data); |
7c673cae FG |
427 | } |
428 | off_t get_data_len() const { return data.length(); } | |
429 | ||
430 | void set_recv_stamp(utime_t t) { recv_stamp = t; } | |
431 | const utime_t& get_recv_stamp() const { return recv_stamp; } | |
432 | void set_dispatch_stamp(utime_t t) { dispatch_stamp = t; } | |
433 | const utime_t& get_dispatch_stamp() const { return dispatch_stamp; } | |
434 | void set_throttle_stamp(utime_t t) { throttle_stamp = t; } | |
435 | const utime_t& get_throttle_stamp() const { return throttle_stamp; } | |
436 | void set_recv_complete_stamp(utime_t t) { recv_complete_stamp = t; } | |
437 | const utime_t& get_recv_complete_stamp() const { return recv_complete_stamp; } | |
438 | ||
439 | void calc_header_crc() { | |
440 | header.crc = ceph_crc32c(0, (unsigned char*)&header, | |
441 | sizeof(header) - sizeof(header.crc)); | |
442 | } | |
443 | void calc_front_crc() { | |
444 | footer.front_crc = payload.crc32c(0); | |
445 | footer.middle_crc = middle.crc32c(0); | |
446 | } | |
447 | void calc_data_crc() { | |
448 | footer.data_crc = data.crc32c(0); | |
449 | } | |
450 | ||
451 | virtual int get_cost() const { | |
452 | return data.length(); | |
453 | } | |
454 | ||
455 | // type | |
456 | int get_type() const { return header.type; } | |
457 | void set_type(int t) { header.type = t; } | |
458 | ||
459 | uint64_t get_tid() const { return header.tid; } | |
460 | void set_tid(uint64_t t) { header.tid = t; } | |
461 | ||
462 | uint64_t get_seq() const { return header.seq; } | |
463 | void set_seq(uint64_t s) { header.seq = s; } | |
464 | ||
465 | unsigned get_priority() const { return header.priority; } | |
466 | void set_priority(__s16 p) { header.priority = p; } | |
467 | ||
468 | // source/dest | |
469 | entity_inst_t get_source_inst() const { | |
470 | return entity_inst_t(get_source(), get_source_addr()); | |
471 | } | |
472 | entity_name_t get_source() const { | |
473 | return entity_name_t(header.src); | |
474 | } | |
475 | entity_addr_t get_source_addr() const { | |
476 | if (connection) | |
477 | return connection->get_peer_addr(); | |
478 | return entity_addr_t(); | |
479 | } | |
11fdf7f2 TL |
480 | entity_addrvec_t get_source_addrs() const { |
481 | if (connection) | |
482 | return connection->get_peer_addrs(); | |
483 | return entity_addrvec_t(); | |
484 | } | |
7c673cae FG |
485 | |
486 | // forwarded? | |
487 | entity_inst_t get_orig_source_inst() const { | |
488 | return get_source_inst(); | |
489 | } | |
490 | entity_name_t get_orig_source() const { | |
491 | return get_source(); | |
492 | } | |
493 | entity_addr_t get_orig_source_addr() const { | |
494 | return get_source_addr(); | |
495 | } | |
11fdf7f2 TL |
496 | entity_addrvec_t get_orig_source_addrs() const { |
497 | return get_source_addrs(); | |
498 | } | |
7c673cae FG |
499 | |
500 | // virtual bits | |
501 | virtual void decode_payload() = 0; | |
502 | virtual void encode_payload(uint64_t features) = 0; | |
11fdf7f2 | 503 | virtual std::string_view get_type_name() const = 0; |
9f95a23c | 504 | virtual void print(std::ostream& out) const { |
7c673cae FG |
505 | out << get_type_name() << " magic: " << magic; |
506 | } | |
507 | ||
9f95a23c | 508 | virtual void dump(ceph::Formatter *f) const; |
7c673cae | 509 | |
9f95a23c | 510 | void encode(uint64_t features, int crcflags, bool skip_header_crc = false); |
7c673cae | 511 | }; |
7c673cae | 512 | |
9f95a23c TL |
513 | extern Message *decode_message(CephContext *cct, |
514 | int crcflags, | |
515 | ceph_msg_header& header, | |
516 | ceph_msg_footer& footer, | |
517 | ceph::buffer::list& front, | |
518 | ceph::buffer::list& middle, | |
519 | ceph::buffer::list& data, | |
520 | Message::ConnectionRef conn); | |
521 | inline std::ostream& operator<<(std::ostream& out, const Message& m) { | |
7c673cae FG |
522 | m.print(out); |
523 | if (m.get_header().version) | |
524 | out << " v" << m.get_header().version; | |
525 | return out; | |
526 | } | |
527 | ||
9f95a23c | 528 | extern void encode_message(Message *m, uint64_t features, ceph::buffer::list& bl); |
7c673cae | 529 | extern Message *decode_message(CephContext *cct, int crcflags, |
9f95a23c | 530 | ceph::buffer::list::const_iterator& bl); |
11fdf7f2 | 531 | |
9f95a23c TL |
532 | /// this is a "safe" version of Message. it does not allow calling get/put |
533 | /// methods on its derived classes. This is intended to prevent some accidental | |
534 | /// reference leaks by forcing . Instead, you must either cast the derived class to a | |
535 | /// RefCountedObject to do the get/put or detach a temporary reference. | |
536 | class SafeMessage : public Message { | |
11fdf7f2 | 537 | public: |
9f95a23c TL |
538 | using Message::Message; |
539 | private: | |
540 | using RefCountedObject::get; | |
541 | using RefCountedObject::put; | |
11fdf7f2 TL |
542 | }; |
543 | ||
9f95a23c TL |
544 | namespace ceph { |
545 | template<class T, typename... Args> | |
546 | ceph::ref_t<T> make_message(Args&&... args) { | |
547 | return {new T(std::forward<Args>(args)...), false}; | |
548 | } | |
549 | } | |
7c673cae FG |
550 | |
551 | #endif |