]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMonSubscribe.h
Import ceph 15.2.8
[ceph.git] / ceph / src / messages / MMonSubscribe.h
CommitLineData
7c673cae
FG
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#ifndef CEPH_MMONSUBSCRIBE_H
16#define CEPH_MMONSUBSCRIBE_H
17
18#include "msg/Message.h"
19#include "include/ceph_features.h"
20
21/*
22 * compatibility with old crap
23 */
24struct ceph_mon_subscribe_item_old {
eafe8130
TL
25 ceph_le64 unused;
26 ceph_le64 have;
7c673cae
FG
27 __u8 onetime;
28} __attribute__ ((packed));
29WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old)
30
31
9f95a23c 32class MMonSubscribe : public Message {
11fdf7f2 33public:
11fdf7f2
TL
34 static constexpr int HEAD_VERSION = 3;
35 static constexpr int COMPAT_VERSION = 1;
7c673cae 36
9f95a23c
TL
37 std::string hostname;
38 std::map<std::string, ceph_mon_subscribe_item> what;
39
40 MMonSubscribe() : Message{CEPH_MSG_MON_SUBSCRIBE, HEAD_VERSION, COMPAT_VERSION} { }
7c673cae
FG
41private:
42 ~MMonSubscribe() override {}
43
9f95a23c 44public:
7c673cae
FG
45 void sub_want(const char *w, version_t start, unsigned flags) {
46 what[w].start = start;
47 what[w].flags = flags;
48 }
49
11fdf7f2 50 std::string_view get_type_name() const override { return "mon_subscribe"; }
9f95a23c 51 void print(std::ostream& o) const override {
7c673cae
FG
52 o << "mon_subscribe(" << what << ")";
53 }
54
55 void decode_payload() override {
9f95a23c 56 using ceph::decode;
11fdf7f2 57 auto p = payload.cbegin();
7c673cae 58 if (header.version < 2) {
9f95a23c 59 std::map<std::string, ceph_mon_subscribe_item_old> oldwhat;
11fdf7f2 60 decode(oldwhat, p);
7c673cae 61 what.clear();
9f95a23c 62 for (auto q = oldwhat.begin(); q != oldwhat.end(); q++) {
7c673cae
FG
63 if (q->second.have)
64 what[q->first].start = q->second.have + 1;
65 else
66 what[q->first].start = 0;
67 what[q->first].flags = 0;
68 if (q->second.onetime)
69 what[q->first].flags |= CEPH_SUBSCRIBE_ONETIME;
70 }
11fdf7f2
TL
71 return;
72 }
73 decode(what, p);
74 if (header.version >= 3) {
75 decode(hostname, p);
7c673cae
FG
76 }
77 }
78 void encode_payload(uint64_t features) override {
11fdf7f2
TL
79 using ceph::encode;
80 if ((features & CEPH_FEATURE_SUBSCRIBE2) == 0) {
7c673cae 81 header.version = 0;
9f95a23c
TL
82 std::map<std::string, ceph_mon_subscribe_item_old> oldwhat;
83 for (auto q = what.begin(); q != what.end(); q++) {
7c673cae
FG
84 if (q->second.start)
85 // warning: start=1 -> have=0, which was ambiguous
86 oldwhat[q->first].have = q->second.start - 1;
87 else
88 oldwhat[q->first].have = 0;
89 oldwhat[q->first].onetime = q->second.flags & CEPH_SUBSCRIBE_ONETIME;
90 }
11fdf7f2
TL
91 encode(oldwhat, payload);
92 return;
7c673cae 93 }
11fdf7f2
TL
94 header.version = HEAD_VERSION;
95 encode(what, payload);
96 encode(hostname, payload);
7c673cae 97 }
9f95a23c
TL
98private:
99 template<class T, typename... Args>
100 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
7c673cae
FG
101};
102
103#endif