From a75eea78e29fa36e01350f0f7f8107b4a5bced4f Mon Sep 17 00:00:00 2001 From: Dragan Dosen Date: Fri, 21 May 2021 16:59:15 +0200 Subject: [PATCH] MINOR: map/acl: print the count of all the map/acl entries in "show map/acl" The output of "show map/acl" now contains the 'entry_cnt' value that represents the count of all the entries for each map/acl, not just the active ones, which means that it also includes entries currently being added. --- doc/management.txt | 8 ++++++-- include/haproxy/pattern-t.h | 1 + src/map.c | 5 +++-- src/pattern.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/management.txt b/doc/management.txt index ab122fc89..b1ef55ec2 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -2220,7 +2220,9 @@ show acl [[@] ] versions will simply report no result. The dump format is the same as for the maps even for the sample values. The data returned are not a list of available ACL, but are the list of all patterns composing any ACL. Many of - these patterns can be shared with maps. + these patterns can be shared with maps. The 'entry_cnt' value represents the + count of all the ACL entries, not just the active ones, which means that it + also includes entries currently being added. show backend Dump the list of backends available in the running process @@ -2523,7 +2525,9 @@ show map [[@] ] version currently being matched against and reported as 'curr_ver' in the map list). It is possible to instead dump other versions by prepending '@' before the map's identifier. The version works as a filter and non-existing - versions will simply report no result. + versions will simply report no result. The 'entry_cnt' value represents the + count of all the map entries, not just the active ones, which means that it + also includes entries currently being added. In the output, the first column is a unique entry identifier, which is usable as a reference for operations "del map" and "set map". The second column is diff --git a/include/haproxy/pattern-t.h b/include/haproxy/pattern-t.h index 0cd9af0ae..27305b2d1 100644 --- a/include/haproxy/pattern-t.h +++ b/include/haproxy/pattern-t.h @@ -110,6 +110,7 @@ struct pat_ref { unsigned int next_gen; /* next generation number (insertions use this one) */ int unique_id; /* Each pattern reference have unique id. */ unsigned long long revision; /* updated for each update */ + unsigned long long entry_cnt; /* the total number of entries */ __decl_thread(HA_SPINLOCK_T lock); /* Lock used to protect pat ref elements */ }; diff --git a/src/map.c b/src/map.c index f1b2be90c..00297022d 100644 --- a/src/map.c +++ b/src/map.c @@ -439,9 +439,10 @@ static int cli_io_handler_pats_list(struct appctx *appctx) /* Build messages. If the reference is used by another category than * the listed categories, display the information in the message. */ - chunk_appendf(&trash, "%d (%s) %s. curr_ver=%u next_ver=%u\n", appctx->ctx.map.ref->unique_id, + chunk_appendf(&trash, "%d (%s) %s. curr_ver=%u next_ver=%u entry_cnt=%llu\n", appctx->ctx.map.ref->unique_id, appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", - appctx->ctx.map.ref->display, appctx->ctx.map.ref->curr_gen, appctx->ctx.map.ref->next_gen); + appctx->ctx.map.ref->display, appctx->ctx.map.ref->curr_gen, appctx->ctx.map.ref->next_gen, + appctx->ctx.map.ref->entry_cnt); if (ci_putchk(si_ic(si), &trash) == -1) { /* let's try again later from this stream. We add ourselves into diff --git a/src/pattern.c b/src/pattern.c index 265b05f48..afc0ad0d0 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -1177,6 +1177,7 @@ void pat_prune_gen(struct pattern_expr *expr) free_pattern_tree(&expr->pattern_tree_2); LIST_INIT(&expr->patterns); expr->ref->revision = rdtsc(); + expr->ref->entry_cnt = 0; } /* @@ -1205,6 +1206,7 @@ int pat_idx_list_val(struct pattern_expr *expr, struct pattern *pat, char **err) patl->from_ref = pat->ref->list_head; pat->ref->list_head = &patl->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1237,6 +1239,7 @@ int pat_idx_list_ptr(struct pattern_expr *expr, struct pattern *pat, char **err) patl->from_ref = pat->ref->list_head; pat->ref->list_head = &patl->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1270,6 +1273,7 @@ int pat_idx_list_str(struct pattern_expr *expr, struct pattern *pat, char **err) patl->from_ref = pat->ref->list_head; pat->ref->list_head = &patl->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1303,6 +1307,7 @@ int pat_idx_list_reg_cap(struct pattern_expr *expr, struct pattern *pat, int cap patl->from_ref = pat->ref->list_head; pat->ref->list_head = &patl->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1354,6 +1359,7 @@ int pat_idx_tree_ip(struct pattern_expr *expr, struct pattern *pat, char **err) node->from_ref = pat->ref->tree_head; pat->ref->tree_head = &node->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1384,6 +1390,7 @@ int pat_idx_tree_ip(struct pattern_expr *expr, struct pattern *pat, char **err) node->from_ref = pat->ref->tree_head; pat->ref->tree_head = &node->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1430,6 +1437,7 @@ int pat_idx_tree_str(struct pattern_expr *expr, struct pattern *pat, char **err) node->from_ref = pat->ref->tree_head; pat->ref->tree_head = &node->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1474,6 +1482,7 @@ int pat_idx_tree_pfx(struct pattern_expr *expr, struct pattern *pat, char **err) node->from_ref = pat->ref->tree_head; pat->ref->tree_head = &node->from_ref; expr->ref->revision = rdtsc(); + expr->ref->entry_cnt++; /* that's ok */ return 1; @@ -1517,6 +1526,7 @@ void pat_delete_gen(struct pat_ref *ref, struct pat_ref_elt *elt) /* update revision number to refresh the cache */ ref->revision = rdtsc(); + ref->entry_cnt--; elt->tree_head = NULL; elt->list_head = NULL; } @@ -1819,6 +1829,7 @@ struct pat_ref *pat_ref_new(const char *reference, const char *display, unsigned ref->flags = flags; ref->unique_id = -1; ref->revision = 0; + ref->entry_cnt = 0; LIST_INIT(&ref->head); LIST_INIT(&ref->pat);