liberasurecode 1.6.3
Erasure Code API library
Loading...
Searching...
No Matches
erasurecode_postprocessing.c
Go to the documentation of this file.
1/*
2 * Copyright 2014 Tushar Gohad, Kevin M Greenan, Eric Lambert
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY
13 * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * liberasurecode postprocessing helpers implementation
25 *
26 * vi: set noai tw=79 ts=4 sw=4:
27 */
28
29#include <zlib.h>
30#include "erasurecode_backend.h"
31#include "erasurecode_helpers.h"
32#include "erasurecode_helpers_ext.h"
33#include "erasurecode_log.h"
34#include "erasurecode_stdinc.h"
35#include "alg_sig.h"
36
37void add_fragment_metadata(ec_backend_t be, char *fragment,
38 int idx, uint64_t orig_data_size, int blocksize,
39 ec_checksum_type_t ct, int add_chksum)
40{
41 //TODO EDL we are ignoring the return codes here, fix that
42 set_libec_version(fragment);
43 set_fragment_idx(fragment, idx);
44 set_orig_data_size(fragment, orig_data_size);
45 set_fragment_payload_size(fragment, blocksize);
46 set_backend_id(fragment, be->common.id);
47 set_backend_version(fragment, be->common.ec_backend_version);
48 set_fragment_backend_metadata_size(fragment, be->common.ops->get_backend_metadata_size(
49 be->desc.backend_desc,
50 blocksize));
51
52 if (add_chksum) {
53 set_checksum(ct, fragment, blocksize);
54 }
55
56 fragment_header_t* header = (fragment_header_t*) fragment;
57
58 if (header->magic != LIBERASURECODE_FRAG_HEADER_MAGIC) {
59 log_error("Invalid fragment header (add fragment metadata)!\n");
60 return;
61 }
62
63 char *flag = getenv("LIBERASURECODE_WRITE_LEGACY_CRC");
64 if (flag && !(flag[0] == '\0' || (flag[0] == '0' && flag[1] == '\0'))) {
65 header->metadata_chksum = liberasurecode_crc32_alt(
66 0, &header->meta, sizeof(fragment_metadata_t));
67 } else {
68 header->metadata_chksum = crc32(0, (unsigned char *) &header->meta,
69 sizeof(fragment_metadata_t));
70 }
71}
72
73int finalize_fragments_after_encode(ec_backend_t instance,
74 int k, int m, int blocksize, uint64_t orig_data_size,
75 char **encoded_data, char **encoded_parity)
76{
77 int i, set_chksum = 1;
78 ec_checksum_type_t ct = instance->args.uargs.ct;
79
80 /* finalize data fragments */
81 for (i = 0; i < k; i++) {
82 char *fragment = get_fragment_ptr_from_data(encoded_data[i]);
83 add_fragment_metadata(instance, fragment, i, orig_data_size,
84 blocksize, ct, set_chksum);
85 encoded_data[i] = fragment;
86 }
87
88 /* finalize parity fragments */
89 for (i = 0; i < m; i++) {
90 char *fragment = get_fragment_ptr_from_data(encoded_parity[i]);
91 add_fragment_metadata(instance, fragment, i + k, orig_data_size,
92 blocksize, ct, set_chksum);
93 encoded_parity[i] = fragment;
94 }
95
96 return 0;
97}
int liberasurecode_crc32_alt(int crc, const void *buf, size_t size)
Definition crc32.c:92
int set_fragment_payload_size(char *buf, int size)
int set_checksum(ec_checksum_type_t ct, char *buf, int blocksize)
char * get_fragment_ptr_from_data(char *buf)
int set_fragment_idx(char *buf, int idx)
int set_fragment_backend_metadata_size(char *buf, int size)
int set_libec_version(char *buf)
int set_backend_id(char *buf, ec_backend_id_t id)
int set_orig_data_size(char *buf, int orig_data_size)
int set_backend_version(char *buf, uint32_t version)
void add_fragment_metadata(ec_backend_t be, char *fragment, int idx, uint64_t orig_data_size, int blocksize, ec_checksum_type_t ct, int add_chksum)
int finalize_fragments_after_encode(ec_backend_t instance, int k, int m, int blocksize, uint64_t orig_data_size, char **encoded_data, char **encoded_parity)