Commit Graph

4577 Commits

Author SHA1 Message Date
Willy Tarreau
2ec2274f90 MEDIUM: lua: remove hlua_sample_fetch
This struct used to carry only a sample fetch function. Thanks to
lua_pushuserdata(), we don't need to have the Lua engine allocate
that struct for us and we can simply push our pointer onto the stack.
This makes the code more readable by removing several occurrences of
"f->f->". Just like the previous patch, it comes with the nice effect
of saving about 1.3% of performance when fetching samples from Lua.
2015-03-11 20:41:47 +01:00
Willy Tarreau
47860ed505 MEDIUM: lua: remove struct hlua_channel
Since last cleanups, this one was only used to carry a struct channel.
Removing it makes the code a bit cleaner (no more chn->chn) and easier
to follow (no more abstraction for a common type). Interestingly it
happens to also make the Lua code slightly faster (about 1.5%) when
using channels, probably thanks to less pointer dereferences and maybe
the use of lua_pushlightuserdata().
2015-03-11 20:41:47 +01:00
Willy Tarreau
2a71af4c4f CLEANUP: lua: hlua_channel_new() doesn't need the pointer to the session anymore
Let's remove it now.
2015-03-11 20:41:47 +01:00
Willy Tarreau
f6870521e5 CLEANUP: lua: remove the session pointer from hlua_channel
It was only used to find what side the channel belongs to.
2015-03-11 20:41:47 +01:00
Willy Tarreau
6c6dc16505 MEDIUM: lua: use CF_ISRESP to detect the channel's side
Instead of comparing with session's channels, we check the channel's
flags to find what side it belongs to.
2015-03-11 20:41:47 +01:00
Willy Tarreau
78955f4c8b MEDIUM: session: simplify receive buffer allocator to only use the channel
Now that we can get the session from the channel, let's simplify the
prototype of session_alloc_recv_buffer() to only require the channel.
Both the caller and the function are now simplified.
2015-03-11 20:41:47 +01:00
Willy Tarreau
d5ccfa3fc5 MINOR: channel: add chn_sess() helper to retrieve session from channel
Channels already have to know what session they below to. Add a helper
to retrieve this pointer so that we'll use it later.
2015-03-11 20:41:47 +01:00
Willy Tarreau
81389679fb CLEANUP: lua: limit usage of si_ic/si_oc
As much as possible, we copy the result of this function into a local
variable to avoid having to check the flag all the time.
2015-03-11 20:41:47 +01:00
Willy Tarreau
afc8a22ad7 CLEANUP: stream-int: limit usage of si_ic/si_oc
As much as possible, we copy the result of this function into a local
variable to avoid having to check the flag all the time.
2015-03-11 20:41:47 +01:00
Willy Tarreau
103197d597 CLEANUP: session: don't use si_{ic,oc} when we know the session.
During the connection establishment, we needlessly rely on pointer
dereferences.
2015-03-11 20:41:47 +01:00
Willy Tarreau
7b8c4f9661 CLEANUP: session: don't needlessly pass a pointer to the stream-int
All functions dealing with connection establishment currently use a
pointer to the stream interface. Now we know it cannot change and is
always s->si[1].
2015-03-11 20:41:47 +01:00
Willy Tarreau
8f128b41ec CLEANUP: session: use local variables to access channels / stream ints
In process_session, we had around 300 accesses to channels and stream-ints
from the session. Not only this inflates the code due to the large offsets
from the original pointer, but readability can be improved. Let's have 4
local variables for the channels and stream-ints.
2015-03-11 20:41:47 +01:00
Willy Tarreau
350f487300 CLEANUP: session: simplify references to chn_{prod,cons}(&s->{req,res})
These 4 combinations are needlessly complicated since the session already
has direct access to the associated stream interfaces without having to
check an indirect pointer.
2015-03-11 20:41:47 +01:00
Willy Tarreau
81cd90069a MEDIUM: channel: remove now unused ->prod and ->cons pointers
Nothing uses them anymore.
2015-03-11 20:41:47 +01:00
Willy Tarreau
5decc05a9e MAJOR: channel: only rely on the new CF_ISRESP flag to find the SI
Now we exclusively use this flag to find what side a channel is and
where the stream ints are. The ->prod and ->cons are not used anymore.
2015-03-11 20:41:47 +01:00
Willy Tarreau
ef573c0f22 MEDIUM: channel: add a new flag "CF_ISRESP" for the response channel
This flag designates the response channel. This will be used to know
what channel we're seeing and finding our way back to the session.
2015-03-11 20:41:47 +01:00
Willy Tarreau
73796535a9 REORG/MEDIUM: channel: only use chn_prod / chn_cons to find stream-interfaces
The purpose of these two macros will be to pass via the session to
find the relevant stream interfaces so that we don't need to store
the ->cons nor ->prod pointers anymore. Currently they're only defined
so that all references could be removed.

Note that many places need a second pass of clean up so that we don't
have any chn_prod(&s->req) anymore and only &s->si[0] instead, and
conversely for the 3 other cases.
2015-03-11 20:41:47 +01:00
Willy Tarreau
50fe03be78 CLEANUP: stream-int: add si_opposite() to find the other stream interface
At a few places we need to find one stream interface from the other one.
Instead of passing via the channel, we simply use the session as an
intermediary, which simply results in applying an offset to the pointer.
2015-03-11 20:41:47 +01:00
Willy Tarreau
4e4292b9af CLEANUP: stream-int: add si_ib/si_ob to dereference the buffers
This makes the code cleaner and is more intuitive to use.
2015-03-11 20:41:46 +01:00
Willy Tarreau
819d332dfd MEDIUM: stream-int: remove any reference to the owner
si->owner is not used anymore now, so let's remove any reference to it.
2015-03-11 20:41:46 +01:00
Willy Tarreau
07373b8660 MEDIUM: stream-int: use si_task() to retrieve the task from the stream int
We go back to the session to get the owner. Here again it's very easy
and is just a matter of relative offsets. Since the owner always exists
and always points to the session's task, we can remove some unneeded
tests.
2015-03-11 20:41:46 +01:00
Willy Tarreau
aefd79004c MEDIUM: stream-int: make si_sess() use the stream int's side
This one relies on the SI's side to find the pointer to the session.
That the stream interface doesn't have to look at the task's context
anymore.
2015-03-11 20:41:46 +01:00
Willy Tarreau
a2df3fa251 MEDIUM: stream-interface: remove now unused pointers to channels
Everyone must now use si_ic() / si_oc() to find the relevant channels,
the points have been totally removed.
2015-03-11 20:41:46 +01:00
Willy Tarreau
0b2fb7f9a3 MAJOR: stream-int: only rely on SI_FL_ISBACK to find the requested channel
In order to plan removal of si->ib / si->ob, we now check the side of the
stream interface and find the session, then the requested channel. In
practice it's just an offset applied to the pointer based on the flag.
2015-03-11 20:41:46 +01:00
Willy Tarreau
a5f5d8dc69 MEDIUM: stream-int: add a flag indicating which side the SI is on
This new flag "SI_FL_ISBACK" is set only on the back SI and is cleared
on the front SI. That way it's possible only by looking at the SI to
know what side it is.
2015-03-11 20:41:46 +01:00
Willy Tarreau
2bb4a96f8f REORG/MEDIUM: stream-int: introduce si_ic/si_oc to access channels
We'll soon remove direct references to the channels from the stream
interface since everything belongs to the same session, so let's
first not dereference si->ib / si->ob anymore and use macros instead.
2015-03-11 20:41:46 +01:00
Willy Tarreau
a27dc19eda CLEANUP: remove now unused channel pool
The channels are now part of the struct session. Their pool is
not needed anymore.
2015-03-11 20:41:46 +01:00
Willy Tarreau
22ec1eadd0 REORG/MAJOR: move session's req and resp channels back into the session
The channels were pointers to outside structs and this is not needed
anymore since the buffers have moved, but this complicates operations.
Move them back into the session so that both channels and stream interfaces
are always allocated for a session. Some places (some early sample fetch
functions) used to validate that a channel was NULL prior to dereferencing
it. Now instead we check if chn->buf is NULL and we force it to remain NULL
until the channel is initialized.
2015-03-11 20:41:46 +01:00
Thierry FOURNIER
17bd152b58 DOC: lua api
This contains the Lua API documentation and the build environment
for Sphinx.
2015-03-11 20:41:33 +01:00
Thierry FOURNIER
2694a1a3c8 MINOR: lua: fetches and converters can return an empty string in place of nil
In some cases we don't want to known if a fetch or converter
fails. We just want a valid string. After this patch, we
have two sets of fetches and two sets of converters. There are:
txn.f, txn.sf, txn.c, txn.sc. The version prefixed by 's' always
returns strings for any type, and returns an empty string in the
error case or when the data are not available. This is particularly
useful when manipulating headers or cookies.
2015-03-11 20:26:49 +01:00
Thierry FOURNIER
397826aedc MINOR: lua: replace function (req|get)_channel by a variable
To add data in channel, it is necessary to process in two times.
First time, get the channel object, and after send data:

   local req = txn:req_channel()
	req:send("data\n")

Now, the function is converted as a variable containing the req
and res aobject. We can process as following:

   txn.req:send("data\n")
2015-03-11 19:55:10 +01:00
Thierry FOURNIER
594afe76e4 MINOR: lua: wrapper for converters
This patch implements a wrapper to give access to the converters
in the Lua code. The converters are used with the transaction.
The automatically created function are prefixed by "conv_".
2015-03-11 19:55:10 +01:00
Thierry FOURNIER
8fd1376014 MINOR: converters: add function to browse converters
This patch adds a fucntion to browse each converter. This
is used with Lua for using the converters with a wrapper.
2015-03-11 19:55:10 +01:00
Thierry FOURNIER
bb53c7b687 MEDIUM: lua: create a namespace for the fetches
HAProxy proposes many sample fetches. It is possible that the
automatic registration of the sample fetches causes a collision
with an existing Lua function. This patch sets a namespace for
the sample fetches.
2015-03-11 19:55:10 +01:00
Thierry FOURNIER
2297bc2fb9 MEDIUM: lua: change the objects configuration
Actually an object is just a userdata value with a metatable.
This mode causes some problems like I can't add lua own data.
This new model uses an array as object base, and affect the
userdata at the index 0.
2015-03-11 19:55:10 +01:00
Thierry FOURNIER
a2d8c650c1 MINOR: replace the Core object by a simple model.
The core entry is just a collection of function, it doesn't depends on
special variable. This patch just converts an object contained in a
metatable in object contained in a normal table.
2015-03-11 19:55:10 +01:00
Willy Tarreau
59551663e5 CLEANUP: lua: use the same function names in C and Lua
A few function names in Lua had underscores which did not appear in their
C counterpart. Since almost all of them already had similar names, better
uniformize the naming convention.
2015-03-10 17:31:07 +01:00
Willy Tarreau
5eadadacda MINOR: lua: convert IP addresses to type string
For now we don't perform any operation on IP addresses, so at least
we'd like to be able to pass them as strings so that we can log them
or whatever in Lua. Without this patch txn.src(txn) returns "nil" and
now it returns the correct IP address.
2015-03-10 17:30:41 +01:00
Thierry FOURNIER
38c5fd60b9 MEDIUM: lua: make the functions hlua_gethlua() and hlua_sethlua() faster
Lua 5.3 provides an opaque space associated with each
coroutine stack. This patch uses this lot of memory to
store the "struct hlua *" associated pointer.

This patch makes the retrieval of the "struct hlua *"
associated struct faster because it replace a lookup in
a tree by an immediate access to the data.
2015-03-10 17:18:24 +01:00
Willy Tarreau
76bd97f405 Revert "BUG/MEDIUM: lua: can't handle the response bytes"
This reverts commit cd9084f776.

This commit introduced a regression making it impossible to leave
process_session() during a forced yield because the analyser was always
set on the response even if not needed. The result was a busy loop
making haproxy spin at 100% without even polling anymore in case a
forced yield was performed.

The problem it tried to address (intercept response data from a request
analyser before forwarding) is not a trivial issue to address since
wakeups based on reads will not necessarily happen unless there's write
activity.

Anyway, if functions are attached specifically to a request or to a
response, it's for a reason. So for now let's be clear about the fact
that it's unreliable to try to process data from the opposite channel
until a better solution is found.
2015-03-10 17:16:10 +01:00
Willy Tarreau
612adb8459 BUG/MAJOR: http: fix stats regression consecutive to HTTP_RULE_RES_YIELD
Commit bc4c1ac ("MEDIUM: http/tcp: permit to resume http and tcp custom actions")
unfortunately broke the stats applet by moving the clearing of the analyser bit
after processing the applet headers. It used to work only in HTTP/1.1 and not
in HTTP/1.0. This is 1.6-specific, no backport is needed.
2015-03-10 15:33:55 +01:00
Willy Tarreau
eee45391db BUG/MINOR: lua: report the correct function name in an error message
"req_channel" was reported instead of "res_channel". This is harmless.
2015-03-10 15:33:55 +01:00
Thierry FOURNIER
fdda6777bf BUG/MEDIUM: buffer: one byte miss in buffer free space check
Space is not avalaible only if the end of the data inserted
is strictly greater than the end of buffer. If these two value
are equal, the space is avamaible.
2015-03-10 10:17:54 +01:00
Thierry FOURNIER
463119ccc1 BUG/BUILD: lua: The strict Lua 5.3 version check is not done.
This patch fix the Lua library check. Only the version
5.3 or later is allowed.

This bug is added by the patch "MEDIUM: lua: use the
Lua-5.3 version of the library" with commit id

   f90838b71a
2015-03-10 10:17:48 +01:00
Thierry FOURNIER
0054392509 BUG/MINOR: lua: sockets receive behavior doesn't follows the specs
Specs says that the receive() function with an argument "*l"
must return a line without the final "\n" ( or without "\r\n").
This patch removes these two final bytes.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
95ad96a7ea BUG/MEDIUM: lua: cannot connect socket
The Lua stack is not waked up when the connect() receive a positive
or negatibe response. This patch adds a signal to wake up the Lua
stack.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
486d52a2a3 BUG/MEDIUM: lua: sockets don't have buffer to write data
When we try to write data in a session from another session, the "req"
buffer is not allowed. This patch try to allocate the buffer. The session
wait if the buffer is not yet avalaible.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
e83766afd1 BUG/MINOR: log: segfault if there are no proxy reference
The HAProxy API allow to send log without defined proxy (it
set to the NULL value). An incomplete test if done to choose
the log tag and an invalid pointer is dereferenced.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
4a6170cce1 BUG/MINOR: lua: check buffers before initializing socket
When a socket is initilized in the body context, a segfaut is generated
because the memory pools are not initilized. This atch check if these
memory pool are initialized.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
d2b597aa10 BUG/MEDIUM: lua: segfault with buffer_replace2
The function buffer_contig_space() returns the contiguous space avalaible
to add data (at the end of the input side) while the function
hlua_channel_send_yield() needs to insert data starting at p. Here we
introduce a new function bi_space_for_replace() which returns the amount
of space that can be inserted at the head of the input side with one of
the buffer_replace* functions.

This patch proposes a function that returns the space avalaible after buf->p.
2015-03-09 18:12:59 +01:00