]> git.proxmox.com Git - ceph.git/blame - ceph/src/erasure-code/lrc/ErasureCodeLrc.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / lrc / ErasureCodeLrc.h
CommitLineData
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)
38#define ERROR_LRC_RULESET_OP -(MAX_ERRNO + 14)
39#define ERROR_LRC_RULESET_TYPE -(MAX_ERRNO + 15)
40#define ERROR_LRC_RULESET_N -(MAX_ERRNO + 16)
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
47class ErasureCodeLrc : public ErasureCode {
48public:
49 static const string DEFAULT_KML;
50
51 struct Layer {
52 explicit Layer(string _chunks_map) : chunks_map(_chunks_map) { }
53 ErasureCodeInterfaceRef erasure_code;
54 vector<int> data;
55 vector<int> coding;
56 vector<int> chunks;
57 set<int> chunks_as_set;
58 string chunks_map;
59 ErasureCodeProfile profile;
60 };
61 vector<Layer> layers;
62 string directory;
63 unsigned int chunk_count;
64 unsigned int data_chunk_count;
65 string ruleset_root;
66 struct Step {
67 Step(string _op, string _type, int _n) :
68 op(_op),
69 type(_type),
70 n(_n) {}
71 string op;
72 string type;
73 int n;
74 };
75 vector<Step> ruleset_steps;
76
77 explicit ErasureCodeLrc(const std::string &dir)
78 : directory(dir),
79 chunk_count(0), data_chunk_count(0), ruleset_root("default")
80 {
81 ruleset_steps.push_back(Step("chooseleaf", "host", 0));
82 }
83
84 ~ErasureCodeLrc() override {}
85
86 set<int> get_erasures(const set<int> &need,
87 const set<int> &available) const;
88
89 int minimum_to_decode(const set<int> &want_to_read,
90 const set<int> &available,
91 set<int> *minimum) override;
92
93 int create_ruleset(const string &name,
94 CrushWrapper &crush,
95 ostream *ss) const override;
96
97 unsigned int get_chunk_count() const override {
98 return chunk_count;
99 }
100
101 unsigned int get_data_chunk_count() const override {
102 return data_chunk_count;
103 }
104
105 unsigned int get_chunk_size(unsigned int object_size) const override;
106
107 int encode_chunks(const set<int> &want_to_encode,
108 map<int, bufferlist> *encoded) override;
109
110 int decode_chunks(const set<int> &want_to_read,
111 const map<int, bufferlist> &chunks,
112 map<int, bufferlist> *decoded) override;
113
114 int init(ErasureCodeProfile &profile, ostream *ss) override;
115
116 virtual int parse(ErasureCodeProfile &profile, ostream *ss);
117
118 int parse_kml(ErasureCodeProfile &profile, ostream *ss);
119
120 int parse_ruleset(ErasureCodeProfile &profile, ostream *ss);
121
122 int parse_ruleset_step(string description_string,
123 json_spirit::mArray description,
124 ostream *ss);
125
126 int layers_description(const ErasureCodeProfile &profile,
127 json_spirit::mArray *description,
128 ostream *ss) const;
129 int layers_parse(string description_string,
130 json_spirit::mArray description,
131 ostream *ss);
132 int layers_init(ostream *ss);
133 int layers_sanity_checks(string description_string,
134 ostream *ss) const;
135};
136
137#endif