]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MOSDPing.h
f9b775a0de35a4ea07f3b109e2e176364608eec7
[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 = 3;
38 static const int COMPAT_VERSION = 2;
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, peer_as_of_epoch;
63 __u8 op;
64 osd_peer_stat_t peer_stat;
65 utime_t stamp;
66 uint32_t min_message_size;
67
68 MOSDPing(const uuid_d& f, epoch_t e, __u8 o, utime_t s, uint32_t min_message)
69 : Message(MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION),
70 fsid(f), map_epoch(e), peer_as_of_epoch(0), op(o), stamp(s),
71 min_message_size(min_message)
72 { }
73 MOSDPing()
74 : Message(MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION), min_message_size(0)
75 {}
76 private:
77 ~MOSDPing() override {}
78
79 public:
80 void decode_payload() override {
81 bufferlist::iterator p = payload.begin();
82 ::decode(fsid, p);
83 ::decode(map_epoch, p);
84 ::decode(peer_as_of_epoch, p);
85 ::decode(op, p);
86 ::decode(peer_stat, p);
87 ::decode(stamp, p);
88 if (header.version >= 3) {
89 int payload_mid_length = p.get_off();
90 uint32_t size;
91 ::decode(size, p);
92 p.advance(size);
93 min_message_size = size + payload_mid_length;
94 }
95 }
96 void encode_payload(uint64_t features) override {
97 ::encode(fsid, payload);
98 ::encode(map_epoch, payload);
99 ::encode(peer_as_of_epoch, payload);
100 ::encode(op, payload);
101 ::encode(peer_stat, payload);
102 ::encode(stamp, payload);
103
104 size_t s = 0;
105 if (min_message_size > payload.length())
106 s = min_message_size - payload.length();
107 ::encode((uint32_t)s, payload);
108 if (s) {
109 // this should be big enough for normal min_message padding sizes. since
110 // we are targetting jumbo ethernet frames around 9000 bytes, 16k should
111 // be more than sufficient! the compiler will statically zero this so
112 // that at runtime we are only adding a bufferptr reference to it.
113 static char zeros[16384] = {};
114 while (s > sizeof(zeros)) {
115 payload.append(buffer::create_static(sizeof(zeros), zeros));
116 s -= sizeof(zeros);
117 }
118 if (s) {
119 payload.append(buffer::create_static(s, zeros));
120 }
121 }
122 }
123
124 const char *get_type_name() const override { return "osd_ping"; }
125 void print(ostream& out) const override {
126 out << "osd_ping(" << get_op_name(op)
127 << " e" << map_epoch
128 //<< " as_of " << peer_as_of_epoch
129 << " stamp " << stamp
130 << ")";
131 }
132 };
133
134 #endif