]>
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 | 32 | |
7c673cae FG |
33 | class ErasureCodeIsa : public ErasureCode { |
34 | public: | |
35 | ||
36 | enum eMatrix { | |
37 | kVandermonde = 0, kCauchy = 1 | |
38 | }; | |
39 | ||
40 | int k; | |
41 | int m; | |
42 | int w; | |
43 | ||
44 | ErasureCodeIsaTableCache &tcache; | |
45 | const char *technique; | |
7c673cae FG |
46 | |
47 | ErasureCodeIsa(const char *_technique, | |
48 | ErasureCodeIsaTableCache &_tcache) : | |
49 | k(0), | |
50 | m(0), | |
51 | w(0), | |
52 | tcache(_tcache), | |
224ce89b | 53 | technique(_technique) |
7c673cae FG |
54 | { |
55 | } | |
56 | ||
57 | ||
58 | ~ErasureCodeIsa() override | |
59 | { | |
60 | } | |
61 | ||
7c673cae FG |
62 | unsigned int |
63 | get_chunk_count() const override | |
64 | { | |
65 | return k + m; | |
66 | } | |
67 | ||
68 | unsigned int | |
69 | get_data_chunk_count() const override | |
70 | { | |
71 | return k; | |
72 | } | |
73 | ||
74 | unsigned int get_chunk_size(unsigned int object_size) const override; | |
75 | ||
31f18b77 FG |
76 | int encode_chunks(const std::set<int> &want_to_encode, |
77 | std::map<int, bufferlist> *encoded) override; | |
7c673cae | 78 | |
31f18b77 FG |
79 | int decode_chunks(const std::set<int> &want_to_read, |
80 | const std::map<int, bufferlist> &chunks, | |
81 | std::map<int, bufferlist> *decoded) override; | |
7c673cae | 82 | |
31f18b77 | 83 | int init(ErasureCodeProfile &profile, std::ostream *ss) override; |
7c673cae FG |
84 | |
85 | virtual void isa_encode(char **data, | |
86 | char **coding, | |
87 | int blocksize) = 0; | |
88 | ||
89 | ||
90 | virtual int isa_decode(int *erasures, | |
91 | char **data, | |
92 | char **coding, | |
93 | int blocksize) = 0; | |
94 | ||
95 | virtual unsigned get_alignment() const = 0; | |
96 | ||
97 | virtual void prepare() = 0; | |
98 | ||
99 | private: | |
100 | virtual int parse(ErasureCodeProfile &profile, | |
31f18b77 | 101 | std::ostream *ss) = 0; |
7c673cae FG |
102 | }; |
103 | ||
104 | // ----------------------------------------------------------------------------- | |
105 | ||
106 | class ErasureCodeIsaDefault : public ErasureCodeIsa { | |
107 | private: | |
108 | int matrixtype; | |
109 | ||
110 | public: | |
111 | ||
112 | static const std::string DEFAULT_K; | |
113 | static const std::string DEFAULT_M; | |
114 | ||
115 | unsigned char* encode_coeff; // encoding coefficient | |
116 | unsigned char* encode_tbls; // encoding table | |
117 | ||
118 | ErasureCodeIsaDefault(ErasureCodeIsaTableCache &_tcache, | |
119 | int matrix = kVandermonde) : | |
120 | ||
121 | ErasureCodeIsa("default", _tcache), | |
122 | encode_coeff(0), encode_tbls(0) | |
123 | { | |
124 | matrixtype = matrix; | |
125 | } | |
126 | ||
127 | ||
128 | ~ErasureCodeIsaDefault() override | |
129 | { | |
130 | ||
131 | } | |
132 | ||
133 | void isa_encode(char **data, | |
134 | char **coding, | |
135 | int blocksize) override; | |
136 | ||
137 | virtual bool erasure_contains(int *erasures, int i); | |
138 | ||
139 | int isa_decode(int *erasures, | |
140 | char **data, | |
141 | char **coding, | |
142 | int blocksize) override; | |
143 | ||
144 | unsigned get_alignment() const override; | |
145 | ||
146 | void prepare() override; | |
147 | ||
148 | private: | |
149 | int parse(ErasureCodeProfile &profile, | |
31f18b77 | 150 | std::ostream *ss) override; |
7c673cae FG |
151 | }; |
152 | ||
153 | #endif |