liberasurecode 1.6.3
Erasure Code API library
Loading...
Searching...
No Matches
flat_xor_hd.c
Go to the documentation of this file.
1/*
2 * Copyright 2014 Tushar Gohad
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY
13 * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * liberasurecode flat_xor_hd backend
25 *
26 * vi: set noai tw=79 ts=4 sw=4:
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <xor_code.h>
32
33#include "erasurecode.h"
34#include "erasurecode_backend.h"
35
36#define FLAT_XOR_LIB_MAJOR 1
37#define FLAT_XOR_LIB_MINOR 0
38#define FLAT_XOR_LIB_REV 0
39#define FLAT_XOR_LIB_VER_STR "1.0"
40#define FLAT_XOR_LIB_NAME "flat_xor_hd"
41#if defined(__MACOS__) || defined(__MACOSX__) || defined(__OSX__) || defined(__APPLE__)
42#define FLAT_XOR_SO_NAME "libXorcode" LIBERASURECODE_SO_SUFFIX ".dylib"
43#else
44#define FLAT_XOR_SO_NAME "libXorcode" LIBERASURECODE_SO_SUFFIX ".so.1"
45#endif
46#define DEFAULT_W 32
47
48/* Forward declarations */
49struct ec_backend_op_stubs flat_xor_hd_ops;
50struct ec_backend flat_xor_hd;
51struct ec_backend_common backend_flat_xor_hd;
52
53typedef xor_code_t* (*init_xor_hd_code_func)(int, int, int);
54typedef void (*xor_code_encode_func)(xor_code_t *, char **, char **, int);
55typedef int (*xor_code_decode_func)(xor_code_t *, char **, char **, int *, int, int);
56typedef int (*xor_hd_fragments_needed_func)(xor_code_t *, int *, int *, int *);
57
59 xor_code_t *xor_desc;
64};
65
66static int flat_xor_hd_encode(void *desc,
67 char **data, char **parity, int blocksize)
68{
69 struct flat_xor_hd_descriptor *xdesc =
70 (struct flat_xor_hd_descriptor *) desc;
71
72 xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
73 xor_desc->encode(xor_desc, data, parity, blocksize);
74 return 0;
75}
76
77static int flat_xor_hd_decode(void *desc,
78 char **data, char **parity, int *missing_idxs,
79 int blocksize)
80{
81 struct flat_xor_hd_descriptor *xdesc =
82 (struct flat_xor_hd_descriptor *) desc;
83
84 xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
85 return xor_desc->decode(xor_desc, data, parity, missing_idxs, blocksize, 1);
86}
87
88static int flat_xor_hd_reconstruct(void *desc,
89 char **data, char **parity, int *missing_idxs,
90 int destination_idx, int blocksize)
91{
92 struct flat_xor_hd_descriptor *xdesc =
93 (struct flat_xor_hd_descriptor *) desc;
94
95 xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
96 xor_reconstruct_one(xor_desc, data, parity,
97 missing_idxs, destination_idx, blocksize);
98 return 0;
99}
100
101static int flat_xor_hd_min_fragments(void *desc,
102 int *missing_idxs, int *fragments_to_exclude,
103 int *fragments_needed)
104{
105 struct flat_xor_hd_descriptor *xdesc =
106 (struct flat_xor_hd_descriptor *) desc;
107
108 xor_code_t *xor_desc = (xor_code_t *) xdesc->xor_desc;
109 xor_desc->fragments_needed(xor_desc, missing_idxs, fragments_to_exclude, fragments_needed);
110 return 0;
111}
112
117static int
119{
120 return DEFAULT_W;
121}
122
123static void * flat_xor_hd_init(struct ec_backend_args *args, void *sohandle)
124{
125 int k = args->uargs.k;
126 int m = args->uargs.m;
127 int hd = args->uargs.hd;
128
129 xor_code_t *xor_desc = NULL;
130 struct flat_xor_hd_descriptor *bdesc = NULL;
131
132 /* store w back in args so upper layer can get to it */
133 args->uargs.w = DEFAULT_W;
134
135 /* init xor_code_t descriptor */
136 xor_desc = init_xor_hd_code(k, m, hd);
137 if (NULL == xor_desc) {
138 return NULL;
139 }
140
141 /* fill in flat_xor_hd_descriptor */
142 bdesc = (struct flat_xor_hd_descriptor *)
143 malloc(sizeof(struct flat_xor_hd_descriptor));
144 if (NULL == bdesc) {
145 free (xor_desc);
146 return NULL;
147 }
148
149 bdesc->xor_desc = xor_desc;
150
151 return (void *) bdesc;
152}
153
154static int flat_xor_hd_exit(void *desc)
155{
156 struct flat_xor_hd_descriptor *bdesc =
157 (struct flat_xor_hd_descriptor *) desc;
158
159 free (bdesc->xor_desc);
160 free (bdesc);
161 return 0;
162}
163
164/*
165 * For the time being, we only claim compatibility with versions that
166 * match exactly
167 */
168static bool flat_xor_is_compatible_with(uint32_t version) {
169 return version == backend_flat_xor_hd.ec_backend_version;
170}
171
172struct ec_backend_op_stubs flat_xor_hd_op_stubs = {
173 .INIT = flat_xor_hd_init,
174 .EXIT = flat_xor_hd_exit,
175 .ENCODE = flat_xor_hd_encode,
176 .DECODE = flat_xor_hd_decode,
177 .FRAGSNEEDED = flat_xor_hd_min_fragments,
178 .RECONSTRUCT = flat_xor_hd_reconstruct,
179 .ELEMENTSIZE = flar_xor_hd_element_size,
180 .ISCOMPATIBLEWITH = flat_xor_is_compatible_with,
181 .GETMETADATASIZE = get_backend_metadata_size_zero,
182 .GETENCODEOFFSET = get_encode_offset_zero,
183};
184
185struct ec_backend_common backend_flat_xor_hd = {
186 .id = EC_BACKEND_FLAT_XOR_HD,
187 .name = FLAT_XOR_LIB_NAME,
188 .soname = FLAT_XOR_SO_NAME,
189 .soversion = FLAT_XOR_LIB_VER_STR,
190 .ops = &flat_xor_hd_op_stubs,
191 .ec_backend_version = _VERSION(FLAT_XOR_LIB_MAJOR,
194};
195
static int flat_xor_hd_exit(void *desc)
struct ec_backend flat_xor_hd
Definition flat_xor_hd.c:50
struct ec_backend_common backend_flat_xor_hd
Definition flat_xor_hd.c:51
static int flat_xor_hd_reconstruct(void *desc, char **data, char **parity, int *missing_idxs, int destination_idx, int blocksize)
Definition flat_xor_hd.c:88
int(* xor_hd_fragments_needed_func)(xor_code_t *, int *, int *, int *)
Definition flat_xor_hd.c:56
static bool flat_xor_is_compatible_with(uint32_t version)
struct ec_backend_op_stubs flat_xor_hd_ops
Definition flat_xor_hd.c:49
#define FLAT_XOR_LIB_REV
Definition flat_xor_hd.c:38
static int flar_xor_hd_element_size(void *desc)
Return the element-size, which is the number of bits stored on a given device, per codeword.
xor_code_t *(* init_xor_hd_code_func)(int, int, int)
Definition flat_xor_hd.c:53
static int flat_xor_hd_decode(void *desc, char **data, char **parity, int *missing_idxs, int blocksize)
Definition flat_xor_hd.c:77
#define FLAT_XOR_LIB_MINOR
Definition flat_xor_hd.c:37
int(* xor_code_decode_func)(xor_code_t *, char **, char **, int *, int, int)
Definition flat_xor_hd.c:55
void(* xor_code_encode_func)(xor_code_t *, char **, char **, int)
Definition flat_xor_hd.c:54
struct ec_backend_op_stubs flat_xor_hd_op_stubs
static int flat_xor_hd_min_fragments(void *desc, int *missing_idxs, int *fragments_to_exclude, int *fragments_needed)
static int flat_xor_hd_encode(void *desc, char **data, char **parity, int blocksize)
Definition flat_xor_hd.c:66
#define FLAT_XOR_LIB_NAME
Definition flat_xor_hd.c:40
#define FLAT_XOR_SO_NAME
Definition flat_xor_hd.c:44
static void * flat_xor_hd_init(struct ec_backend_args *args, void *sohandle)
#define FLAT_XOR_LIB_MAJOR
Definition flat_xor_hd.c:36
#define FLAT_XOR_LIB_VER_STR
Definition flat_xor_hd.c:39
#define DEFAULT_W
Definition flat_xor_hd.c:46
xor_code_encode_func xor_code_encode
Definition flat_xor_hd.c:61
xor_code_decode_func xor_code_decode
Definition flat_xor_hd.c:62
xor_hd_fragments_needed_func xor_hd_fragments_needed
Definition flat_xor_hd.c:63
init_xor_hd_code_func init_xor_hd_code
Definition flat_xor_hd.c:60
xor_code_t * xor_desc
Definition flat_xor_hd.c:59
void xor_reconstruct_one(xor_code_t *code_desc, char **data, char **parity, int *missing_idxs, int index_to_reconstruct, int blocksize)
Definition xor_code.c:245
xor_code_t * init_xor_hd_code(int k, int m, int hd)