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