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   	private:
37   	  static constexpr int HEAD_VERSION = 5;
38   	  static constexpr 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 ping_stamp;               ///< when the PING was sent
65   	  ceph::signedspan mono_ping_stamp; ///< relative to sender's clock
66   	  ceph::signedspan mono_send_stamp; ///< replier's send stamp
67   	  std::optional<ceph::time_detail::signedspan> delta_ub;  ///< ping sender
68   	  epoch_t up_from = 0;
69   	
70   	  uint32_t min_message_size = 0;
71   	
72   	  MOSDPing(const uuid_d& f, epoch_t e, __u8 o,
73   		   utime_t s,
74   		   ceph::signedspan ms,
75   		   ceph::signedspan mss,
76   		   epoch_t upf,
77   		   uint32_t min_message,
78   		   std::optional<ceph::time_detail::signedspan> delta_ub = {})
79   	    : Message{MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION},
80   	      fsid(f), map_epoch(e), op(o),
81   	      ping_stamp(s),
82   	      mono_ping_stamp(ms),
83   	      mono_send_stamp(mss),
84   	      delta_ub(delta_ub),
85   	      up_from(upf),
86   	      min_message_size(min_message)
87   	  { }
88   	  MOSDPing()
89   	    : Message{MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION}
(2) Event uninit_member: Non-static class member field "mono_ping_stamp.__r" is not initialized in this constructor nor in any functions that it calls.
(4) Event uninit_member: Non-static class member field "mono_send_stamp.__r" is not initialized in this constructor nor in any functions that it calls.
Also see events: [member_decl][member_decl]
90   	  {}
91   	private:
92   	  ~MOSDPing() override {}
93   	
94   	public:
95   	  void decode_payload() override {
96   	    auto p = payload.cbegin();
97   	    decode(fsid, p);
98   	    decode(map_epoch, p);
99   	    decode(op, p);
100  	    decode(ping_stamp, p);
101  	
102  	    int payload_mid_length = p.get_off();
103  	    uint32_t size;
104  	    decode(size, p);
105  	
106  	    if (header.version >= 5) {
107  	      decode(up_from, p);
108  	      decode(mono_ping_stamp, p);
109  	      decode(mono_send_stamp, p);
110  	      decode(delta_ub, p);
111  	    }
112  	
113  	    p.advance(size);
114  	    min_message_size = size + payload_mid_length;
115  	  }
116  	  void encode_payload(uint64_t features) override {
117  	    using ceph::encode;
118  	    encode(fsid, payload);
119  	    encode(map_epoch, payload);
120  	    encode(op, payload);
121  	    encode(ping_stamp, payload);
122  	
123  	    size_t s = 0;
124  	    if (min_message_size > payload.length()) {
125  	      s = min_message_size - payload.length();
126  	    }
127  	    encode((uint32_t)s, payload);
128  	
129  	    encode(up_from, payload);
130  	    encode(mono_ping_stamp, payload);
131  	    encode(mono_send_stamp, payload);
132  	    encode(delta_ub, payload);
133  	
134  	    if (s) {
135  	      // this should be big enough for normal min_message padding sizes. since
136  	      // we are targeting jumbo ethernet frames around 9000 bytes, 16k should
137  	      // be more than sufficient!  the compiler will statically zero this so
138  	      // that at runtime we are only adding a bufferptr reference to it.
139  	      static char zeros[16384] = {};
140  	      while (s > sizeof(zeros)) {
141  	        payload.append(buffer::create_static(sizeof(zeros), zeros));
142  	        s -= sizeof(zeros);
143  	      }
144  	      if (s) {
145  	        payload.append(buffer::create_static(s, zeros));
146  	      }
147  	    }
148  	  }
149  	
150  	  std::string_view get_type_name() const override { return "osd_ping"; }
151  	  void print(ostream& out) const override {
152  	    out << "osd_ping(" << get_op_name(op)
153  		<< " e" << map_epoch
154  		<< " up_from " << up_from
155  		<< " ping_stamp " << ping_stamp << "/" << mono_ping_stamp
156  		<< " send_stamp " << mono_send_stamp;
157  	    if (delta_ub) {
158  	      out << " delta_ub " << *delta_ub;
159  	    }
160  	    out << ")";
161  	  }
162  	private:
163  	  template<class T, typename... Args>
164  	  friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
165  	};
166  	
167  	#endif
168