Fix: handle concurrent flush vs get_next_subbuf on metadata cache

The "flush" operation can be performed on the metadata file descriptor
concurrently with get_next_subbuffer operations by different processes
(e.g. lttng session daemon issuing flush at "stop" concurrently with
consumer daemon issuing get_next_subbuf for metadata I/O). We need
to protect the metadata cache from those concurrent use by introducing a
mutex.

This fixes a race where metadata from a kernel trace is corrupted due to
this scenario. The corruption shows up like the same metadata content (a
metadata packet) being written twice consecutively in the metadata
stream, thus triggering a babeltrace "parse error" when trying to read
the trace.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: lttng-modules teardown NULL pointer OOPS

Accessing the lttng channel and lttng session from the metadata ring
buffer client is a bad idea, because we don't have any reference
ensuring those are valid for the lifetime of the metadata cache.
Therefore, rather than keeping a lttng channel as private data pointer
for the metadata ring buffer channel, keep a pointer to the metadata
cache instead: this will ensure we don't shoot ourself in the foot and
access data we for which coherency is not guaranteed (we don't hold any
reference to it).

Anyway, the only reason why we needed to access the lttng session from
the metadata client in the first place was the UUID of the session. Copy
it into the metadata cache instead.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
System call filtering

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Syscall filtering: apply to syscall exit

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Extract system call exit return value

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Extract syscall exit ret value on x86 32/64

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Add syscall inout table

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Update syscall inout table

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
System call inout/output arg processing

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Remove sys_ prefix from syscall names

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
syscall: extract pipe and pipe2 output args

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Extract input/output arguments from accept and connect syscalls

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Rename LTTng instrumentation macros

Since LTTng instrumentation macros have a different layout than the
Linux kernel TRACE_EVENT macros, privatize the name.

Here is the mapping:

DECLARE_EVENT_CLASS -> LTTNG_TRACEPOINT_EVENT_CLASS
DEFINE_EVENT -> LTTNG_TRACEPOINT_EVENT_INSTANCE
TRACE_EVENT -> LTTNG_TRACEPOINT_EVENT
TRACE_EVENT_CONDITION -> LTTNG_TRACEPOINT_EVENT_CONDITION
DEFINE_EVENT_CONDITION -> LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION
TRACE_EVENT_MAP -> LTTNG_TRACEPOINT_EVENT_MAP
DEFINE_EVENT_MAP -> LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP

LTTNG_V4L2_TRACEPOINT_EVENT -> LTTNG_TRACEPOINT_EVENT_V4L2
DEFINE_WRITEBACK_WORK_EVENT ->
LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE
DEFINE_WBC_EVENT -> LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE

DEFINE_EVENT_NOARGS -> LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
TRACE_EVENT_FLAGS -> REMOVE

LTTNG_DECLARE_EVENT_CLASS -> LTTNG_TRACEPOINT_EVENT_CLASS_CODE
LTTNG_DECLARE_EVENT_CLASS_NOARGS ->
LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
LTTNG_TRACE_EVENT -> LTTNG_TRACEPOINT_EVENT_CODE

TRACE_EVENT_MAP_NOARGS -> LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
DECLARE_EVENT_CLASS_NOARGS -> LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS

DEFINE_EVENT_MAP_NOARGS -> LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS

DEFINE_EVENT_PRINT -> LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT
DEFINE_EVENT_PRINT_MAP -> LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP

DEFINE_EVENT_CONDITION_MAP ->
LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP
TRACE_EVENT_CONDITION_MAP -> LTTNG_TRACEPOINT_EVENT_CONDITION_MAP

TRACE_EVENT_NOARGS -> LTTNG_TRACEPOINT_EVENT_NOARGS
TRACE_EVENT_FN_MAP -> LTTNG_TRACEPOINT_EVENT_FN_MAP
TRACE_EVENT_FN -> LTTNG_TRACEPOINT_EVENT_FN

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Rename LTTng syscall instrumentation macros

Mapping:

SC_LTTNG_TRACE_EVENT -> SC_LTTNG_TRACEPOINT_EVENT_CODE
SC_TRACE_EVENT -> SC_LTTNG_TRACEPOINT_EVENT
SC_DECLARE_EVENT_CLASS_NOARGS -> SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
SC_DEFINE_EVENT_NOARGS -> SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
syscall instrumentation: handle copy_from_user return value

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix generate syscall header script: add missing escape char

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-get-syscall-inout.sh depends on bash

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
syscall tracing: input/output parameter handling for all arch

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: syscall filtering: disable all syscalls

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: tracepoint list anonymous file name

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>