From d869e13ed895ba8cb41193582680059054e75acf Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 17 May 2022 18:05:31 +0200 Subject: [PATCH] CLEANUP: applet: rename the sedesc pointer from "endp" to "sedesc" Now at least it makes it obvious that it's the stream endpoint descriptor and not an endpoint. There were few changes thanks to the previous refactor of the flags. --- addons/promex/service-prometheus.c | 2 +- include/haproxy/applet-t.h | 2 +- include/haproxy/applet.h | 24 +++++++++---------- src/applet.c | 38 +++++++++++++++--------------- src/cache.c | 2 +- src/cli.c | 2 +- src/hlua.c | 2 +- src/http_client.c | 3 +-- src/stats.c | 2 +- 9 files changed, 38 insertions(+), 39 deletions(-) diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index 8274de228..6471dae1d 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -1564,7 +1564,7 @@ static void promex_appctx_handle_io(struct appctx *appctx) } res_htx->flags |= HTX_FL_EOM; res->flags |= CF_EOI; - se_fl_set(appctx->endp, SE_FL_EOI); + se_fl_set(appctx->sedesc, SE_FL_EOI); appctx->st0 = PROMEX_ST_END; /* fall through */ diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index ca0e2c2b7..e528452fa 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -63,7 +63,7 @@ struct appctx { struct buffer *chunk; /* used to store unfinished commands */ struct applet *applet; /* applet this context refers to */ struct session *sess; /* session for frontend applets (NULL for backend applets) */ - struct sedesc *endp; + struct sedesc *sedesc; /* stream endpoint descriptor the applet is attached to */ struct act_rule *rule; /* rule associated with the applet. */ int (*io_handler)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */ void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK, diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 7cc97426d..3c80adba7 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -40,23 +40,23 @@ int appctx_buf_available(void *arg); void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void appctx_shut(struct appctx *appctx); -struct appctx *appctx_new(struct applet *applet, struct sedesc *endp, unsigned long thread_mask); +struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned long thread_mask); int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input); void appctx_free_on_early_error(struct appctx *appctx); -static inline struct appctx *appctx_new_on(struct applet *applet, struct sedesc *endp, uint thr) +static inline struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, uint thr) { - return appctx_new(applet, endp, 1UL << thr); + return appctx_new(applet, sedesc, 1UL << thr); } -static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *endp) +static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *sedesc) { - return appctx_new(applet, endp, tid_bit); + return appctx_new(applet, sedesc, tid_bit); } -static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct sedesc *endp) +static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct sedesc *sedesc) { - return appctx_new(applet, endp, MAX_THREADS_MASK); + return appctx_new(applet, sedesc, MAX_THREADS_MASK); } /* Helper function to call .init applet callback function, if it exists. Returns 0 @@ -84,8 +84,8 @@ static inline void __appctx_free(struct appctx *appctx) LIST_DEL_INIT(&appctx->buffer_wait.list); if (appctx->sess) session_free(appctx->sess); - BUG_ON(appctx->endp && !se_fl_test(appctx->endp, SE_FL_ORPHAN)); - sedesc_free(appctx->endp); + BUG_ON(appctx->sedesc && !se_fl_test(appctx->sedesc, SE_FL_ORPHAN)); + sedesc_free(appctx->sedesc); pool_free(pool_head_appctx, appctx); _HA_ATOMIC_DEC(&nb_applets); } @@ -112,10 +112,10 @@ static inline void appctx_wakeup(struct appctx *appctx) task_wakeup(appctx->t, TASK_WOKEN_OTHER); } -/* returns the conn_stream the appctx is attached to, via the endp */ +/* returns the conn_stream the appctx is attached to, via the sedesc */ static inline struct conn_stream *appctx_cs(const struct appctx *appctx) { - return appctx->endp->cs; + return appctx->sedesc->cs; } /* returns the stream the appctx is attached to. Note that a stream *must* @@ -123,7 +123,7 @@ static inline struct conn_stream *appctx_cs(const struct appctx *appctx) */ static inline struct stream *appctx_strm(const struct appctx *appctx) { - return __cs_strm(appctx->endp->cs); + return __cs_strm(appctx->sedesc->cs); } #endif /* _HAPROXY_APPLET_H */ diff --git a/src/applet.c b/src/applet.c index b4c9bef32..8d45ac1c3 100644 --- a/src/applet.c +++ b/src/applet.c @@ -31,12 +31,12 @@ DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct appctx)); * appctx_free(). is assigned as the applet, but it can be NULL. The * applet's task is always created on the current thread. */ -struct appctx *appctx_new(struct applet *applet, struct sedesc *endp, unsigned long thread_mask) +struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned long thread_mask) { struct appctx *appctx; /* Backend appctx cannot be started on another thread than the local one */ - BUG_ON(thread_mask != tid_bit && endp); + BUG_ON(thread_mask != tid_bit && sedesc); appctx = pool_zalloc(pool_head_appctx); if (unlikely(!appctx)) @@ -46,14 +46,14 @@ struct appctx *appctx_new(struct applet *applet, struct sedesc *endp, unsigned l appctx->obj_type = OBJ_TYPE_APPCTX; appctx->applet = applet; appctx->sess = NULL; - if (!endp) { - endp = sedesc_new(); - if (!endp) + if (!sedesc) { + sedesc = sedesc_new(); + if (!sedesc) goto fail_endp; - endp->se = appctx; - se_fl_set(endp, SE_FL_T_APPLET | SE_FL_ORPHAN); + sedesc->se = appctx; + se_fl_set(sedesc, SE_FL_T_APPLET | SE_FL_ORPHAN); } - appctx->endp = endp; + appctx->sedesc = sedesc; appctx->t = task_new(thread_mask); if (unlikely(!appctx->t)) @@ -69,7 +69,7 @@ struct appctx *appctx_new(struct applet *applet, struct sedesc *endp, unsigned l return appctx; fail_task: - sedesc_free(appctx->endp); + sedesc_free(appctx->sedesc); fail_endp: pool_free(pool_head_appctx, appctx); fail_appctx: @@ -93,12 +93,12 @@ int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buff /* async startup is only possible for frontend appctx. Thus for orphan * appctx. Because no backend appctx can be orphan. */ - BUG_ON(!se_fl_test(appctx->endp, SE_FL_ORPHAN)); + BUG_ON(!se_fl_test(appctx->sedesc, SE_FL_ORPHAN)); sess = session_new(px, NULL, &appctx->obj_type); if (!sess) return -1; - if (!cs_new_from_endp(appctx->endp, sess, input)) { + if (!cs_new_from_endp(appctx->sedesc, sess, input)) { session_free(sess); return -1; } @@ -114,7 +114,7 @@ void appctx_free_on_early_error(struct appctx *appctx) /* If a frontend apctx is attached to a conn-stream, release the stream * instead of the appctx. */ - if (!se_fl_test(appctx->endp, SE_FL_ORPHAN) && !(appctx_cs(appctx)->flags & CS_FL_ISBACK)) { + if (!se_fl_test(appctx->sedesc, SE_FL_ORPHAN) && !(appctx_cs(appctx)->flags & CS_FL_ISBACK)) { stream_free(appctx_strm(appctx)); return; } @@ -140,18 +140,18 @@ void *applet_reserve_svcctx(struct appctx *appctx, size_t size) return appctx->svcctx; } -/* call the applet's release() function if any, and marks the endp as shut. +/* call the applet's release() function if any, and marks the sedesc as shut. * Needs to be called upon close(). */ void appctx_shut(struct appctx *appctx) { - if (se_fl_test(appctx->endp, SE_FL_SHR | SE_FL_SHW)) + if (se_fl_test(appctx->sedesc, SE_FL_SHR | SE_FL_SHW)) return; if (appctx->applet->release) appctx->applet->release(appctx); - se_fl_set(appctx->endp, SE_FL_SHRR | SE_FL_SHWN); + se_fl_set(appctx->sedesc, SE_FL_SHRR | SE_FL_SHWN); } /* Callback used to wake up an applet when a buffer is available. The applet @@ -167,7 +167,7 @@ int appctx_buf_available(void *arg) struct conn_stream *cs = appctx_cs(appctx); /* allocation requested ? */ - if (!se_fl_test(appctx->endp, SE_FL_RXBLK_BUFF)) + if (!se_fl_test(appctx->sedesc, SE_FL_RXBLK_BUFF)) return 0; cs_rx_buff_rdy(cs); @@ -199,7 +199,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state) return NULL; } - if (se_fl_test(app->endp, SE_FL_ORPHAN)) { + if (se_fl_test(app->sedesc, SE_FL_ORPHAN)) { /* Finalize init of orphan appctx. .init callback function must * be defined and it must finalize appctx startup. */ @@ -244,8 +244,8 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state) /* measure the call rate and check for anomalies when too high */ rate = update_freq_ctr(&app->call_rate, 1); if (rate >= 100000 && app->call_rate.prev_ctr && // looped more than 100k times over last second - ((b_size(cs_ib(cs)) && se_fl_test(app->endp, SE_FL_RXBLK_BUFF)) || // asks for a buffer which is present - (b_size(cs_ib(cs)) && !b_data(cs_ib(cs)) && se_fl_test(app->endp, SE_FL_RXBLK_ROOM)) || // asks for room in an empty buffer + ((b_size(cs_ib(cs)) && se_fl_test(app->sedesc, SE_FL_RXBLK_BUFF)) || // asks for a buffer which is present + (b_size(cs_ib(cs)) && !b_data(cs_ib(cs)) && se_fl_test(app->sedesc, SE_FL_RXBLK_ROOM)) || // asks for room in an empty buffer (b_data(cs_ob(cs)) && cs_tx_endp_ready(cs) && !cs_tx_blocked(cs)) || // asks for data already present (!b_data(cs_ib(cs)) && b_data(cs_ob(cs)) && // didn't return anything ... (cs_oc(cs)->flags & (CF_WRITE_PARTIAL|CF_SHUTW_NOW)) == CF_SHUTW_NOW))) { // ... and left data pending after a shut diff --git a/src/cache.c b/src/cache.c index 4f52d7298..8b36b2e4b 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1527,7 +1527,7 @@ static void http_cache_io_handler(struct appctx *appctx) /* no more data are expected. */ res_htx->flags |= HTX_FL_EOM; res->flags |= CF_EOI; - se_fl_set(appctx->endp, SE_FL_EOI); + se_fl_set(appctx->sedesc, SE_FL_EOI); appctx->st0 = HTX_CACHE_END; } diff --git a/src/cli.c b/src/cli.c index f9a0a4f2b..9d17df97a 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1108,7 +1108,7 @@ static void cli_io_handler(struct appctx *appctx) } break; default: /* abnormal state */ - se_fl_set(appctx->endp, SE_FL_ERROR); + se_fl_set(appctx->sedesc, SE_FL_ERROR); break; } diff --git a/src/hlua.c b/src/hlua.c index 8ba4fbf79..47bfe90e2 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -9615,7 +9615,7 @@ void hlua_applet_http_fct(struct appctx *ctx) res_htx->flags |= HTX_FL_EOM; res->flags |= CF_EOI; - se_fl_set(ctx->endp, SE_FL_EOI); + se_fl_set(ctx->sedesc, SE_FL_EOI); strm->txn->status = http_ctx->status; http_ctx->flags |= APPLET_RSP_SENT; } diff --git a/src/http_client.c b/src/http_client.c index 67427d5de..9fb942f49 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -732,8 +732,7 @@ static void httpclient_applet_io_handler(struct appctx *appctx) /* if the request contains the HTX_FL_EOM, we finished the request part. */ if (htx->flags & HTX_FL_EOM) { req->flags |= CF_EOI; - se_fl_set(appctx->endp, - SE_FL_EOI); + se_fl_set(appctx->sedesc, SE_FL_EOI); appctx->st0 = HTTPCLIENT_S_RES_STLINE; } diff --git a/src/stats.c b/src/stats.c index 24207aec6..2a4dc136b 100644 --- a/src/stats.c +++ b/src/stats.c @@ -4349,7 +4349,7 @@ static void http_stats_io_handler(struct appctx *appctx) } res_htx->flags |= HTX_FL_EOM; res->flags |= CF_EOI; - se_fl_set(appctx->endp, SE_FL_EOI); + se_fl_set(appctx->sedesc, SE_FL_EOI); appctx->st0 = STAT_HTTP_END; } -- 2.47.3