From owner-svn-src-head@freebsd.org Sat Oct 20 21:49:45 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C45CFF756C; Sat, 20 Oct 2018 21:49:45 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 32FE78BCA6; Sat, 20 Oct 2018 21:49:45 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 282E723E00; Sat, 20 Oct 2018 21:49:45 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9KLnjJJ045665; Sat, 20 Oct 2018 21:49:45 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9KLnjFA045664; Sat, 20 Oct 2018 21:49:45 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201810202149.w9KLnjFA045664@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 20 Oct 2018 21:49:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339497 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 339497 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2018 21:49:45 -0000 Author: cem Date: Sat Oct 20 21:49:44 2018 New Revision: 339497 URL: https://svnweb.freebsd.org/changeset/base/339497 Log: ZSTDIO: Correctly initialize zstd context with provided 'level' Prior to this revision, we allocated sufficient context space for 'level' but never actually set the compress level parameter, so we would always get the default '3'. Reviewed by: markj, vangyzen MFC after: 12 hours Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D17144 Modified: head/sys/kern/subr_compressor.c Modified: head/sys/kern/subr_compressor.c ============================================================================== --- head/sys/kern/subr_compressor.c Sat Oct 20 21:45:17 2018 (r339496) +++ head/sys/kern/subr_compressor.c Sat Oct 20 21:49:44 2018 (r339497) @@ -275,8 +275,9 @@ zstdio_init(size_t maxiosize, int level) ZSTD_CCtx *dump_compressor; struct zstdio_stream *s; void *wkspc, *owkspc, *buffer; - size_t wkspc_size, buf_size; + size_t wkspc_size, buf_size, rc; + s = NULL; wkspc_size = ZSTD_estimateCStreamSize(level); owkspc = wkspc = malloc(wkspc_size + 8, M_COMPRESS, M_WAITOK | M_NODUMP); @@ -286,12 +287,23 @@ zstdio_init(size_t maxiosize, int level) dump_compressor = ZSTD_initStaticCCtx(wkspc, wkspc_size); if (dump_compressor == NULL) { - free(owkspc, M_COMPRESS); printf("%s: workspace too small.\n", __func__); - return (NULL); + goto out; } - (void)ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_checksumFlag, 1); + rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_checksumFlag, 1); + if (ZSTD_isError(rc)) { + printf("%s: error setting checksumFlag: %s\n", __func__, + ZSTD_getErrorName(rc)); + goto out; + } + rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_compressionLevel, + level); + if (ZSTD_isError(rc)) { + printf("%s: error setting compressLevel: %s\n", __func__, + ZSTD_getErrorName(rc)); + goto out; + } buf_size = ZSTD_CStreamOutSize() * 2; buffer = malloc(buf_size, M_COMPRESS, M_WAITOK | M_NODUMP); @@ -306,6 +318,9 @@ zstdio_init(size_t maxiosize, int level) zstdio_reset(s); +out: + if (s == NULL) + free(owkspc, M_COMPRESS); return (s); }