Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / erasure-code / ErasureCode.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 distributed storage system
5  *
6  * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
7  *
8  * Author: Loic Dachary <loic@dachary.org>
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2.1 of the License, or (at your option) any later version.
14  * 
15  */
16
17 #ifndef CEPH_ERASURE_CODE_H
18 #define CEPH_ERASURE_CODE_H
19
20 /*! @file ErasureCode.h
21     @brief Base class for erasure code plugins implementors
22
23  */ 
24
25 #include "ErasureCodeInterface.h"
26
27 namespace ceph {
28
29   class ErasureCode : public ErasureCodeInterface {
30   public:
31     static const unsigned SIMD_ALIGN;
32
33     std::vector<int> chunk_mapping;
34     ErasureCodeProfile _profile;
35
36     // for CRUSH rule
37     std::string rule_root;
38     std::string rule_failure_domain;
39     std::string rule_device_class;
40
41     ~ErasureCode() override {}
42
43     int init(ErasureCodeProfile &profile, std::ostream *ss) override;
44
45     const ErasureCodeProfile &get_profile() const override {
46       return _profile;
47     }
48
49     int create_rule(const std::string &name,
50                     CrushWrapper &crush,
51                     std::ostream *ss) const;
52
53     int sanity_check_k(int k, std::ostream *ss);
54
55     unsigned int get_coding_chunk_count() const override {
56       return get_chunk_count() - get_data_chunk_count();
57     }
58
59     int minimum_to_decode(const std::set<int> &want_to_read,
60                                   const std::set<int> &available_chunks,
61                                   std::set<int> *minimum) override;
62
63     int minimum_to_decode_with_cost(const std::set<int> &want_to_read,
64                                             const std::map<int, int> &available,
65                                             std::set<int> *minimum) override;
66
67     int encode_prepare(const bufferlist &raw,
68                        std::map<int, bufferlist> &encoded) const;
69
70     int encode(const std::set<int> &want_to_encode,
71                        const bufferlist &in,
72                        std::map<int, bufferlist> *encoded) override;
73
74     int encode_chunks(const std::set<int> &want_to_encode,
75                               std::map<int, bufferlist> *encoded) override;
76
77     int decode(const std::set<int> &want_to_read,
78                        const std::map<int, bufferlist> &chunks,
79                        std::map<int, bufferlist> *decoded) override;
80
81     int decode_chunks(const std::set<int> &want_to_read,
82                               const std::map<int, bufferlist> &chunks,
83                               std::map<int, bufferlist> *decoded) override;
84
85     const std::vector<int> &get_chunk_mapping() const override;
86
87     int to_mapping(const ErasureCodeProfile &profile,
88                    std::ostream *ss);
89
90     static int to_int(const std::string &name,
91                       ErasureCodeProfile &profile,
92                       int *value,
93                       const std::string &default_value,
94                       std::ostream *ss);
95
96     static int to_bool(const std::string &name,
97                        ErasureCodeProfile &profile,
98                        bool *value,
99                        const std::string &default_value,
100                        std::ostream *ss);
101
102     static int to_string(const std::string &name,
103                          ErasureCodeProfile &profile,
104                          std::string *value,
105                          const std::string &default_value,
106                          std::ostream *ss);
107
108     int decode_concat(const std::map<int, bufferlist> &chunks,
109                               bufferlist *decoded) override;
110
111   protected:
112     int parse(const ErasureCodeProfile &profile,
113               std::ostream *ss);
114
115   private:
116     int chunk_index(unsigned int i) const;
117   };
118 }
119
120 #endif