From: Willy Tarreau Date: Thu, 29 Apr 2021 14:55:17 +0000 (+0200) Subject: MINOR: map: get rid of map_add_key_value() X-Git-Tag: v2.4-dev18~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4053b03caa02b21ceff0b764461693aa13ec6d57;p=thirdparty%2Fhaproxy.git MINOR: map: get rid of map_add_key_value() This function was only used once in cli_parse_add_map(), and half of the work it used to do was already known from the caller or testable outside of the lock. Given that we'll need to modify it soon to pass a generation number, let's remerge it in the caller instead, using pat_ref_load() which is the one we'll need. --- diff --git a/src/map.c b/src/map.c index 75356ab8eb..490f8bb69b 100644 --- a/src/map.c +++ b/src/map.c @@ -744,20 +744,6 @@ static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx, return 1; } -static int map_add_key_value(struct appctx *appctx, const char *key, const char *value, char **err) -{ - int ret; - - HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); - if (appctx->ctx.map.display_flags == PAT_REF_MAP) - ret = pat_ref_add(appctx->ctx.map.ref, key, value, err); - else - ret = pat_ref_add(appctx->ctx.map.ref, key, NULL, err); - HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); - - return ret; -} - static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx, void *private) { if (strcmp(args[1], "map") == 0 || @@ -842,7 +828,13 @@ static int cli_parse_add_map(char **args, char *payload, struct appctx *appctx, value[l] = 0; } - ret = map_add_key_value(appctx, key, value, &err); + if (appctx->ctx.map.display_flags != PAT_REF_MAP) + value = NULL; + + HA_SPIN_LOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); + ret = !!pat_ref_load(appctx->ctx.map.ref, appctx->ctx.map.ref->curr_gen, key, value, -1, &err); + HA_SPIN_UNLOCK(PATREF_LOCK, &appctx->ctx.map.ref->lock); + if (!ret) { if (err) return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));