]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/shec/ErasureCodeShec.h
2974bce9d38cc02afd65d6e5f677f6d4ffbd1d69
[ceph.git] / ceph / src / erasure-code / shec / ErasureCodeShec.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 - scalable distributed file system
5 *
6 * Copyright (C) 2014 FUJITSU LIMITED
7 * Copyright (C) 2013, 2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Copyright (C) 2014 Red Hat <contact@redhat.com>
9 *
10 * Author: Takanori Nakao <nakao.takanori@jp.fujitsu.com>
11 * Author: Takeshi Miyamae <miyamae.takeshi@jp.fujitsu.com>
12 * Author: Loic Dachary <loic@dachary.org>
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 */
20
21 #ifndef CEPH_ERASURE_CODE_SHEC_H
22 #define CEPH_ERASURE_CODE_SHEC_H
23
24 #include "erasure-code/ErasureCode.h"
25 #include "ErasureCodeShecTableCache.h"
26
27 #define DEFAULT_RULESET_ROOT "default"
28 #define DEFAULT_RULESET_FAILURE_DOMAIN "host"
29
30 class ErasureCodeShec : public ErasureCode {
31
32 public:
33 enum {
34 MULTIPLE = 0,
35 SINGLE = 1
36 };
37
38 ErasureCodeShecTableCache &tcache;
39 int k;
40 int DEFAULT_K;
41 int m;
42 int DEFAULT_M;
43 int c;
44 int DEFAULT_C;
45 int w;
46 int DEFAULT_W;
47 int technique;
48 string ruleset_root;
49 string ruleset_failure_domain;
50 int *matrix;
51
52 ErasureCodeShec(const int _technique,
53 ErasureCodeShecTableCache &_tcache) :
54 tcache(_tcache),
55 k(0),
56 DEFAULT_K(4),
57 m(0),
58 DEFAULT_M(3),
59 c(0),
60 DEFAULT_C(2),
61 w(0),
62 DEFAULT_W(8),
63 technique(_technique),
64 ruleset_root(DEFAULT_RULESET_ROOT),
65 ruleset_failure_domain(DEFAULT_RULESET_FAILURE_DOMAIN),
66 matrix(0)
67 {}
68
69 ~ErasureCodeShec() override {}
70
71 int create_ruleset(const string &name,
72 CrushWrapper &crush,
73 ostream *ss) const override;
74
75 unsigned int get_chunk_count() const override {
76 return k + m;
77 }
78
79 unsigned int get_data_chunk_count() const override {
80 return k;
81 }
82
83 unsigned int get_chunk_size(unsigned int object_size) const override;
84
85 int minimum_to_decode(const set<int> &want_to_read,
86 const set<int> &available_chunks,
87 set<int> *minimum) override;
88
89 int minimum_to_decode_with_cost(const set<int> &want_to_read,
90 const map<int, int> &available,
91 set<int> *minimum) override;
92
93 int encode(const set<int> &want_to_encode,
94 const bufferlist &in,
95 map<int, bufferlist> *encoded) override;
96 int encode_chunks(const set<int> &want_to_encode,
97 map<int, bufferlist> *encoded) override;
98
99 int decode(const set<int> &want_to_read,
100 const map<int, bufferlist> &chunks,
101 map<int, bufferlist> *decoded) override;
102 int decode_chunks(const set<int> &want_to_read,
103 const map<int, bufferlist> &chunks,
104 map<int, bufferlist> *decoded) override;
105
106 int init(ErasureCodeProfile &profile, ostream *ss) override;
107 virtual void shec_encode(char **data,
108 char **coding,
109 int blocksize) = 0;
110 virtual int shec_decode(int *erasures,
111 int *avails,
112 char **data,
113 char **coding,
114 int blocksize) = 0;
115 virtual unsigned get_alignment() const = 0;
116 virtual void prepare() = 0;
117
118 virtual int shec_matrix_decode(int *erased, int *avails,
119 char **data_ptrs, char **coding_ptrs, int size);
120 virtual int* shec_reedsolomon_coding_matrix(int is_single);
121
122 private:
123 virtual int parse(const ErasureCodeProfile &profile) = 0;
124
125 virtual double shec_calc_recovery_efficiency1(int k, int m1, int m2, int c1, int c2);
126 virtual int shec_make_decoding_matrix(bool prepare,
127 int *want, int *avails,
128 int *decoding_matrix,
129 int *dm_row, int *dm_column,
130 int *minimum);
131 };
132
133 class ErasureCodeShecReedSolomonVandermonde : public ErasureCodeShec {
134 public:
135
136 ErasureCodeShecReedSolomonVandermonde(ErasureCodeShecTableCache &_tcache,
137 int technique = MULTIPLE) :
138 ErasureCodeShec(technique, _tcache)
139 {}
140
141 ~ErasureCodeShecReedSolomonVandermonde() override {
142 }
143
144 void shec_encode(char **data,
145 char **coding,
146 int blocksize) override;
147 int shec_decode(int *erasures,
148 int *avails,
149 char **data,
150 char **coding,
151 int blocksize) override;
152 unsigned get_alignment() const override;
153 void prepare() override;
154 private:
155 int parse(const ErasureCodeProfile &profile) override;
156 };
157
158 #endif