]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/ErasureCodeJerasure.h
5696c6e90c4fd92fb321c6a7af2e0ff6b98dd587
[ceph.git] / 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 #define DEFAULT_RULESET_ROOT "default"
24 #define DEFAULT_RULESET_FAILURE_DOMAIN "host"
25
26 class ErasureCodeJerasure : public ErasureCode {
27 public:
28 int k;
29 std::string DEFAULT_K;
30 int m;
31 std::string DEFAULT_M;
32 int w;
33 std::string DEFAULT_W;
34 const char *technique;
35 std::string ruleset_root;
36 std::string ruleset_failure_domain;
37 bool per_chunk_alignment;
38
39 explicit ErasureCodeJerasure(const char *_technique) :
40 k(0),
41 DEFAULT_K("2"),
42 m(0),
43 DEFAULT_M("1"),
44 w(0),
45 DEFAULT_W("8"),
46 technique(_technique),
47 ruleset_root(DEFAULT_RULESET_ROOT),
48 ruleset_failure_domain(DEFAULT_RULESET_FAILURE_DOMAIN),
49 per_chunk_alignment(false)
50 {}
51
52 ~ErasureCodeJerasure() override {}
53
54 int create_ruleset(const std::string &name,
55 CrushWrapper &crush,
56 std::ostream *ss) const override;
57
58 unsigned int get_chunk_count() const override {
59 return k + m;
60 }
61
62 unsigned int get_data_chunk_count() const override {
63 return k;
64 }
65
66 unsigned int get_chunk_size(unsigned int object_size) const override;
67
68 int encode_chunks(const std::set<int> &want_to_encode,
69 std::map<int, bufferlist> *encoded) override;
70
71 int decode_chunks(const std::set<int> &want_to_read,
72 const std::map<int, bufferlist> &chunks,
73 std::map<int, bufferlist> *decoded) override;
74
75 int init(ErasureCodeProfile &profile, std::ostream *ss) override;
76
77 virtual void jerasure_encode(char **data,
78 char **coding,
79 int blocksize) = 0;
80 virtual int jerasure_decode(int *erasures,
81 char **data,
82 char **coding,
83 int blocksize) = 0;
84 virtual unsigned get_alignment() const = 0;
85 virtual void prepare() = 0;
86 static bool is_prime(int value);
87 protected:
88 virtual int parse(ErasureCodeProfile &profile, std::ostream *ss);
89 };
90
91 class ErasureCodeJerasureReedSolomonVandermonde : public ErasureCodeJerasure {
92 public:
93 int *matrix;
94
95 ErasureCodeJerasureReedSolomonVandermonde() :
96 ErasureCodeJerasure("reed_sol_van"),
97 matrix(0)
98 {
99 DEFAULT_K = "7";
100 DEFAULT_M = "3";
101 DEFAULT_W = "8";
102 }
103 ~ErasureCodeJerasureReedSolomonVandermonde() override {
104 if (matrix)
105 free(matrix);
106 }
107
108 void jerasure_encode(char **data,
109 char **coding,
110 int blocksize) override;
111 int jerasure_decode(int *erasures,
112 char **data,
113 char **coding,
114 int blocksize) override;
115 unsigned get_alignment() const override;
116 void prepare() override;
117 private:
118 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
119 };
120
121 class ErasureCodeJerasureReedSolomonRAID6 : public ErasureCodeJerasure {
122 public:
123 int *matrix;
124
125 ErasureCodeJerasureReedSolomonRAID6() :
126 ErasureCodeJerasure("reed_sol_r6_op"),
127 matrix(0)
128 {
129 DEFAULT_K = "7";
130 DEFAULT_W = "8";
131 }
132 ~ErasureCodeJerasureReedSolomonRAID6() override {
133 if (matrix)
134 free(matrix);
135 }
136
137 void jerasure_encode(char **data,
138 char **coding,
139 int blocksize) override;
140 int jerasure_decode(int *erasures,
141 char **data,
142 char **coding,
143 int blocksize) override;
144 unsigned get_alignment() const override;
145 void prepare() override;
146 private:
147 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
148 };
149
150 #define DEFAULT_PACKETSIZE "2048"
151
152 class ErasureCodeJerasureCauchy : public ErasureCodeJerasure {
153 public:
154 int *bitmatrix;
155 int **schedule;
156 int packetsize;
157
158 explicit ErasureCodeJerasureCauchy(const char *technique) :
159 ErasureCodeJerasure(technique),
160 bitmatrix(0),
161 schedule(0),
162 packetsize(0)
163 {
164 DEFAULT_K = "7";
165 DEFAULT_M = "3";
166 DEFAULT_W = "8";
167 }
168 ~ErasureCodeJerasureCauchy() override {
169 if (bitmatrix)
170 free(bitmatrix);
171 if (schedule)
172 free(schedule);
173 }
174
175 void jerasure_encode(char **data,
176 char **coding,
177 int blocksize) override;
178 int jerasure_decode(int *erasures,
179 char **data,
180 char **coding,
181 int blocksize) override;
182 unsigned get_alignment() const override;
183 void prepare_schedule(int *matrix);
184 private:
185 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
186 };
187
188 class ErasureCodeJerasureCauchyOrig : public ErasureCodeJerasureCauchy {
189 public:
190 ErasureCodeJerasureCauchyOrig() :
191 ErasureCodeJerasureCauchy("cauchy_orig")
192 {}
193
194 void prepare() override;
195 };
196
197 class ErasureCodeJerasureCauchyGood : public ErasureCodeJerasureCauchy {
198 public:
199 ErasureCodeJerasureCauchyGood() :
200 ErasureCodeJerasureCauchy("cauchy_good")
201 {}
202
203 void prepare() override;
204 };
205
206 class ErasureCodeJerasureLiberation : public ErasureCodeJerasure {
207 public:
208 int *bitmatrix;
209 int **schedule;
210 int packetsize;
211
212 explicit ErasureCodeJerasureLiberation(const char *technique = "liberation") :
213 ErasureCodeJerasure(technique),
214 bitmatrix(0),
215 schedule(0),
216 packetsize(0)
217 {
218 DEFAULT_K = "2";
219 DEFAULT_M = "2";
220 DEFAULT_W = "7";
221 }
222 ~ErasureCodeJerasureLiberation() override;
223
224 void jerasure_encode(char **data,
225 char **coding,
226 int blocksize) override;
227 int jerasure_decode(int *erasures,
228 char **data,
229 char **coding,
230 int blocksize) override;
231 unsigned get_alignment() const override;
232 virtual bool check_k(std::ostream *ss) const;
233 virtual bool check_w(std::ostream *ss) const;
234 virtual bool check_packetsize_set(std::ostream *ss) const;
235 virtual bool check_packetsize(std::ostream *ss) const;
236 virtual int revert_to_default(ErasureCodeProfile &profile,
237 std::ostream *ss);
238 void prepare() override;
239 private:
240 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
241 };
242
243 class ErasureCodeJerasureBlaumRoth : public ErasureCodeJerasureLiberation {
244 public:
245 ErasureCodeJerasureBlaumRoth() :
246 ErasureCodeJerasureLiberation("blaum_roth")
247 {
248 }
249
250 bool check_w(std::ostream *ss) const override;
251 void prepare() override;
252 };
253
254 class ErasureCodeJerasureLiber8tion : public ErasureCodeJerasureLiberation {
255 public:
256 ErasureCodeJerasureLiber8tion() :
257 ErasureCodeJerasureLiberation("liber8tion")
258 {
259 DEFAULT_K = "2";
260 DEFAULT_M = "2";
261 DEFAULT_W = "8";
262 }
263
264 void prepare() override;
265 private:
266 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
267 };
268
269 #endif