MINOR: applet: Use the CS to register and release applets instead of SI

si_register_applet() and si_applet_release() are renamed
cs_register_applet() and cs_applet_release() and now manipulate a
conn-stream instead of a stream-inteface.
This commit is contained in:
Christopher Faulet 2022-04-01 11:36:58 +02:00
parent 0c6a64cd5f
commit 3704663e5f
8 changed files with 44 additions and 42 deletions

View File

@ -54,6 +54,9 @@ int cs_reset_endp(struct conn_stream *cs);
void cs_detach_endp(struct conn_stream *cs);
void cs_detach_app(struct conn_stream *cs);
struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app);
void cs_applet_release(struct conn_stream *cs);
/* Returns the endpoint target without any control */
static inline void *__cs_endp_target(const struct conn_stream *cs)
{

View File

@ -41,7 +41,6 @@ void si_free(struct stream_interface *si);
/* main event functions used to move data between sockets and buffers */
int conn_si_send_proxy(struct connection *conn, unsigned int flag);
struct appctx *si_register_handler(struct stream_interface *si, struct applet *app);
void si_applet_wake_cb(struct stream_interface *si);
void si_update_rx(struct stream_interface *si);
void si_update_tx(struct stream_interface *si);
@ -110,16 +109,6 @@ static inline int si_init(struct stream_interface *si)
return 0;
}
/* call the applet's release function if any. Needs to be called upon close() */
static inline void si_applet_release(struct stream_interface *si)
{
struct appctx *appctx;
appctx = __cs_appctx(si->cs);
if (appctx->applet->release && !cs_state_in(si->cs->state, CS_SB_DIS|CS_SB_CLO))
appctx->applet->release(appctx);
}
/* Returns non-zero if the stream interface's Rx path is blocked */
static inline int si_rx_blocked(const struct stream_interface *si)
{

View File

@ -2132,7 +2132,7 @@ void back_handle_st_req(struct stream *s)
struct appctx *appctx = cs_appctx(s->csb);
if (!appctx || appctx->applet != __objt_applet(s->target))
appctx = si_register_handler(cs->si, objt_applet(s->target));
appctx = cs_register_applet(cs, objt_applet(s->target));
if (!appctx) {
/* No more memory, let's immediately abort. Force the

View File

@ -1816,7 +1816,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
}
s->target = &http_cache_applet.obj_type;
if ((appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target)))) {
if ((appctx = cs_register_applet(s->csb, objt_applet(s->target)))) {
appctx->st0 = HTX_CACHE_INIT;
appctx->rule = rule;
appctx->ctx.cache.entry = res;

View File

@ -11,6 +11,7 @@
*/
#include <haproxy/api.h>
#include <haproxy/applet.h>
#include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/pool.h>
@ -283,8 +284,7 @@ void cs_detach_endp(struct conn_stream *cs)
struct appctx *appctx = cs_appctx(cs);
cs->endp->flags |= CS_EP_ORPHAN;
if (cs->si)
si_applet_release(cs->si);
cs_applet_release(cs);
appctx_free(appctx);
cs->endp = NULL;
}
@ -354,3 +354,36 @@ int cs_reset_endp(struct conn_stream *cs)
cs->endp->flags |= CS_EP_DETACHED;
return 0;
}
/* Register an applet to handle a conn-stream as a new appctx. The CS will
* wake it up every time it is solicited. The appctx must be deleted by the task
* handler using cs_detach_endp(), possibly from within the function itself.
* It also pre-initializes the applet's context and returns it (or NULL in case
* it could not be allocated).
*/
struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app)
{
struct appctx *appctx;
DPRINTF(stderr, "registering handler %p for cs %p (was %p)\n", app, cs, cs_strm_task(cs));
appctx = appctx_new(app, cs->endp);
if (!appctx)
return NULL;
cs_attach_applet(cs, appctx, appctx);
appctx->owner = cs;
appctx->t->nice = __cs_strm(cs)->task->nice;
si_cant_get(cs->si);
appctx_wakeup(appctx);
return appctx;
}
/* call the applet's release function if any. Needs to be called upon close() */
void cs_applet_release(struct conn_stream *cs)
{
struct appctx *appctx = __cs_appctx(cs);
if (appctx->applet->release && !cs_state_in(cs->state, CS_SB_DIS|CS_SB_CLO))
appctx->applet->release(appctx);
}

View File

@ -423,7 +423,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
*/
if (!s->target && http_stats_check_uri(s, txn, px)) {
s->target = &http_stats_applet.obj_type;
if (unlikely(!si_register_handler(cs_si(s->csb), objt_applet(s->target)))) {
if (unlikely(!cs_register_applet(s->csb, objt_applet(s->target)))) {
s->logs.tv_request = now;
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;

View File

@ -1012,7 +1012,7 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
if (flags & ACT_OPT_FIRST) {
/* Register applet. this function schedules the applet. */
s->target = &rule->applet.obj_type;
appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target));
appctx = cs_register_applet(s->csb, objt_applet(s->target));
if (unlikely(!appctx))
return ACT_RET_ERR;

View File

@ -269,29 +269,6 @@ static void cs_app_chk_snd(struct conn_stream *cs)
task_wakeup(cs_strm_task(cs), TASK_WOKEN_IO);
}
/* Register an applet to handle a stream_interface as a new appctx. The SI will
* wake it up every time it is solicited. The appctx must be deleted by the task
* handler using si_release_endpoint(), possibly from within the function itself.
* It also pre-initializes the applet's context and returns it (or NULL in case
* it could not be allocated).
*/
struct appctx *si_register_handler(struct stream_interface *si, struct applet *app)
{
struct appctx *appctx;
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si_task(si));
appctx = appctx_new(app, si->cs->endp);
if (!appctx)
return NULL;
cs_attach_applet(si->cs, appctx, appctx);
appctx->owner = si->cs;
appctx->t->nice = si_strm(si)->task->nice;
si_cant_get(si);
appctx_wakeup(appctx);
return appctx;
}
/* This callback is used to send a valid PROXY protocol line to a socket being
* established. It returns 0 if it fails in a fatal way or needs to poll to go
* further, otherwise it returns non-zero and removes itself from the connection's
@ -1655,7 +1632,7 @@ static void cs_app_shutr_applet(struct conn_stream *cs)
return;
if (cs_oc(cs)->flags & CF_SHUTW) {
si_applet_release(cs->si);
cs_applet_release(cs);
cs->state = CS_ST_DIS;
__cs_strm(cs)->conn_exp = TICK_ETERNITY;
}
@ -1713,7 +1690,7 @@ static void cs_app_shutw_applet(struct conn_stream *cs)
case CS_ST_QUE:
case CS_ST_TAR:
/* Note that none of these states may happen with applets */
si_applet_release(cs->si);
cs_applet_release(cs);
cs->state = CS_ST_DIS;
/* fall through */
default: