Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / erasure-code / isa / ErasureCodePluginIsa.cc
1 /*
2  * Ceph - scalable distributed file system
3  *
4  * Copyright (C) 2014 CERN (Switzerland)
5  *
6  * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch>
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  */
14
15
16 /**
17  * @file   ErasureCodePluginIsa.cc
18  *
19  * @brief  Erasure Code Plug-in class wrapping the INTEL ISA-L library
20  *
21  * The factory plug-in class allows to call individual encoding techniques.
22  * The INTEL ISA-L library provides two pre-defined encoding matrices
23  * (cauchy, reed_sol_van = default).
24  */
25
26 // -----------------------------------------------------------------------------
27 #include "ceph_ver.h"
28 #include "include/buffer.h"
29 #include "ErasureCodePluginIsa.h"
30 #include "ErasureCodeIsa.h"
31 // -----------------------------------------------------------------------------
32
33 int ErasureCodePluginIsa::factory(const std::string &directory,
34                       ErasureCodeProfile &profile,
35                       ErasureCodeInterfaceRef *erasure_code,
36                       std::ostream *ss)
37 {
38     ErasureCodeIsa *interface;
39     std::string t;
40     if (profile.find("technique") == profile.end())
41       profile["technique"] = "reed_sol_van";
42     t = profile.find("technique")->second;
43     if ((t == "reed_sol_van")) {
44       interface = new ErasureCodeIsaDefault(tcache,
45                                             ErasureCodeIsaDefault::kVandermonde);
46     } else {
47       if ((t == "cauchy")) {
48         interface = new ErasureCodeIsaDefault(tcache,
49                                               ErasureCodeIsaDefault::kCauchy);
50       } else {
51         *ss << "technique=" << t << " is not a valid coding technique. "
52           << " Choose one of the following: "
53           << "reed_sol_van,"
54           << "cauchy" << std::endl;
55         return -ENOENT;
56       }
57     }
58
59     int r = interface->init(profile, ss);
60     if (r) {
61       delete interface;
62       return r;
63     }
64     *erasure_code = ErasureCodeInterfaceRef(interface);
65     return 0;
66 }
67
68 #ifndef BUILDING_FOR_EMBEDDED
69
70 // -----------------------------------------------------------------------------
71
72 const char *__erasure_code_version()
73 {
74   return CEPH_GIT_NICE_VER;
75 }
76
77 // -----------------------------------------------------------------------------
78
79 int __erasure_code_init(char *plugin_name, char *directory)
80 {
81   ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
82
83   return instance.add(plugin_name, new ErasureCodePluginIsa());
84 }
85
86 #endif