55 struct doca_buf *src_doca_buf;
56 struct doca_buf *dst_doca_buf;
58 uint32_t max_bufs = 2;
59 uint64_t output_checksum = 0;
60 uint32_t adler_checksum = 0;
63 void *dst_buf_data, *dst_buf_tail;
64 size_t data_len, write_len, written_len;
67 uint64_t max_buf_size, max_output_size;
69 bool zlib_compatible =
cfg->is_with_frame;
71 out_file = fopen(
cfg->output_path,
"wr");
72 if (out_file ==
NULL) {
90 goto destroy_resources;
92 if (file_size > max_buf_size) {
93 DOCA_LOG_ERR(
"Invalid file size. Should be smaller than %lu", max_buf_size);
95 goto destroy_resources;
98 max_output_size = max_buf_size;
107 goto destroy_resources;
110 dst_buffer = calloc(1, max_output_size);
111 if (dst_buffer ==
NULL) {
114 goto destroy_resources;
144 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing source buffer: %s",
156 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing destination buffer: %s",
158 goto destroy_src_buf;
164 DOCA_LOG_ERR(
"Unable to set data in the DOCA buffer representing source buffer: %s",
166 goto destroy_dst_buf;
169 if (zlib_compatible) {
173 DOCA_LOG_ERR(
"Unable to set data in the DOCA buffer representing destination buffer: %s",
175 goto destroy_dst_buf;
179 if (
cfg->output_checksum || zlib_compatible) {
183 goto destroy_dst_buf;
189 goto destroy_dst_buf;
195 DOCA_LOG_ERR(
"Unable to get data length in the DOCA buffer representing destination buffer: %s",
197 goto destroy_dst_buf;
199 write_len = data_len;
201 if (zlib_compatible) {
208 DOCA_LOG_ERR(
"Unable to get data length in the DOCA buffer representing destination buffer: %s",
210 goto destroy_dst_buf;
212 dst_buf_tail = ((uint8_t *)dst_buf_data + data_len);
218 DOCA_LOG_ERR(
"Unable to set data in the DOCA buffer representing destination buffer: %s",
220 goto destroy_dst_buf;
225 be_adler_checksum =
htobe32(adler_checksum);
234 written_len = fwrite(dst_buffer,
sizeof(uint8_t), write_len, out_file);
235 if (written_len != write_len) {
236 DOCA_LOG_ERR(
"Failed to write the DOCA buffer representing destination buffer into a file");
238 goto destroy_dst_buf;
241 DOCA_LOG_INFO(
"File was compressed successfully and saved in: %s",
cfg->output_path);
242 if (
cfg->output_checksum)
248 DOCA_LOG_ERR(
"Failed to decrease DOCA destination buffer reference count: %s",
255 DOCA_LOG_ERR(
"Failed to decrease DOCA source buffer reference count: %s",
doca_error_t destroy_compress_resources(struct compress_resources *resources)
void init_compress_zlib_header(struct compress_zlib_header *zlib_header)
doca_error_t allocate_compress_resources(const char *pci_addr, uint32_t max_bufs, struct compress_resources *resources)
doca_error_t submit_compress_deflate_task(struct compress_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint64_t *output_checksum)
@ COMPRESS_MODE_COMPRESS_DEFLATE
#define ZLIB_TRAILER_SIZE
#define ZLIB_COMPATIBILITY_ADDITIONAL_MEMORY
#define ADLER_CHECKSUM_SHIFT
doca_error_t compress_deflate(struct compress_cfg *cfg, char *file_data, size_t file_size)
DOCA_LOG_REGISTER(COMPRESS_DEFLATE)
struct rdma_resources resources
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_get_data(const struct doca_buf *buf, void **data)
Get the buffer's data.
DOCA_STABLE doca_error_t doca_buf_get_data_len(const struct doca_buf *buf, size_t *data_len)
Get buffer's data length.
DOCA_STABLE doca_error_t doca_buf_set_data(struct doca_buf *buf, void *data, size_t data_len)
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_decompress_deflate_get_max_buf_size(const struct doca_devinfo *devinfo, uint64_t *max_buffer_size)
Get decompress deflate max size.
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
@ DOCA_ERROR_OPERATING_SYSTEM
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
const struct ip_frag_config * cfg
struct doca_mmap * src_mmap
struct doca_buf_inventory * buf_inv
struct doca_mmap * dst_mmap