]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MOSDPing.h
update sources to v12.1.1
[ceph.git] / ceph / src / messages / MOSDPing.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) 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;
63 __u8 op;
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 epoch_t dummy_epoch = {};
107 osd_peer_stat_t dummy_stat = {};
108 header.version = 3;
109 header.compat_version = 2;
110 ::encode(dummy_epoch, payload);
111 ::encode(op, payload);
112 ::encode(dummy_stat, payload);
113 } else {
114 ::encode(op, payload);
115 }
116 ::encode(stamp, payload);
117 size_t s = 0;
118 if (min_message_size > payload.length())
119 s = min_message_size - payload.length();
120 ::encode((uint32_t)s, payload);
121 if (s) {
122 // this should be big enough for normal min_message padding sizes. since
123 // we are targetting jumbo ethernet frames around 9000 bytes, 16k should
124 // be more than sufficient! the compiler will statically zero this so
125 // that at runtime we are only adding a bufferptr reference to it.
126 static char zeros[16384] = {};
127 while (s > sizeof(zeros)) {
128 payload.append(buffer::create_static(sizeof(zeros), zeros));
129 s -= sizeof(zeros);
130 }
131 if (s) {
132 payload.append(buffer::create_static(s, zeros));
133 }
134 }
135 }
136
137 const char *get_type_name() const override { return "osd_ping"; }
138 void print(ostream& out) const override {
139 out << "osd_ping(" << get_op_name(op)
140 << " e" << map_epoch
141 << " stamp " << stamp
142 << ")";
143 }
144 };
145
146 #endif