]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | /** | |
17 | * This is used to send pings between daemons (so far, the OSDs) for | |
18 | * heartbeat purposes. We include a timestamp and distinguish between | |
19 | * outgoing pings and responses to those. If you set the | |
20 | * min_message in the constructor, the message will inflate itself | |
21 | * to the specified size -- this is good for dealing with network | |
22 | * issues with jumbo frames. See http://tracker.ceph.com/issues/20087 | |
23 | * | |
24 | */ | |
25 | ||
26 | #ifndef CEPH_MOSDPING_H | |
27 | #define CEPH_MOSDPING_H | |
28 | ||
29 | #include "common/Clock.h" | |
30 | ||
31 | #include "msg/Message.h" | |
32 | #include "osd/osd_types.h" | |
33 | ||
34 | ||
35 | class MOSDPing : public Message { | |
36 | ||
37 | static const int HEAD_VERSION = 4; | |
38 | static const int COMPAT_VERSION = 4; | |
39 | ||
40 | public: | |
41 | enum { | |
42 | HEARTBEAT = 0, | |
43 | START_HEARTBEAT = 1, | |
44 | YOU_DIED = 2, | |
45 | STOP_HEARTBEAT = 3, | |
46 | PING = 4, | |
47 | PING_REPLY = 5, | |
48 | }; | |
49 | const char *get_op_name(int op) const { | |
50 | switch (op) { | |
51 | case HEARTBEAT: return "heartbeat"; | |
52 | case START_HEARTBEAT: return "start_heartbeat"; | |
53 | case STOP_HEARTBEAT: return "stop_heartbeat"; | |
54 | case YOU_DIED: return "you_died"; | |
55 | case PING: return "ping"; | |
56 | case PING_REPLY: return "ping_reply"; | |
57 | default: return "???"; | |
58 | } | |
59 | } | |
60 | ||
61 | uuid_d fsid; | |
62 | epoch_t map_epoch = 0; | |
63 | __u8 op = 0; | |
64 | utime_t stamp; | |
65 | uint32_t min_message_size; | |
66 | ||
67 | MOSDPing(const uuid_d& f, epoch_t e, __u8 o, utime_t s, uint32_t min_message) | |
68 | : Message(MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION), | |
69 | fsid(f), map_epoch(e), op(o), stamp(s), min_message_size(min_message) | |
70 | { } | |
71 | MOSDPing() | |
72 | : Message(MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION), min_message_size(0) | |
73 | {} | |
74 | private: | |
75 | ~MOSDPing() override {} | |
76 | ||
77 | public: | |
78 | void decode_payload() override { | |
79 | bufferlist::iterator p = payload.begin(); | |
80 | ::decode(fsid, p); | |
81 | ::decode(map_epoch, p); | |
82 | if (header.version < 4) { | |
83 | osd_peer_stat_t peer_stat; | |
84 | epoch_t peer_as_of_epoch; | |
85 | ::decode(peer_as_of_epoch, p); | |
86 | ::decode(op, p); | |
87 | ::decode(peer_stat, p); | |
88 | } else { | |
89 | ::decode(op, p); | |
90 | } | |
91 | ::decode(stamp, p); | |
92 | if (header.version >= 3) { | |
93 | int payload_mid_length = p.get_off(); | |
94 | uint32_t size; | |
95 | ::decode(size, p); | |
96 | p.advance(size); | |
97 | min_message_size = size + payload_mid_length; | |
98 | } | |
99 | } | |
100 | void encode_payload(uint64_t features) override { | |
101 | ::encode(fsid, payload); | |
102 | ::encode(map_epoch, payload); | |
103 | ||
104 | // with luminous, we drop peer_as_of_epoch and peer_stat | |
105 | if (HAVE_FEATURE(features, SERVER_LUMINOUS)) { | |
106 | header.version = HEAD_VERSION; | |
107 | ::encode(op, payload); | |
108 | } else { | |
109 | epoch_t dummy_epoch = {}; | |
110 | osd_peer_stat_t dummy_stat = {}; | |
111 | header.version = 3; | |
112 | header.compat_version = 2; | |
113 | ::encode(dummy_epoch, payload); | |
114 | ::encode(op, payload); | |
115 | ::encode(dummy_stat, payload); | |
116 | } | |
117 | ::encode(stamp, payload); | |
118 | size_t s = 0; | |
119 | if (min_message_size > payload.length()) | |
120 | s = min_message_size - payload.length(); | |
121 | ::encode((uint32_t)s, payload); | |
122 | if (s) { | |
123 | // this should be big enough for normal min_message padding sizes. since | |
124 | // we are targetting jumbo ethernet frames around 9000 bytes, 16k should | |
125 | // be more than sufficient! the compiler will statically zero this so | |
126 | // that at runtime we are only adding a bufferptr reference to it. | |
127 | static char zeros[16384] = {}; | |
128 | while (s > sizeof(zeros)) { | |
129 | payload.append(buffer::create_static(sizeof(zeros), zeros)); | |
130 | s -= sizeof(zeros); | |
131 | } | |
132 | if (s) { | |
133 | payload.append(buffer::create_static(s, zeros)); | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | const char *get_type_name() const override { return "osd_ping"; } | |
139 | void print(ostream& out) const override { | |
140 | out << "osd_ping(" << get_op_name(op) | |
141 | << " e" << map_epoch | |
142 | << " stamp " << stamp | |
143 | << ")"; | |
144 | } | |
145 | }; | |
146 | ||
147 | #endif |