From cf7f320f9d8ddda994ca0d8af7772da396bc00e9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 13 May 2007 22:46:04 +0200 Subject: [PATCH] [MAJOR] last bunch of capture changes for mempool v2 The header captures had lots of pools. They have all been transformed. --- include/common/memory.h | 1 - include/types/capture.h | 2 +- include/types/proxy.h | 3 ++- src/cfgparse.c | 12 ++++++++++++ src/client.c | 24 +++++++++++------------- src/haproxy.c | 8 ++++---- src/proto_http.c | 2 +- src/session.c | 8 ++++---- 8 files changed, 35 insertions(+), 25 deletions(-) diff --git a/include/common/memory.h b/include/common/memory.h index c50ab9a837..45ac7f962a 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -27,7 +27,6 @@ #include #include -#define sizeof_capture CAPTURE_LEN /* * Returns a pointer to an area of <__len> bytes taken from the pool or * dynamically allocated. In the first case, <__pool> is updated to point to diff --git a/include/types/capture.h b/include/types/capture.h index 49f4d535ac..e37cc483f9 100644 --- a/include/types/capture.h +++ b/include/types/capture.h @@ -31,7 +31,7 @@ struct cap_hdr { int namelen; /* length of the header name, to speed-up lookups */ int len; /* capture length, not including terminal zero */ int index; /* index in the output array */ - void *pool; /* pool of pre-allocated memory area of (len+1) bytes */ + struct pool_head *pool; /* pool of pre-allocated memory area of (len+1) bytes */ }; extern struct pool_head *pool2_capture; diff --git a/include/types/proxy.h b/include/types/proxy.h index 532348ec9a..9be81d59e8 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -140,7 +140,8 @@ struct proxy { int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */ struct cap_hdr *req_cap; /* chained list of request headers to be captured */ struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */ - void *req_cap_pool, *rsp_cap_pool; /* pools of pre-allocated char ** used to build the sessions */ + struct pool_head *req_cap_pool, /* pools of pre-allocated char ** used to build the sessions */ + *rsp_cap_pool; void *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */ char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */ int grace; /* grace time after stop request */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 6dd7ab6173..b532ce92d0 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -824,6 +824,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args) hdr->name = strdup(args[3]); hdr->namelen = strlen(args[3]); hdr->len = atol(args[5]); + hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); hdr->index = curproxy->nb_req_cap++; curproxy->req_cap = hdr; curproxy->to_log |= LW_REQHDR; @@ -846,6 +847,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args) hdr->name = strdup(args[3]); hdr->namelen = strlen(args[3]); hdr->len = atol(args[5]); + hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); hdr->index = curproxy->nb_rsp_cap++; curproxy->rsp_cap = hdr; curproxy->to_log |= LW_RSPHDR; @@ -2401,6 +2403,16 @@ int readcfgfile(const char *file) memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt)); } + /* The small pools required for the capture lists */ + if (curproxy->nb_req_cap) + curproxy->req_cap_pool = create_pool("ptrcap", + curproxy->nb_req_cap * sizeof(char *), + MEM_F_SHARED); + if (curproxy->nb_rsp_cap) + curproxy->rsp_cap_pool = create_pool("ptrcap", + curproxy->nb_rsp_cap * sizeof(char *), + MEM_F_SHARED); + /* for backwards compatibility with "listen" instances, if * fullconn is not set but maxconn is set, then maxconn * is used. diff --git a/src/client.c b/src/client.c index 6a1a3dfb65..38815e7712 100644 --- a/src/client.c +++ b/src/client.c @@ -233,9 +233,8 @@ int event_accept(int fd) { txn->hdr_idx.size = MAX_HTTP_HDR; if (p->nb_req_cap > 0) { - if ((txn->req.cap = - pool_alloc_from(p->req_cap_pool, p->nb_req_cap*sizeof(char *))) - == NULL) { /* no memory */ + if ((txn->req.cap = pool_alloc2(p->req_cap_pool)) == NULL) { + /* no memory */ close(cfd); /* nothing can be done for this fd without memory */ pool_free2(pool2_task, t); pool_free2(pool2_session, s); @@ -246,11 +245,10 @@ int event_accept(int fd) { if (p->nb_rsp_cap > 0) { - if ((txn->rsp.cap = - pool_alloc_from(p->rsp_cap_pool, p->nb_rsp_cap*sizeof(char *))) - == NULL) { /* no memory */ + if ((txn->rsp.cap = pool_alloc2(p->rsp_cap_pool)) == NULL) { + /* no memory */ if (txn->req.cap != NULL) - pool_free_to(p->req_cap_pool, txn->req.cap); + pool_free2(p->req_cap_pool, txn->req.cap); close(cfd); /* nothing can be done for this fd without memory */ pool_free2(pool2_task, t); pool_free2(pool2_session, s); @@ -264,9 +262,9 @@ int event_accept(int fd) { pool_alloc_from(p->hdr_idx_pool, txn->hdr_idx.size*sizeof(*txn->hdr_idx.v))) == NULL) { /* no memory */ if (txn->rsp.cap != NULL) - pool_free_to(p->rsp_cap_pool, txn->rsp.cap); + pool_free2(p->rsp_cap_pool, txn->rsp.cap); if (txn->req.cap != NULL) - pool_free_to(p->req_cap_pool, txn->req.cap); + pool_free2(p->req_cap_pool, txn->req.cap); close(cfd); /* nothing can be done for this fd without memory */ pool_free2(pool2_task, t); pool_free2(pool2_session, s); @@ -351,9 +349,9 @@ int event_accept(int fd) { if (txn->hdr_idx.v != NULL) pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v); if (txn->rsp.cap != NULL) - pool_free_to(p->rsp_cap_pool, txn->rsp.cap); + pool_free2(p->rsp_cap_pool, txn->rsp.cap); if (txn->req.cap != NULL) - pool_free_to(p->req_cap_pool, txn->req.cap); + pool_free2(p->req_cap_pool, txn->req.cap); close(cfd); /* nothing can be done for this fd without memory */ pool_free2(pool2_task, t); pool_free2(pool2_session, s); @@ -374,9 +372,9 @@ int event_accept(int fd) { if (txn->hdr_idx.v != NULL) pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v); if (txn->rsp.cap != NULL) - pool_free_to(p->rsp_cap_pool, txn->rsp.cap); + pool_free2(p->rsp_cap_pool, txn->rsp.cap); if (txn->req.cap != NULL) - pool_free_to(p->req_cap_pool, txn->req.cap); + pool_free2(p->req_cap_pool, txn->req.cap); close(cfd); /* nothing can be done for this fd without memory */ pool_free2(pool2_task, t); pool_free2(pool2_session, s); diff --git a/src/haproxy.c b/src/haproxy.c index 344238976d..4e22e1920d 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -616,7 +616,7 @@ void deinit(void) h_next = h->next; if (h->name) free(h->name); - pool_destroy(h->pool); + pool_destroy2(h->pool); free(h); h = h_next; }/* end while(h) */ @@ -627,7 +627,7 @@ void deinit(void) if (h->name) free(h->name); - pool_destroy(h->pool); + pool_destroy2(h->pool); free(h); h = h_next; }/* end while(h) */ @@ -652,8 +652,8 @@ void deinit(void) l = l_next; }/* end while(l) */ - pool_destroy((void **) p->req_cap_pool); - pool_destroy((void **) p->rsp_cap_pool); + pool_destroy2(p->req_cap_pool); + pool_destroy2(p->rsp_cap_pool); p = p->next; }/* end while(p) */ diff --git a/src/proto_http.c b/src/proto_http.c index 64ab50799e..4e9e68361d 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -775,7 +775,7 @@ void capture_headers(char *som, struct hdr_idx *idx, (strncasecmp(sol, h->name, h->namelen) == 0)) { if (cap[h->index] == NULL) cap[h->index] = - pool_alloc_from(h->pool, h->len + 1); + pool_alloc2(h->pool); if (cap[h->index] == NULL) { Alert("HTTP capture : out of memory.\n"); diff --git a/src/session.c b/src/session.c index 38889c4e22..01073de621 100644 --- a/src/session.c +++ b/src/session.c @@ -51,17 +51,17 @@ void session_free(struct session *s) struct cap_hdr *h; for (h = s->fe->rsp_cap; h; h = h->next) { if (txn->rsp.cap[h->index] != NULL) - pool_free_to(h->pool, txn->rsp.cap[h->index]); + pool_free2(h->pool, txn->rsp.cap[h->index]); } - pool_free_to(s->fe->rsp_cap_pool, txn->rsp.cap); + pool_free2(s->fe->rsp_cap_pool, txn->rsp.cap); } if (txn->req.cap != NULL) { struct cap_hdr *h; for (h = s->fe->req_cap; h; h = h->next) { if (txn->req.cap[h->index] != NULL) - pool_free_to(h->pool, txn->req.cap[h->index]); + pool_free2(h->pool, txn->req.cap[h->index]); } - pool_free_to(s->fe->req_cap_pool, txn->req.cap); + pool_free2(s->fe->req_cap_pool, txn->req.cap); } if (txn->uri) -- 2.39.5