API to get total fragment size

Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
This commit is contained in:
Tushar Gohad
2014-07-20 16:59:21 -07:00
parent af4279dfb2
commit 4de83981d3
4 changed files with 32 additions and 20 deletions

View File

@@ -147,10 +147,11 @@ int get_aligned_data_size(ec_backend_t instance, int data_len);
char *get_data_ptr_from_fragment(char *buf);
char *get_fragment_ptr_from_data_novalidate(char *buf);
char *get_fragment_ptr_from_data(char *buf);
uint64_t get_fragment_size(char *buf);
int set_fragment_idx(char *buf, int idx);
int get_fragment_idx(char *buf);
int set_fragment_size(char *buf, int size);
int get_fragment_size(char *buf);
int set_fragment_payload_size(char *buf, int size);
int get_fragment_payload_size(char *buf);
int set_orig_data_size(char *buf, int orig_data_size);
int get_orig_data_size(char *buf);
int validate_fragment(char *buf);

View File

@@ -79,7 +79,7 @@ static int jerasure_rs_vand_encode(void *desc, char **data, char **parity,
int blocksize)
{
struct jerasure_rs_vand_descriptor *jerasure_desc =
(struct jerasure_rs_vand_descriptor*)desc;
(struct jerasure_rs_vand_descriptor*) desc;
/* FIXME - make jerasure_matrix_encode return a value */
jerasure_desc->jerasure_matrix_encode(jerasure_desc->k, jerasure_desc->m,

View File

@@ -38,15 +38,8 @@
*
* The following methods provide wrappers for allocating and deallocating
* memory.
*
* Future discussions may want to consider moving closer to the recommended
* guidelines in the Python\C API reference manual. One potential issue,
* however, may be how we enforce memory alignment in the Python heap.
*
* 2.7: https://docs.python.org/2.7/c-api/memory.html
* 3.4: https://docs.python.org/3.4/c-api/memory.html
*/
void *get_aligned_buffer16(int size)
void *get_aligned_buffer16(int size)
{
void *buf;
@@ -136,6 +129,24 @@ int free_fragment_buffer(char *buf)
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */
/**
* Return total fragment length (on-disk, on-wire)
*
* @param buf - pointer to fragment buffer
*
* @return fragment size on disk
*/
uint64_t get_fragment_size(char *buf)
{
fragment_header_t *header = NULL;
if (NULL == buf)
return -1;
header = (fragment_header_t *) buf;
return (header->size + sizeof(fragment_header_t));
}
/**
* Compute a size aligned to the number of data and the underlying wordsize
* of the EC algorithm.
@@ -229,7 +240,7 @@ int get_fragment_idx(char *buf)
return header->idx;
}
int set_fragment_size(char *buf, int size)
int set_fragment_payload_size(char *buf, int size)
{
fragment_header_t *header = (fragment_header_t *) buf;
@@ -243,7 +254,7 @@ int set_fragment_size(char *buf, int size)
return 0;
}
int get_fragment_size(char *buf)
int get_fragment_payload_size(char *buf)
{
fragment_header_t *header = (fragment_header_t *) buf;

View File

@@ -48,7 +48,7 @@ int prepare_fragments_for_encode(ec_backend_t instance,
for (i = 0; i < k; i++) {
int payload_size = data_len > *blocksize ? *blocksize : data_len;
char *fragment = alloc_fragment_buffer(*blocksize);
char *fragment = alloc_fragment_buffer(*blocksize);
if (NULL == fragment) {
ret = -ENOMEM;
goto out_error;
@@ -62,7 +62,7 @@ int prepare_fragments_for_encode(ec_backend_t instance,
/* Fragment size will always be the same
* (may be able to get rid of this) */
set_fragment_size(fragment, *blocksize);
set_fragment_payload_size(fragment, *blocksize);
orig_data += payload_size;
data_len -= payload_size;
@@ -75,7 +75,7 @@ int prepare_fragments_for_encode(ec_backend_t instance,
goto out_error;
}
encoded_parity[i] = get_data_ptr_from_fragment(fragment);
set_fragment_size(fragment, *blocksize);
set_fragment_payload_size(fragment, *blocksize);
}
out:
@@ -156,7 +156,7 @@ int prepare_fragments_for_decode(
log_error("Invalid orig_data_size in fragment header!");
return -1;
}
payload_size = get_fragment_size(data[i]);
payload_size = get_fragment_payload_size(data[i]);
if (orig_data_size < 0) {
log_error("Invalid fragment_size in fragment header!");
return -1;
@@ -172,7 +172,7 @@ int prepare_fragments_for_decode(
}
/* Perform the same allocation, alignment checks on the parity fragments */
for (i=0; i < m; i++) {
for (i = 0; i < m; i++) {
/*
* Allocate or replace with aligned buffer, if the buffer was not aligned.
* DO NOT FREE: the python GC should free the original when cleaning up 'data_list'
@@ -286,7 +286,7 @@ int fragments_to_string(int k, int m,
for (i = 0; i < num_fragments; i++) {
index = get_fragment_idx(fragments[i]);
data_size = get_fragment_size(fragments[i]);
data_size = get_fragment_payload_size(fragments[i]);
if ((index < 0) || (data_size < 0)) {
log_error("Invalid fragment header information!");
goto out;
@@ -336,7 +336,7 @@ int fragments_to_string(int k, int m,
/* Copy fragment data into cstring (fragments should be in index order) */
for (i = 0; i < num_data && orig_data_size > 0; i++) {
char* fragment_data = get_data_ptr_from_fragment(data[i]);
int fragment_size = get_fragment_size(data[i]);
int fragment_size = get_fragment_payload_size(data[i]);
int payload_size = orig_data_size > fragment_size ? fragment_size : orig_data_size;
memcpy(internal_payload + string_off, fragment_data, payload_size);