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
= 3;
38 static const int COMPAT_VERSION
= 2;
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 "???";
62 epoch_t map_epoch
, peer_as_of_epoch
;
64 osd_peer_stat_t peer_stat
;
66 uint32_t min_message_size
;
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
)
74 : Message(MSG_OSD_PING
, HEAD_VERSION
, COMPAT_VERSION
), min_message_size(0)
77 ~MOSDPing() override
{}
80 void decode_payload() override
{
81 bufferlist::iterator p
= payload
.begin();
83 ::decode(map_epoch
, p
);
84 ::decode(peer_as_of_epoch
, p
);
86 ::decode(peer_stat
, p
);
88 if (header
.version
>= 3) {
89 int payload_mid_length
= p
.get_off();
93 min_message_size
= size
+ payload_mid_length
;
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
);
105 if (min_message_size
> payload
.length())
106 s
= min_message_size
- payload
.length();
107 ::encode((uint32_t)s
, payload
);
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
));
119 payload
.append(buffer::create_static(s
, zeros
));
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
)
128 //<< " as_of " << peer_as_of_epoch
129 << " stamp " << stamp