Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MOSDPGRemove.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_MOSDPGREMOVE_H
17 #define CEPH_MOSDPGREMOVE_H
18
19 #include "common/hobject.h"
20 #include "msg/Message.h"
21
22
23 class MOSDPGRemove : public Message {
24
25   static const int HEAD_VERSION = 3;
26   static const int COMPAT_VERSION = 2;
27
28   epoch_t epoch = 0;
29
30  public:
31   vector<spg_t> pg_list;
32
33   epoch_t get_epoch() const { return epoch; }
34
35   MOSDPGRemove() :
36     Message(MSG_OSD_PG_REMOVE, HEAD_VERSION, COMPAT_VERSION) {}
37   MOSDPGRemove(epoch_t e, vector<spg_t>& l) :
38     Message(MSG_OSD_PG_REMOVE, HEAD_VERSION, COMPAT_VERSION) {
39     this->epoch = e;
40     pg_list.swap(l);
41   }
42 private:
43   ~MOSDPGRemove() override {}
44
45 public:  
46   const char *get_type_name() const override { return "PGrm"; }
47
48   void encode_payload(uint64_t features) override {
49     if (HAVE_FEATURE(features, SERVER_LUMINOUS)) {
50       header.version = HEAD_VERSION;
51     } else {
52       // for jewel+kraken
53       header.version = 2;
54       ::encode(epoch, payload);
55
56       vector<pg_t> _pg_list;
57       _pg_list.reserve(pg_list.size());
58       vector<shard_id_t> _shard_list;
59       _shard_list.reserve(pg_list.size());
60       for (auto i = pg_list.begin(); i != pg_list.end(); ++i) {
61         _pg_list.push_back(i->pgid);
62         _shard_list.push_back(i->shard);
63       }
64       ::encode(_pg_list, payload);
65       ::encode(_shard_list, payload);
66       return;
67     }
68     ::encode(epoch, payload);
69     ::encode(pg_list, payload);
70   }
71   void decode_payload() override {
72     bufferlist::iterator p = payload.begin();
73     if (header.version == 2) {
74       // jewel/kraken
75       ::decode(epoch, p);
76       vector<pg_t> _pg_list;
77       ::decode(_pg_list, p);
78
79       vector<shard_id_t> _shard_list(_pg_list.size(), shard_id_t::NO_SHARD);
80       _shard_list.clear();
81       ::decode(_shard_list, p);
82       assert(_shard_list.size() == _pg_list.size());
83       pg_list.reserve(_shard_list.size());
84       for (unsigned i = 0; i < _shard_list.size(); ++i) {
85         pg_list.push_back(spg_t(_pg_list[i], _shard_list[i]));
86       }
87       return;
88     }
89     ::decode(epoch, p);
90     ::decode(pg_list, p);
91   }
92   void print(ostream& out) const override {
93     out << "osd pg remove(" << "epoch " << epoch << "; ";
94     for (vector<spg_t>::const_iterator i = pg_list.begin();
95          i != pg_list.end();
96          ++i) {
97       out << "pg" << *i << "; ";
98     }
99     out << ")";
100   }
101 };
102
103 #endif