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