summaryrefslogtreecommitdiffstats
path: root/src/messages/MMonSubscribe.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/messages/MMonSubscribe.h
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/messages/MMonSubscribe.h')
-rw-r--r--src/messages/MMonSubscribe.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/messages/MMonSubscribe.h b/src/messages/MMonSubscribe.h
new file mode 100644
index 00000000..bbc88334
--- /dev/null
+++ b/src/messages/MMonSubscribe.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) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * 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_MMONSUBSCRIBE_H
+#define CEPH_MMONSUBSCRIBE_H
+
+#include "msg/Message.h"
+#include "include/ceph_features.h"
+
+/*
+ * compatibility with old crap
+ */
+struct ceph_mon_subscribe_item_old {
+ ceph_le64 unused;
+ ceph_le64 have;
+ __u8 onetime;
+} __attribute__ ((packed));
+WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old)
+
+
+class MMonSubscribe : public MessageInstance<MMonSubscribe> {
+public:
+ friend factory;
+
+ static constexpr int HEAD_VERSION = 3;
+ static constexpr int COMPAT_VERSION = 1;
+
+ string hostname;
+ map<string, ceph_mon_subscribe_item> what;
+
+ MMonSubscribe() : MessageInstance(CEPH_MSG_MON_SUBSCRIBE, HEAD_VERSION, COMPAT_VERSION) { }
+private:
+ ~MMonSubscribe() override {}
+
+public:
+ void sub_want(const char *w, version_t start, unsigned flags) {
+ what[w].start = start;
+ what[w].flags = flags;
+ }
+
+ std::string_view get_type_name() const override { return "mon_subscribe"; }
+ void print(ostream& o) const override {
+ o << "mon_subscribe(" << what << ")";
+ }
+
+ void decode_payload() override {
+ auto p = payload.cbegin();
+ if (header.version < 2) {
+ map<string, ceph_mon_subscribe_item_old> oldwhat;
+ decode(oldwhat, p);
+ what.clear();
+ for (map<string, ceph_mon_subscribe_item_old>::iterator q = oldwhat.begin();
+ q != oldwhat.end();
+ q++) {
+ if (q->second.have)
+ what[q->first].start = q->second.have + 1;
+ else
+ what[q->first].start = 0;
+ what[q->first].flags = 0;
+ if (q->second.onetime)
+ what[q->first].flags |= CEPH_SUBSCRIBE_ONETIME;
+ }
+ return;
+ }
+ decode(what, p);
+ if (header.version >= 3) {
+ decode(hostname, p);
+ }
+ }
+ void encode_payload(uint64_t features) override {
+ using ceph::encode;
+ if ((features & CEPH_FEATURE_SUBSCRIBE2) == 0) {
+ header.version = 0;
+ map<string, ceph_mon_subscribe_item_old> oldwhat;
+ for (map<string, ceph_mon_subscribe_item>::iterator q = what.begin();
+ q != what.end();
+ q++) {
+ if (q->second.start)
+ // warning: start=1 -> have=0, which was ambiguous
+ oldwhat[q->first].have = q->second.start - 1;
+ else
+ oldwhat[q->first].have = 0;
+ oldwhat[q->first].onetime = q->second.flags & CEPH_SUBSCRIBE_ONETIME;
+ }
+ encode(oldwhat, payload);
+ return;
+ }
+ header.version = HEAD_VERSION;
+ encode(what, payload);
+ encode(hostname, payload);
+ }
+};
+
+#endif