Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MOSDPGPushReply.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) 2013 Inktank Storage, Inc.
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 #ifndef MOSDPGPUSHREPLY_H
16 #define MOSDPGPUSHREPLY_H
17
18 #include "MOSDFastDispatchOp.h"
19
20 class MOSDPGPushReply : public MOSDFastDispatchOp {
21   static const int HEAD_VERSION = 3;
22   static const int COMPAT_VERSION = 2;
23
24 public:
25   pg_shard_t from;
26   spg_t pgid;
27   epoch_t map_epoch, min_epoch;
28   vector<PushReplyOp> replies;
29   uint64_t cost;
30
31   epoch_t get_map_epoch() const override {
32     return map_epoch;
33   }
34   epoch_t get_min_epoch() const override {
35     return min_epoch;
36   }
37   spg_t get_spg() const override {
38     return pgid;
39   }
40
41   MOSDPGPushReply()
42     : MOSDFastDispatchOp(MSG_OSD_PG_PUSH_REPLY, HEAD_VERSION, COMPAT_VERSION),
43       cost(0)
44     {}
45
46   void compute_cost(CephContext *cct) {
47     cost = 0;
48     for (vector<PushReplyOp>::iterator i = replies.begin();
49          i != replies.end();
50          ++i) {
51       cost += i->cost(cct);
52     }
53   }
54
55   int get_cost() const override {
56     return cost;
57   }
58
59   void decode_payload() override {
60     bufferlist::iterator p = payload.begin();
61     ::decode(pgid.pgid, p);
62     ::decode(map_epoch, p);
63     ::decode(replies, p);
64     ::decode(cost, p);
65     ::decode(pgid.shard, p);
66     ::decode(from, p);
67     if (header.version >= 3) {
68       ::decode(min_epoch, p);
69     } else {
70       min_epoch = map_epoch;
71     }
72   }
73
74   void encode_payload(uint64_t features) override {
75     ::encode(pgid.pgid, payload);
76     ::encode(map_epoch, payload);
77     ::encode(replies, payload);
78     ::encode(cost, payload);
79     ::encode(pgid.shard, payload);
80     ::encode(from, payload);
81     ::encode(min_epoch, payload);
82   }
83
84   void print(ostream& out) const override {
85     out << "MOSDPGPushReply(" << pgid
86         << " " << map_epoch << "/" << min_epoch
87         << " " << replies;
88     out << ")";
89   }
90
91   const char *get_type_name() const override { return "MOSDPGPushReply"; }
92 };
93
94 #endif