Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MOSDPGQuery.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_MOSDPGQUERY_H
17 #define CEPH_MOSDPGQUERY_H
18
19 #include "common/hobject.h"
20 #include "msg/Message.h"
21
22 /*
23  * PGQuery - query another OSD as to the contents of their PGs
24  */
25
26 class MOSDPGQuery : public Message {
27   static const int HEAD_VERSION = 4;
28   static const int COMPAT_VERSION = 3;
29
30   version_t epoch = 0;
31
32  public:
33   version_t get_epoch() const { return epoch; }
34   map<spg_t, pg_query_t>  pg_list;
35
36   MOSDPGQuery() : Message(MSG_OSD_PG_QUERY,
37                           HEAD_VERSION,
38                           COMPAT_VERSION) {
39     set_priority(CEPH_MSG_PRIO_HIGH);
40   }
41   MOSDPGQuery(epoch_t e, map<spg_t,pg_query_t>& ls) :
42     Message(MSG_OSD_PG_QUERY,
43             HEAD_VERSION,
44             COMPAT_VERSION),
45     epoch(e) {
46     pg_list.swap(ls);
47     set_priority(CEPH_MSG_PRIO_HIGH);
48   }
49 private:
50   ~MOSDPGQuery() override {}
51
52 public:  
53   const char *get_type_name() const override { return "pg_query"; }
54   void print(ostream& out) const override {
55     out << "pg_query(";
56     for (map<spg_t,pg_query_t>::const_iterator p = pg_list.begin();
57          p != pg_list.end(); ++p) {
58       if (p != pg_list.begin())
59         out << ",";
60       out << p->first;
61     }
62     out << " epoch " << epoch << ")";
63   }
64
65   void encode_payload(uint64_t features) override {
66     if (HAVE_FEATURE(features, SERVER_LUMINOUS)) {
67       header.version = HEAD_VERSION;
68     } else {
69       // for kraken/jewel only
70       header.version = 3;
71       ::encode(epoch, payload);
72       vector<pair<pg_t, pg_query_t> > _pg_list;
73       _pg_list.reserve(pg_list.size());
74       vector<shard_id_t> _shard_list;
75       _shard_list.reserve(pg_list.size());
76       for (map<spg_t, pg_query_t>::iterator i = pg_list.begin();
77            i != pg_list.end();
78            ++i) {
79         _pg_list.push_back(make_pair(i->first.pgid, i->second));
80         _shard_list.push_back(i->first.shard);
81       }
82       ::encode(_pg_list, payload, features);
83       ::encode(_shard_list, payload);
84       return;
85     }
86     ::encode(epoch, payload);
87     ::encode(pg_list, payload, features);
88   }
89   void decode_payload() override {
90     bufferlist::iterator p = payload.begin();
91     if (header.version < 4) {
92       // for kraken/jewel only
93       ::decode(epoch, p);
94       vector<pair<pg_t, pg_query_t> > _pg_list;
95       ::decode(_pg_list, p);
96       vector<shard_id_t> _shard_list(_pg_list.size(), shard_id_t::NO_SHARD);
97       _shard_list.clear();
98       ::decode(_shard_list, p);
99       assert(_pg_list.size() == _shard_list.size());
100       for (unsigned i = 0; i < _pg_list.size(); ++i) {
101         pg_list.insert(
102           make_pair(
103             spg_t(_pg_list[i].first, _shard_list[i]), _pg_list[i].second));
104       }
105       return;
106     }
107     ::decode(epoch, p);
108     ::decode(pg_list, p);
109   }
110 };
111
112 #endif