Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MMonScrub.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, 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 #ifndef CEPH_MMONSCRUB_H
14 #define CEPH_MMONSCRUB_H
15
16 #include "msg/Message.h"
17 #include "mon/mon_types.h"
18
19 class MMonScrub : public Message
20 {
21   static const int HEAD_VERSION = 2;
22   static const int COMPAT_VERSION = 2;
23
24 public:
25   typedef enum {
26     OP_SCRUB = 1,         // leader->peon: scrub (a range of) keys
27     OP_RESULT = 2,        // peon->leader: result of a scrub
28   } op_type_t;
29
30   static const char *get_opname(op_type_t op) {
31     switch (op) {
32     case OP_SCRUB: return "scrub";
33     case OP_RESULT: return "result";
34     default: assert(0 == "unknown op type"); return NULL;
35     }
36   }
37
38   op_type_t op;
39   version_t version;
40   ScrubResult result;
41   int32_t num_keys;
42   pair<string,string> key;
43
44   MMonScrub()
45     : Message(MSG_MON_SCRUB, HEAD_VERSION, COMPAT_VERSION),
46       num_keys(-1)
47   { }
48
49   MMonScrub(op_type_t op, version_t v, int32_t num_keys)
50     : Message(MSG_MON_SCRUB, HEAD_VERSION, COMPAT_VERSION),
51       op(op), version(v), num_keys(num_keys)
52   { }
53
54   const char *get_type_name() const override { return "mon_scrub"; }
55
56   void print(ostream& out) const override {
57     out << "mon_scrub(" << get_opname((op_type_t)op);
58     out << " v " << version;
59     if (op == OP_RESULT)
60       out << " " << result;
61     out << " num_keys " << num_keys;
62     out << " key (" << key << ")";
63     out << ")";
64   }
65
66   void encode_payload(uint64_t features) override {
67     uint8_t o = op;
68     ::encode(o, payload);
69     ::encode(version, payload);
70     ::encode(result, payload);
71     ::encode(num_keys, payload);
72     ::encode(key, payload);
73   }
74
75   void decode_payload() override {
76     bufferlist::iterator p = payload.begin();
77     uint8_t o;
78     ::decode(o, p);
79     op = (op_type_t)o;
80     ::decode(version, p);
81     ::decode(result, p);
82     ::decode(num_keys, p);
83     ::decode(key, p);
84   }
85 };
86
87 #endif /* CEPH_MMONSCRUB_H */