From: Willy Tarreau Date: Tue, 11 May 2021 14:49:55 +0000 (+0200) Subject: CLEANUP: pattern: remove the unused and dangerous pat_ref_reload() X-Git-Tag: v2.4.0~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da7f11bfb58c42c024cd4ba5aa32b008c1390f56;p=thirdparty%2Fhaproxy.git CLEANUP: pattern: remove the unused and dangerous pat_ref_reload() This function was not used anymore after the atomic updates were implemented in 2.3, and it must not be used given that it does not yield and can easily make the process hang for tens of seconds on large acls/maps. Let's remove it before someone uses it as an example to implement something else! --- diff --git a/include/haproxy/pattern.h b/include/haproxy/pattern.h index 7f785095d6..81ef5df2e6 100644 --- a/include/haproxy/pattern.h +++ b/include/haproxy/pattern.h @@ -193,7 +193,6 @@ int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt); int pat_ref_prune(struct pat_ref *ref); int pat_ref_commit_elt(struct pat_ref *ref, struct pat_ref_elt *elt, char **err); int pat_ref_purge_range(struct pat_ref *ref, uint from, uint to, int budget); -void pat_ref_reload(struct pat_ref *ref, struct pat_ref *replace); /* Create a new generation number for next pattern updates and returns it. This * must be used to atomically insert new patterns that will atomically replace diff --git a/src/pattern.c b/src/pattern.c index 5ec7316b12..265b05f486 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -2081,96 +2081,6 @@ int pat_ref_purge_range(struct pat_ref *ref, uint from, uint to, int budget) return done; } -/* This function prunes , replaces all references by the references - * of , and reindexes all the news values. - * - * The patterns are loaded in best effort and the errors are ignored, - * but written in the logs. - */ -void pat_ref_reload(struct pat_ref *ref, struct pat_ref *replace) -{ - struct pattern_expr *expr; - struct pat_ref_elt *elt, *safe; - struct bref *bref, *back; - struct pattern pattern; - - - HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); - list_for_each_entry(expr, &ref->pat, list) { - HA_RWLOCK_WRLOCK(PATEXP_LOCK, &expr->lock); - } - - /* all expr are locked, we can safely remove all pat_ref */ - list_for_each_entry_safe(elt, safe, &ref->head, list) { - list_for_each_entry_safe(bref, back, &elt->back_refs, users) { - /* we have to unlink all watchers. */ - LIST_DEL_INIT(&bref->users); - bref->ref = NULL; - } - pat_delete_gen(ref, elt); - LIST_DELETE(&elt->list); - free(elt->pattern); - free(elt->sample); - free(elt); - } - - /* switch pat_ret_elt lists */ - LIST_INSERT(&replace->head, &ref->head); - LIST_DELETE(&replace->head); - - list_for_each_entry(expr, &ref->pat, list) { - list_for_each_entry(elt, &ref->head, list) { - char *err = NULL; - struct sample_data *data = NULL; - - /* Create sample */ - if (elt->sample && expr->pat_head->parse_smp) { - /* New sample. */ - data = malloc(sizeof(*data)); - if (!data) - continue; - - /* Parse value. */ - if (!expr->pat_head->parse_smp(elt->sample, data)) { - memprintf(&err, "unable to parse '%s'", elt->sample); - send_log(NULL, LOG_NOTICE, "%s", err); - free(err); - free(data); - continue; - } - - } - - /* initialise pattern */ - memset(&pattern, 0, sizeof(pattern)); - pattern.data = data; - pattern.ref = elt; - - /* parse pattern */ - if (!expr->pat_head->parse(elt->pattern, &pattern, expr->mflags, &err)) { - send_log(NULL, LOG_NOTICE, "%s", err); - free(err); - free(data); - continue; - } - - /* index pattern */ - if (!expr->pat_head->index(expr, &pattern, &err)) { - send_log(NULL, LOG_NOTICE, "%s", err); - free(err); - free(data); - continue; - } - } - HA_RWLOCK_WRUNLOCK(PATEXP_LOCK, &expr->lock); - } - HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); - -#if defined(HA_HAVE_MALLOC_TRIM) - malloc_trim(0); -#endif -} - /* This function prunes all entries of and all their associated * pattern_expr. It may return before the end of the list is reached, * returning 0, to yield, indicating to the caller that it must call it again.