]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 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_LRC_H | |
19 | #define CEPH_ERASURE_CODE_LRC_H | |
20 | ||
21 | #include "include/err.h" | |
22 | #include "json_spirit/json_spirit.h" | |
23 | #include "erasure-code/ErasureCode.h" | |
24 | ||
25 | #define ERROR_LRC_ARRAY -(MAX_ERRNO + 1) | |
26 | #define ERROR_LRC_OBJECT -(MAX_ERRNO + 2) | |
27 | #define ERROR_LRC_INT -(MAX_ERRNO + 3) | |
28 | #define ERROR_LRC_STR -(MAX_ERRNO + 4) | |
29 | #define ERROR_LRC_PLUGIN -(MAX_ERRNO + 5) | |
30 | #define ERROR_LRC_DESCRIPTION -(MAX_ERRNO + 6) | |
31 | #define ERROR_LRC_PARSE_JSON -(MAX_ERRNO + 7) | |
32 | #define ERROR_LRC_MAPPING -(MAX_ERRNO + 8) | |
33 | #define ERROR_LRC_MAPPING_SIZE -(MAX_ERRNO + 9) | |
34 | #define ERROR_LRC_FIRST_MAPPING -(MAX_ERRNO + 10) | |
35 | #define ERROR_LRC_COUNT_CONSTRAINT -(MAX_ERRNO + 11) | |
36 | #define ERROR_LRC_CONFIG_OPTIONS -(MAX_ERRNO + 12) | |
37 | #define ERROR_LRC_LAYERS_COUNT -(MAX_ERRNO + 13) | |
224ce89b WB |
38 | #define ERROR_LRC_RULE_OP -(MAX_ERRNO + 14) |
39 | #define ERROR_LRC_RULE_TYPE -(MAX_ERRNO + 15) | |
40 | #define ERROR_LRC_RULE_N -(MAX_ERRNO + 16) | |
7c673cae FG |
41 | #define ERROR_LRC_ALL_OR_NOTHING -(MAX_ERRNO + 17) |
42 | #define ERROR_LRC_GENERATED -(MAX_ERRNO + 18) | |
43 | #define ERROR_LRC_K_M_MODULO -(MAX_ERRNO + 19) | |
44 | #define ERROR_LRC_K_MODULO -(MAX_ERRNO + 20) | |
45 | #define ERROR_LRC_M_MODULO -(MAX_ERRNO + 21) | |
46 | ||
47 | class ErasureCodeLrc : public ErasureCode { | |
48 | public: | |
31f18b77 | 49 | static const std::string DEFAULT_KML; |
7c673cae FG |
50 | |
51 | struct Layer { | |
31f18b77 | 52 | explicit Layer(std::string _chunks_map) : chunks_map(_chunks_map) { } |
7c673cae | 53 | ErasureCodeInterfaceRef erasure_code; |
31f18b77 FG |
54 | std::vector<int> data; |
55 | std::vector<int> coding; | |
56 | std::vector<int> chunks; | |
57 | std::set<int> chunks_as_set; | |
58 | std::string chunks_map; | |
7c673cae FG |
59 | ErasureCodeProfile profile; |
60 | }; | |
31f18b77 FG |
61 | std::vector<Layer> layers; |
62 | std::string directory; | |
7c673cae FG |
63 | unsigned int chunk_count; |
64 | unsigned int data_chunk_count; | |
224ce89b WB |
65 | std::string rule_root; |
66 | std::string rule_device_class; | |
7c673cae | 67 | struct Step { |
31f18b77 | 68 | Step(std::string _op, std::string _type, int _n) : |
7c673cae FG |
69 | op(_op), |
70 | type(_type), | |
71 | n(_n) {} | |
31f18b77 FG |
72 | std::string op; |
73 | std::string type; | |
7c673cae FG |
74 | int n; |
75 | }; | |
224ce89b | 76 | std::vector<Step> rule_steps; |
7c673cae FG |
77 | |
78 | explicit ErasureCodeLrc(const std::string &dir) | |
79 | : directory(dir), | |
224ce89b | 80 | chunk_count(0), data_chunk_count(0), rule_root("default") |
7c673cae | 81 | { |
224ce89b | 82 | rule_steps.push_back(Step("chooseleaf", "host", 0)); |
7c673cae FG |
83 | } |
84 | ||
85 | ~ErasureCodeLrc() override {} | |
86 | ||
31f18b77 FG |
87 | std::set<int> get_erasures(const std::set<int> &need, |
88 | const std::set<int> &available) const; | |
7c673cae | 89 | |
31f18b77 FG |
90 | int minimum_to_decode(const std::set<int> &want_to_read, |
91 | const std::set<int> &available, | |
92 | std::set<int> *minimum) override; | |
7c673cae | 93 | |
224ce89b | 94 | int create_rule(const std::string &name, |
7c673cae | 95 | CrushWrapper &crush, |
31f18b77 | 96 | std::ostream *ss) const override; |
7c673cae FG |
97 | |
98 | unsigned int get_chunk_count() const override { | |
99 | return chunk_count; | |
100 | } | |
101 | ||
102 | unsigned int get_data_chunk_count() const override { | |
103 | return data_chunk_count; | |
104 | } | |
105 | ||
106 | unsigned int get_chunk_size(unsigned int object_size) const override; | |
107 | ||
31f18b77 FG |
108 | int encode_chunks(const std::set<int> &want_to_encode, |
109 | std::map<int, bufferlist> *encoded) override; | |
7c673cae | 110 | |
31f18b77 FG |
111 | int decode_chunks(const std::set<int> &want_to_read, |
112 | const std::map<int, bufferlist> &chunks, | |
113 | std::map<int, bufferlist> *decoded) override; | |
7c673cae | 114 | |
31f18b77 | 115 | int init(ErasureCodeProfile &profile, std::ostream *ss) override; |
7c673cae | 116 | |
31f18b77 | 117 | virtual int parse(ErasureCodeProfile &profile, std::ostream *ss); |
7c673cae | 118 | |
31f18b77 | 119 | int parse_kml(ErasureCodeProfile &profile, std::ostream *ss); |
7c673cae | 120 | |
224ce89b | 121 | int parse_rule(ErasureCodeProfile &profile, std::ostream *ss); |
7c673cae | 122 | |
224ce89b WB |
123 | int parse_rule_step(std::string description_string, |
124 | json_spirit::mArray description, | |
125 | std::ostream *ss); | |
7c673cae FG |
126 | |
127 | int layers_description(const ErasureCodeProfile &profile, | |
128 | json_spirit::mArray *description, | |
31f18b77 FG |
129 | std::ostream *ss) const; |
130 | int layers_parse(std::string description_string, | |
7c673cae | 131 | json_spirit::mArray description, |
31f18b77 FG |
132 | std::ostream *ss); |
133 | int layers_init(std::ostream *ss); | |
134 | int layers_sanity_checks(std::string description_string, | |
135 | std::ostream *ss) const; | |
7c673cae FG |
136 | }; |
137 | ||
138 | #endif |