]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MOSDPGInfo.h
import 15.2.2 octopus source
[ceph.git] / ceph / src / messages / MOSDPGInfo.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
16 #ifndef CEPH_MOSDPGINFO_H
17 #define CEPH_MOSDPGINFO_H
18
19 #include "msg/Message.h"
20 #include "osd/osd_types.h"
21
22 class MOSDPGInfo : public Message {
23 private:
24 static constexpr int HEAD_VERSION = 6;
25 static constexpr int COMPAT_VERSION = 5;
26
27 epoch_t epoch = 0;
28
29 public:
30 using pg_list_t = std::vector<pg_notify_t>;
31 pg_list_t pg_list;
32
33 epoch_t get_epoch() const { return epoch; }
34
35 MOSDPGInfo()
36 : MOSDPGInfo{0, {}}
37 {}
38 MOSDPGInfo(epoch_t mv)
39 : MOSDPGInfo(mv, {})
40 {}
41 MOSDPGInfo(epoch_t mv, pg_list_t&& l)
42 : Message{MSG_OSD_PG_INFO, HEAD_VERSION, COMPAT_VERSION},
43 epoch{mv},
44 pg_list{std::move(l)}
45 {
46 set_priority(CEPH_MSG_PRIO_HIGH);
47 }
48 private:
49 ~MOSDPGInfo() override {}
50
51 public:
52 std::string_view get_type_name() const override { return "pg_info"; }
53 void print(ostream& out) const override {
54 out << "pg_info(";
55 for (auto i = pg_list.begin();
56 i != pg_list.end();
57 ++i) {
58 if (i != pg_list.begin())
59 out << " ";
60 out << *i;
61 }
62 out << " epoch " << epoch
63 << ")";
64 }
65
66 void encode_payload(uint64_t features) override {
67 using ceph::encode;
68 header.version = HEAD_VERSION;
69 encode(epoch, payload);
70 if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) {
71 // pretend to be vector<pair<pg_notify_t,PastIntervals>>
72 header.version = 5;
73 encode((uint32_t)pg_list.size(), payload);
74 for (auto& i : pg_list) {
75 encode(i, payload); // this embeds a dup (ignored) PastIntervals
76 encode(i.past_intervals, payload);
77 }
78 return;
79 }
80 encode(pg_list, payload);
81 }
82 void decode_payload() override {
83 auto p = payload.cbegin();
84 decode(epoch, p);
85 if (header.version == 5) {
86 // decode legacy vector<pair<pg_notify_t,PastIntervals>>
87 uint32_t num;
88 decode(num, p);
89 pg_list.resize(num);
90 for (unsigned i = 0; i < num; ++i) {
91 decode(pg_list[i], p);
92 decode(pg_list[i].past_intervals, p);
93 }
94 return;
95 }
96 decode(pg_list, p);
97 }
98 private:
99 template<class T, typename... Args>
100 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
101 };
102
103 #endif