diff --git a/config/spl-build.m4 b/config/spl-build.m4 index 13c68358b..97b38234b 100644 --- a/config/spl-build.m4 +++ b/config/spl-build.m4 @@ -80,6 +80,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ SPL_AC_SHRINK_DCACHE_MEMORY SPL_AC_SHRINK_ICACHE_MEMORY SPL_AC_KERN_PATH_PARENT + SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE ]) AC_DEFUN([SPL_AC_MODULE_SYMVERS], [ @@ -1802,3 +1803,25 @@ AC_DEFUN([SPL_AC_KERN_PATH_PARENT], [ [kern_path_parent() is available])], []) ]) + +dnl # +dnl # 2.6.39 API compat, +dnl # The function zlib_deflate_workspacesize() now take 2 arguments. +dnl # This was done to avoid always having to allocate the maximum size +dnl # workspace (268K). The caller can now specific the windowBits and +dnl # memLevel compression parameters to get a smaller workspace. +dnl # +AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE], + [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args]) + SPL_LINUX_TRY_COMPILE([ + #include + ],[ + return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL); + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1, + [zlib_deflate_workspacesize() wants 2 args]) + ],[ + AC_MSG_RESULT(no) + ]) +]) diff --git a/configure b/configure index 476100181..d05ff84ac 100755 --- a/configure +++ b/configure @@ -15654,6 +15654,70 @@ _ACEOF fi + { $as_echo "$as_me:$LINENO: checking whether zlib_deflate_workspacesize() wants 2 args" >&5 +$as_echo_n "checking whether zlib_deflate_workspacesize() wants 2 args... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL); + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + ;; user) @@ -19668,6 +19732,70 @@ _ACEOF fi + { $as_echo "$as_me:$LINENO: checking whether zlib_deflate_workspacesize() wants 2 args" >&5 +$as_echo_n "checking whether zlib_deflate_workspacesize() wants 2 args... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL); + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + diff --git a/include/linux/zlib_compat.h b/include/linux/zlib_compat.h new file mode 100644 index 000000000..410dc485e --- /dev/null +++ b/include/linux/zlib_compat.h @@ -0,0 +1,37 @@ +/*****************************************************************************\ + * Copyright (C) 2011 Lawrence Livermore National Security, LLC. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Brian Behlendorf . + * UCRL-CODE-235197 + * + * This file is part of the SPL, Solaris Porting Layer. + * For details, see . + * + * The SPL is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * The SPL is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with the SPL. If not, see . +\*****************************************************************************/ + +#ifndef _SPL_ZLIB_COMPAT_H +#define _SPL_ZLIB_COMPAT_H + +#include + +#ifdef HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE +#define spl_zlib_deflate_workspacesize(wb, ml) \ + zlib_deflate_workspacesize(wb, ml) +#else +#define spl_zlib_deflate_workspacesize(wb, ml) \ + zlib_deflate_workspacesize() +#endif /* HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE */ + +#endif /* SPL_ZLIB_COMPAT_H */ diff --git a/include/sys/types.h b/include/sys/types.h index 786474baa..0c3d88ec3 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -41,6 +41,7 @@ #include #include #include +#include #ifndef HAVE_UINTPTR_T typedef unsigned long uintptr_t; diff --git a/module/spl/spl-zlib.c b/module/spl/spl-zlib.c index 02825b461..c42562f81 100644 --- a/module/spl/spl-zlib.c +++ b/module/spl/spl-zlib.c @@ -198,10 +198,14 @@ EXPORT_SYMBOL(z_uncompress); int zlib_init(void) { + int size; SENTRY; + + size = MAX(spl_zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL), + zlib_inflate_workspacesize()); + zlib_workspace_cache = kmem_cache_create("spl_zlib_workspace_cache", - max(zlib_deflate_workspacesize(), zlib_inflate_workspacesize()), - 0, NULL, NULL, NULL, NULL, NULL, KMC_VMEM); + size, 0, NULL, NULL, NULL, NULL, NULL, KMC_VMEM); if (!zlib_workspace_cache) SRETURN(1); diff --git a/spl_config.h.in b/spl_config.h.in index 7f084f544..b2ba74b8c 100644 --- a/spl_config.h.in +++ b/spl_config.h.in @@ -21,6 +21,9 @@ /* vfs_unlink() wants 2 args */ #undef HAVE_2ARGS_VFS_UNLINK +/* zlib_deflate_workspacesize() wants 2 args */ +#undef HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE + /* file_fsync() wants 3 args */ #undef HAVE_3ARGS_FILE_FSYNC