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