1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph distributed storage system
6 * Copyright (C) 2013, 2014 Cloudwatt <libre.licensing@cloudwatt.com>
7 * Copyright (C) 2014 Red Hat <contact@redhat.com>
9 * Author: Loic Dachary <loic@dachary.org>
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.
18 #ifndef CEPH_ERASURE_CODE_JERASURE_H
19 #define CEPH_ERASURE_CODE_JERASURE_H
21 #include "erasure-code/ErasureCode.h"
23 class ErasureCodeJerasure : public ErasureCode {
26 std::string DEFAULT_K;
28 std::string DEFAULT_M;
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;
36 explicit ErasureCodeJerasure(const char *_technique) :
43 technique(_technique),
44 per_chunk_alignment(false)
47 ~ErasureCodeJerasure() override {}
49 unsigned int get_chunk_count() const override {
53 unsigned int get_data_chunk_count() const override {
57 unsigned int get_chunk_size(unsigned int object_size) const override;
59 int encode_chunks(const std::set<int> &want_to_encode,
60 std::map<int, bufferlist> *encoded) override;
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;
66 int init(ErasureCodeProfile &profile, std::ostream *ss) override;
68 virtual void jerasure_encode(char **data,
71 virtual int jerasure_decode(int *erasures,
75 virtual unsigned get_alignment() const = 0;
76 virtual void prepare() = 0;
77 static bool is_prime(int value);
79 virtual int parse(ErasureCodeProfile &profile, std::ostream *ss);
82 class ErasureCodeJerasureReedSolomonVandermonde : public ErasureCodeJerasure {
86 ErasureCodeJerasureReedSolomonVandermonde() :
87 ErasureCodeJerasure("reed_sol_van"),
94 ~ErasureCodeJerasureReedSolomonVandermonde() override {
99 void jerasure_encode(char **data,
101 int blocksize) override;
102 int jerasure_decode(int *erasures,
105 int blocksize) override;
106 unsigned get_alignment() const override;
107 void prepare() override;
109 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
112 class ErasureCodeJerasureReedSolomonRAID6 : public ErasureCodeJerasure {
116 ErasureCodeJerasureReedSolomonRAID6() :
117 ErasureCodeJerasure("reed_sol_r6_op"),
123 ~ErasureCodeJerasureReedSolomonRAID6() override {
128 void jerasure_encode(char **data,
130 int blocksize) override;
131 int jerasure_decode(int *erasures,
134 int blocksize) override;
135 unsigned get_alignment() const override;
136 void prepare() override;
138 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
141 #define DEFAULT_PACKETSIZE "2048"
143 class ErasureCodeJerasureCauchy : public ErasureCodeJerasure {
149 explicit ErasureCodeJerasureCauchy(const char *technique) :
150 ErasureCodeJerasure(technique),
159 ~ErasureCodeJerasureCauchy() override {
166 void jerasure_encode(char **data,
168 int blocksize) override;
169 int jerasure_decode(int *erasures,
172 int blocksize) override;
173 unsigned get_alignment() const override;
174 void prepare_schedule(int *matrix);
176 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
179 class ErasureCodeJerasureCauchyOrig : public ErasureCodeJerasureCauchy {
181 ErasureCodeJerasureCauchyOrig() :
182 ErasureCodeJerasureCauchy("cauchy_orig")
185 void prepare() override;
188 class ErasureCodeJerasureCauchyGood : public ErasureCodeJerasureCauchy {
190 ErasureCodeJerasureCauchyGood() :
191 ErasureCodeJerasureCauchy("cauchy_good")
194 void prepare() override;
197 class ErasureCodeJerasureLiberation : public ErasureCodeJerasure {
203 explicit ErasureCodeJerasureLiberation(const char *technique = "liberation") :
204 ErasureCodeJerasure(technique),
213 ~ErasureCodeJerasureLiberation() override;
215 void jerasure_encode(char **data,
217 int blocksize) override;
218 int jerasure_decode(int *erasures,
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,
229 void prepare() override;
231 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;
234 class ErasureCodeJerasureBlaumRoth : public ErasureCodeJerasureLiberation {
236 ErasureCodeJerasureBlaumRoth() :
237 ErasureCodeJerasureLiberation("blaum_roth")
241 bool check_w(std::ostream *ss) const override;
242 void prepare() override;
245 class ErasureCodeJerasureLiber8tion : public ErasureCodeJerasureLiberation {
247 ErasureCodeJerasureLiber8tion() :
248 ErasureCodeJerasureLiberation("liber8tion")
255 void prepare() override;
257 int parse(ErasureCodeProfile &profile, std::ostream *ss) override;