summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTushar Gohad <tushar.gohad@intel.com>2014-07-22 22:07:17 -0700
committerTushar Gohad <tushar.gohad@intel.com>2014-07-22 22:07:17 -0700
commit779ff7402495b18d65e50d2a2e46e3c6b75568ef (patch)
treea0f28d55b9fb9bfcf1fedfebec2c307b30e620bb /src
parentf50e15dfa904a31a612965349dc8d213adcf9017 (diff)
downloadliberasurecode-779ff7402495b18d65e50d2a2e46e3c6b75568ef.tar.gz
null_code: First cut
Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
Diffstat (limited to 'src')
-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
6 files changed, 302 insertions, 2 deletions
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"