summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--include/erasurecode/erasurecode.h3
-rw-r--r--src/Makefile.am3
-rw-r--r--src/backends/null/null.c220
-rw-r--r--src/builtin/null_code/Makefile.am9
-rw-r--r--src/builtin/null_code/null_code.c68
-rw-r--r--src/erasurecode.c3
-rw-r--r--src/erasurecode_helpers.c1
-rw-r--r--test/liberasurecode_test.c19
9 files changed, 325 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 28e7246..0412ad7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,7 @@ AC_SUBST(ac_aux_dir)
AC_SUBST(OBJECTS)
AC_CONFIG_FILES([\
+ src/builtin/null_code/Makefile \
src/builtin/xor_codes/Makefile \
src/Makefile \
test/Makefile \
diff --git a/include/erasurecode/erasurecode.h b/include/erasurecode/erasurecode.h
index b994ba0..07cac3f 100644
--- a/include/erasurecode/erasurecode.h
+++ b/include/erasurecode/erasurecode.h
@@ -74,6 +74,9 @@ struct ec_args {
int hd; /* hamming distance (3 or 4) */
} flat_xor_hd_args; /* args specific to XOR codes */
struct {
+ uint64_t arg1; /* sample arg */
+ } null_args; /* args specific to the null codes */
+ struct {
uint64_t x, y; /* reserved for future expansion */
uint64_t z, a; /* reserved for future expansion */
} reserved;
diff --git a/src/Makefile.am b/src/Makefile.am
index 2bbbca1..9d844f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = builtin/xor_codes
+SUBDIRS = builtin/xor_codes builtin/null_code
lib_LTLIBRARIES = liberasurecode.la
@@ -14,6 +14,7 @@ liberasurecode_la_SOURCES = \
erasurecode_postprocessing.c \
utils/chksum/crc32.c \
utils/chksum/alg_sig.c \
+ backends/null/null.c \
backends/xor/flat_xor_hd.c \
backends/jerasure/jerasure_rs_vand.c
diff --git a/src/backends/null/null.c b/src/backends/null/null.c
new file mode 100644
index 0000000..b04cd99
--- /dev/null
+++ b/src/backends/null/null.c
@@ -0,0 +1,220 @@
+/*
+ * <Copyright>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY
+ * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * liberasurecode null backend
+ *
+ * vi: set noai tw=79 ts=4 sw=4:
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "erasurecode.h"
+#include "erasurecode_backend.h"
+
+/* Forward declarations */
+struct ec_backend null;
+struct ec_backend_op_stubs null_ops;
+
+struct null_descriptor {
+ /* calls required for init */
+ void* (*init_null_code)(int k, int m, int hd);
+
+ /* calls required for encode */
+ int (*null_code_encode)(void *code_desc, char **data, char **parity,
+ int blocksize);
+
+ /* calls required for decode */
+ int (*null_code_decode)(void *code_desc, char **data, char **parity,
+ int *missing_idxs, int blocksize, int decode_parity);
+
+ /* calls required for reconstruct */
+ int (*null_reconstruct)(char **available_fragments, int num_fragments,
+ uint64_t fragment_len, int destination_idx, char* out_fragment);
+
+ /* set of fragments needed to reconstruct at a minimum */
+ int (*null_code_fragments_needed)(void *code_desc, int *missing_idxs,
+ int *fragments_needed);
+
+ /* fields needed to hold state */
+ int *matrix;
+ int k;
+ int m;
+ int w;
+ int arg1;
+};
+
+#define DEFAULT_W 32
+
+static int null_encode(void *desc, char **data, char **parity,
+ int blocksize)
+{
+ struct null_descriptor *xdesc =
+ (struct null_descriptor *) desc;
+
+ return 0;
+}
+
+static int null_decode(void *desc, char **data, char **parity,
+ int *missing_idxs, int blocksize)
+{
+ struct null_descriptor *xdesc =
+ (struct null_descriptor *) desc;
+
+ return 0;
+}
+
+static int null_reconstruct(void *desc, char **data, char **parity,
+ int *missing_idxs, int destination_idx, int blocksize)
+{
+ struct null_descriptor *xdesc =
+ (struct null_descriptor *) desc;
+
+ return 0;
+}
+
+static int null_min_fragments(void *desc, int *missing_idxs,
+ int *fragments_needed)
+{
+ struct null_descriptor *xdesc =
+ (struct null_descriptor *) desc;
+
+ return 0;
+}
+
+/**
+ * Return the element-size, which is the number of bits stored
+ * on a given device, per codeword. This is usually just 'w'.
+ */
+static int
+null_element_size(void* desc)
+{
+ return DEFAULT_W;
+}
+
+static void * null_init(struct ec_backend_args *args, void *backend_sohandle)
+{
+ int k, m, arg1, w;
+ struct null_descriptor *xdesc = NULL;
+
+ /* allocate and fill in null_descriptor */
+ xdesc = (struct null_descriptor *) malloc(sizeof(struct null_descriptor));
+ if (NULL == xdesc) {
+ return NULL;
+ }
+
+ xdesc->k = args->uargs.k;
+ xdesc->m = args->uargs.m;
+
+ if (xdesc->w <= 0)
+ xdesc->w = DEFAULT_W;
+
+ /* Sample on how to pass extra args to the backend */
+ xdesc->arg1 = args->uargs.priv_args1.null_args.arg1;
+
+ /* store w back in args so upper layer can get to it */
+ args->uargs.w = DEFAULT_W;
+
+ /* validate EC arguments */
+ {
+ long long max_symbols;
+ if (xdesc->w != 8 && xdesc->w != 16 && xdesc->w != 32) {
+ goto error;
+ }
+ max_symbols = 1LL << xdesc->w;
+ if ((xdesc->k + xdesc->m) > max_symbols) {
+ goto error;
+ }
+ }
+
+ /* fill in function addresses */
+ xdesc->init_null_code = dlsym(
+ backend_sohandle, "null_code_init");
+ if (NULL == xdesc->init_null_code) {
+ goto error;
+ }
+
+ xdesc->null_code_encode = dlsym(
+ backend_sohandle, "null_code_encode");
+ if (NULL == xdesc->null_code_encode) {
+ goto error;
+ }
+
+ xdesc->null_code_decode = dlsym(
+ backend_sohandle, "null_code_decode");
+ if (NULL == xdesc->null_code_decode) {
+ goto error;
+ }
+
+ xdesc->null_reconstruct = dlsym(
+ backend_sohandle, "null_reconstruct");
+ if (NULL == xdesc->null_reconstruct) {
+ goto error;
+ }
+
+ xdesc->null_code_fragments_needed = dlsym(
+ backend_sohandle, "null_code_fragments_needed");
+ if (NULL == xdesc->null_code_fragments_needed) {
+ goto error;
+ }
+
+ return (void *) xdesc;
+
+error:
+ if (NULL != xdesc) {
+ free(xdesc);
+ xdesc = NULL;
+ }
+
+ return NULL;
+}
+
+static int null_exit(void *desc)
+{
+ struct null_descriptor *xdesc = (struct null_descriptor *) desc;
+
+ free (xdesc);
+}
+
+struct ec_backend_op_stubs null_op_stubs = {
+ .INIT = null_init,
+ .EXIT = null_exit,
+ .ENCODE = null_encode,
+ .DECODE = null_decode,
+ .FRAGSNEEDED = null_min_fragments,
+ .RECONSTRUCT = null_reconstruct,
+ .ELEMENTSIZE = null_element_size,
+};
+
+struct ec_backend_common backend_null = {
+ .id = EC_BACKEND_NULL,
+ .name = "null",
+#if defined(__MACOS__) || defined(__MACOSX__) || defined(__OSX__) || defined(__APPLE__)
+ .soname = "libnullcode.dylib",
+#else
+ .soname = "libnullcode.so",
+#endif
+ .soversion = "1.0",
+ .ops = &null_op_stubs,
+};
+
diff --git a/src/builtin/null_code/Makefile.am b/src/builtin/null_code/Makefile.am
new file mode 100644
index 0000000..3166256
--- /dev/null
+++ b/src/builtin/null_code/Makefile.am
@@ -0,0 +1,9 @@
+lib_LTLIBRARIES = libnullcode.la
+
+# libnullcode params
+libnullcode_la_SOURCES = null_code.c
+libnullcode_la_CPPFLAGS = -I$(top_srcdir)/include/null_code
+
+# Version format (C - A).(A).(R) for C:R:A input
+libnullcode_la_LDFLAGS = -rpath '$(libdir)' -version-info 1:1:0
+
diff --git a/src/builtin/null_code/null_code.c b/src/builtin/null_code/null_code.c
new file mode 100644
index 0000000..8dfa542
--- /dev/null
+++ b/src/builtin/null_code/null_code.c
@@ -0,0 +1,68 @@
+/*
+ * <Copyright>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY
+ * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * null EC backend
+ *
+ * vi: set noai tw=79 ts=4 sw=4:
+ */
+
+#include <stdint.h>
+
+/* calls required for init */
+void* null_code_init(int k, int m, int hd)
+{
+ /* add your code here */
+}
+
+/* calls required for encode */
+int null_code_encode(void *code_desc, char **data, char **parity,
+ int blocksize)
+{
+ /* add your code here */
+ return 0;
+}
+
+/* calls required for decode */
+int null_code_decode(void *code_desc, char **data, char **parity,
+ int *missing_idxs, int blocksize, int decode_parity)
+{
+ /* add your code here */
+ return 0;
+}
+
+/* calls required for reconstruct */
+int null_reconstruct(char **available_fragments, int num_fragments,
+ uint64_t fragment_len, int destination_idx, char* out_fragment)
+{
+ /* add your code here */
+ return 0;
+}
+
+/* set of fragments needed to reconstruct at a minimum */
+int null_code_fragments_needed(void *code_desc, int *missing_idxs,
+ int *fragments_needed)
+{
+ /* add your code here */
+ return 0;
+}
+
diff --git a/src/erasurecode.c b/src/erasurecode.c
index 6f8f296..6dc8d48 100644
--- a/src/erasurecode.c
+++ b/src/erasurecode.c
@@ -48,11 +48,12 @@ liberasurecode_exit(void) {
/* =~=*=~==~=*=~==~=*=~= Supported EC backends =~=*=~==~=*=~==~=*=~==~=*=~== */
/* EC backend references */
+extern struct ec_backend_common backend_null;
extern struct ec_backend_common backend_flat_xor_hd;
extern struct ec_backend_common backend_jerasure_rs_vand;
ec_backend_t ec_backends_supported[EC_BACKENDS_MAX] = {
- /* backend_null */ NULL,
+ (ec_backend_t) &backend_null,
(ec_backend_t) &backend_jerasure_rs_vand,
/* backend_rs_cauchy_orig */ NULL,
(ec_backend_t) &backend_flat_xor_hd,
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c
index 5b532a6..11a8079 100644
--- a/src/erasurecode_helpers.c
+++ b/src/erasurecode_helpers.c
@@ -25,6 +25,7 @@
*
* vi: set noai tw=79 ts=4 sw=4:
*/
+#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include "erasurecode_backend.h"
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index dc52536..7153cf9 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -85,6 +85,11 @@ static int test_simple_encode_decode(
desc = liberasurecode_instance_create(backend, args);
assert(desc > 0 || -EBACKENDNOTAVAIL == desc);
+ if (-EBACKENDNOTAVAIL == desc) {
+ fprintf (stderr, "Backend library not available! ");
+ return 0;
+ }
+
orig_data = create_buffer(orig_data_size, 'x');
if (NULL == orig_data) {
rc = -ENOMEM;
@@ -110,6 +115,12 @@ out:
return rc;
}
+struct ec_args null_args = {
+ .k = 8,
+ .m = 4,
+ .priv_args1.null_args.arg1 = 11,
+};
+
struct ec_args flat_xor_hd_args = {
.k = 10,
.m = 6,
@@ -129,6 +140,10 @@ struct testcase testcases[] = {
.skip = true},
{"create_and_destroy_backend",
test_create_and_destroy_backend,
+ "null", &null_args,
+ .skip = false},
+ {"create_and_destroy_backend",
+ test_create_and_destroy_backend,
"flat_xor_hd", &flat_xor_hd_args,
.skip = false},
{"create_and_destroy_backend",
@@ -137,6 +152,10 @@ struct testcase testcases[] = {
.skip = false},
{"simple_encode_flat_xor_hd",
test_simple_encode_decode,
+ "null", &null_args,
+ .skip = true},
+ {"simple_encode_flat_xor_hd",
+ test_simple_encode_decode,
"flat_xor_hd", &flat_xor_hd_args,
.skip = false},
{"simple_encode_jerasure_rs_vand",