Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / erasure-code / jerasure / ErasureCodeJerasure.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) 2013, 2014 Cloudwatt <libre.licensing@cloudwatt.com>
7  * Copyright (C) 2014 Red Hat <contact@redhat.com>
8  *
9  * Author: Loic Dachary <loic@dachary.org>
10  *
11  *  This library is free software; you can redistribute it and/or
12  *  modify it under the terms of the GNU Lesser General Public
13  *  License as published by the Free Software Foundation; either
14  *  version 2.1 of the License, or (at your option) any later version.
15  * 
16  */
17
18 #ifndef CEPH_ERASURE_CODE_JERASURE_H
19 #define CEPH_ERASURE_CODE_JERASURE_H
20
21 #include "erasure-code/ErasureCode.h"
22
23 class ErasureCodeJerasure : public ErasureCode {
24 public:
25   int k;
26   std::string DEFAULT_K;
27   int m;
28   std::string DEFAULT_M;
29   int w;
30   std::string DEFAULT_W;
31   const char *technique;
32   std::string rule_root;
33   std::string rule_failure_domain;
34   bool per_chunk_alignment;
35
36   explicit ErasureCodeJerasure(const char *_technique) :
37     k(0),
38     DEFAULT_K("2"),
39     m(0),
40     DEFAULT_M("1"),
41     w(0),
42     DEFAULT_W("8"),
43     technique(_technique),
44     per_chunk_alignment(false)
45   {}
46
47   ~ErasureCodeJerasure() override {}
48   
49   unsigned int get_chunk_count() const override {
50     return k + m;
51   }
52
53   unsigned int get_data_chunk_count() const override {
54     return k;
55   }
56
57   unsigned int get_chunk_size(unsigned int object_size) const override;
58
59   int encode_chunks(const std::set<int> &want_to_encode,
60                             std::map<int, bufferlist> *encoded) override;
61
62   int decode_chunks(const std::set<int> &want_to_read,
63                             const std::map<int, bufferlist> &chunks,
64                             std::map<int, bufferlist> *decoded) override;
65
66   int init(ErasureCodeProfile &profile, std::ostream *ss) override;
67
68   virtual void jerasure_encode(char **data,
69                                char **coding,
70                                int blocksize) = 0;
71   virtual int jerasure_decode(int *erasures,
72                                char **data,
73                                char **coding,
74                                int blocksize) = 0;
75   virtual unsigned get_alignment() const = 0;
76   virtual void prepare() = 0;
77   static bool is_prime(int value);
78 protected:
79   virtual int parse(ErasureCodeProfile &profile, std::ostream *ss);
80 };
81
82 class ErasureCodeJerasureReedSolomonVandermonde : public ErasureCodeJerasure {
83 public:
84   int *matrix;
85
86   ErasureCodeJerasureReedSolomonVandermonde() :
87     ErasureCodeJerasure("reed_sol_van"),
88     matrix(0)
89   {
90     DEFAULT_K = "7";
91     DEFAULT_M = "3";
92     DEFAULT_W = "8";
93   }
94   ~ErasureCodeJerasureReedSolomonVandermonde() override {
95     if (matrix)
96       free(matrix);
97   }
98
99   void jerasure_encode(char **data,
100                                char **coding,
101                                int blocksize) override;
102   int jerasure_decode(int *erasures,
103                                char **data,
104                                char **coding,
105                                int blocksize) override;
106   unsigned get_alignment() const override;
107   void prepare() override;
108 private:
109   int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
110 };
111
112 class ErasureCodeJerasureReedSolomonRAID6 : public ErasureCodeJerasure {
113 public:
114   int *matrix;
115
116   ErasureCodeJerasureReedSolomonRAID6() :
117     ErasureCodeJerasure("reed_sol_r6_op"),
118     matrix(0)
119   {
120     DEFAULT_K = "7";
121     DEFAULT_W = "8";
122   }
123   ~ErasureCodeJerasureReedSolomonRAID6() override {
124     if (matrix)
125       free(matrix);
126   }
127
128   void jerasure_encode(char **data,
129                                char **coding,
130                                int blocksize) override;
131   int jerasure_decode(int *erasures,
132                                char **data,
133                                char **coding,
134                                int blocksize) override;
135   unsigned get_alignment() const override;
136   void prepare() override;
137 private:
138   int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
139 };
140
141 #define DEFAULT_PACKETSIZE "2048"
142
143 class ErasureCodeJerasureCauchy : public ErasureCodeJerasure {
144 public:
145   int *bitmatrix;
146   int **schedule;
147   int packetsize;
148
149   explicit ErasureCodeJerasureCauchy(const char *technique) :
150     ErasureCodeJerasure(technique),
151     bitmatrix(0),
152     schedule(0),
153     packetsize(0)
154   {
155     DEFAULT_K = "7";
156     DEFAULT_M = "3";
157     DEFAULT_W = "8";
158   }
159   ~ErasureCodeJerasureCauchy() override {
160     if (bitmatrix)
161       free(bitmatrix);
162     if (schedule)
163       free(schedule);
164   }
165
166   void jerasure_encode(char **data,
167                                char **coding,
168                                int blocksize) override;
169   int jerasure_decode(int *erasures,
170                                char **data,
171                                char **coding,
172                                int blocksize) override;
173   unsigned get_alignment() const override;
174   void prepare_schedule(int *matrix);
175 private:
176   int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
177 };
178
179 class ErasureCodeJerasureCauchyOrig : public ErasureCodeJerasureCauchy {
180 public:
181   ErasureCodeJerasureCauchyOrig() :
182     ErasureCodeJerasureCauchy("cauchy_orig")
183   {}
184
185   void prepare() override;
186 };
187
188 class ErasureCodeJerasureCauchyGood : public ErasureCodeJerasureCauchy {
189 public:
190   ErasureCodeJerasureCauchyGood() :
191     ErasureCodeJerasureCauchy("cauchy_good")
192   {}
193
194   void prepare() override;
195 };
196
197 class ErasureCodeJerasureLiberation : public ErasureCodeJerasure {
198 public:
199   int *bitmatrix;
200   int **schedule;
201   int packetsize;
202
203   explicit ErasureCodeJerasureLiberation(const char *technique = "liberation") :
204     ErasureCodeJerasure(technique),
205     bitmatrix(0),
206     schedule(0),
207     packetsize(0)
208   {
209     DEFAULT_K = "2";
210     DEFAULT_M = "2";
211     DEFAULT_W = "7";
212   }
213   ~ErasureCodeJerasureLiberation() override;
214
215   void jerasure_encode(char **data,
216                                char **coding,
217                                int blocksize) override;
218   int jerasure_decode(int *erasures,
219                                char **data,
220                                char **coding,
221                                int blocksize) override;
222   unsigned get_alignment() const override;
223   virtual bool check_k(std::ostream *ss) const;
224   virtual bool check_w(std::ostream *ss) const;
225   virtual bool check_packetsize_set(std::ostream *ss) const;
226   virtual bool check_packetsize(std::ostream *ss) const;
227   virtual int revert_to_default(ErasureCodeProfile &profile,
228                                 std::ostream *ss);
229   void prepare() override;
230 private:
231   int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
232 };
233
234 class ErasureCodeJerasureBlaumRoth : public ErasureCodeJerasureLiberation {
235 public:
236   ErasureCodeJerasureBlaumRoth() :
237     ErasureCodeJerasureLiberation("blaum_roth")
238   {
239   }
240
241   bool check_w(std::ostream *ss) const override;
242   void prepare() override;
243 };
244
245 class ErasureCodeJerasureLiber8tion : public ErasureCodeJerasureLiberation {
246 public:
247   ErasureCodeJerasureLiber8tion() :
248     ErasureCodeJerasureLiberation("liber8tion")
249   {
250     DEFAULT_K = "2";
251     DEFAULT_M = "2";
252     DEFAULT_W = "8";
253   }
254
255   void prepare() override;
256 private:
257   int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
258 };
259
260 #endif