From 3cd1f28e4a30787be8303b00d43fdf1da3c23f33 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Thu, 20 Feb 2020 23:53:48 +0000 Subject: [PATCH] clamp kernel dump compression level when using gzip If the configured compression level for kernel dumps it outside the supported range, clamp it to the closest supported level. Previously, dumpon would fail. zstd already does this internally, so the compressor needs no change. Reviewed by: cem markj MFC after: 2 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D23765 --- sys/kern/subr_compressor.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/kern/subr_compressor.c b/sys/kern/subr_compressor.c index 5950ade1d3ca..b202d271cfa3 100644 --- a/sys/kern/subr_compressor.c +++ b/sys/kern/subr_compressor.c @@ -117,6 +117,13 @@ gz_init(size_t maxiosize, int level) s->gz_stream.next_in = Z_NULL; s->gz_stream.avail_in = 0; + if (level != Z_DEFAULT_COMPRESSION) { + if (level < Z_BEST_SPEED) + level = Z_BEST_SPEED; + else if (level > Z_BEST_COMPRESSION) + level = Z_BEST_COMPRESSION; + } + error = deflateInit2(&s->gz_stream, level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (error != 0)