summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Gohad <tushar.gohad@intel.com>2014-09-30 06:35:03 -0700
committerTushar Gohad <tushar.gohad@intel.com>2014-09-30 07:15:16 -0700
commit032b57d9b1c7aadc547fccbacf88af786c9067e7 (patch)
treef007a6716585434a77de352601a6525428939c7b
parent6c8d66e68beee67f81812a21cc69d73ff7b2b0b5 (diff)
downloadliberasurecode-backend_metadata_adder.tar.gz
Add support for custom backend metadatabackend_metadata_adder
A backend may have the need to add custom metadata to the encoded data/parity fragments, in addition to the liberasurecode "fragment metadata headers". This patch gives the ability to a EC backend writer to specify a "metadata adder" that is taken into account when allocating output data/parity fragment buffers. Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
-rw-r--r--include/erasurecode/erasurecode_backend.h4
-rw-r--r--include/erasurecode/erasurecode_helpers.h2
-rw-r--r--include/erasurecode/erasurecode_preprocessing.h1
-rw-r--r--src/backends/isa-l/isa_l_vand.c1
-rw-r--r--src/backends/jerasure/jerasure_rs_cauchy.c1
-rw-r--r--src/backends/jerasure/jerasure_rs_vand.c1
-rw-r--r--src/backends/null/null.c1
-rw-r--r--src/backends/xor/flat_xor_hd.c1
-rw-r--r--src/erasurecode.c4
-rw-r--r--src/erasurecode_helpers.c10
-rw-r--r--src/erasurecode_preprocessing.c18
11 files changed, 32 insertions, 12 deletions
diff --git a/include/erasurecode/erasurecode_backend.h b/include/erasurecode/erasurecode_backend.h
index a6e4440..956b2f1 100644
--- a/include/erasurecode/erasurecode_backend.h
+++ b/include/erasurecode/erasurecode_backend.h
@@ -106,6 +106,10 @@ struct ec_backend_common {
char soversion[MAX_LEN]; /* EC backend shared library version */
struct ec_backend_op_stubs *ops; /* EC backend stubs */
+ int metadata_adder; /* EC backend custom metadata adder -
+ * metadata_adder bytes are added to
+ * the fragment size when allocating
+ * data/parity fragment buffers */
};
/* EC backend definition */
diff --git a/include/erasurecode/erasurecode_helpers.h b/include/erasurecode/erasurecode_helpers.h
index e8fddaa..46dc669 100644
--- a/include/erasurecode/erasurecode_helpers.h
+++ b/include/erasurecode/erasurecode_helpers.h
@@ -118,7 +118,7 @@ void init_fragment_header(char *buf)
void *alloc_zeroed_buffer(int size);
void *alloc_and_set_buffer(int size, int value);
void *check_and_free_buffer(void *buf);
-char *alloc_fragment_buffer(int size);
+char *alloc_fragment_buffer(ec_backend_t instance, int size);
int free_fragment_buffer(char *buf);
void *get_aligned_buffer16(int size);
int get_aligned_data_size(ec_backend_t instance, int data_len);
diff --git a/include/erasurecode/erasurecode_preprocessing.h b/include/erasurecode/erasurecode_preprocessing.h
index 7ca891d..0b479c6 100644
--- a/include/erasurecode/erasurecode_preprocessing.h
+++ b/include/erasurecode/erasurecode_preprocessing.h
@@ -37,6 +37,7 @@ int prepare_fragments_for_encode(
int *blocksize);
int prepare_fragments_for_decode(
+ ec_backend_t instance,
int k, int m,
char **data, char **parity,
int *missing_idxs,
diff --git a/src/backends/isa-l/isa_l_vand.c b/src/backends/isa-l/isa_l_vand.c
index fe11696..e7a575e 100644
--- a/src/backends/isa-l/isa_l_vand.c
+++ b/src/backends/isa-l/isa_l_vand.c
@@ -588,4 +588,5 @@ struct ec_backend_common backend_isa_l_rs_vand = {
#endif
.soversion = "2.0",
.ops = &isa_l_rs_vand_op_stubs,
+ .metadata_adder = 0,
};
diff --git a/src/backends/jerasure/jerasure_rs_cauchy.c b/src/backends/jerasure/jerasure_rs_cauchy.c
index 1c8b528..9d8466a 100644
--- a/src/backends/jerasure/jerasure_rs_cauchy.c
+++ b/src/backends/jerasure/jerasure_rs_cauchy.c
@@ -384,4 +384,5 @@ struct ec_backend_common backend_jerasure_rs_cauchy = {
#endif
.soversion = "2.0",
.ops = &jerasure_rs_cauchy_op_stubs,
+ .metadata_adder = 0,
};
diff --git a/src/backends/jerasure/jerasure_rs_vand.c b/src/backends/jerasure/jerasure_rs_vand.c
index 5866cd5..a8a8257 100644
--- a/src/backends/jerasure/jerasure_rs_vand.c
+++ b/src/backends/jerasure/jerasure_rs_vand.c
@@ -325,4 +325,5 @@ struct ec_backend_common backend_jerasure_rs_vand = {
#endif
.soversion = "2.0",
.ops = &jerasure_rs_vand_op_stubs,
+ .metadata_adder = 0,
};
diff --git a/src/backends/null/null.c b/src/backends/null/null.c
index f71312c..6ca5c98 100644
--- a/src/backends/null/null.c
+++ b/src/backends/null/null.c
@@ -223,5 +223,6 @@ struct ec_backend_common backend_null = {
#endif
.soversion = "1.0",
.ops = &null_op_stubs,
+ .metadata_adder = 0,
};
diff --git a/src/backends/xor/flat_xor_hd.c b/src/backends/xor/flat_xor_hd.c
index 289f36e..0979b30 100644
--- a/src/backends/xor/flat_xor_hd.c
+++ b/src/backends/xor/flat_xor_hd.c
@@ -170,5 +170,6 @@ struct ec_backend_common backend_flat_xor_hd = {
#endif
.soversion = "1.0",
.ops = &flat_xor_hd_op_stubs,
+ .metadata_adder = 0,
};
diff --git a/src/erasurecode.c b/src/erasurecode.c
index b3d1395..61cd269 100644
--- a/src/erasurecode.c
+++ b/src/erasurecode.c
@@ -598,7 +598,7 @@ int liberasurecode_decode(int desc,
* (realloc_bm).
*
*/
- ret = prepare_fragments_for_decode(k, m,
+ ret = prepare_fragments_for_decode(instance, k, m,
data, parity, missing_idxs,
&orig_data_size, &blocksize,
fragment_len, &realloc_bm);
@@ -765,7 +765,7 @@ int liberasurecode_reconstruct_fragment(int desc,
* It passes back a bitmap telling us which buffers need to be freed by
* us (realloc_bm).
*/
- ret = prepare_fragments_for_decode(k, m, data, parity, missing_idxs,
+ ret = prepare_fragments_for_decode(instance, k, m, data, parity, missing_idxs,
&orig_data_size, &blocksize,
fragment_len, &realloc_bm);
if (ret < 0) {
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c
index 6e4c882..42877eb 100644
--- a/src/erasurecode_helpers.c
+++ b/src/erasurecode_helpers.c
@@ -103,14 +103,20 @@ void * check_and_free_buffer(void * buf)
return NULL;
}
-char *alloc_fragment_buffer(int size)
+char *alloc_fragment_buffer(ec_backend_t instance, int size)
{
char *buf;
fragment_header_t *header = NULL;
+ if (NULL != instance) {
+ /* Account for any custom backend metadata in the fragment size */
+ size += instance->common.metadata_adder;
+ }
+
+ /* liberasurecode metadata */
size += sizeof(fragment_header_t);
- buf = get_aligned_buffer16(size);
+ buf = get_aligned_buffer16(size);
if (buf) {
header = (fragment_header_t *) buf;
header->magic = LIBERASURECODE_FRAG_HEADER_MAGIC;
diff --git a/src/erasurecode_preprocessing.c b/src/erasurecode_preprocessing.c
index c3e5ed6..ec471fb 100644
--- a/src/erasurecode_preprocessing.c
+++ b/src/erasurecode_preprocessing.c
@@ -49,7 +49,7 @@ int prepare_fragments_for_encode(ec_backend_t instance,
for (i = 0; i < k; i++) {
int payload_size = data_len > bsize ? bsize : data_len;
- char *fragment = (char *) alloc_fragment_buffer(bsize);
+ char *fragment = (char *) alloc_fragment_buffer(instance, bsize);
if (NULL == fragment) {
ret = -ENOMEM;
goto out_error;
@@ -67,7 +67,7 @@ int prepare_fragments_for_encode(ec_backend_t instance,
}
for (i = 0; i < m; i++) {
- char *fragment = (char *) alloc_fragment_buffer(bsize);
+ char *fragment = (char *) alloc_fragment_buffer(instance, bsize);
if (NULL == fragment) {
ret = -ENOMEM;
goto out_error;
@@ -107,7 +107,7 @@ out_error:
* case, the caller has to free up in the success case, so it may as well do
* so in the failure case.
*/
-int prepare_fragments_for_decode(
+int prepare_fragments_for_decode(ec_backend_t instance,
int k, int m,
char **data, char **parity,
int *missing_idxs,
@@ -135,14 +135,16 @@ int prepare_fragments_for_decode(
* 'data_list'
*/
if (NULL == data[i]) {
- data[i] = alloc_fragment_buffer(fragment_size - sizeof(fragment_header_t));
+ data[i] = alloc_fragment_buffer(instance,
+ fragment_size - sizeof(fragment_header_t));
if (NULL == data[i]) {
log_error("Could not allocate data buffer!");
return -1;
}
*realloc_bm = *realloc_bm | (1 << i);
} else if (!is_addr_aligned((unsigned long)data[i], 16)) {
- char *tmp_buf = alloc_fragment_buffer(fragment_size - sizeof(fragment_header_t));
+ char *tmp_buf = alloc_fragment_buffer(instance,
+ fragment_size - sizeof(fragment_header_t));
memcpy(tmp_buf, data[i], fragment_size);
data[i] = tmp_buf;
*realloc_bm = *realloc_bm | (1 << i);
@@ -170,14 +172,16 @@ int prepare_fragments_for_decode(
* DO NOT FREE: the python GC should free the original when cleaning up 'data_list'
*/
if (NULL == parity[i]) {
- parity[i] = alloc_fragment_buffer(fragment_size-sizeof(fragment_header_t));
+ parity[i] = alloc_fragment_buffer(instance,
+ fragment_size - sizeof(fragment_header_t));
if (NULL == parity[i]) {
log_error("Could not allocate parity buffer!");
return -1;
}
*realloc_bm = *realloc_bm | (1 << (k + i));
} else if (!is_addr_aligned((unsigned long)parity[i], 16)) {
- char *tmp_buf = alloc_fragment_buffer(fragment_size-sizeof(fragment_header_t));
+ char *tmp_buf = alloc_fragment_buffer(instance,
+ fragment_size - sizeof(fragment_header_t));
memcpy(tmp_buf, parity[i], fragment_size);
parity[i] = tmp_buf;
*realloc_bm = *realloc_bm | (1 << (k + i));