]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MOSDPGInfo.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / messages / MOSDPGInfo.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
16#ifndef CEPH_MOSDPGINFO_H
17#define CEPH_MOSDPGINFO_H
18
19#include "msg/Message.h"
20#include "osd/osd_types.h"
21
9f95a23c 22class MOSDPGInfo : public Message {
11fdf7f2 23private:
9f95a23c 24 static constexpr int HEAD_VERSION = 6;
11fdf7f2 25 static constexpr int COMPAT_VERSION = 5;
7c673cae 26
d2e6a577 27 epoch_t epoch = 0;
7c673cae
FG
28
29public:
9f95a23c
TL
30 using pg_list_t = std::vector<pg_notify_t>;
31 pg_list_t pg_list;
7c673cae
FG
32
33 epoch_t get_epoch() const { return epoch; }
34
35 MOSDPGInfo()
9f95a23c
TL
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 {
7c673cae
FG
46 set_priority(CEPH_MSG_PRIO_HIGH);
47 }
48private:
49 ~MOSDPGInfo() override {}
50
51public:
11fdf7f2 52 std::string_view get_type_name() const override { return "pg_info"; }
7c673cae
FG
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 << " ";
9f95a23c 60 out << *i;
7c673cae
FG
61 }
62 out << " epoch " << epoch
63 << ")";
64 }
65
66 void encode_payload(uint64_t features) override {
11fdf7f2 67 using ceph::encode;
9f95a23c 68 header.version = HEAD_VERSION;
11fdf7f2 69 encode(epoch, payload);
9f95a23c
TL
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 }
11fdf7f2 80 encode(pg_list, payload);
7c673cae
FG
81 }
82 void decode_payload() override {
11fdf7f2
TL
83 auto p = payload.cbegin();
84 decode(epoch, p);
9f95a23c
TL
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 }
11fdf7f2 96 decode(pg_list, p);
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