MINOR: lua: move the tcp service storage outside of appctx.ctx

The use-service mechanism for Lua in TCP mode relies on the
hlua_tcp storage in appctx->ctx. We can move its definition to
hlua.c and simply use appctx_reserve_svcctx() to reserve and access
the stoage. One tiny side effect is that the task dump used in panics
will not show anymore the Lua call stack in its trace. For this a
better API is needed from the Lua code to expose a function that does
the job from an appctx.
This commit is contained in:
Willy Tarreau 2022-05-06 14:07:13 +02:00
parent 5321da9df0
commit e23f33bbfe
3 changed files with 24 additions and 18 deletions

View File

@ -99,11 +99,6 @@ struct appctx {
char storage[APPLET_MAX_SVCCTX]; /* storage of svcctx above */
} svc; /* generic storage for most commands */
union {
struct {
struct hlua *hlua;
int flags;
struct task *task;
} hlua_apptcp; /* used by the Lua TCP services */
struct {
struct hlua *hlua;
int left_bytes; /* The max amount of bytes that we can read. */

View File

@ -267,7 +267,7 @@ void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx);
}
else if (task->process == task_run_applet && (appctx = task->context) &&
(appctx->applet->fct == hlua_applet_tcp_fct && (hlua = appctx->ctx.hlua_apptcp.hlua))) {
(appctx->applet->fct == hlua_applet_tcp_fct)) {
chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx);
}
else if (task->process == task_run_applet && (appctx = task->context) &&

View File

@ -252,6 +252,13 @@ struct hlua_csk_ctx {
int die;
};
/* appctx context used by TCP services */
struct hlua_tcp_ctx {
struct hlua *hlua;
int flags;
struct task *task;
};
/* used by registered CLI keywords */
struct hlua_cli_ctx {
struct hlua *hlua;
@ -9209,6 +9216,7 @@ struct task *hlua_applet_wakeup(struct task *t, void *context, unsigned int stat
static int hlua_applet_tcp_init(struct appctx *ctx)
{
struct hlua_tcp_ctx *tcp_ctx = applet_reserve_svcctx(ctx, sizeof(*tcp_ctx));
struct conn_stream *cs = ctx->owner;
struct stream *strm = __cs_strm(cs);
struct hlua *hlua;
@ -9223,8 +9231,8 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
return 0;
}
HLUA_INIT(hlua);
ctx->ctx.hlua_apptcp.hlua = hlua;
ctx->ctx.hlua_apptcp.flags = 0;
tcp_ctx->hlua = hlua;
tcp_ctx->flags = 0;
/* Create task used by signal to wakeup applets. */
task = task_new_here();
@ -9236,7 +9244,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
task->nice = 0;
task->context = ctx;
task->process = hlua_applet_wakeup;
ctx->ctx.hlua_apptcp.task = task;
tcp_ctx->task = task;
/* In the execution wrappers linked with a stream, the
* Lua context can be not initialized. This behavior
@ -9306,15 +9314,16 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
void hlua_applet_tcp_fct(struct appctx *ctx)
{
struct hlua_tcp_ctx *tcp_ctx = ctx->svcctx;
struct conn_stream *cs = ctx->owner;
struct stream *strm = __cs_strm(cs);
struct channel *res = cs_ic(cs);
struct act_rule *rule = ctx->rule;
struct proxy *px = strm->be;
struct hlua *hlua = ctx->ctx.hlua_apptcp.hlua;
struct hlua *hlua = tcp_ctx->hlua;
/* The applet execution is already done. */
if (ctx->ctx.hlua_apptcp.flags & APPLET_DONE) {
if (tcp_ctx->flags & APPLET_DONE) {
/* eat the whole request */
co_skip(cs_oc(cs), co_data(cs_oc(cs)));
return;
@ -9328,7 +9337,7 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
switch (hlua_ctx_resume(hlua, 1)) {
/* finished. */
case HLUA_E_OK:
ctx->ctx.hlua_apptcp.flags |= APPLET_DONE;
tcp_ctx->flags |= APPLET_DONE;
/* eat the whole request */
co_skip(cs_oc(cs), co_data(cs_oc(cs)));
@ -9339,7 +9348,7 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
/* yield. */
case HLUA_E_AGAIN:
if (hlua->wake_time != TICK_ETERNITY)
task_schedule(ctx->ctx.hlua_apptcp.task, hlua->wake_time);
task_schedule(tcp_ctx->task, hlua->wake_time);
return;
/* finished with error. */
@ -9380,15 +9389,17 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
/* For all other cases, just close the stream. */
cs_shutw(cs);
cs_shutr(cs);
ctx->ctx.hlua_apptcp.flags |= APPLET_DONE;
tcp_ctx->flags |= APPLET_DONE;
}
static void hlua_applet_tcp_release(struct appctx *ctx)
{
task_destroy(ctx->ctx.hlua_apptcp.task);
ctx->ctx.hlua_apptcp.task = NULL;
hlua_ctx_destroy(ctx->ctx.hlua_apptcp.hlua);
ctx->ctx.hlua_apptcp.hlua = NULL;
struct hlua_tcp_ctx *tcp_ctx = ctx->svcctx;
task_destroy(tcp_ctx->task);
tcp_ctx->task = NULL;
hlua_ctx_destroy(tcp_ctx->hlua);
tcp_ctx->hlua = NULL;
}
/* The function returns 1 if the initialisation is complete, 0 if