Unverified Commit 184df27e authored by Sebastian Gottschall's avatar Sebastian Gottschall Committed by GitHub
Browse files

Avoid symbol collision with in-kernel zstdlib



For Linux, when zfs is compiled as an in kernel static variant
and the in kernel zstd library is compiled statically into the kernel
a symbol collision will occur.  This wrapper header renames all
of the relevant zstd functions to avoid this problem.
Reviewed-by: default avatarKjeld Schouten <kjeld@schouten-lebbing.nl>
Reviewed-by: default avatarBrian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: default avatarSebastian Gottschall <s.gottschall@dd-wrt.com>
Closes #10775 
parent 04c37b68
......@@ -83,13 +83,13 @@ typedef struct zfs_zstd_header {
int zstd_init(void);
void zstd_fini(void);
size_t zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level);
int zstd_get_level(void *s_start, size_t s_len, uint8_t *level);
int zstd_decompress_level(void *s_start, void *d_start, size_t s_len,
size_t zfs_zstd_compress(void *s_start, void *d_start, 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,
size_t d_len, uint8_t *level);
int zstd_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len,
int n);
int zfs_zstd_decompress(void *s_start, void *d_start, size_t s_len,
size_t d_len, int n);
#ifdef __cplusplus
}
......
......@@ -13,3 +13,9 @@ KERNEL_C = \
zfs_zstd.c
nodist_libzstd_la_SOURCES = $(KERNEL_C)
lib/zstd.$(OBJEXT): CFLAGS += -fno-tree-vectorize -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h -Wp,-w
lib/zstd.l$(OBJEXT): CFLAGS += -fno-tree-vectorize -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h -Wp,-w
zfs_zstd.$(OBJEXT): CFLAGS += -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h
zfs_zstd.l$(OBJEXT): CFLAGS += -include $(top_srcdir)/module/zstd/include/zstd_compat_wrapper.h
......@@ -66,8 +66,8 @@ zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = {
{"gzip-9", 9, gzip_compress, gzip_decompress, NULL},
{"zle", 64, zle_compress, zle_decompress, NULL},
{"lz4", 0, lz4_compress_zfs, lz4_decompress_zfs, NULL},
{"zstd", ZIO_ZSTD_LEVEL_DEFAULT, zstd_compress, zstd_decompress,
zstd_decompress_level},
{"zstd", ZIO_ZSTD_LEVEL_DEFAULT, zfs_zstd_compress,
zfs_zstd_decompress, zfs_zstd_decompress_level},
};
uint8_t
......
......@@ -24,7 +24,9 @@ $(obj)/lib/zstd.o: c_flags += -fno-tree-vectorize
$(obj)/lib/zstd.o: c_flags += -Wframe-larger-than=20480
# Disable aarch64 neon SIMD instructions for kernel mode
$(obj)/lib/zstd.o: c_flags += -include $(zstd_include)/aarch64_compat.h
$(obj)/lib/zstd.o: c_flags += -include $(zstd_include)/aarch64_compat.h -include $(zstd_include)/zstd_compat_wrapper.h -Wp,-w
$(obj)/zfs_zstd.o: c_flags += -include $(zstd_include)/zstd_compat_wrapper.h
$(MODULE)-objs += zfs_zstd.o
$(MODULE)-objs += lib/zstd.o
......
......@@ -48,6 +48,11 @@ ${zstd}/contrib/single_file_libs/combine.sh \
-r ${zstd}/lib -o module/zstd/lib/zstd.c module/zstd/zstd-in.c
~~~
Note: if the zstd library for zfs is updated to a newer version,
the macro list in include/zstd_compat_wrapper.h usually needs to be updated.
this can be done with some hand crafting of the output of the following
script: nm zstd.o | awk '{print "#define "$3 " zfs_" $3}' > macrotable
## Altering ZSTD and breaking changes
......
This diff is collapsed.
......@@ -342,7 +342,7 @@ zstd_enum_to_level(enum zio_zstd_levels level, int16_t *zstd_level)
/* Compress block using zstd */
size_t
zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level)
{
size_t c_len;
......@@ -446,8 +446,8 @@ zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,
/* Decompress block using zstd and return its stored level */
int
zstd_decompress_level(void *s_start, void *d_start, size_t s_len, size_t d_len,
uint8_t *level)
zfs_zstd_decompress_level(void *s_start, void *d_start, size_t s_len,
size_t d_len, uint8_t *level)
{
ZSTD_DCtx *dctx;
size_t result;
......@@ -521,11 +521,12 @@ zstd_decompress_level(void *s_start, void *d_start, size_t s_len, size_t d_len,
/* Decompress datablock using zstd */
int
zstd_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len,
zfs_zstd_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level __maybe_unused)
{
return (zstd_decompress_level(s_start, d_start, s_len, d_len, NULL));
return (zfs_zstd_decompress_level(s_start, d_start, s_len, d_len,
NULL));
}
/* Allocator for zstd compression context using mempool_allocator */
......@@ -731,7 +732,7 @@ ZFS_MODULE_DESCRIPTION("ZSTD Compression for ZFS");
ZFS_MODULE_LICENSE("BSD");
ZFS_MODULE_VERSION(ZSTD_VERSION_STRING);
EXPORT_SYMBOL(zstd_compress);
EXPORT_SYMBOL(zstd_decompress_level);
EXPORT_SYMBOL(zstd_decompress);
EXPORT_SYMBOL(zfs_zstd_compress);
EXPORT_SYMBOL(zfs_zstd_decompress_level);
EXPORT_SYMBOL(zfs_zstd_decompress);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment