]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: map: get rid of map_add_key_value()
authorWilly Tarreau <w@1wt.eu>
Thu, 29 Apr 2021 14:55:17 +0000 (16:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 30 Apr 2021 13:36:31 +0000 (15:36 +0200)
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.

src/map.c

index 75356ab8ebcbcad837fc94272c3013b34ffb6a10..490f8bb69b3a1a618b0da5da457587d0516dc65e 100644 (file)
--- 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));