Skip to content

Commit

Permalink
[contrib][linux-kernel] Add zstd_min_clevel() and zstd_max_clevel()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrelln committed Mar 30, 2021
1 parent a494308 commit d334ad2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contrib/linux-kernel/linux_zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ zstd_error_code zstd_get_error_code(size_t code);
*/
const char *zstd_get_error_name(size_t code);

/**
* zstd_min_clevel() - minimum allowed compression level
*
* Return: The minimum allowed compression level.
*/
int zstd_min_clevel(void);

/**
* zstd_max_clevel() - maximum allowed compression level
*
* Return: The maximum allowed compression level.
*/
int zstd_max_clevel(void);

/* ====== Parameter Selection ====== */

/**
Expand Down
9 changes: 9 additions & 0 deletions contrib/linux-kernel/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ static void test_decompress_unzstd(test_data_t const *data) {
fprintf(stderr, "Ok\n");
}

static void test_f2fs() {
fprintf(stderr, "testing f2fs uses... ");
CONTROL(zstd_min_clevel() < 0);
CONTROL(zstd_max_clevel() == 22);
fprintf(stderr, "Ok\n");
}

static char *g_stack = NULL;

static void __attribute__((noinline)) use(void *x) {
Expand All @@ -195,13 +202,15 @@ static void __attribute__((noinline)) check_stack() {

static void test_stack_usage(test_data_t const *data) {
set_stack();
test_f2fs();
test_btrfs(data);
test_decompress_unzstd(data);
check_stack();
}

int main(void) {
test_data_t data = create_test_data();
test_f2fs();
test_btrfs(&data);
test_decompress_unzstd(&data);
test_stack_usage(&data);
Expand Down
12 changes: 12 additions & 0 deletions contrib/linux-kernel/zstd_compress_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
#include "common/zstd_deps.h"
#include "common/zstd_internal.h"

int zstd_min_clevel(void)
{
return ZSTD_minCLevel();
}
EXPORT_SYMBOL(zstd_min_clevel);

int zstd_max_clevel(void)
{
return ZSTD_maxCLevel();
}
EXPORT_SYMBOL(zstd_max_clevel);

size_t zstd_compress_bound(size_t src_size)
{
return ZSTD_compressBound(src_size);
Expand Down

0 comments on commit d334ad2

Please sign in to comment.