From e3b2225f0b12de8a9eb94d3deeeb27d7dd2b133b Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 19 May 2016 12:56:39 +0100 Subject: [PATCH] messages: add ceph-mgr messages Signed-off-by: John Spray --- src/messages/MMDSMap.h | 31 ++--------- src/messages/MMgrBeacon.h | 69 +++++++++++++++++++++++ src/messages/MMgrConfigure.h | 53 ++++++++++++++++++ src/messages/MMgrDigest.h | 53 ++++++++++++++++++ src/messages/MMgrMap.h | 54 ++++++++++++++++++ src/messages/MMgrOpen.h | 50 +++++++++++++++++ src/messages/MMgrReport.h | 105 +++++++++++++++++++++++++++++++++++ src/msg/Message.cc | 31 +++++++++++ src/msg/Message.h | 14 +++++ 9 files changed, 434 insertions(+), 26 deletions(-) create mode 100644 src/messages/MMgrBeacon.h create mode 100644 src/messages/MMgrConfigure.h create mode 100644 src/messages/MMgrDigest.h create mode 100644 src/messages/MMgrMap.h create mode 100644 src/messages/MMgrOpen.h create mode 100644 src/messages/MMgrReport.h diff --git a/src/messages/MMDSMap.h b/src/messages/MMDSMap.h index 36b9e958144..d177369ce75 100644 --- a/src/messages/MMDSMap.h +++ b/src/messages/MMDSMap.h @@ -21,31 +21,10 @@ #include "include/ceph_features.h" class MMDSMap : public Message { - public: - /* - map maps; - map incremental_maps; + static const int HEAD_VERSION = 1; + static const int COMPAT_VERSION = 1; +public: - epoch_t get_first() { - epoch_t e = 0; - map::iterator i = maps.begin(); - if (i != maps.end()) e = i->first; - i = incremental_maps.begin(); - if (i != incremental_maps.end() && - (e == 0 || i->first < e)) e = i->first; - return e; - } - epoch_t get_last() { - epoch_t e = 0; - map::reverse_iterator i = maps.rbegin(); - if (i != maps.rend()) e = i->first; - i = incremental_maps.rbegin(); - if (i != incremental_maps.rend() && - (e == 0 || i->first > e)) e = i->first; - return e; - } - */ - uuid_d fsid; epoch_t epoch; bufferlist encoded; @@ -54,9 +33,9 @@ class MMDSMap : public Message { bufferlist& get_encoded() { return encoded; } MMDSMap() : - Message(CEPH_MSG_MDS_MAP) {} + Message(CEPH_MSG_MDS_MAP, HEAD_VERSION, COMPAT_VERSION) {} MMDSMap(const uuid_d &f, MDSMap *mm) : - Message(CEPH_MSG_MDS_MAP), + Message(CEPH_MSG_MDS_MAP, HEAD_VERSION, COMPAT_VERSION), fsid(f) { epoch = mm->get_epoch(); mm->encode(encoded, -1); // we will reencode with fewer features as necessary diff --git a/src/messages/MMgrBeacon.h b/src/messages/MMgrBeacon.h new file mode 100644 index 00000000000..e38227e2421 --- /dev/null +++ b/src/messages/MMgrBeacon.h @@ -0,0 +1,69 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#ifndef CEPH_MMGRBEACON_H +#define CEPH_MMGRBEACON_H + +#include "messages/PaxosServiceMessage.h" + +#include "include/types.h" + + +class MMgrBeacon : public PaxosServiceMessage { + + static const int HEAD_VERSION = 1; + static const int COMPAT_VERSION = 1; + +protected: + uint64_t gid; + entity_addr_t server_addr; + +public: + MMgrBeacon() + : PaxosServiceMessage(MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION) + { + } + + MMgrBeacon(uint64_t gid_, entity_addr_t server_addr_) + : PaxosServiceMessage(MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION), + gid(gid_), server_addr(server_addr_) + { + } + + uint64_t get_gid() const { return gid; } + entity_addr_t get_server_addr() const { return server_addr; } + +private: + ~MMgrBeacon() {} + +public: + + const char *get_type_name() const { return "mgrbeacon"; } + + void print(ostream& out) const { + out << get_type_name() << "(" << gid << ", " << server_addr << ")"; + } + + void encode_payload(uint64_t features) { + paxos_encode(); + ::encode(server_addr, payload, features); + } + void decode_payload() { + bufferlist::iterator p = payload.begin(); + paxos_decode(p); + ::decode(server_addr, p); + } +}; + +#endif diff --git a/src/messages/MMgrConfigure.h b/src/messages/MMgrConfigure.h new file mode 100644 index 00000000000..e9b7439a9fa --- /dev/null +++ b/src/messages/MMgrConfigure.h @@ -0,0 +1,53 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + + +#ifndef CEPH_MMGRCONFIGURE_H_ +#define CEPH_MMGRCONFIGURE_H_ + +#include "msg/Message.h" + +/** + * This message is sent from ceph-mgr to MgrClient, instructing it + * it about what data to send back to ceph-mgr at what frequency. + */ +class MMgrConfigure : public Message +{ + static const int HEAD_VERSION = 1; + static const int COMPAT_VERSION = 1; + +public: + uint32_t stats_period; + + void decode_payload() + { + bufferlist::iterator p = payload.begin(); + ::decode(stats_period, p); + } + + void encode_payload(uint64_t features) { + ::encode(stats_period, payload); + } + + const char *get_type_name() const { return "mgrconfigure"; } + void print(ostream& out) const { + out << get_type_name() << "()"; + } + + MMgrConfigure() + : Message(MSG_MGR_CONFIGURE, HEAD_VERSION, COMPAT_VERSION) + {} +}; + +#endif + diff --git a/src/messages/MMgrDigest.h b/src/messages/MMgrDigest.h new file mode 100644 index 00000000000..3823a1d50ee --- /dev/null +++ b/src/messages/MMgrDigest.h @@ -0,0 +1,53 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + + +#ifndef CEPH_MMGRDIGEST_H +#define CEPH_MMGRDIGEST_H + +#include "msg/Message.h" + +/** + * The mgr digest is a way for the mgr to subscribe to things + * other than the cluster maps, which are needed by + */ +class MMgrDigest : public Message { +public: + bufferlist mon_status_json; + bufferlist health_json; + + MMgrDigest() : + Message(MSG_MGR_DIGEST) {} + + const char *get_type_name() const { return "mgrdigest"; } + void print(ostream& out) const { + out << get_type_name(); + } + + void decode_payload() { + bufferlist::iterator p = payload.begin(); + ::decode(mon_status_json, p); + ::decode(health_json, p); + } + void encode_payload(uint64_t features) { + ::encode(mon_status_json, payload); + ::encode(health_json, payload); + } + +private: + ~MMgrDigest() {} + +}; + +#endif diff --git a/src/messages/MMgrMap.h b/src/messages/MMgrMap.h new file mode 100644 index 00000000000..00dfcb8168c --- /dev/null +++ b/src/messages/MMgrMap.h @@ -0,0 +1,54 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + + +#ifndef CEPH_MMGRMAP_H +#define CEPH_MMGRMAP_H + +#include "msg/Message.h" +#include "mon/MgrMap.h" + +class MMgrMap : public Message { +protected: + MgrMap map; + +public: + const MgrMap & get_map() {return map;} + + MMgrMap() : + Message(MSG_MGR_MAP) {} + MMgrMap(const MgrMap &map_) : + Message(MSG_MGR_MAP), map(map_) + { + } + +private: + ~MMgrMap() {} + +public: + const char *get_type_name() const { return "mgrmap"; } + void print(ostream& out) const { + out << get_type_name() << "(e " << map.epoch << ")"; + } + + void decode_payload() { + bufferlist::iterator p = payload.begin(); + ::decode(map, p); + } + void encode_payload(uint64_t features) { + ::encode(map, payload, features); + } +}; + +#endif diff --git a/src/messages/MMgrOpen.h b/src/messages/MMgrOpen.h new file mode 100644 index 00000000000..2fdfa055b78 --- /dev/null +++ b/src/messages/MMgrOpen.h @@ -0,0 +1,50 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + + +#ifndef CEPH_MMGROPEN_H_ +#define CEPH_MMGROPEN_H_ + +#include "msg/Message.h" + +class MMgrOpen : public Message +{ + static const int HEAD_VERSION = 1; + static const int COMPAT_VERSION = 1; + +public: + + std::string daemon_name; + + void decode_payload() + { + bufferlist::iterator p = payload.begin(); + ::decode(daemon_name, p); + } + + void encode_payload(uint64_t features) { + ::encode(daemon_name, payload); + } + + const char *get_type_name() const { return "mgropen"; } + void print(ostream& out) const { + out << get_type_name() << "(" << daemon_name << ")"; + } + + MMgrOpen() + : Message(MSG_MGR_OPEN, HEAD_VERSION, COMPAT_VERSION) + {} +}; + +#endif + diff --git a/src/messages/MMgrReport.h b/src/messages/MMgrReport.h new file mode 100644 index 00000000000..907cf47e014 --- /dev/null +++ b/src/messages/MMgrReport.h @@ -0,0 +1,105 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + + +#ifndef CEPH_MMGRREPORT_H_ +#define CEPH_MMGRREPORT_H_ + +#include "msg/Message.h" + +#include "common/perf_counters.h" + +class PerfCounterType +{ +public: + std::string path; + std::string description; + std::string nick; + enum perfcounter_type_d type; + + void encode(bufferlist &bl) const + { + // TODO: decide whether to drop the per-type + // encoding here, we could rely on the MgrReport + // verisoning instead. + ENCODE_START(1, 1, bl); + ::encode(path, bl); + ::encode(description, bl); + ::encode(nick, bl); + assert(type < 256); + ::encode((uint8_t)type, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator &p) + { + DECODE_START(1, p); + ::decode(path, p); + ::decode(description, p); + ::decode(nick, p); + ::decode((uint8_t&)type, p); + DECODE_FINISH(p); + } +}; +WRITE_CLASS_ENCODER(PerfCounterType) + +class MMgrReport : public Message +{ + static const int HEAD_VERSION = 1; + static const int COMPAT_VERSION = 1; + +public: + /** + * Client is responsible for remembering whether it has introduced + * each perf counter to the server. When first sending a particular + * counter, it must inline the counter's schema here. + */ + std::vector declare_types; + + // For all counters present, sorted by idx, output + // as many bytes as are needed to represent them + + // Decode: iterate over the types we know about, sorted by idx, + // and use the current type's type to decide how to decode + // the next bytes from the bufferlist. + bufferlist packed; + + std::string daemon_name; + + void decode_payload() + { + bufferlist::iterator p = payload.begin(); + ::decode(daemon_name, p); + ::decode(declare_types, p); + ::decode(packed, p); + } + + void encode_payload(uint64_t features) { + ::encode(daemon_name, payload); + ::encode(declare_types, payload); + ::encode(packed, payload); + } + + const char *get_type_name() const { return "mgrreport"; } + void print(ostream& out) const { + out << get_type_name() << "(" << declare_types.size() << " " + << packed.length() << ")"; + } + + MMgrReport() + : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION) + {} +}; + +#endif + diff --git a/src/msg/Message.cc b/src/msg/Message.cc index 743c89c33e1..7b87667f384 100644 --- a/src/msg/Message.cc +++ b/src/msg/Message.cc @@ -156,6 +156,13 @@ using namespace std; #include "messages/MCacheExpire.h" #include "messages/MInodeFileCaps.h" +#include "messages/MMgrBeacon.h" +#include "messages/MMgrMap.h" +#include "messages/MMgrDigest.h" +#include "messages/MMgrReport.h" +#include "messages/MMgrOpen.h" +#include "messages/MMgrConfigure.h" + #include "messages/MLock.h" #include "messages/MWatchNotify.h" @@ -706,6 +713,30 @@ Message *decode_message(CephContext *cct, int crcflags, m = new MLock(); break; + case MSG_MGR_BEACON: + m = new MMgrBeacon(); + break; + + case MSG_MGR_MAP: + m = new MMgrMap(); + break; + + case MSG_MGR_DIGEST: + m = new MMgrDigest(); + break; + + case MSG_MGR_OPEN: + m = new MMgrOpen(); + break; + + case MSG_MGR_REPORT: + m = new MMgrReport(); + break; + + case MSG_MGR_CONFIGURE: + m = new MMgrConfigure(); + break; + case MSG_TIMECHECK: m = new MTimeCheck(); break; diff --git a/src/msg/Message.h b/src/msg/Message.h index bc64b891bf6..40eb336dd57 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -176,6 +176,20 @@ // Special #define MSG_NOP 0x607 +// *** ceph-mgr <-> OSD/MDS daemons *** +#define MSG_MGR_OPEN 0x700 +#define MSG_MGR_CONFIGURE 0x701 +#define MSG_MGR_REPORT 0x702 + +// *** ceph-mgr <-> ceph-mon *** +#define MSG_MGR_BEACON 0x703 + +// *** ceph-mon(MgrMonitor) -> OSD/MDS daemons *** +#define MSG_MGR_MAP 0x704 + +// *** ceph-mon(MgrMonitor) -> ceph-mgr +#define MSG_MGR_DIGEST 0x705 + // ====================================================== // abstract Message class