1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph distributed storage system
6 * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
17 #ifndef CEPH_ERASURE_CODE_H
18 #define CEPH_ERASURE_CODE_H
20 /*! @file ErasureCode.h
21 @brief Base class for erasure code plugins implementors
27 #include "ErasureCodeInterface.h"
31 class ErasureCode
: public ErasureCodeInterface
{
33 static const unsigned SIMD_ALIGN
;
35 vector
<int> chunk_mapping
;
36 ErasureCodeProfile _profile
;
38 ~ErasureCode() override
{}
40 int init(ErasureCodeProfile
&profile
, ostream
*ss
) override
{
45 const ErasureCodeProfile
&get_profile() const override
{
49 int sanity_check_k(int k
, ostream
*ss
);
51 unsigned int get_coding_chunk_count() const override
{
52 return get_chunk_count() - get_data_chunk_count();
55 int minimum_to_decode(const set
<int> &want_to_read
,
56 const set
<int> &available_chunks
,
57 set
<int> *minimum
) override
;
59 int minimum_to_decode_with_cost(const set
<int> &want_to_read
,
60 const map
<int, int> &available
,
61 set
<int> *minimum
) override
;
63 int encode_prepare(const bufferlist
&raw
,
64 map
<int, bufferlist
> &encoded
) const;
66 int encode(const set
<int> &want_to_encode
,
68 map
<int, bufferlist
> *encoded
) override
;
70 int encode_chunks(const set
<int> &want_to_encode
,
71 map
<int, bufferlist
> *encoded
) override
;
73 int decode(const set
<int> &want_to_read
,
74 const map
<int, bufferlist
> &chunks
,
75 map
<int, bufferlist
> *decoded
) override
;
77 int decode_chunks(const set
<int> &want_to_read
,
78 const map
<int, bufferlist
> &chunks
,
79 map
<int, bufferlist
> *decoded
) override
;
81 const vector
<int> &get_chunk_mapping() const override
;
83 int to_mapping(const ErasureCodeProfile
&profile
,
86 static int to_int(const std::string
&name
,
87 ErasureCodeProfile
&profile
,
89 const std::string
&default_value
,
92 static int to_bool(const std::string
&name
,
93 ErasureCodeProfile
&profile
,
95 const std::string
&default_value
,
98 static int to_string(const std::string
&name
,
99 ErasureCodeProfile
&profile
,
101 const std::string
&default_value
,
104 int decode_concat(const map
<int, bufferlist
> &chunks
,
105 bufferlist
*decoded
) override
;
108 int parse(const ErasureCodeProfile
&profile
,
112 int chunk_index(unsigned int i
) const;