]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Ceph - scalable distributed file system | |
3 | * | |
4 | * Copyright (C) 2014 CERN (Switzerland) | |
5 | * | |
6 | * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch> | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | * | |
13 | */ | |
14 | ||
15 | /** | |
16 | * @file ErasureCodeIsa.cc | |
17 | * | |
18 | * @brief Erasure Code CODEC using the INTEL ISA-L library. | |
19 | * | |
20 | * The INTEL ISA-L library supports two pre-defined encoding matrices (cauchy = default, reed_sol_van = default) | |
21 | * The default CODEC implementation using these two matrices is implemented in class ErasureCodeIsaDefault. | |
22 | * ISA-L allows to use custom matrices which might be added later as implementations deriving from the base class ErasoreCodeIsa. | |
23 | */ | |
24 | ||
25 | #ifndef CEPH_ERASURE_CODE_ISA_L_H | |
26 | #define CEPH_ERASURE_CODE_ISA_L_H | |
27 | ||
28 | // ----------------------------------------------------------------------------- | |
7c673cae FG |
29 | #include "erasure-code/ErasureCode.h" |
30 | #include "ErasureCodeIsaTableCache.h" | |
31 | // ----------------------------------------------------------------------------- | |
7c673cae FG |
32 | |
33 | #define DEFAULT_RULESET_ROOT "default" | |
34 | #define DEFAULT_RULESET_FAILURE_DOMAIN "host" | |
35 | ||
36 | class ErasureCodeIsa : public ErasureCode { | |
37 | public: | |
38 | ||
39 | enum eMatrix { | |
40 | kVandermonde = 0, kCauchy = 1 | |
41 | }; | |
42 | ||
43 | int k; | |
44 | int m; | |
45 | int w; | |
46 | ||
47 | ErasureCodeIsaTableCache &tcache; | |
48 | const char *technique; | |
31f18b77 FG |
49 | std::string ruleset_root; |
50 | std::string ruleset_failure_domain; | |
7c673cae FG |
51 | |
52 | ErasureCodeIsa(const char *_technique, | |
53 | ErasureCodeIsaTableCache &_tcache) : | |
54 | k(0), | |
55 | m(0), | |
56 | w(0), | |
57 | tcache(_tcache), | |
58 | technique(_technique), | |
59 | ruleset_root(DEFAULT_RULESET_ROOT), | |
60 | ruleset_failure_domain(DEFAULT_RULESET_FAILURE_DOMAIN) | |
61 | { | |
62 | } | |
63 | ||
64 | ||
65 | ~ErasureCodeIsa() override | |
66 | { | |
67 | } | |
68 | ||
31f18b77 | 69 | int create_ruleset(const std::string &name, |
7c673cae | 70 | CrushWrapper &crush, |
31f18b77 | 71 | std::ostream *ss) const override; |
7c673cae FG |
72 | |
73 | unsigned int | |
74 | get_chunk_count() const override | |
75 | { | |
76 | return k + m; | |
77 | } | |
78 | ||
79 | unsigned int | |
80 | get_data_chunk_count() const override | |
81 | { | |
82 | return k; | |
83 | } | |
84 | ||
85 | unsigned int get_chunk_size(unsigned int object_size) const override; | |
86 | ||
31f18b77 FG |
87 | int encode_chunks(const std::set<int> &want_to_encode, |
88 | std::map<int, bufferlist> *encoded) override; | |
7c673cae | 89 | |
31f18b77 FG |
90 | int decode_chunks(const std::set<int> &want_to_read, |
91 | const std::map<int, bufferlist> &chunks, | |
92 | std::map<int, bufferlist> *decoded) override; | |
7c673cae | 93 | |
31f18b77 | 94 | int init(ErasureCodeProfile &profile, std::ostream *ss) override; |
7c673cae FG |
95 | |
96 | virtual void isa_encode(char **data, | |
97 | char **coding, | |
98 | int blocksize) = 0; | |
99 | ||
100 | ||
101 | virtual int isa_decode(int *erasures, | |
102 | char **data, | |
103 | char **coding, | |
104 | int blocksize) = 0; | |
105 | ||
106 | virtual unsigned get_alignment() const = 0; | |
107 | ||
108 | virtual void prepare() = 0; | |
109 | ||
110 | private: | |
111 | virtual int parse(ErasureCodeProfile &profile, | |
31f18b77 | 112 | std::ostream *ss) = 0; |
7c673cae FG |
113 | }; |
114 | ||
115 | // ----------------------------------------------------------------------------- | |
116 | ||
117 | class ErasureCodeIsaDefault : public ErasureCodeIsa { | |
118 | private: | |
119 | int matrixtype; | |
120 | ||
121 | public: | |
122 | ||
123 | static const std::string DEFAULT_K; | |
124 | static const std::string DEFAULT_M; | |
125 | ||
126 | unsigned char* encode_coeff; // encoding coefficient | |
127 | unsigned char* encode_tbls; // encoding table | |
128 | ||
129 | ErasureCodeIsaDefault(ErasureCodeIsaTableCache &_tcache, | |
130 | int matrix = kVandermonde) : | |
131 | ||
132 | ErasureCodeIsa("default", _tcache), | |
133 | encode_coeff(0), encode_tbls(0) | |
134 | { | |
135 | matrixtype = matrix; | |
136 | } | |
137 | ||
138 | ||
139 | ~ErasureCodeIsaDefault() override | |
140 | { | |
141 | ||
142 | } | |
143 | ||
144 | void isa_encode(char **data, | |
145 | char **coding, | |
146 | int blocksize) override; | |
147 | ||
148 | virtual bool erasure_contains(int *erasures, int i); | |
149 | ||
150 | int isa_decode(int *erasures, | |
151 | char **data, | |
152 | char **coding, | |
153 | int blocksize) override; | |
154 | ||
155 | unsigned get_alignment() const override; | |
156 | ||
157 | void prepare() override; | |
158 | ||
159 | private: | |
160 | int parse(ErasureCodeProfile &profile, | |
31f18b77 | 161 | std::ostream *ss) override; |
7c673cae FG |
162 | }; |
163 | ||
164 | #endif |