diff options
author | Rob Norris <[email protected]> | 2024-06-30 12:10:00 +1000 |
---|---|---|
committer | Tony Hutter <[email protected]> | 2024-08-22 16:22:24 -0700 |
commit | d3c12383c95cf7988ac00234a42a4da7989c9034 (patch) | |
tree | 5150793d5877686d9bc71b6b95e41934feab5fce /include/sys | |
parent | 522816498c0ea0d8dfa449cd18e2032b8ac0a9b8 (diff) |
compress: change compression providers API to use ABDs
This commit changes the provider compress and decompress API to take ABD
pointers instead of buffer pointers for both data source and
destination. It then updates all providers to match.
This doesn't actually change the providers to do chunked compression,
just changes the API to allow such an update in the future. Helper
macros are added to easily adapt the ABD functions to their buffer-based
implementations.
Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <[email protected]>
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/zio_compress.h | 58 | ||||
-rw-r--r-- | include/sys/zstd/zstd.h | 6 |
2 files changed, 49 insertions, 15 deletions
diff --git a/include/sys/zio_compress.h b/include/sys/zio_compress.h index 56376fdd1..d41b5dfd4 100644 --- a/include/sys/zio_compress.h +++ b/include/sys/zio_compress.h @@ -22,7 +22,7 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2019, Allan Jude - * Copyright (c) 2019, Klara Inc. + * Copyright (c) 2019, 2024, Klara, Inc. * Use is subject to license terms. * Copyright (c) 2015, 2016 by Delphix. All rights reserved. */ @@ -122,13 +122,13 @@ enum zio_zstd_levels { struct zio_prop; /* Common signature for all zio compress functions. */ -typedef size_t zio_compress_func_t(void *src, void *dst, +typedef size_t zio_compress_func_t(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int); /* Common signature for all zio decompress functions. */ -typedef int zio_decompress_func_t(void *src, void *dst, +typedef int zio_decompress_func_t(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int); /* Common signature for all zio decompress and get level functions. */ -typedef int zio_decompresslevel_func_t(void *src, void *dst, +typedef int zio_decompresslevel_func_t(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, uint8_t *level); /* @@ -153,21 +153,21 @@ extern void lz4_fini(void); /* * Compression routines. */ -extern size_t zfs_lzjb_compress(void *src, void *dst, size_t s_len, +extern size_t zfs_lzjb_compress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern int zfs_lzjb_decompress(void *src, void *dst, size_t s_len, +extern int zfs_lzjb_decompress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern size_t zfs_gzip_compress(void *src, void *dst, size_t s_len, +extern size_t zfs_gzip_compress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern int zfs_gzip_decompress(void *src, void *dst, size_t s_len, +extern int zfs_gzip_decompress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern size_t zfs_zle_compress(void *src, void *dst, size_t s_len, +extern size_t zfs_zle_compress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern int zfs_zle_decompress(void *src, void *dst, size_t s_len, +extern int zfs_zle_decompress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern size_t zfs_lz4_compress(void *src, void *dst, size_t s_len, +extern size_t zfs_lz4_compress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); -extern int zfs_lz4_decompress(void *src, void *dst, size_t s_len, +extern int zfs_lz4_decompress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); /* @@ -179,6 +179,40 @@ extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len, size_t d_len, uint8_t *level); extern int zio_compress_to_feature(enum zio_compress comp); +#define ZFS_COMPRESS_WRAP_DECL(name) \ +size_t \ +name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int n) \ +{ \ + void *s_buf = abd_borrow_buf_copy(src, s_len); \ + void *d_buf = abd_borrow_buf(dst, d_len); \ + size_t c_len = name##_buf(s_buf, d_buf, s_len, d_len, n); \ + abd_return_buf(src, s_buf, s_len); \ + abd_return_buf_copy(dst, d_buf, d_len); \ + return (c_len); \ +} +#define ZFS_DECOMPRESS_WRAP_DECL(name) \ +int \ +name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int n) \ +{ \ + void *s_buf = abd_borrow_buf_copy(src, s_len); \ + void *d_buf = abd_borrow_buf(dst, d_len); \ + int err = name##_buf(s_buf, d_buf, s_len, d_len, n); \ + abd_return_buf(src, s_buf, s_len); \ + abd_return_buf_copy(dst, d_buf, d_len); \ + return (err); \ +} +#define ZFS_DECOMPRESS_LEVEL_WRAP_DECL(name) \ +int \ +name(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, uint8_t *n) \ +{ \ + void *s_buf = abd_borrow_buf_copy(src, s_len); \ + void *d_buf = abd_borrow_buf(dst, d_len); \ + int err = name##_buf(s_buf, d_buf, s_len, d_len, n); \ + abd_return_buf(src, s_buf, s_len); \ + abd_return_buf_copy(dst, d_buf, d_len); \ + return (err); \ +} + #ifdef __cplusplus } #endif diff --git a/include/sys/zstd/zstd.h b/include/sys/zstd/zstd.h index f9e7ac0b3..6d212b082 100644 --- a/include/sys/zstd/zstd.h +++ b/include/sys/zstd/zstd.h @@ -90,12 +90,12 @@ typedef struct zfs_zstd_meta { int zstd_init(void); void zstd_fini(void); -size_t zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, +size_t zfs_zstd_compress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int level); int zfs_zstd_get_level(void *s_start, size_t s_len, uint8_t *level); -int zfs_zstd_decompress_level(void *s_start, void *d_start, size_t s_len, +int zfs_zstd_decompress_level(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, uint8_t *level); -int zfs_zstd_decompress(void *s_start, void *d_start, size_t s_len, +int zfs_zstd_decompress(abd_t *src, abd_t *dst, size_t s_len, size_t d_len, int n); void zfs_zstd_cache_reap_now(void); |