Added functionality needed to support the get_segment_info() API in PyECLib.

This commit is contained in:
Kevin Greenan
2014-07-21 08:53:59 -07:00
parent 19cd7d3b49
commit bf219bde4f
5 changed files with 89 additions and 1 deletions

View File

@@ -194,6 +194,21 @@ int liberasurecode_get_fragment_metadata(char *fragment);
*/
int liberasurecode_verify_stripe_metadata(char **fragments);
/**
* This computes the aligned size of a buffer passed into
* the encode function. The encode function must pad fragments
* to be algined with the word size (w) and the last fragment also
* needs to be aligned. This computes the sum of the algined fragment
* sizes for a given buffer to encode.
*/
int liberasurecode_get_aligned_data_size(int desc, int data_len);
/**
* This will return the minumum encode size, which is the minimum
* buffer size that can be encoded.
*/
int liberasurecode_get_minimum_encode_size(int desc);
/* ==~=*=~===~=*=~==~=*=~== liberasurecode Error codes =~=*=~==~=~=*=~==~== */

View File

@@ -58,6 +58,7 @@ struct ec_backend_args {
#define DECODE decode
#define FRAGSNEEDED fragments_needed
#define RECONSTRUCT reconstruct
#define ELEMENTSIZE element_size
#define FN_NAME(s) str(s)
#define str(s) #s
@@ -82,6 +83,7 @@ struct ec_backend_op_stubs {
int (*RECONSTRUCT)(void *desc,
char **data, char **parity, int *missing_idxs, int destination_idx,
int blocksize);
int (*ELEMENTSIZE)(void *desc);
};
/* ==~=*=~==~=*=~==~=*=~= backend struct definitions =~=*=~==~=*=~==~=*==~== */

View File

@@ -245,6 +245,23 @@ error:
return NULL;
}
/**
* Return the element-size, which is the number of bits stored
* on a given device, per codeword. For Vandermonde, this is
* 'w'. For somthing like cauchy, this is packetsize * w.
*
* Returns the size in bits!
*/
static int
jerasure_rs_vand_element_size(void* desc)
{
struct jerasure_rs_vand_descriptor *jerasure_desc =
(struct jerasure_rs_vand_descriptor*)desc;
/* Note that cauchy will return pyeclib_handle->w * PYECC_CAUCHY_PACKETSIZE * 8 */
return jerasure_desc->w;
}
static int jerasure_rs_vand_exit(void *desc)
{
struct jerasure_rs_vand_descriptor *jerasure_desc =
@@ -262,6 +279,7 @@ struct ec_backend_op_stubs jerasure_rs_vand_op_stubs = {
.DECODE = jerasure_rs_vand_decode,
.FRAGSNEEDED = jerasure_rs_vand_min_fragments,
.RECONSTRUCT = jerasure_rs_vand_reconstruct,
.ELEMENTSIZE = jerasure_rs_vand_element_size,
};
struct ec_backend_common backend_jerasure_rs_vand = {

View File

@@ -49,6 +49,8 @@ struct flat_xor_hd_descriptor {
int *fragments_needed);
};
#define DEFAULT_W 32
static int flat_xor_hd_encode(void *desc,
char **data, char **parity, int blocksize)
{
@@ -79,7 +81,16 @@ static int flat_xor_hd_min_fragments(void *desc,
xor_desc->fragments_needed(xor_desc, missing_idxs, fragments_needed);
}
#define DEFAULT_W 32
/**
* Return the element-size, which is the number of bits stored
* on a given device, per codeword. This is usually just 'w'.
*/
static int
flar_xor_hd_element_size(void* desc)
{
return DEFAULT_W;
}
static void * flat_xor_hd_init(struct ec_backend_args *args, void *sohandle)
{
int k = args->uargs.k;
@@ -126,6 +137,7 @@ struct ec_backend_op_stubs flat_xor_hd_op_stubs = {
.DECODE = flat_xor_hd_decode,
.FRAGSNEEDED = flat_xor_hd_min_fragments,
.RECONSTRUCT = flat_xor_hd_reconstruct,
.ELEMENTSIZE = flar_xor_hd_element_size,
};
struct ec_backend_common backend_flat_xor_hd = {

View File

@@ -698,6 +698,47 @@ int liberasurecode_fragments_needed(int desc, int *missing_idxs,
out_error:
return ret;
}
/**
* This computes the aligned size of a buffer passed into
* the encode function. The encode function must pad fragments
* to be algined with the word size (w) and the last fragment also
* needs to be aligned. This computes the sum of the algined fragment
* sizes for a given buffer to encode.
*/
int liberasurecode_get_aligned_data_size(int desc, int data_len)
{
int word_size;
int alignment_multiple;
int ret = 0;
int k;
ec_backend_t instance = liberasurecode_backend_instance_get_by_desc(desc);
k = instance->args.uargs.k;
if (NULL == instance) {
ret = -EBACKENDNOTAVAIL;
goto out;
}
word_size = instance->common.ops->element_size(instance->desc.backend_desc) / 8;
alignment_multiple = k * word_size;
ret = (int)ceill((double)data_len / alignment_multiple) * alignment_multiple;
out:
return ret;
}
/**
* This will return the minumum encode size, which is the minimum
* buffer size that can be encoded.
*/
int liberasurecode_get_minimum_encode_size(int desc)
{
return liberasurecode_get_aligned_data_size(desc, 1);
}
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=* misc *=~==~=*=~==~=*=~==~=*=~==~=*=~== */