/* Clears remaining memory of the path repo */ static apr_status_t pr_cleanup(void *data) { path_repo_t *repo = data; int i; #ifdef DEBUG L1("path_repo: snapshot interval: %d\n", SNAPSHOT_INTERVAL); L1("path_repo: cache size: %d\n", CACHE_SIZE); L1("path_repo: stored deltas: %d kB\n", repo->delta_bytes / 1024); L1("path_repo: stored deltas (raw): %d kB\n", repo->delta_bytes_raw / 1024); L1("path_repo: total recon time: %ld ms\n", apr_time_msec(repo->recon_time)); L1("path_repo: total store time: %ld ms\n", apr_time_msec(repo->store_time)); L1("path_repo: cache miss rate: %.2f%% (%d of %d)\n", 100.0f*repo->cache_misses / (repo->cache_hits+repo->cache_misses), repo->cache_misses, (repo->cache_hits+repo->cache_misses)); #endif cb_tree_clear(&repo->tree); for (i = 0; i < repo->cache->nelts; i++) { if (APR_ARRAY_IDX(repo->cache, i, pr_cache_entry_t).tree.root) { cb_tree_clear(&APR_ARRAY_IDX(repo->cache, i, pr_cache_entry_t).tree); } } mukv_close(repo->db); #ifdef USE_SNAPPY snappy_free_env(&repo->snappy_env); #endif return APR_SUCCESS; }
static ssize_t compress_iov_to_buffer(struct trace_record *target, const struct iovec *iov, int iovcnt) { if (NULL == iov) { errno = EFAULT; return -1; } if (iovcnt < 1) { return 0; } char *src_buf = iov[0].iov_base; size_t input_len = iov[0].iov_len; size_t compressed_length = 0; struct snappy_env env; int rc = snappy_init_env(&env); if (rc < 0) { goto finish; } if (iovcnt > 1) { /* TODO: Snappy should be able to accept an input IOV directly. Since this support is currently broken we use a workaround instead. */ input_len = total_iovec_len(iov, iovcnt); src_buf = malloc(input_len); if ((NULL == src_buf) || (copy_iov_to_buffer(src_buf, iov, iovcnt) != (ssize_t) input_len)) { rc = -errno; goto finish; } } if (input_len > 0) { /* Don't bother compressing trailing padding chars. Those will be re-inserted by the reader. */ input_len -= trace_r_count_chr_occurrences(src_buf + 1, input_len - 1, TRACE_UNUSED_SPACE_FILL_VALUE); rc = snappy_compress(&env, src_buf, input_len, (char *)target, &compressed_length); } finish: snappy_free_env(&env); if (src_buf != iov[0].iov_base) { free(src_buf); } if (0 != rc) { errno = -rc; ERR("Buffer compression failed with err", errno, strerror(errno)); return (ssize_t) -1; } TRACE_ASSERT(((ssize_t) compressed_length > 0) || (0 == input_len)); return (ssize_t) compressed_length; }
int ness_compress(ness_compress_method_t m, const char *src, uint32_t src_size, char *dst, uint32_t *dst_size) { int ret = NESS_OK; switch (m) { case NESS_NO_COMPRESS: memcpy(dst + 1, src, src_size); *dst_size = src_size + 1; dst[0] = NESS_NO_COMPRESS; break; case NESS_SNAPPY_METHOD: if (src_size == 0) { *dst_size = 1; } else { size_t out_size; int status; struct snappy_env env; snappy_init_env(&env); status = snappy_compress(&env, src, src_size, dst + 1, &out_size); snappy_free_env(&env); if (status != 0) { __ERROR("snappy compress error %d, src_size %d, dst_size %d", status, src_size, dst_size); ret = 0; } *dst_size = out_size + 1; } dst[0] = NESS_SNAPPY_METHOD; break; default: ret = 0; __ERROR("%s", "no compress method support!"); break; } return ret; }
int ness_decompress(const char *src, uint32_t src_size, char *dst, uint32_t dst_size) { int ret = NESS_OK; /* compressed data is NULL */ if (src_size == 1) return NESS_ERR; switch (src[0] & 0xF) { case NESS_NO_COMPRESS: memcpy(dst, src + 1, src_size - 1); break; case NESS_SNAPPY_METHOD: { int status; struct snappy_env env; snappy_init_env(&env); status = snappy_uncompress(src + 1, src_size - 1, dst); snappy_free_env(&env); if (status != 0) { __ERROR("snappy uncompress error %d", status); ret = 0; goto ERR; } (void)dst_size; } break; default: ret = 0; __ERROR("%s", "no decompress method support!"); break; } ERR: return ret; }
static void snappy_exit(struct crypto_tfm *tfm) { struct snappy_ctx *ctx = crypto_tfm_ctx(tfm); snappy_free_env(&ctx->env); }