MINOR: hlua: add hlua_stream_ctx_prepare helper function
Stream-dedicated hlua ctx creation and attachment is now performed in hlua_stream_ctx_prepare() helper function to ease code maintenance. No functional behavior change should be expected.
This commit is contained in:
parent
12cf8d4db7
commit
2fdb9d41b3
106
src/hlua.c
106
src/hlua.c
@ -8886,6 +8886,35 @@ struct task *hlua_process_task(struct task *task, void *context, unsigned int st
|
|||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper function to prepare the lua ctx for a given stream
|
||||||
|
*
|
||||||
|
* ctx will be enforced in <state_id> parent stack on initial creation
|
||||||
|
*
|
||||||
|
* Returns 1 for success and 0 for failure
|
||||||
|
*/
|
||||||
|
static int hlua_stream_ctx_prepare(struct stream *s, int state_id)
|
||||||
|
{
|
||||||
|
/* In the execution wrappers linked with a stream, the
|
||||||
|
* Lua context can be not initialized. This behavior
|
||||||
|
* permits to save performances because a systematic
|
||||||
|
* Lua initialization cause 5% performances loss.
|
||||||
|
*/
|
||||||
|
if (!s->hlua) {
|
||||||
|
struct hlua *hlua;
|
||||||
|
|
||||||
|
hlua = pool_alloc(pool_head_hlua);
|
||||||
|
if (!hlua)
|
||||||
|
return 0;
|
||||||
|
HLUA_INIT(hlua);
|
||||||
|
if (!hlua_ctx_init(hlua, state_id, s->task)) {
|
||||||
|
pool_free(pool_head_hlua, hlua);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
s->hlua = hlua;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is an LUA binding that register LUA function to be
|
/* This function is an LUA binding that register LUA function to be
|
||||||
* executed after the HAProxy configuration parsing and before the
|
* executed after the HAProxy configuration parsing and before the
|
||||||
* HAProxy scheduler starts. This function expect only one LUA
|
* HAProxy scheduler starts. This function expect only one LUA
|
||||||
@ -9725,26 +9754,10 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||||||
if (!stream)
|
if (!stream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* In the execution wrappers linked with a stream, the
|
if (!hlua_stream_ctx_prepare(stream, fcn_ref_to_stack_id(fcn))) {
|
||||||
* Lua context can be not initialized. This behavior
|
|
||||||
* permits to save performances because a systematic
|
|
||||||
* Lua initialization cause 5% performances loss.
|
|
||||||
*/
|
|
||||||
if (!stream->hlua) {
|
|
||||||
struct hlua *hlua;
|
|
||||||
|
|
||||||
hlua = pool_alloc(pool_head_hlua);
|
|
||||||
if (!hlua) {
|
|
||||||
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
HLUA_INIT(hlua);
|
|
||||||
stream->hlua = hlua;
|
|
||||||
if (!hlua_ctx_init(stream->hlua, fcn_ref_to_stack_id(fcn), stream->task)) {
|
|
||||||
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is the first run, initialize the data for the call. */
|
/* If it is the first run, initialize the data for the call. */
|
||||||
if (!HLUA_IS_RUNNING(stream->hlua)) {
|
if (!HLUA_IS_RUNNING(stream->hlua)) {
|
||||||
@ -9866,26 +9879,10 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||||||
if (!stream)
|
if (!stream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* In the execution wrappers linked with a stream, the
|
if (!hlua_stream_ctx_prepare(stream, fcn_ref_to_stack_id(fcn))) {
|
||||||
* Lua context can be not initialized. This behavior
|
|
||||||
* permits to save performances because a systematic
|
|
||||||
* Lua initialization cause 5% performances loss.
|
|
||||||
*/
|
|
||||||
if (!stream->hlua) {
|
|
||||||
struct hlua *hlua;
|
|
||||||
|
|
||||||
hlua = pool_alloc(pool_head_hlua);
|
|
||||||
if (!hlua) {
|
|
||||||
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hlua->T = NULL;
|
|
||||||
stream->hlua = hlua;
|
|
||||||
if (!hlua_ctx_init(stream->hlua, fcn_ref_to_stack_id(fcn), stream->task)) {
|
|
||||||
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is the first run, initialize the data for the call. */
|
/* If it is the first run, initialize the data for the call. */
|
||||||
if (!HLUA_IS_RUNNING(stream->hlua)) {
|
if (!HLUA_IS_RUNNING(stream->hlua)) {
|
||||||
@ -10211,28 +10208,11 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In the execution wrappers linked with a stream, the
|
if (!hlua_stream_ctx_prepare(s, fcn_ref_to_stack_id(rule->arg.hlua_rule->fcn))) {
|
||||||
* Lua context can be not initialized. This behavior
|
|
||||||
* permits to save performances because a systematic
|
|
||||||
* Lua initialization cause 5% performances loss.
|
|
||||||
*/
|
|
||||||
if (!s->hlua) {
|
|
||||||
struct hlua *hlua;
|
|
||||||
|
|
||||||
hlua = pool_alloc(pool_head_hlua);
|
|
||||||
if (!hlua) {
|
|
||||||
SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
|
SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
|
||||||
rule->arg.hlua_rule->fcn->name);
|
rule->arg.hlua_rule->fcn->name);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
HLUA_INIT(hlua);
|
|
||||||
s->hlua = hlua;
|
|
||||||
if (!hlua_ctx_init(s->hlua, fcn_ref_to_stack_id(rule->arg.hlua_rule->fcn), s->task)) {
|
|
||||||
SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
|
|
||||||
rule->arg.hlua_rule->fcn->name);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is the first run, initialize the data for the call. */
|
/* If it is the first run, initialize the data for the call. */
|
||||||
if (!HLUA_IS_RUNNING(s->hlua)) {
|
if (!HLUA_IS_RUNNING(s->hlua)) {
|
||||||
@ -11669,30 +11649,12 @@ static int hlua_filter_new(struct stream *s, struct filter *filter)
|
|||||||
struct hlua_flt_ctx *flt_ctx = NULL;
|
struct hlua_flt_ctx *flt_ctx = NULL;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
/* In the execution wrappers linked with a stream, the
|
if (!hlua_stream_ctx_prepare(s, reg_flt_to_stack_id(conf->reg))) {
|
||||||
* Lua context can be not initialized. This behavior
|
SEND_ERR(s->be, "Lua filter '%s': can't initialize filter Lua context.\n",
|
||||||
* permits to save performances because a systematic
|
|
||||||
* Lua initialization cause 5% performances loss.
|
|
||||||
*/
|
|
||||||
if (!s->hlua) {
|
|
||||||
struct hlua *hlua;
|
|
||||||
|
|
||||||
hlua = pool_alloc(pool_head_hlua);
|
|
||||||
if (!hlua) {
|
|
||||||
SEND_ERR(s->be, "Lua filter '%s': can't initialize Lua context.\n",
|
|
||||||
conf->reg->name);
|
conf->reg->name);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
HLUA_INIT(hlua);
|
|
||||||
s->hlua = hlua;
|
|
||||||
if (!hlua_ctx_init(s->hlua, reg_flt_to_stack_id(conf->reg), s->task)) {
|
|
||||||
SEND_ERR(s->be, "Lua filter '%s': can't initialize Lua context.\n",
|
|
||||||
conf->reg->name);
|
|
||||||
ret = 0;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
flt_ctx = pool_zalloc(pool_head_hlua_flt_ctx);
|
flt_ctx = pool_zalloc(pool_head_hlua_flt_ctx);
|
||||||
if (!flt_ctx) {
|
if (!flt_ctx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user