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
25 #include "ErasureCodeInterface.h"
29 class ErasureCode
: public ErasureCodeInterface
{
31 static const unsigned SIMD_ALIGN
;
33 std::vector
<int> chunk_mapping
;
34 ErasureCodeProfile _profile
;
36 ~ErasureCode() override
{}
38 int init(ErasureCodeProfile
&profile
, std::ostream
*ss
) override
{
43 const ErasureCodeProfile
&get_profile() const override
{
47 int sanity_check_k(int k
, std::ostream
*ss
);
49 unsigned int get_coding_chunk_count() const override
{
50 return get_chunk_count() - get_data_chunk_count();
53 int minimum_to_decode(const std::set
<int> &want_to_read
,
54 const std::set
<int> &available_chunks
,
55 std::set
<int> *minimum
) override
;
57 int minimum_to_decode_with_cost(const std::set
<int> &want_to_read
,
58 const std::map
<int, int> &available
,
59 std::set
<int> *minimum
) override
;
61 int encode_prepare(const bufferlist
&raw
,
62 std::map
<int, bufferlist
> &encoded
) const;
64 int encode(const std::set
<int> &want_to_encode
,
66 std::map
<int, bufferlist
> *encoded
) override
;
68 int encode_chunks(const std::set
<int> &want_to_encode
,
69 std::map
<int, bufferlist
> *encoded
) override
;
71 int decode(const std::set
<int> &want_to_read
,
72 const std::map
<int, bufferlist
> &chunks
,
73 std::map
<int, bufferlist
> *decoded
) override
;
75 int decode_chunks(const std::set
<int> &want_to_read
,
76 const std::map
<int, bufferlist
> &chunks
,
77 std::map
<int, bufferlist
> *decoded
) override
;
79 const std::vector
<int> &get_chunk_mapping() const override
;
81 int to_mapping(const ErasureCodeProfile
&profile
,
84 static int to_int(const std::string
&name
,
85 ErasureCodeProfile
&profile
,
87 const std::string
&default_value
,
90 static int to_bool(const std::string
&name
,
91 ErasureCodeProfile
&profile
,
93 const std::string
&default_value
,
96 static int to_string(const std::string
&name
,
97 ErasureCodeProfile
&profile
,
99 const std::string
&default_value
,
102 int decode_concat(const std::map
<int, bufferlist
> &chunks
,
103 bufferlist
*decoded
) override
;
106 int parse(const ErasureCodeProfile
&profile
,
110 int chunk_index(unsigned int i
) const;