diff options
author | Kevin Greenan <kmgreen2@gmail.com> | 2014-07-21 08:53:59 -0700 |
---|---|---|
committer | Kevin Greenan <kmgreen2@gmail.com> | 2014-07-21 09:10:33 -0700 |
commit | bf219bde4f8decf64de52f46cc9af3eae513edf6 (patch) | |
tree | fce65906811b30ed22395832b771c29e411e408e /src/erasurecode.c | |
parent | 19cd7d3b4960b8f28258e36fe2a42e8301b3c358 (diff) | |
download | liberasurecode-bf219bde4f8decf64de52f46cc9af3eae513edf6.tar.gz |
Added functionality needed to support the get_segment_info() API in PyECLib.
Diffstat (limited to 'src/erasurecode.c')
-rw-r--r-- | src/erasurecode.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/erasurecode.c b/src/erasurecode.c index 8eaf324..a559d5d 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -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 *=~==~=*=~==~=*=~==~=*=~==~=*=~== */ |