1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
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
26 #ifndef CEPH_MOSDPING_H
27 #define CEPH_MOSDPING_H
29 #include "common/Clock.h"
31 #include "msg/Message.h"
32 #include "osd/osd_types.h"
35 class MOSDPing
: public Message
{
37 static const int HEAD_VERSION
= 4;
38 static const int COMPAT_VERSION
= 4;
49 const char *get_op_name(int op
) const {
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 "???";
65 uint32_t min_message_size
;
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
)
72 : Message(MSG_OSD_PING
, HEAD_VERSION
, COMPAT_VERSION
), min_message_size(0)
75 ~MOSDPing() override
{}
78 void decode_payload() override
{
79 bufferlist::iterator p
= payload
.begin();
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
);
87 ::decode(peer_stat
, p
);
92 if (header
.version
>= 3) {
93 int payload_mid_length
= p
.get_off();
97 min_message_size
= size
+ payload_mid_length
;
100 void encode_payload(uint64_t features
) override
{
101 ::encode(fsid
, payload
);
102 ::encode(map_epoch
, payload
);
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
);
109 epoch_t dummy_epoch
= {};
110 osd_peer_stat_t dummy_stat
= {};
112 header
.compat_version
= 2;
113 ::encode(dummy_epoch
, payload
);
114 ::encode(op
, payload
);
115 ::encode(dummy_stat
, payload
);
117 ::encode(stamp
, payload
);
119 if (min_message_size
> payload
.length())
120 s
= min_message_size
- payload
.length();
121 ::encode((uint32_t)s
, payload
);
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
));
133 payload
.append(buffer::create_static(s
, zeros
));
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
)
142 << " stamp " << stamp