]>
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 | #ifdef ENCODE_DUMP | |
5 | # include <typeinfo> | |
6 | # include <cxxabi.h> | |
7 | #endif | |
8 | ||
9 | #include <iostream> | |
10 | using namespace std; | |
11 | ||
12 | #include "include/types.h" | |
13 | ||
14 | #include "global/global_context.h" | |
15 | ||
16 | #include "Message.h" | |
17 | ||
18 | #include "messages/MPGStats.h" | |
19 | ||
20 | #include "messages/MGenericMessage.h" | |
21 | ||
22 | #include "messages/MPGStatsAck.h" | |
23 | ||
24 | #include "messages/MStatfs.h" | |
25 | #include "messages/MStatfsReply.h" | |
26 | ||
27 | #include "messages/MGetPoolStats.h" | |
28 | #include "messages/MGetPoolStatsReply.h" | |
29 | ||
30 | ||
31 | #include "messages/MPoolOp.h" | |
32 | #include "messages/MPoolOpReply.h" | |
33 | ||
34 | #include "messages/PaxosServiceMessage.h" | |
35 | #include "messages/MMonCommand.h" | |
36 | #include "messages/MMonCommandAck.h" | |
37 | #include "messages/MMonPaxos.h" | |
38 | ||
39 | #include "messages/MMonProbe.h" | |
40 | #include "messages/MMonJoin.h" | |
41 | #include "messages/MMonElection.h" | |
42 | #include "messages/MMonSync.h" | |
43 | #include "messages/MMonScrub.h" | |
44 | ||
45 | #include "messages/MLog.h" | |
46 | #include "messages/MLogAck.h" | |
47 | ||
48 | #include "messages/MPing.h" | |
49 | ||
50 | #include "messages/MCommand.h" | |
51 | #include "messages/MCommandReply.h" | |
52 | #include "messages/MBackfillReserve.h" | |
53 | #include "messages/MRecoveryReserve.h" | |
54 | ||
55 | #include "messages/MRoute.h" | |
56 | #include "messages/MForward.h" | |
57 | ||
58 | #include "messages/MOSDBoot.h" | |
59 | #include "messages/MOSDAlive.h" | |
60 | #include "messages/MOSDBeacon.h" | |
61 | #include "messages/MOSDPGTemp.h" | |
62 | #include "messages/MOSDFailure.h" | |
63 | #include "messages/MOSDMarkMeDown.h" | |
64 | #include "messages/MOSDFull.h" | |
65 | #include "messages/MOSDPing.h" | |
66 | #include "messages/MOSDOp.h" | |
67 | #include "messages/MOSDOpReply.h" | |
68 | #include "messages/MOSDSubOp.h" | |
69 | #include "messages/MOSDSubOpReply.h" | |
70 | #include "messages/MOSDRepOp.h" | |
71 | #include "messages/MOSDRepOpReply.h" | |
72 | #include "messages/MOSDMap.h" | |
73 | #include "messages/MMonGetOSDMap.h" | |
74 | ||
75 | #include "messages/MOSDPGCreated.h" | |
76 | #include "messages/MOSDPGNotify.h" | |
77 | #include "messages/MOSDPGQuery.h" | |
78 | #include "messages/MOSDPGLog.h" | |
79 | #include "messages/MOSDPGRemove.h" | |
80 | #include "messages/MOSDPGInfo.h" | |
81 | #include "messages/MOSDPGCreate.h" | |
82 | #include "messages/MOSDPGTrim.h" | |
83 | #include "messages/MOSDScrub.h" | |
84 | #include "messages/MOSDScrubReserve.h" | |
85 | #include "messages/MOSDRepScrub.h" | |
86 | #include "messages/MOSDRepScrubMap.h" | |
c07f9fc5 | 87 | #include "messages/MOSDForceRecovery.h" |
7c673cae FG |
88 | #include "messages/MOSDPGScan.h" |
89 | #include "messages/MOSDPGBackfill.h" | |
90 | #include "messages/MOSDBackoff.h" | |
91 | #include "messages/MOSDPGBackfillRemove.h" | |
c07f9fc5 FG |
92 | #include "messages/MOSDPGRecoveryDelete.h" |
93 | #include "messages/MOSDPGRecoveryDeleteReply.h" | |
7c673cae FG |
94 | |
95 | #include "messages/MRemoveSnaps.h" | |
96 | ||
97 | #include "messages/MMonMap.h" | |
98 | #include "messages/MMonGetMap.h" | |
99 | #include "messages/MMonGetVersion.h" | |
100 | #include "messages/MMonGetVersionReply.h" | |
101 | #include "messages/MMonHealth.h" | |
224ce89b | 102 | #include "messages/MMonHealthChecks.h" |
7c673cae FG |
103 | #include "messages/MMonMetadata.h" |
104 | #include "messages/MDataPing.h" | |
105 | #include "messages/MAuth.h" | |
106 | #include "messages/MAuthReply.h" | |
107 | #include "messages/MMonSubscribe.h" | |
108 | #include "messages/MMonSubscribeAck.h" | |
109 | #include "messages/MMonGlobalID.h" | |
110 | #include "messages/MClientSession.h" | |
111 | #include "messages/MClientReconnect.h" | |
112 | #include "messages/MClientRequest.h" | |
113 | #include "messages/MClientRequestForward.h" | |
114 | #include "messages/MClientReply.h" | |
115 | #include "messages/MClientCaps.h" | |
116 | #include "messages/MClientCapRelease.h" | |
117 | #include "messages/MClientLease.h" | |
118 | #include "messages/MClientSnap.h" | |
119 | #include "messages/MClientQuota.h" | |
120 | ||
121 | #include "messages/MMDSSlaveRequest.h" | |
122 | ||
123 | #include "messages/MMDSMap.h" | |
124 | #include "messages/MFSMap.h" | |
125 | #include "messages/MFSMapUser.h" | |
126 | #include "messages/MMDSBeacon.h" | |
127 | #include "messages/MMDSLoadTargets.h" | |
128 | #include "messages/MMDSResolve.h" | |
129 | #include "messages/MMDSResolveAck.h" | |
130 | #include "messages/MMDSCacheRejoin.h" | |
131 | #include "messages/MMDSFindIno.h" | |
132 | #include "messages/MMDSFindInoReply.h" | |
133 | #include "messages/MMDSOpenIno.h" | |
134 | #include "messages/MMDSOpenInoReply.h" | |
135 | ||
136 | #include "messages/MDirUpdate.h" | |
137 | #include "messages/MDiscover.h" | |
138 | #include "messages/MDiscoverReply.h" | |
139 | ||
140 | #include "messages/MMDSFragmentNotify.h" | |
a8e16298 | 141 | #include "messages/MMDSFragmentNotifyAck.h" |
7c673cae FG |
142 | |
143 | #include "messages/MExportDirDiscover.h" | |
144 | #include "messages/MExportDirDiscoverAck.h" | |
145 | #include "messages/MExportDirCancel.h" | |
146 | #include "messages/MExportDirPrep.h" | |
147 | #include "messages/MExportDirPrepAck.h" | |
148 | #include "messages/MExportDir.h" | |
149 | #include "messages/MExportDirAck.h" | |
150 | #include "messages/MExportDirNotify.h" | |
151 | #include "messages/MExportDirNotifyAck.h" | |
152 | #include "messages/MExportDirFinish.h" | |
153 | ||
154 | #include "messages/MExportCaps.h" | |
155 | #include "messages/MExportCapsAck.h" | |
156 | #include "messages/MGatherCaps.h" | |
157 | ||
158 | ||
159 | #include "messages/MDentryUnlink.h" | |
160 | #include "messages/MDentryLink.h" | |
161 | ||
162 | #include "messages/MHeartbeat.h" | |
163 | ||
164 | #include "messages/MMDSTableRequest.h" | |
165 | ||
166 | //#include "messages/MInodeUpdate.h" | |
167 | #include "messages/MCacheExpire.h" | |
168 | #include "messages/MInodeFileCaps.h" | |
169 | ||
170 | #include "messages/MMgrBeacon.h" | |
171 | #include "messages/MMgrMap.h" | |
172 | #include "messages/MMgrDigest.h" | |
173 | #include "messages/MMgrReport.h" | |
174 | #include "messages/MMgrOpen.h" | |
175 | #include "messages/MMgrConfigure.h" | |
31f18b77 | 176 | #include "messages/MMonMgrReport.h" |
224ce89b | 177 | #include "messages/MServiceMap.h" |
7c673cae FG |
178 | |
179 | #include "messages/MLock.h" | |
180 | ||
181 | #include "messages/MWatchNotify.h" | |
182 | #include "messages/MTimeCheck.h" | |
183 | ||
184 | #include "common/config.h" | |
185 | ||
186 | #include "messages/MOSDPGPush.h" | |
187 | #include "messages/MOSDPGPushReply.h" | |
188 | #include "messages/MOSDPGPull.h" | |
189 | ||
190 | #include "messages/MOSDECSubOpWrite.h" | |
191 | #include "messages/MOSDECSubOpWriteReply.h" | |
192 | #include "messages/MOSDECSubOpRead.h" | |
193 | #include "messages/MOSDECSubOpReadReply.h" | |
194 | ||
195 | #include "messages/MOSDPGUpdateLogMissing.h" | |
196 | #include "messages/MOSDPGUpdateLogMissingReply.h" | |
197 | ||
198 | #define DEBUGLVL 10 // debug level of output | |
199 | ||
200 | #define dout_subsys ceph_subsys_ms | |
201 | ||
202 | void Message::encode(uint64_t features, int crcflags) | |
203 | { | |
204 | // encode and copy out of *m | |
205 | if (empty_payload()) { | |
206 | assert(middle.length() == 0); | |
207 | encode_payload(features); | |
208 | ||
209 | if (byte_throttler) { | |
210 | byte_throttler->take(payload.length() + middle.length()); | |
211 | } | |
212 | ||
213 | // if the encoder didn't specify past compatibility, we assume it | |
214 | // is incompatible. | |
215 | if (header.compat_version == 0) | |
216 | header.compat_version = header.version; | |
217 | } | |
218 | if (crcflags & MSG_CRC_HEADER) | |
219 | calc_front_crc(); | |
220 | ||
221 | // update envelope | |
222 | header.front_len = get_payload().length(); | |
223 | header.middle_len = get_middle().length(); | |
224 | header.data_len = get_data().length(); | |
225 | if (crcflags & MSG_CRC_HEADER) | |
226 | calc_header_crc(); | |
227 | ||
228 | footer.flags = CEPH_MSG_FOOTER_COMPLETE; | |
229 | ||
230 | if (crcflags & MSG_CRC_DATA) { | |
231 | calc_data_crc(); | |
232 | ||
233 | #ifdef ENCODE_DUMP | |
234 | bufferlist bl; | |
235 | ::encode(get_header(), bl); | |
236 | ||
237 | // dump the old footer format | |
238 | ceph_msg_footer_old old_footer; | |
239 | old_footer.front_crc = footer.front_crc; | |
240 | old_footer.middle_crc = footer.middle_crc; | |
241 | old_footer.data_crc = footer.data_crc; | |
242 | old_footer.flags = footer.flags; | |
243 | ::encode(old_footer, bl); | |
244 | ||
245 | ::encode(get_payload(), bl); | |
246 | ::encode(get_middle(), bl); | |
247 | ::encode(get_data(), bl); | |
248 | ||
249 | // this is almost an exponential backoff, except because we count | |
250 | // bits we tend to sample things we encode later, which should be | |
251 | // more representative. | |
252 | static int i = 0; | |
253 | i++; | |
254 | int bits = 0; | |
255 | for (unsigned t = i; t; bits++) | |
256 | t &= t - 1; | |
257 | if (bits <= 2) { | |
258 | char fn[200]; | |
259 | int status; | |
260 | snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", | |
261 | abi::__cxa_demangle(typeid(*this).name(), 0, 0, &status), | |
262 | getpid(), i++); | |
91327a77 | 263 | int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC, 0644); |
7c673cae FG |
264 | if (fd >= 0) { |
265 | bl.write_fd(fd); | |
266 | ::close(fd); | |
267 | } | |
268 | } | |
269 | #endif | |
270 | } else { | |
271 | footer.flags = (unsigned)footer.flags | CEPH_MSG_FOOTER_NOCRC; | |
272 | } | |
273 | } | |
274 | ||
275 | void Message::dump(Formatter *f) const | |
276 | { | |
277 | stringstream ss; | |
278 | print(ss); | |
279 | f->dump_string("summary", ss.str()); | |
280 | } | |
281 | ||
282 | Message *decode_message(CephContext *cct, int crcflags, | |
283 | ceph_msg_header& header, | |
284 | ceph_msg_footer& footer, | |
285 | bufferlist& front, bufferlist& middle, | |
286 | bufferlist& data, Connection* conn) | |
287 | { | |
288 | // verify crc | |
289 | if (crcflags & MSG_CRC_HEADER) { | |
290 | __u32 front_crc = front.crc32c(0); | |
291 | __u32 middle_crc = middle.crc32c(0); | |
292 | ||
293 | if (front_crc != footer.front_crc) { | |
294 | if (cct) { | |
295 | ldout(cct, 0) << "bad crc in front " << front_crc << " != exp " << footer.front_crc << dendl; | |
296 | ldout(cct, 20) << " "; | |
297 | front.hexdump(*_dout); | |
298 | *_dout << dendl; | |
299 | } | |
300 | return 0; | |
301 | } | |
302 | if (middle_crc != footer.middle_crc) { | |
303 | if (cct) { | |
304 | ldout(cct, 0) << "bad crc in middle " << middle_crc << " != exp " << footer.middle_crc << dendl; | |
305 | ldout(cct, 20) << " "; | |
306 | middle.hexdump(*_dout); | |
307 | *_dout << dendl; | |
308 | } | |
309 | return 0; | |
310 | } | |
311 | } | |
312 | if (crcflags & MSG_CRC_DATA) { | |
313 | if ((footer.flags & CEPH_MSG_FOOTER_NOCRC) == 0) { | |
314 | __u32 data_crc = data.crc32c(0); | |
315 | if (data_crc != footer.data_crc) { | |
316 | if (cct) { | |
317 | ldout(cct, 0) << "bad crc in data " << data_crc << " != exp " << footer.data_crc << dendl; | |
318 | ldout(cct, 20) << " "; | |
319 | data.hexdump(*_dout); | |
320 | *_dout << dendl; | |
321 | } | |
322 | return 0; | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | // make message | |
328 | Message *m = 0; | |
329 | int type = header.type; | |
330 | switch (type) { | |
331 | ||
332 | // -- with payload -- | |
333 | ||
334 | case MSG_PGSTATS: | |
335 | m = new MPGStats; | |
336 | break; | |
337 | case MSG_PGSTATSACK: | |
338 | m = new MPGStatsAck; | |
339 | break; | |
340 | ||
341 | case CEPH_MSG_STATFS: | |
342 | m = new MStatfs; | |
343 | break; | |
344 | case CEPH_MSG_STATFS_REPLY: | |
345 | m = new MStatfsReply; | |
346 | break; | |
347 | case MSG_GETPOOLSTATS: | |
348 | m = new MGetPoolStats; | |
349 | break; | |
350 | case MSG_GETPOOLSTATSREPLY: | |
351 | m = new MGetPoolStatsReply; | |
352 | break; | |
353 | case CEPH_MSG_POOLOP: | |
354 | m = new MPoolOp; | |
355 | break; | |
356 | case CEPH_MSG_POOLOP_REPLY: | |
357 | m = new MPoolOpReply; | |
358 | break; | |
359 | case MSG_MON_COMMAND: | |
360 | m = new MMonCommand; | |
361 | break; | |
362 | case MSG_MON_COMMAND_ACK: | |
363 | m = new MMonCommandAck; | |
364 | break; | |
365 | case MSG_MON_PAXOS: | |
366 | m = new MMonPaxos; | |
367 | break; | |
368 | ||
369 | case MSG_MON_PROBE: | |
370 | m = new MMonProbe; | |
371 | break; | |
372 | case MSG_MON_JOIN: | |
373 | m = new MMonJoin; | |
374 | break; | |
375 | case MSG_MON_ELECTION: | |
376 | m = new MMonElection; | |
377 | break; | |
378 | case MSG_MON_SYNC: | |
379 | m = new MMonSync; | |
380 | break; | |
381 | case MSG_MON_SCRUB: | |
382 | m = new MMonScrub; | |
383 | break; | |
384 | ||
385 | case MSG_LOG: | |
386 | m = new MLog; | |
387 | break; | |
388 | case MSG_LOGACK: | |
389 | m = new MLogAck; | |
390 | break; | |
391 | ||
392 | case CEPH_MSG_PING: | |
393 | m = new MPing(); | |
394 | break; | |
395 | case MSG_COMMAND: | |
396 | m = new MCommand; | |
397 | break; | |
398 | case MSG_COMMAND_REPLY: | |
399 | m = new MCommandReply; | |
400 | break; | |
401 | case MSG_OSD_BACKFILL_RESERVE: | |
402 | m = new MBackfillReserve; | |
403 | break; | |
404 | case MSG_OSD_RECOVERY_RESERVE: | |
405 | m = new MRecoveryReserve; | |
406 | break; | |
c07f9fc5 FG |
407 | case MSG_OSD_FORCE_RECOVERY: |
408 | m = new MOSDForceRecovery; | |
409 | break; | |
7c673cae FG |
410 | |
411 | case MSG_ROUTE: | |
412 | m = new MRoute; | |
413 | break; | |
414 | case MSG_FORWARD: | |
415 | m = new MForward; | |
416 | break; | |
417 | ||
418 | case CEPH_MSG_MON_MAP: | |
419 | m = new MMonMap; | |
420 | break; | |
421 | case CEPH_MSG_MON_GET_MAP: | |
422 | m = new MMonGetMap; | |
423 | break; | |
424 | case CEPH_MSG_MON_GET_OSDMAP: | |
425 | m = new MMonGetOSDMap; | |
426 | break; | |
427 | case CEPH_MSG_MON_GET_VERSION: | |
428 | m = new MMonGetVersion(); | |
429 | break; | |
430 | case CEPH_MSG_MON_GET_VERSION_REPLY: | |
431 | m = new MMonGetVersionReply(); | |
432 | break; | |
433 | case CEPH_MSG_MON_METADATA: | |
434 | m = new MMonMetadata(); | |
435 | break; | |
436 | ||
437 | case MSG_OSD_BOOT: | |
438 | m = new MOSDBoot(); | |
439 | break; | |
440 | case MSG_OSD_ALIVE: | |
441 | m = new MOSDAlive(); | |
442 | break; | |
443 | case MSG_OSD_BEACON: | |
444 | m = new MOSDBeacon(); | |
445 | break; | |
446 | case MSG_OSD_PGTEMP: | |
447 | m = new MOSDPGTemp; | |
448 | break; | |
449 | case MSG_OSD_FAILURE: | |
450 | m = new MOSDFailure(); | |
451 | break; | |
452 | case MSG_OSD_MARK_ME_DOWN: | |
453 | m = new MOSDMarkMeDown(); | |
454 | break; | |
455 | case MSG_OSD_FULL: | |
456 | m = new MOSDFull(); | |
457 | break; | |
458 | case MSG_OSD_PING: | |
459 | m = new MOSDPing(); | |
460 | break; | |
461 | case CEPH_MSG_OSD_OP: | |
462 | m = new MOSDOp(); | |
463 | break; | |
464 | case CEPH_MSG_OSD_OPREPLY: | |
465 | m = new MOSDOpReply(); | |
466 | break; | |
467 | case MSG_OSD_SUBOP: | |
468 | m = new MOSDSubOp(); | |
469 | break; | |
470 | case MSG_OSD_SUBOPREPLY: | |
471 | m = new MOSDSubOpReply(); | |
472 | break; | |
473 | case MSG_OSD_REPOP: | |
474 | m = new MOSDRepOp(); | |
475 | break; | |
476 | case MSG_OSD_REPOPREPLY: | |
477 | m = new MOSDRepOpReply(); | |
478 | break; | |
479 | case MSG_OSD_PG_CREATED: | |
480 | m = new MOSDPGCreated(); | |
481 | break; | |
482 | case MSG_OSD_PG_UPDATE_LOG_MISSING: | |
483 | m = new MOSDPGUpdateLogMissing(); | |
484 | break; | |
485 | case MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY: | |
486 | m = new MOSDPGUpdateLogMissingReply(); | |
487 | break; | |
488 | case CEPH_MSG_OSD_BACKOFF: | |
489 | m = new MOSDBackoff; | |
490 | break; | |
491 | ||
492 | case CEPH_MSG_OSD_MAP: | |
493 | m = new MOSDMap; | |
494 | break; | |
495 | ||
496 | case CEPH_MSG_WATCH_NOTIFY: | |
497 | m = new MWatchNotify; | |
498 | break; | |
499 | ||
500 | case MSG_OSD_PG_NOTIFY: | |
501 | m = new MOSDPGNotify; | |
502 | break; | |
503 | case MSG_OSD_PG_QUERY: | |
504 | m = new MOSDPGQuery; | |
505 | break; | |
506 | case MSG_OSD_PG_LOG: | |
507 | m = new MOSDPGLog; | |
508 | break; | |
509 | case MSG_OSD_PG_REMOVE: | |
510 | m = new MOSDPGRemove; | |
511 | break; | |
512 | case MSG_OSD_PG_INFO: | |
513 | m = new MOSDPGInfo; | |
514 | break; | |
515 | case MSG_OSD_PG_CREATE: | |
516 | m = new MOSDPGCreate; | |
517 | break; | |
518 | case MSG_OSD_PG_TRIM: | |
519 | m = new MOSDPGTrim; | |
520 | break; | |
521 | ||
522 | case MSG_OSD_SCRUB: | |
523 | m = new MOSDScrub; | |
524 | break; | |
525 | case MSG_OSD_SCRUB_RESERVE: | |
526 | m = new MOSDScrubReserve; | |
527 | break; | |
528 | case MSG_REMOVE_SNAPS: | |
529 | m = new MRemoveSnaps; | |
530 | break; | |
531 | case MSG_OSD_REP_SCRUB: | |
532 | m = new MOSDRepScrub; | |
533 | break; | |
534 | case MSG_OSD_REP_SCRUBMAP: | |
535 | m = new MOSDRepScrubMap; | |
536 | break; | |
537 | case MSG_OSD_PG_SCAN: | |
538 | m = new MOSDPGScan; | |
539 | break; | |
540 | case MSG_OSD_PG_BACKFILL: | |
541 | m = new MOSDPGBackfill; | |
542 | break; | |
543 | case MSG_OSD_PG_BACKFILL_REMOVE: | |
544 | m = new MOSDPGBackfillRemove; | |
545 | break; | |
546 | case MSG_OSD_PG_PUSH: | |
547 | m = new MOSDPGPush; | |
548 | break; | |
549 | case MSG_OSD_PG_PULL: | |
550 | m = new MOSDPGPull; | |
551 | break; | |
552 | case MSG_OSD_PG_PUSH_REPLY: | |
553 | m = new MOSDPGPushReply; | |
554 | break; | |
c07f9fc5 FG |
555 | case MSG_OSD_PG_RECOVERY_DELETE: |
556 | m = new MOSDPGRecoveryDelete; | |
557 | break; | |
558 | case MSG_OSD_PG_RECOVERY_DELETE_REPLY: | |
559 | m = new MOSDPGRecoveryDeleteReply; | |
560 | break; | |
7c673cae FG |
561 | case MSG_OSD_EC_WRITE: |
562 | m = new MOSDECSubOpWrite; | |
563 | break; | |
564 | case MSG_OSD_EC_WRITE_REPLY: | |
565 | m = new MOSDECSubOpWriteReply; | |
566 | break; | |
567 | case MSG_OSD_EC_READ: | |
568 | m = new MOSDECSubOpRead; | |
569 | break; | |
570 | case MSG_OSD_EC_READ_REPLY: | |
571 | m = new MOSDECSubOpReadReply; | |
572 | break; | |
573 | // auth | |
574 | case CEPH_MSG_AUTH: | |
575 | m = new MAuth; | |
576 | break; | |
577 | case CEPH_MSG_AUTH_REPLY: | |
578 | m = new MAuthReply; | |
579 | break; | |
580 | ||
581 | case MSG_MON_GLOBAL_ID: | |
582 | m = new MMonGlobalID; | |
583 | break; | |
584 | ||
585 | // clients | |
586 | case CEPH_MSG_MON_SUBSCRIBE: | |
587 | m = new MMonSubscribe; | |
588 | break; | |
589 | case CEPH_MSG_MON_SUBSCRIBE_ACK: | |
590 | m = new MMonSubscribeAck; | |
591 | break; | |
592 | case CEPH_MSG_CLIENT_SESSION: | |
593 | m = new MClientSession; | |
594 | break; | |
595 | case CEPH_MSG_CLIENT_RECONNECT: | |
596 | m = new MClientReconnect; | |
597 | break; | |
598 | case CEPH_MSG_CLIENT_REQUEST: | |
599 | m = new MClientRequest; | |
600 | break; | |
601 | case CEPH_MSG_CLIENT_REQUEST_FORWARD: | |
602 | m = new MClientRequestForward; | |
603 | break; | |
604 | case CEPH_MSG_CLIENT_REPLY: | |
605 | m = new MClientReply; | |
606 | break; | |
607 | case CEPH_MSG_CLIENT_CAPS: | |
608 | m = new MClientCaps; | |
609 | break; | |
610 | case CEPH_MSG_CLIENT_CAPRELEASE: | |
611 | m = new MClientCapRelease; | |
612 | break; | |
613 | case CEPH_MSG_CLIENT_LEASE: | |
614 | m = new MClientLease; | |
615 | break; | |
616 | case CEPH_MSG_CLIENT_SNAP: | |
617 | m = new MClientSnap; | |
618 | break; | |
619 | case CEPH_MSG_CLIENT_QUOTA: | |
620 | m = new MClientQuota; | |
621 | break; | |
622 | ||
623 | // mds | |
624 | case MSG_MDS_SLAVE_REQUEST: | |
625 | m = new MMDSSlaveRequest; | |
626 | break; | |
627 | ||
628 | case CEPH_MSG_MDS_MAP: | |
629 | m = new MMDSMap; | |
630 | break; | |
631 | case CEPH_MSG_FS_MAP: | |
632 | m = new MFSMap; | |
633 | break; | |
634 | case CEPH_MSG_FS_MAP_USER: | |
635 | m = new MFSMapUser; | |
636 | break; | |
637 | case MSG_MDS_BEACON: | |
638 | m = new MMDSBeacon; | |
639 | break; | |
640 | case MSG_MDS_OFFLOAD_TARGETS: | |
641 | m = new MMDSLoadTargets; | |
642 | break; | |
643 | case MSG_MDS_RESOLVE: | |
644 | m = new MMDSResolve; | |
645 | break; | |
646 | case MSG_MDS_RESOLVEACK: | |
647 | m = new MMDSResolveAck; | |
648 | break; | |
649 | case MSG_MDS_CACHEREJOIN: | |
650 | m = new MMDSCacheRejoin; | |
651 | break; | |
652 | ||
653 | case MSG_MDS_DIRUPDATE: | |
654 | m = new MDirUpdate(); | |
655 | break; | |
656 | ||
657 | case MSG_MDS_DISCOVER: | |
658 | m = new MDiscover(); | |
659 | break; | |
660 | case MSG_MDS_DISCOVERREPLY: | |
661 | m = new MDiscoverReply(); | |
662 | break; | |
663 | ||
664 | case MSG_MDS_FINDINO: | |
665 | m = new MMDSFindIno; | |
666 | break; | |
667 | case MSG_MDS_FINDINOREPLY: | |
668 | m = new MMDSFindInoReply; | |
669 | break; | |
670 | ||
671 | case MSG_MDS_OPENINO: | |
672 | m = new MMDSOpenIno; | |
673 | break; | |
674 | case MSG_MDS_OPENINOREPLY: | |
675 | m = new MMDSOpenInoReply; | |
676 | break; | |
677 | ||
678 | case MSG_MDS_FRAGMENTNOTIFY: | |
679 | m = new MMDSFragmentNotify; | |
680 | break; | |
681 | ||
a8e16298 TL |
682 | case MSG_MDS_FRAGMENTNOTIFYACK: |
683 | m = new MMDSFragmentNotifyAck; | |
684 | break; | |
685 | ||
7c673cae FG |
686 | case MSG_MDS_EXPORTDIRDISCOVER: |
687 | m = new MExportDirDiscover(); | |
688 | break; | |
689 | case MSG_MDS_EXPORTDIRDISCOVERACK: | |
690 | m = new MExportDirDiscoverAck(); | |
691 | break; | |
692 | case MSG_MDS_EXPORTDIRCANCEL: | |
693 | m = new MExportDirCancel(); | |
694 | break; | |
695 | ||
696 | case MSG_MDS_EXPORTDIR: | |
697 | m = new MExportDir; | |
698 | break; | |
699 | case MSG_MDS_EXPORTDIRACK: | |
700 | m = new MExportDirAck; | |
701 | break; | |
702 | case MSG_MDS_EXPORTDIRFINISH: | |
703 | m = new MExportDirFinish; | |
704 | break; | |
705 | ||
706 | case MSG_MDS_EXPORTDIRNOTIFY: | |
707 | m = new MExportDirNotify(); | |
708 | break; | |
709 | ||
710 | case MSG_MDS_EXPORTDIRNOTIFYACK: | |
711 | m = new MExportDirNotifyAck(); | |
712 | break; | |
713 | ||
714 | case MSG_MDS_EXPORTDIRPREP: | |
715 | m = new MExportDirPrep(); | |
716 | break; | |
717 | ||
718 | case MSG_MDS_EXPORTDIRPREPACK: | |
719 | m = new MExportDirPrepAck(); | |
720 | break; | |
721 | ||
722 | case MSG_MDS_EXPORTCAPS: | |
723 | m = new MExportCaps; | |
724 | break; | |
725 | case MSG_MDS_EXPORTCAPSACK: | |
726 | m = new MExportCapsAck; | |
727 | break; | |
728 | case MSG_MDS_GATHERCAPS: | |
729 | m = new MGatherCaps; | |
730 | break; | |
731 | ||
732 | ||
733 | case MSG_MDS_DENTRYUNLINK: | |
734 | m = new MDentryUnlink; | |
735 | break; | |
736 | case MSG_MDS_DENTRYLINK: | |
737 | m = new MDentryLink; | |
738 | break; | |
739 | ||
740 | case MSG_MDS_HEARTBEAT: | |
741 | m = new MHeartbeat(); | |
742 | break; | |
743 | ||
744 | case MSG_MDS_CACHEEXPIRE: | |
745 | m = new MCacheExpire(); | |
746 | break; | |
747 | ||
748 | case MSG_MDS_TABLE_REQUEST: | |
749 | m = new MMDSTableRequest; | |
750 | break; | |
751 | ||
752 | /* case MSG_MDS_INODEUPDATE: | |
753 | m = new MInodeUpdate(); | |
754 | break; | |
755 | */ | |
756 | ||
757 | case MSG_MDS_INODEFILECAPS: | |
758 | m = new MInodeFileCaps(); | |
759 | break; | |
760 | ||
761 | case MSG_MDS_LOCK: | |
762 | m = new MLock(); | |
763 | break; | |
764 | ||
765 | case MSG_MGR_BEACON: | |
766 | m = new MMgrBeacon(); | |
767 | break; | |
768 | ||
31f18b77 FG |
769 | case MSG_MON_MGR_REPORT: |
770 | m = new MMonMgrReport(); | |
771 | break; | |
772 | ||
224ce89b WB |
773 | case MSG_SERVICE_MAP: |
774 | m = new MServiceMap(); | |
775 | break; | |
776 | ||
7c673cae FG |
777 | case MSG_MGR_MAP: |
778 | m = new MMgrMap(); | |
779 | break; | |
780 | ||
781 | case MSG_MGR_DIGEST: | |
782 | m = new MMgrDigest(); | |
783 | break; | |
784 | ||
785 | case MSG_MGR_OPEN: | |
786 | m = new MMgrOpen(); | |
787 | break; | |
788 | ||
789 | case MSG_MGR_REPORT: | |
790 | m = new MMgrReport(); | |
791 | break; | |
792 | ||
793 | case MSG_MGR_CONFIGURE: | |
794 | m = new MMgrConfigure(); | |
795 | break; | |
796 | ||
797 | case MSG_TIMECHECK: | |
798 | m = new MTimeCheck(); | |
799 | break; | |
800 | ||
801 | case MSG_MON_HEALTH: | |
802 | m = new MMonHealth(); | |
803 | break; | |
224ce89b WB |
804 | |
805 | case MSG_MON_HEALTH_CHECKS: | |
806 | m = new MMonHealthChecks(); | |
807 | break; | |
808 | ||
7c673cae FG |
809 | #if defined(HAVE_XIO) |
810 | case MSG_DATA_PING: | |
811 | m = new MDataPing(); | |
812 | break; | |
813 | #endif | |
814 | // -- simple messages without payload -- | |
815 | ||
816 | case CEPH_MSG_SHUTDOWN: | |
817 | m = new MGenericMessage(type); | |
818 | break; | |
819 | ||
820 | default: | |
821 | if (cct) { | |
822 | ldout(cct, 0) << "can't decode unknown message type " << type << " MSG_AUTH=" << CEPH_MSG_AUTH << dendl; | |
823 | if (cct->_conf->ms_die_on_bad_msg) | |
824 | ceph_abort(); | |
825 | } | |
826 | return 0; | |
827 | } | |
828 | ||
829 | m->set_cct(cct); | |
830 | ||
831 | // m->header.version, if non-zero, should be populated with the | |
832 | // newest version of the encoding the code supports. If set, check | |
833 | // it against compat_version. | |
834 | if (m->get_header().version && | |
835 | m->get_header().version < header.compat_version) { | |
836 | if (cct) { | |
837 | ldout(cct, 0) << "will not decode message of type " << type | |
838 | << " version " << header.version | |
839 | << " because compat_version " << header.compat_version | |
840 | << " > supported version " << m->get_header().version << dendl; | |
841 | if (cct->_conf->ms_die_on_bad_msg) | |
842 | ceph_abort(); | |
843 | } | |
844 | m->put(); | |
845 | return 0; | |
846 | } | |
847 | ||
848 | m->set_connection(conn); | |
849 | m->set_header(header); | |
850 | m->set_footer(footer); | |
851 | m->set_payload(front); | |
852 | m->set_middle(middle); | |
853 | m->set_data(data); | |
854 | ||
855 | try { | |
856 | m->decode_payload(); | |
857 | } | |
858 | catch (const buffer::error &e) { | |
859 | if (cct) { | |
860 | lderr(cct) << "failed to decode message of type " << type | |
861 | << " v" << header.version | |
862 | << ": " << e.what() << dendl; | |
863 | ldout(cct, cct->_conf->ms_dump_corrupt_message_level) << "dump: \n"; | |
864 | m->get_payload().hexdump(*_dout); | |
865 | *_dout << dendl; | |
866 | if (cct->_conf->ms_die_on_bad_msg) | |
867 | ceph_abort(); | |
868 | } | |
869 | m->put(); | |
870 | return 0; | |
871 | } | |
872 | ||
873 | // done! | |
874 | return m; | |
875 | } | |
876 | ||
877 | void Message::encode_trace(bufferlist &bl, uint64_t features) const | |
878 | { | |
879 | auto p = trace.get_info(); | |
880 | static const blkin_trace_info empty = { 0, 0, 0 }; | |
881 | if (!p) { | |
882 | p = ∅ | |
883 | } | |
884 | ::encode(*p, bl); | |
885 | } | |
886 | ||
887 | void Message::decode_trace(bufferlist::iterator &p, bool create) | |
888 | { | |
889 | blkin_trace_info info = {}; | |
890 | ::decode(info, p); | |
891 | ||
892 | #ifdef WITH_BLKIN | |
893 | if (!connection) | |
894 | return; | |
895 | ||
896 | const auto msgr = connection->get_messenger(); | |
897 | const auto endpoint = msgr->get_trace_endpoint(); | |
898 | if (info.trace_id) { | |
899 | trace.init(get_type_name(), endpoint, &info, true); | |
900 | trace.event("decoded trace"); | |
901 | } else if (create || (msgr->get_myname().is_osd() && | |
902 | msgr->cct->_conf->osd_blkin_trace_all)) { | |
903 | // create a trace even if we didn't get one on the wire | |
904 | trace.init(get_type_name(), endpoint); | |
905 | trace.event("created trace"); | |
906 | } | |
907 | trace.keyval("tid", get_tid()); | |
908 | trace.keyval("entity type", get_source().type_str()); | |
909 | trace.keyval("entity num", get_source().num()); | |
910 | #endif | |
911 | } | |
912 | ||
913 | ||
914 | // This routine is not used for ordinary messages, but only when encapsulating a message | |
915 | // for forwarding and routing. It's also used in a backward compatibility test, which only | |
916 | // effectively tests backward compability for those functions. To avoid backward compatibility | |
917 | // problems, we currently always encode and decode using the old footer format that doesn't | |
918 | // allow for message authentication. Eventually we should fix that. PLR | |
919 | ||
920 | void encode_message(Message *msg, uint64_t features, bufferlist& payload) | |
921 | { | |
922 | bufferlist front, middle, data; | |
923 | ceph_msg_footer_old old_footer; | |
924 | ceph_msg_footer footer; | |
925 | msg->encode(features, MSG_CRC_ALL); | |
926 | ::encode(msg->get_header(), payload); | |
927 | ||
928 | // Here's where we switch to the old footer format. PLR | |
929 | ||
930 | footer = msg->get_footer(); | |
931 | old_footer.front_crc = footer.front_crc; | |
932 | old_footer.middle_crc = footer.middle_crc; | |
933 | old_footer.data_crc = footer.data_crc; | |
934 | old_footer.flags = footer.flags; | |
935 | ::encode(old_footer, payload); | |
936 | ||
937 | ::encode(msg->get_payload(), payload); | |
938 | ::encode(msg->get_middle(), payload); | |
939 | ::encode(msg->get_data(), payload); | |
940 | } | |
941 | ||
942 | // See above for somewhat bogus use of the old message footer. We switch to the current footer | |
943 | // after decoding the old one so the other form of decode_message() doesn't have to change. | |
944 | // We've slipped in a 0 signature at this point, so any signature checking after this will | |
945 | // fail. PLR | |
946 | ||
947 | Message *decode_message(CephContext *cct, int crcflags, bufferlist::iterator& p) | |
948 | { | |
949 | ceph_msg_header h; | |
950 | ceph_msg_footer_old fo; | |
951 | ceph_msg_footer f; | |
952 | bufferlist fr, mi, da; | |
953 | ::decode(h, p); | |
954 | ::decode(fo, p); | |
955 | f.front_crc = fo.front_crc; | |
956 | f.middle_crc = fo.middle_crc; | |
957 | f.data_crc = fo.data_crc; | |
958 | f.flags = fo.flags; | |
959 | f.sig = 0; | |
960 | ::decode(fr, p); | |
961 | ::decode(mi, p); | |
962 | ::decode(da, p); | |
963 | return decode_message(cct, crcflags, h, f, fr, mi, da, nullptr); | |
964 | } | |
965 |