From: Willy Tarreau Date: Mon, 22 Jul 2013 22:07:04 +0000 (+0200) Subject: MEDIUM: counters: factor out smp_fetch_sc*_inc_gpc0 X-Git-Tag: v1.5-dev20~317 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=710d38cea590d3e918ed5f27b59eb08d596ce875;p=thirdparty%2Fhaproxy.git MEDIUM: counters: factor out smp_fetch_sc*_inc_gpc0 smp_fetch_sc0_inc_gpc0, smp_fetch_sc1_inc_gpc0, smp_fetch_sc2_inc_gpc0, smp_fetch_src_inc_gpc0 and smp_fetch_inc_gpc0 were merged into a single function which relies on the fetch name to decide what to return. --- diff --git a/src/session.c b/src/session.c index af6f3eb1cd..5fb069aead 100644 --- a/src/session.c +++ b/src/session.c @@ -2673,29 +2673,36 @@ smp_fetch_sc_gpc0_rate(struct proxy *px, struct session *l4, void *l7, unsigned return 1; } -/* Increment the General Purpose Counter 0 value in the stksess entry and - * return it into temp integer. +/* Increment the General Purpose Counter 0 value from the session's tracked + * frontend counters and return it into temp integer. + * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. */ static int -smp_fetch_inc_gpc0(struct stktable *table, struct sample *smp, struct stksess *ts) +smp_fetch_sc_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp, const char *kw) { + struct stkctr *stkctr = smp_fetch_sc_stkctr(l4, args, kw); + + if (!stkctr) + return 0; + smp->flags = SMP_F_VOL_TEST; smp->type = SMP_T_UINT; smp->data.uint = 0; - if (ts != NULL) { + if (stkctr->entry != NULL) { void *ptr; /* First, update gpc0_rate if it's tracked. Second, update its * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. */ - ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0_RATE); + ptr = stktable_data_ptr(stkctr->table, stkctr->entry, STKTABLE_DT_GPC0_RATE); if (ptr) { update_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), - table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); + stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); smp->data.uint = (&stktable_data_cast(ptr, gpc0_rate))->curr_ctr; } - ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); + ptr = stktable_data_ptr(stkctr->table, stkctr->entry, STKTABLE_DT_GPC0); if (ptr) smp->data.uint = ++stktable_data_cast(ptr, gpc0); @@ -2703,60 +2710,6 @@ smp_fetch_inc_gpc0(struct stktable *table, struct sample *smp, struct stksess *t return 1; } -/* Increment the General Purpose Counter 0 value from the session's tracked - * frontend counters and return it into temp integer. - */ -static int -smp_fetch_sc0_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp, const char *kw) -{ - if (!l4->stkctr[0].entry) - return 0; - return smp_fetch_inc_gpc0(l4->stkctr[0].table, smp, l4->stkctr[0].entry); -} - -/* Increment the General Purpose Counter 0 value from the session's tracked - * backend counters and return it into temp integer. - */ -static int -smp_fetch_sc1_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp, const char *kw) -{ - if (!l4->stkctr[1].entry) - return 0; - return smp_fetch_inc_gpc0(l4->stkctr[1].table, smp, l4->stkctr[1].entry); -} - -/* Increment the General Purpose Counter 0 value from the session's tracked - * backend counters and return it into temp integer. - */ -static int -smp_fetch_sc2_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp, const char *kw) -{ - if (!l4->stkctr[2].entry) - return 0; - return smp_fetch_inc_gpc0(l4->stkctr[2].table, smp, l4->stkctr[2].entry); -} - -/* Increment the General Purpose Counter 0 value from the session's source - * address in the table pointed to by expr, and return it into temp integer. - * Accepts exactly 1 argument of type table. - */ -static int -smp_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, - const struct arg *args, struct sample *smp, const char *kw) -{ - struct stktable_key *key; - - key = addr_to_stktable_key(&l4->si[0].conn->addr.from); - if (!key) - return 0; - - px = args->data.prx; - return smp_fetch_inc_gpc0(&px->table, smp, stktable_update_key(&px->table, key)); -} - /* Clear the General Purpose Counter 0 value in the stksess entry and * return its previous value into temp integer. */ @@ -3877,7 +3830,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc0_http_err_rate", smp_fetch_sc0_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc0_http_req_cnt", smp_fetch_sc0_http_req_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc0_http_req_rate", smp_fetch_sc0_http_req_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, - { "sc0_inc_gpc0", smp_fetch_sc0_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, + { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc0_kbytes_in", smp_fetch_sc0_kbytes_in, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc0_kbytes_out", smp_fetch_sc0_kbytes_out, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc0_sess_cnt", smp_fetch_sc0_sess_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, @@ -3896,7 +3849,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc1_http_err_rate", smp_fetch_sc1_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc1_http_req_cnt", smp_fetch_sc1_http_req_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc1_http_req_rate", smp_fetch_sc1_http_req_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, - { "sc1_inc_gpc0", smp_fetch_sc1_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, + { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc1_kbytes_in", smp_fetch_sc1_kbytes_in, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc1_kbytes_out", smp_fetch_sc1_kbytes_out, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc1_sess_cnt", smp_fetch_sc1_sess_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, @@ -3915,7 +3868,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc2_http_err_rate", smp_fetch_sc2_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc2_http_req_cnt", smp_fetch_sc2_http_req_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc2_http_req_rate", smp_fetch_sc2_http_req_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, - { "sc2_inc_gpc0", smp_fetch_sc2_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, + { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, { "sc2_kbytes_in", smp_fetch_sc2_kbytes_in, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc2_kbytes_out", smp_fetch_sc2_kbytes_out, 0, NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "sc2_sess_cnt", smp_fetch_sc2_sess_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, }, @@ -3934,7 +3887,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "src_http_err_rate", smp_fetch_src_http_err_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "src_http_req_cnt", smp_fetch_src_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "src_http_req_rate", smp_fetch_src_http_req_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, - { "src_inc_gpc0", smp_fetch_src_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, + { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "src_kbytes_in", smp_fetch_src_kbytes_in, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "src_kbytes_out", smp_fetch_src_kbytes_out, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, { "src_sess_cnt", smp_fetch_src_sess_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },