MEDIUM: compression: move the zlib-specific stuff from global.h to compression.c

This finishes to clean up the zlib-specific parts. It also unbreaks recent
commit b97c6fb ("CLEANUP: compression: use the build options list to report
the algos") which broke USE_ZLIB due to MAXWBITS not being defined anymore
in haproxy.c.
This commit is contained in:
Willy Tarreau 2016-12-22 19:46:17 +01:00
parent 14e36a101c
commit 368780334c
4 changed files with 64 additions and 63 deletions

View File

@ -155,10 +155,6 @@ struct global {
unsigned int ssl_max_record; /* SSL max record size */
unsigned int ssl_default_dh_param; /* SSL maximum DH parameter size */
int ssl_ctx_cache; /* max number of entries in the ssl_ctx cache. */
#endif
#ifdef USE_ZLIB
int zlibmemlevel; /* zlib memlevel */
int zlibwindowsize; /* zlib window size */
#endif
int comp_maxlevel; /* max HTTP compression level */
unsigned short idle_timer; /* how long before an empty buffer is considered idle (ms) */

View File

@ -901,54 +901,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
}
global.tune.max_http_hdr = atol(args[1]);
}
else if (!strcmp(args[0], "tune.zlib.memlevel")) {
#ifdef USE_ZLIB
if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;
if (*args[1]) {
global.tune.zlibmemlevel = atoi(args[1]);
if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) {
Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
} else {
Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
#else
Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
#endif
}
else if (!strcmp(args[0], "tune.zlib.windowsize")) {
#ifdef USE_ZLIB
if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;
if (*args[1]) {
global.tune.zlibwindowsize = atoi(args[1]);
if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) {
Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
} else {
Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
#else
Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
#endif
}
else if (!strcmp(args[0], "tune.comp.maxlevel")) {
if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;

View File

@ -26,6 +26,7 @@
#undef free_func
#endif /* USE_ZLIB */
#include <common/cfgparse.h>
#include <common/compat.h>
#include <common/memory.h>
@ -53,6 +54,9 @@ static struct pool_head *zlib_pool_pending_buf = NULL;
long zlib_used_memory = 0;
static int global_tune_zlibmemlevel = 8; /* zlib memlevel */
static int global_tune_zlibwindowsize = MAX_WBITS; /* zlib window size */
#endif
unsigned int compress_min_idle = 0;
@ -479,7 +483,7 @@ static int gzip_init(struct comp_ctx **comp_ctx, int level)
strm = &(*comp_ctx)->strm;
if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize + 16, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@ -499,7 +503,7 @@ static int raw_def_init(struct comp_ctx **comp_ctx, int level)
strm = &(*comp_ctx)->strm;
if (deflateInit2(strm, level, Z_DEFLATED, -global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
if (deflateInit2(strm, level, Z_DEFLATED, -global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@ -521,7 +525,7 @@ static int deflate_init(struct comp_ctx **comp_ctx, int level)
strm = &(*comp_ctx)->strm;
if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
deinit_comp_ctx(comp_ctx);
return -1;
}
@ -619,8 +623,61 @@ static int deflate_end(struct comp_ctx **comp_ctx)
return ret;
}
/* config parser for global "tune.zlibmemlevel" */
static int zlib_parse_global_memlevel(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, const char *file, int line,
char **err)
{
if (too_many_args(1, args, err, NULL))
return -1;
if (*(args[1]) == 0) {
memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]);
return -1;
}
global_tune_zlibmemlevel = atoi(args[1]);
if (global_tune_zlibmemlevel < 1 || global_tune_zlibmemlevel > 9) {
memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]);
return -1;
}
return 0;
}
/* config parser for global "tune.zlibwindowsize" */
static int zlib_parse_global_windowsize(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, const char *file, int line,
char **err)
{
if (too_many_args(1, args, err, NULL))
return -1;
if (*(args[1]) == 0) {
memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]);
return -1;
}
global_tune_zlibwindowsize = atoi(args[1]);
if (global_tune_zlibwindowsize < 8 || global_tune_zlibwindowsize > 15) {
memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]);
return -1;
}
return 0;
}
#endif /* USE_ZLIB */
/* config keyword parsers */
static struct cfg_kw_list cfg_kws = {ILH, {
#ifdef USE_ZLIB
{ CFG_GLOBAL, "tune.zlib.memlevel", zlib_parse_global_memlevel },
{ CFG_GLOBAL, "tune.zlib.windowsize", zlib_parse_global_windowsize },
#endif
{ 0, NULL, NULL }
}};
__attribute__((constructor))
static void __comp_fetch_init(void)
{
@ -631,6 +688,9 @@ static void __comp_fetch_init(void)
slz_make_crc_table();
slz_prepare_dist_table();
#endif
#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
global.tune.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U,
#endif
#ifdef USE_ZLIB
memprintf(&ptr, "Built with zlib version : " ZLIB_VERSION);
memprintf(&ptr, "%s\nRunning on zlib version : %s", ptr, zlibVersion());
@ -646,4 +706,5 @@ static void __comp_fetch_init(void)
memprintf(&ptr, "%s none", ptr);
hap_register_build_opts(ptr, 1);
cfg_register_keywords(&cfg_kws);
}

View File

@ -123,11 +123,7 @@ struct global global = {
.nbproc = 1,
.req_count = 0,
.logsrvs = LIST_HEAD_INIT(global.logsrvs),
#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U,
#else
.maxzlibmem = 0,
#endif
.comp_rate_lim = 0,
.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED,
.unix_bind = {
@ -150,10 +146,6 @@ struct global global = {
.ssl_max_record = DEFAULT_SSL_MAX_RECORD,
#endif
.ssl_ctx_cache = DEFAULT_SSL_CTX_CACHE,
#endif
#ifdef USE_ZLIB
.zlibmemlevel = 8,
.zlibwindowsize = MAX_WBITS,
#endif
.comp_maxlevel = 1,
#ifdef DEFAULT_IDLE_TIMER