lttng-tools.git
5 years agouserspace-probe: tests: add testcase for unsupported instrumentation
Francis Deslauriers [Mon, 26 Nov 2018 16:41:51 +0000 (11:41 -0500)] 
userspace-probe: tests: add testcase for unsupported instrumentation

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agouserspace-probe: Print error on binary not found
Francis Deslauriers [Sat, 24 Nov 2018 00:20:45 +0000 (19:20 -0500)] 
userspace-probe: Print error on binary not found

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agouserspace-probe: Print error for unsupported instrumentation mode
Francis Deslauriers [Sat, 24 Nov 2018 00:03:21 +0000 (19:03 -0500)] 
userspace-probe: Print error for unsupported instrumentation mode

This patch adds an error message printed when the user tries to place an
userspace-probe using unsupported probe location descriptions.
Hopefully, this will help users understand why their command failed.

Here are examples of unsupported uses of an address location:
* "elf:/path/to/binary:0x400430"
* "elf:/path/to/binary:4194364"

Here are examples of unsupported uses of offset from symbol location:
* "elf:/path/to/binary:my_symbol+0x323"
* "elf:/path/to/binary:my_symbol+43"

I expect users to try using the address locations and offset from symbol
locations for ELF instrumentation location because those methods are
available with the --probe option used to instrument the kernel.

Supporting those location descriptions in the future would require
the validation that the address or the offset from a symbol is indeed at
the boundary of an instruction.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: use sys/types.h for ssize_t on Cygwin
Michael Jeanson [Tue, 27 Nov 2018 19:24:01 +0000 (14:24 -0500)] 
Fix: use sys/types.h for ssize_t on Cygwin

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAdd *.exe to gitignore for Cygwin
Michael Jeanson [Tue, 27 Nov 2018 19:24:27 +0000 (14:24 -0500)] 
Add *.exe to gitignore for Cygwin

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRevert stubbing of runas functions
Michael Jeanson [Thu, 29 Nov 2018 21:22:07 +0000 (16:22 -0500)] 
Revert stubbing of runas functions

All the runas functions were stubbed on builds where the sessiond isn't
built which is the case for all platforms except Linux. This was done
because of 2 new commands that require elf.h which is not present on
MacOSX. However the other commands can be used by the relayd.

Revert this and and only stub the relevant commands when "elf.h" is not
present on the system.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRevert stubbing of unix socket functions
Michael Jeanson [Thu, 29 Nov 2018 21:22:06 +0000 (16:22 -0500)] 
Revert stubbing of unix socket functions

Instead of stubbing useful UNIX socket functions to work around
Linux-only credential passing, ifdef the relevant parts like it was
already done for other functions.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: warning 'fd' may be used uninitialized
Michael Jeanson [Thu, 29 Nov 2018 21:49:51 +0000 (16:49 -0500)] 
Fix: warning 'fd' may be used uninitialized

Initialize fd to invalid '-1' and remove unnecessary file_opened.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: worker structure is leaked in run_as process
Jérémie Galarneau [Thu, 6 Dec 2018 20:49:04 +0000 (15:49 -0500)] 
Fix: worker structure is leaked in run_as process

The run_as structure (handle) is allocated and initialized before
the fork() that spawns the run_as process. Currently, that structure
is only cleaned-up on the parent's end.

This fix performs the clean-up on the worker's side as well.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: ensure the ht clean pipe is empty before processing quit pipe
Jérémie Galarneau [Thu, 6 Dec 2018 20:38:14 +0000 (15:38 -0500)] 
Fix: ensure the ht clean pipe is empty before processing quit pipe

The ht-cleanup thread does not ensure that all data pending on its
ht_clean_pipe has been read (and processed) before processing the
"quit" event on the quit_pipe.

This causes a number of urcu hash tables to be leaked on exit of
the sessiond even though they have been pushed on the cleanup
pipe.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoPerform the clean-up of application notify sockets in main thread
Jérémie Galarneau [Thu, 6 Dec 2018 19:47:34 +0000 (14:47 -0500)] 
Perform the clean-up of application notify sockets in main thread

The notify sockets of applications are owned by the "notify-apps"
thread. If an application exits during the course of the session
daemon's life, the notify thread will take care of cleaning its
associated notify socket.

However, there is no teardown/clean-up code to handle their
clean-up when the daemon is torn down.

This change adds a new step in the sessiond clean-up code that
closes closes all notify sockets present in the
ust_app_by_notify_sock hash table at the time of the sessiond
cleanup.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoClean-up: remove redundant exit labels from sessiond initialization
Jérémie Galarneau [Thu, 6 Dec 2018 19:22:20 +0000 (14:22 -0500)] 
Clean-up: remove redundant exit labels from sessiond initialization

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoMake the launch of the application registration thread blocking
Jérémie Galarneau [Thu, 6 Dec 2018 17:03:48 +0000 (12:03 -0500)] 
Make the launch of the application registration thread blocking

Waiting for the application registration thread to be ready to
accept application connection ensures that the application
registration socket is created and being listened-to before the parent
is signalled.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoStop the application registration thread before orphaned threads
Jérémie Galarneau [Thu, 6 Dec 2018 16:09:32 +0000 (11:09 -0500)] 
Stop the application registration thread before orphaned threads

The application registration thread receives new connections from
applications, provides them to the dispatch thread. The dispatch
thread, in turn, forwards the command and notification sockets of
applications (liblttng-ust) to the application management and
application notification threads.

Not shutting down the application registration thread is problematic
since application connections will be accepted but not associated
to an "ust_app" structure as the following threads are no longer
present.

The remaining threads can then be safely torn down as part of the
orphaned threads.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRename ust-thread to notify-apps
Jérémie Galarneau [Thu, 6 Dec 2018 14:39:02 +0000 (09:39 -0500)] 
Rename ust-thread to notify-apps

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoTeardown the notification thread after the sessiond clean-up
Jérémie Galarneau [Wed, 5 Dec 2018 20:00:09 +0000 (15:00 -0500)] 
Teardown the notification thread after the sessiond clean-up

The notification thread may receive commands issued through the
call_rcu thread during the destruction of some of the sessiond's
data structure.

This change tears down the notification thread after the clean-up
has occured and the issuance of an RCU barrier. This ensures that
all previously-queued call_rcu work has been performed and that
any ensuing notification thread commands have been queued in return.

It is safe, at that point, to queue a "quit" command in the
notification thread's command queue. The notification thread's
shutdown method will issue the command and wait for its completion
before returning.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the consumer management thread using lttng_thread
Jérémie Galarneau [Wed, 5 Dec 2018 04:19:25 +0000 (23:19 -0500)] 
Launch the consumer management thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoStop sessions before destroying on teardown of session daemon
Jérémie Galarneau [Tue, 4 Dec 2018 22:46:00 +0000 (17:46 -0500)] 
Stop sessions before destroying on teardown of session daemon

Stopping sessions ensures that trace data is no longer produced
for a session which will allow pending rotations to complete.

It also ensure that no data is produced beyond the last rename
of a rotated session's output folder.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRemove the sessiond "ready" counter mechanism
Jérémie Galarneau [Tue, 4 Dec 2018 16:50:30 +0000 (11:50 -0500)] 
Remove the sessiond "ready" counter mechanism

This commit replaces the sessiond "ready" counter scheme with
the use of the lttng_thread util. The launch of the threads which
need to be active before the sessiond can signal its parents
(when launched in daemon mode) is now blocking. This means that
their associated "launch" functions wait until the threads mark
themselves as ready (through the use of a "ready" semaphore)
before returning and allowing the initialization of the sessiond
to continue.

The threads which expose externally-visible resources (UNIX and
TCP sockets) which must be fully initialized before marking the
session daemon as ready are:
  - Health thread,
  - Agent thread,
  - Client thread.

Previously, the "load session" thread was part of this group.
However, it is no longer necessary to perform the loading of
session configurations in a dedicated thread. The main thread
performs that operation itself. It is safe to do so since it
is performed after the launch of the client thread. The client
thread has to be fully initialized as the session loading code
"impersonates" a client to initialize the loaded sessions.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLoad session configurations from lttng-sessiond's main thread
Jérémie Galarneau [Mon, 3 Dec 2018 00:04:45 +0000 (19:04 -0500)] 
Load session configurations from lttng-sessiond's main thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the kernel management thread using lttng_thread
Jérémie Galarneau [Sun, 2 Dec 2018 22:06:45 +0000 (17:06 -0500)] 
Launch the kernel management thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch agent management thread using lttng_thread
Jérémie Galarneau [Sun, 2 Dec 2018 21:20:16 +0000 (16:20 -0500)] 
Launch agent management thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoMark lttng_pipe as const where possible
Jérémie Galarneau [Sat, 1 Dec 2018 01:04:08 +0000 (20:04 -0500)] 
Mark lttng_pipe as const where possible

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the application notification thread using lttng_thread
Jérémie Galarneau [Tue, 4 Dec 2018 22:37:45 +0000 (17:37 -0500)] 
Launch the application notification thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the application management thread with lttng_thread
Jérémie Galarneau [Sat, 1 Dec 2018 00:25:06 +0000 (19:25 -0500)] 
Launch the application management thread with lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch application registration thread using lttng_thread
Jérémie Galarneau [Fri, 30 Nov 2018 21:33:38 +0000 (16:33 -0500)] 
Launch application registration thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the ust registration dispatch thread using lttng_thread
Jérémie Galarneau [Fri, 30 Nov 2018 20:57:04 +0000 (15:57 -0500)] 
Launch the ust registration dispatch thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the client management thread using lttng_thread
Jérémie Galarneau [Fri, 30 Nov 2018 19:29:32 +0000 (14:29 -0500)] 
Launch the client management thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the timer thread using lttng_thread
Jérémie Galarneau [Fri, 30 Nov 2018 17:12:12 +0000 (12:12 -0500)] 
Launch the timer thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the rotation thread using lttng_thread
Jérémie Galarneau [Wed, 28 Nov 2018 21:53:53 +0000 (16:53 -0500)] 
Launch the rotation thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: flush the rotation thread's job queue on exit
Jérémie Galarneau [Wed, 28 Nov 2018 21:12:25 +0000 (16:12 -0500)] 
Fix: flush the rotation thread's job queue on exit

The rotation thread's job queue can transitively hold references
to a number of ltt_session objects which will prevent the session
daemon to exit as it waits for all sessions to have completed
their destruction.

This fix ensures that the job queue is flushed when activity
is observed on the quit pipe.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoStop rotation pending check timer from the rotation thread
Jérémie Galarneau [Tue, 27 Nov 2018 23:17:16 +0000 (18:17 -0500)] 
Stop rotation pending check timer from the rotation thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the notification thread using lttng_thread
Jérémie Galarneau [Tue, 27 Nov 2018 21:37:05 +0000 (16:37 -0500)] 
Launch the notification thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the health management thread using lttng_thread
Jérémie Galarneau [Tue, 27 Nov 2018 17:39:06 +0000 (12:39 -0500)] 
Launch the health management thread using lttng_thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoLaunch the ht-cleanup thread using lttng_thread util
Jérémie Galarneau [Mon, 26 Nov 2018 20:15:24 +0000 (15:15 -0500)] 
Launch the ht-cleanup thread using lttng_thread util

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAdd a thread utility class and thread list
Jérémie Galarneau [Mon, 26 Nov 2018 20:09:10 +0000 (15:09 -0500)] 
Add a thread utility class and thread list

As part of the re-work of the order of the teardown of the sessiond's
threads, this utility is introduced to track running threads and unify
the mechanisms through which they are launched and shutdown.

This makes it easier to reason about (and track) the order in which
threads are launched and shutdown.

The lttng_thread class allows threads to be implemented by
defining the following methods:
  - An entry point ("main" function),
  - A shutdown method,
  - A clean-up method.

Since the sessiond's threads use a variety of techniques to initiate
their teardown (through an explicit command in a queue, using the
global "quit" pipe, or through a futex + variable), it is more
practical to let them define a shutdown method which notifies the
thread to shutdown than to impose a standard mechanism.

A clean-up method is meant to work around situations where the
ownership of data structures shared between the main thread and
a worker thread can be ambiguous (mostly in error paths).
The clean-up method is invoked when the last reference to a thread
is released.

While some threads need to be shutdown in a particular order, most of
them can be shutdown in bulk. The lttng_thread utility maintains a
global thread list which allows for a generic path through which
threads can be shutdown using the lttng_thread_list_shutdown_orphans()
function.

The lttng_thread_shutdown() method, in return, allows the user
(most likely the main thread) to explicitly teardown threads which
must be shutdown in a specific order before issuing the bulk
lttng_thread_list_shutdown_orphans() call.

Note that lttng_thread objects are reference counted. The thread
list holds a reference to each thread until it is shutdown. Hence,
it is safe to hold a reference to a thread, invoke its shutdown
method, and then invoke lttng_thread_list_shutdown_orphans().

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoDon't perform an implicit rotation on session stop
Jérémie Galarneau [Wed, 21 Nov 2018 15:41:07 +0000 (10:41 -0500)] 
Don't perform an implicit rotation on session stop

Performing a periodic rotation on stop does not allow a user to start
and stop a session within a given chunk.

There is no functionality lost from not performing the rotation
implicitly on stop; the user could decide to explicitly perform the
rotation himself.

The timestamp of the last stop command is sampled to allow the trace
archive chunk to be accurately named should a rotation be performed.

Moreover, this change moves the implicit rotation performed at the
moment of the stop to the moment of the session's destruction. This
ensures that users don't end-up with a partially-named trace archive
chunk folder upon destruction (timestamp_begin-id).

In effect, this will perform an implicit session rotation as part of
the "session destroy" command if the session was rotated at any point
during its lifetime.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoWait for the destruction of sessions before tearing down main thread
Jérémie Galarneau [Thu, 22 Nov 2018 21:07:49 +0000 (16:07 -0500)] 
Wait for the destruction of sessions before tearing down main thread

The main thread can no longer assume that it is the last thread to
use the session objects (since they are now ref-counted). Hence,
this commit introduces utils to allow the main thread to wait for
the destruction of all sessions.

The logic of the teardown is as follows:

1) The main thread waits for activity on the quit pipe.
2) Once the main thread unblocks, the main thread waits for the
   client thread to stop in order to guarantee that no new sessions
   are created.
3) The main thread then waits for the session list to be emptied
4) Once the session list is empty, continue the rest of the teardown
   as usual.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: rotation_unavailable returned on failure to read time
Jérémie Galarneau [Thu, 22 Nov 2018 01:53:43 +0000 (20:53 -0500)] 
Fix: rotation_unavailable returned on failure to read time

A "rotation feature unavailable" error code is returned if the
session daemon fails to sample time. The TIME(2) man page has
makes no mention of an error that could happen in this use case
(as time()'s parameter is NULL, EFAULT does not apply).

However, a more general error code is more appropriate should
this call fail.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: mark rotation pending check timer is never marked as disabled
Jérémie Galarneau [Wed, 21 Nov 2018 23:09:52 +0000 (18:09 -0500)] 
Fix: mark rotation pending check timer is never marked as disabled

The rotation pending check timer is launched in "one-shot" mode.
However, it is marked as enabled for the whole duration of the
rotation pending check phase.

This change ensures that the timer is marked as disabled when
the session rotation pending reaches the "completed" state.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAcquire a reference to a session when a timer is active
Jérémie Galarneau [Wed, 21 Nov 2018 15:30:15 +0000 (10:30 -0500)] 
Acquire a reference to a session when a timer is active

The timers associated to a session don't directly
reference a session since, up to recently, session
objects were not reference counted. There was
essentially no mechanism in place to prevent a
session from being destroyed while one of its timers
was active.

For this reason, the session was queried by id on
every execution of its timers. However, this did
not prevent the session from being destroyed; it only
allowed the periodic jobs to handle that condition
gracefully.

This change that a reference to the session is held
at all times by periodic jobs that are "in-flight".

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoReference count ltt_session objects
Jérémie Galarneau [Wed, 21 Nov 2018 00:24:58 +0000 (19:24 -0500)] 
Reference count ltt_session objects

The lifetime of ltt_session objects is mishandled in a number
of situations. For instance, if a rotation is launched on a
session and the session is destroyed during the rotation, it
is not possible for the session daemon to identify the completion
of the rotation. This then prevents the session daemon from
renaming the last chunk of a now-destroyed session and from
notifying clients that a new trace archive chunk is available.

This change only introduces reference counting of the ltt_session
objects; it does not change any behavior with regards to the
lifetime of the sessions themselved. Follow-up commits introduce
those changes.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: typo 'occured' -> 'occurred'
Michael Jeanson [Thu, 15 Nov 2018 17:24:48 +0000 (12:24 -0500)] 
Fix: typo 'occured' -> 'occurred'

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: typo 'retrive' -> 'retrieve'
Michael Jeanson [Thu, 15 Nov 2018 17:24:47 +0000 (12:24 -0500)] 
Fix: typo 'retrive' -> 'retrieve'

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: typo 'convet' -> 'convert'
Michael Jeanson [Thu, 15 Nov 2018 17:16:37 +0000 (12:16 -0500)] 
Fix: typo 'convet' -> 'convert'

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: typo 'leat' -> 'least'
Michael Jeanson [Thu, 15 Nov 2018 17:16:36 +0000 (12:16 -0500)] 
Fix: typo 'leat' -> 'least'

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: max_t/min_t macros are missing cast on input
Mathieu Desnoyers [Tue, 13 Nov 2018 17:12:21 +0000 (12:12 -0500)] 
Fix: max_t/min_t macros are missing cast on input

The semantic expected from max_t and min_t is to perform the max/min
comparison in the type provided as first parameter.

Cast the input parameters to the proper type before comparing them,
rather than after. There is no more need to cast the result of the
expression now that both inputs are cast to the right type.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: Connect timeout arithmetic in inet/inet6 (v4)
Mathieu Desnoyers [Tue, 13 Nov 2018 17:12:20 +0000 (12:12 -0500)] 
Fix: Connect timeout arithmetic in inet/inet6 (v4)

The nanoseconds part of the timespec struct time_a is not always
bigger than time_b since it wraps around each second.

Use 64-bit arithmetic to compute the difference.

Merge/move duplicated code into utils.c.

This function is really doing two things. Split it into
timespec_to_ms() and timespec_abs_diff().

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: cmd_snapshot_record can return unexpected error codes
Jérémie Galarneau [Fri, 16 Nov 2018 21:46:36 +0000 (16:46 -0500)] 
Fix: cmd_snapshot_record can return unexpected error codes

cmd_snapshot_record() does not correctly handle the various error
reporting conventions used by the functions it uses. In certain cases,
invalid error codes (not part of enum lttng_error_code) can bubble up
to the command handler which results in erroneous error messages being
reported by the client.

This change harmonizes the error handling and changes a number of
functions used to explicitly return 'enum lttng_error_code' instead
of 'int'.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoDocs: document why a negative socket may be passed
Jérémie Galarneau [Fri, 16 Nov 2018 18:55:57 +0000 (13:55 -0500)] 
Docs: document why a negative socket may be passed

The fix in 4821263c4 checks for a negative socket. While the
commit message explains the reason for the check, it is not
obvious why this check is needed when looking at the code
itself.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-enable-event.1.txt: fix SDT acronym, add missing "are supported"
Philippe Proulx [Tue, 13 Nov 2018 17:52:04 +0000 (12:52 -0500)] 
lttng-enable-event.1.txt: fix SDT acronym, add missing "are supported"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-enable-rotation.1.txt: --timer option should be fairly precise
Philippe Proulx [Tue, 13 Nov 2018 17:48:52 +0000 (12:48 -0500)] 
lttng-enable-rotation.1.txt: --timer option should be fairly precise

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agodoc/man: remove AUTHORS section
Philippe Proulx [Fri, 9 Nov 2018 17:01:37 +0000 (12:01 -0500)] 
doc/man: remove AUTHORS section

Many people have contributed to LTTng-tools and the original authors are
not necessarily the top ones now. For instance, GitHub reports this top
5 as of this patch:

1. jgalar    952 commits  45,889 ++  13,959 --
2. compudj    880 commits  56,579 ++  28,095 --
3. PSRCode    303 commits  25,553 ++  10,909 --
4. eepp    199 commits  12,119 ++  6,461 --
5. jdesfossez    174 commits  32,546 ++  3,381 --

Also, man-pages(7), the conventions for writing Linux man pages, says:

> Use of an AUTHORS section is strongly discouraged.

Let's just keep the project's copyrights and some special thanks without
selecting specific authors to list on each man page.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-enable-event.1.txt: uprobe: update style and content
Philippe Proulx [Fri, 9 Nov 2018 16:46:38 +0000 (11:46 -0500)] 
lttng-enable-event.1.txt: uprobe: update style and content

* Better inline styles for option variables.
* Option descriptions moved to the OPTIONS section.
* Expand SDT acronym.
* Add note indicating that SDT probes surrounded by reference counts
  are not supported.
* Use "application" and "library" instead of "executable".

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agodoc/man: add links between man pages about session rotation
Philippe Proulx [Fri, 9 Nov 2018 15:28:49 +0000 (10:28 -0500)] 
doc/man: add links between man pages about session rotation

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-enable-event.1.txt: document dynamic user space probes
Philippe Proulx [Fri, 9 Nov 2018 00:09:26 +0000 (19:09 -0500)] 
lttng-enable-event.1.txt: document dynamic user space probes

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-{enable,disable}-rotation.1.txt: both types can be specified
Philippe Proulx [Fri, 9 Nov 2018 00:08:48 +0000 (19:08 -0500)] 
lttng-{enable,disable}-rotation.1.txt: both types can be specified

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-disable-rotation.1.txt: remove LIMITATIONS section
Philippe Proulx [Thu, 8 Nov 2018 21:37:27 +0000 (16:37 -0500)] 
lttng-disable-rotation.1.txt: remove LIMITATIONS section

`lttng disable-rotation` only unsets what has been previously set by
`lttng enable-rotation`. The real limitations are for
`lttng enable-rotation` and `lttng rotate`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-enable-rotation.1.txt: add that SIZE/PERIOD are approximations
Philippe Proulx [Thu, 8 Nov 2018 21:36:57 +0000 (16:36 -0500)] 
lttng-enable-rotation.1.txt: add that SIZE/PERIOD are approximations

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agolttng-rotate.1.txt: lttng-relayd(8) also has --output option
Philippe Proulx [Thu, 8 Nov 2018 21:36:29 +0000 (16:36 -0500)] 
lttng-rotate.1.txt: lttng-relayd(8) also has --output option

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: sessiond: ust_app_rotate_session error handling
Mathieu Desnoyers [Wed, 14 Nov 2018 20:34:49 +0000 (15:34 -0500)] 
Fix: sessiond: ust_app_rotate_session error handling

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: sessiond: snapshot: handle consumer return codes
Mathieu Desnoyers [Wed, 14 Nov 2018 21:46:05 +0000 (16:46 -0500)] 
Fix: sessiond: snapshot: handle consumer return codes

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: consumer: snapshot error return code
Mathieu Desnoyers [Wed, 14 Nov 2018 21:35:52 +0000 (16:35 -0500)] 
Fix: consumer: snapshot error return code

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: sessiond: consumer.c: rotation error handling
Mathieu Desnoyers [Wed, 14 Nov 2018 21:28:24 +0000 (16:28 -0500)] 
Fix: sessiond: consumer.c: rotation error handling

Return more specific error codes in the various error paths
of the session rotation commands.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: consumer: rotation error return codes
Mathieu Desnoyers [Wed, 14 Nov 2018 21:11:48 +0000 (16:11 -0500)] 
Fix: consumer: rotation error return codes

The return codes of rotation commands from consumerd are not
in sync with reality. Some are simply copy-pasted from old code.

Add new return codes to describe each error situation, and split the
"channel lookup" error from other errors so sessiond can distinguish
between an error caused by an exiting application (per-pid buffers)
(LTTCOMM_CONSUMERD_CHAN_NOT_FOUND) and an actual error while performing
the command.

Move the channel lookup into the rotation caller, because it is used by
two sub-functions: we don't want to lookup to succeed for the first and
then fail for the second.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: create_channel_per_pid: remove channel on error
Mathieu Desnoyers [Wed, 14 Nov 2018 22:49:21 +0000 (17:49 -0500)] 
Fix: create_channel_per_pid: remove channel on error

The notification system of the session daemon tracks the lifetime
of per-pid buffers (in effect, channel keys) using two hooks:
  - the successful completion of create_channel_per_pid()
  - the deletion of the channel from an application's registry

Multiple error paths in create_channel_per_pid() can leave a channel
in an app's registry without notifying the notification system of its
existence.

When the channel is finally cleaned-up, the channel deletion hook will
inform the notification system that the channel should be deleted,
resulting in an error as that channel was previously unknown.

This fix ensures we remove the application's channel from its registry
on error (with the notify parameter set to 'false'), thus ensuring
that the notification system never tracks the incomplete channel.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: channel errors on local stress-tests
Mathieu Desnoyers [Wed, 14 Nov 2018 22:46:26 +0000 (17:46 -0500)] 
Fix: channel errors on local stress-tests

On local stress-tests with per-pid buffers, error paths triggered
when trying to create a channel on an application already going away
end up tiggering the channel destruction with "-1" socket parameter.
This function attempts to send a notification of channel destruction
(erroneously) and attempts to sum counters into a channel object which
may not have been populated yet.

Therefore, don't perform those side-effects when invoked from error path
caused by channel creation error.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: channel_ust_create: remove channel on agent error
Mathieu Desnoyers [Wed, 14 Nov 2018 22:45:38 +0000 (17:45 -0500)] 
Fix: channel_ust_create: remove channel on agent error

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: cmd_rotate_session() returns unexpected error codes
Jérémie Galarneau [Wed, 14 Nov 2018 22:30:17 +0000 (17:30 -0500)] 
Fix: cmd_rotate_session() returns unexpected error codes

Certain paths in cmd_rotate_session() result in its return value not
obeying the convention for commands: return LTTNG_OK on success, and a
negative LTTNG_ERR_* code on error.

This patch separates the use of 'int ret' from a separate 'enum
lttng_error_code' value to ensure 'ret' values never bubble-up to the
caller.

Note that this patch assumes that ust_app_rotate_session() returns an
lttng_error_code, which is not the case right now (upcoming patch).

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: session rotation logging statement references snapshot
Jérémie Galarneau [Wed, 14 Nov 2018 22:07:48 +0000 (17:07 -0500)] 
Fix: session rotation logging statement references snapshot

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoClean-up: typo in logging message Totation -> Rotation
Jérémie Galarneau [Wed, 14 Nov 2018 22:02:04 +0000 (17:02 -0500)] 
Clean-up: typo in logging message Totation -> Rotation

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: rotation error may leave session in "ONGOING" state
Jérémie Galarneau [Wed, 14 Nov 2018 21:52:12 +0000 (16:52 -0500)] 
Fix: rotation error may leave session in "ONGOING" state

The errors that can occur during the launch of a rotation may
leave a session's rotation state in the "ONGOING" state.

This means that clients polling for the rotation's state (or using the
notification channel) will never see the rotation enter the ERROR
or COMPLETED states, resulting in a hang.

This change introduces session_reset_rotation_state() which
implements the logic needed to reset a session's rotation state
and populate the result of the last rotation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: session_list lock must be held to launch a rotation
Jérémie Galarneau [Wed, 14 Nov 2018 21:00:15 +0000 (16:00 -0500)] 
Fix: session_list lock must be held to launch a rotation

The timer.h functions are documented as needing the session_list
lock to be held. Since timers are setup during the launch of a
rotation, the session_list lock must be taken while a job is
executed by the rotation thread.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAdd an ASSERT_LOCKED(lock) macro
Jérémie Galarneau [Wed, 14 Nov 2018 20:43:49 +0000 (15:43 -0500)] 
Add an ASSERT_LOCKED(lock) macro

This macro validates that a given lock is taken by using
pthread_mutex_trylock().

The use of this macro is disouraged in hot paths for performance
reasons. It is meant to catch errors in "cold" code path (e.g. error
handling) where the additional safety it provides has no material
effect on performance.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoClean-up: move global sessiond symbols out of main.o
Jérémie Galarneau [Wed, 14 Nov 2018 20:32:24 +0000 (15:32 -0500)] 
Clean-up: move global sessiond symbols out of main.o

The global symbols defined in main.c prevent the use of numerous
functions from various other files. For instance, using timer.h
utils from session.o forces the redefinition of symbols that
are defined in main.o in the session unit tests.

This is a problem that has often occured in the past, more or less
forcing the unit tests to link against all sessiond objects. Moving
the global symbols to their own files (thread-utils.c,
process-utils.c, globals.c, and ready.c) does not solve this problem,
but it allows the unit tests to link against their resulting
objects and forego the stub-ing of symbols.

In the future, we could consider moving most the session daemon
to an internal library which could be re-used by the unit tests.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: split index and data file rotation logic
Jérémie Galarneau [Mon, 12 Nov 2018 21:52:26 +0000 (16:52 -0500)] 
Fix: split index and data file rotation logic

Issue
---

There is no guarantee that index and data positions (sequence numbers)
match at a given time as both are received on different sockets.

Currently, the relay determines whether or not it should rotate a
stream's data and index files based on the lowest sequence number
of both the data and index file.

When the data connection "lags" behind the control connection, index
entries received on the control connection that belong in the "next"
chunk are written to the "previous" chunk's index file.

While there is logic to ensure that trace data received after the
current rotation position is copied to the "previous" chunk when the
rotation is performed, the same is not true for the index file
rotation.

This is fine as it should not be needed. The consumerd <-> relayd
protocol ensures that a rotation command issued on a stream will
provide a rotation position that is either:
  - the stream's current position,
  - a position that will be reached in the future.

Then, the control connection will receive index entries that are
either <= to the rotation target sequence number.

Therefore, it is correct to check if an index file should be rotated
everytime an index entry is flushed and change the index output file
when the rotation position is reached.

Again, this is not true for the data connection as it would be
possible to receive a rotation command with a position that is
before the current data sequence number.

Solution
---

This change splits the logic to evaluate the moment at which a
rotation should be performed (changing the actual file to which data
is written) so that both index and data files are rotated
independently.

Hence, when an index is flushed, the relay will always evaluate
whether or not it should switch the index file to its new destination
(i.e. perform the rotation of the index).

The "data" reception logic remains mostly unchanged, except that
the trace sequence number is no longer used. Only the data stream's
position is considered to evaluate whether the data stream file
should be rotated.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: trace_archive_id is not sent in add_stream command
Jérémie Galarneau [Mon, 12 Nov 2018 22:48:53 +0000 (17:48 -0500)] 
Fix: trace_archive_id is not sent in add_stream command

The trace_archive_id argument of relayd_add_stream() is not
forwarded to the "2.11" implementation of the command. This means
that all streams on the relayd are created in the "chunk_id == 0"
EPOCH.

This may cause remote rotations to never complete when a stream
is created while a rotation is ongoing. In such a case, the
stream's chunk_id would be 0, but it would not have a rotation
sequence number. This would cause the rotation completion check
to always return that the rotation is "ongoing".

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: condition unsubscription error leaves session locked
Jérémie Galarneau [Mon, 12 Nov 2018 22:26:46 +0000 (17:26 -0500)] 
Fix: condition unsubscription error leaves session locked

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: rotation thread does not unregister from RCU on init error
Jérémie Galarneau [Mon, 12 Nov 2018 22:25:25 +0000 (17:25 -0500)] 
Fix: rotation thread does not unregister from RCU on init error

Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRemove unused nr_stream_rotate_pending from consumer channel
Jérémie Galarneau [Thu, 8 Nov 2018 17:09:04 +0000 (12:09 -0500)] 
Remove unused nr_stream_rotate_pending from consumer channel

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: session destruction blocks indefinitely if rotation is ongoing
Jérémie Galarneau [Tue, 30 Oct 2018 12:47:52 +0000 (13:47 +0100)] 
Fix: session destruction blocks indefinitely if rotation is ongoing

Issue
---

The destruction of an active session can hang indefinitely if it
occurs while a rotation is ongoing. This was observed when automatic
session rotations were scheduled on a time basis.

The destruction of the session causes it to be stopped. The 'stop'
command causes the session's timers to be stopped. These timers
include the rotation pending check timer.

Meanwhile, 'data pending' queries are performed against the session
until one of them returns that no data is pending.

The 'data pending' check returns that data is pending if a session
rotation is ongoing at the moment of the check.

Hence, stopping the rotation completion check timer causes the
session to remain in the 'session ongoing' state forever and
prevents the session destruction from completing.

Solution
---

The session's rotation schedule timer is correctly stopped when
a 'stop' is performed; we don't want new rotations to be issued
from this point. However, it is incorrect to stop the
'rotation pending check' timer at this stage if a rotation is
ongoing.

This commit leaves the 'rotation pending check' timer running,
allowing the rotation thread to update the session's rotation
state on completion of the rotation. The operations that were
performed as part of the stop command, namely renaming the
'current' chunk, are then performed from the context of the
rotation thread.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoClean-up: remove non-existent function's declaration
Jérémie Galarneau [Tue, 30 Oct 2018 13:15:27 +0000 (14:15 +0100)] 
Clean-up: remove non-existent function's declaration

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAlways choose large event header for UST channels
Mathieu Desnoyers [Wed, 17 Oct 2018 21:16:12 +0000 (17:16 -0400)] 
Always choose large event header for UST channels

UST can receive the session start command before all probe provider
library constructors have completed running, therefore finding less
events than eventually enabled within the process. Moreover, with
per-uid buffers, many processes end up registering events into shared
buffers. Therefore, the guess based on number of events from the first
process to use the buffer is incorrect.

Considering that we typically have applications with more than 30
events, we will modify the session daemon so it selects the "large"
header type independently of the number of events.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix relayd: stream index file created in the wrong directory
Jérémie Galarneau [Fri, 12 Oct 2018 23:49:42 +0000 (19:49 -0400)] 
Fix relayd: stream index file created in the wrong directory

This fix addresses an issue that can cause a stream's index
file to be created in the wrong trace archive chunk's
directory.

The data connection creates a stream's first index file.

This can happen _after_ a ROTATE_STREAM command. More specifically,
the data of the first packet of a stream can be received after a
ROTATE_STREAM command.

The ROTATE_STREAM command changes the streams path_name to point to
the "next" chunk. If a rotation is pending for a stream, as
indicated by "rotate_at_seq_num != -1ULL", it means that we are still
receiving data that belongs in the stream's former path.

In fact, we may have never received any data for this stream at this
point.

In this specific case, we must ensure that the index file is created
in the streams's former path, "prev_path_name", on reception of the
first packet's data on the data connection.

All other rotations beyond the first one are not affected by this
problem since the actual rotation operation creates the new chunk's
index file.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agorelayd: add payload logging to session rotation commands
Jérémie Galarneau [Fri, 12 Oct 2018 23:49:18 +0000 (19:49 -0400)] 
relayd: add payload logging to session rotation commands

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agorelayd: rename stream prev_seq to prev_data_seq
Jérémie Galarneau [Fri, 12 Oct 2018 22:34:06 +0000 (18:34 -0400)] 
relayd: rename stream prev_seq to prev_data_seq

Since there are now two "previous sequence numbers" that are
tracked, it makes sense to give them more descriptive names.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: take index seq number into account for rotation pending check
Jérémie Galarneau [Fri, 12 Oct 2018 22:31:51 +0000 (18:31 -0400)] 
Fix: take index seq number into account for rotation pending check

The rotation pending check is only performed on the sequence number of
the received data. However, it is expected that the index of the
stream has been written to disk by the time this check returns that
no rotation is pending.

This patch ensures that the minimum between the data and index
sequence numbers are used to perform this check.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: take index sequence number into account for data pending check
Jérémie Galarneau [Fri, 12 Oct 2018 22:22:35 +0000 (18:22 -0400)] 
Fix: take index sequence number into account for data pending check

The data pending checks are only performed on the sequence number of
the received data. However, it is expected that the index of the
stream (when applicable) has been written to disk by the time this
check returns that no data is pending.

This patch ensures that the minimum between the data and index
sequence numbers are used to perform this check.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agorelayd: keep track of prev_index_seq in relayd_stream
Jérémie Galarneau [Fri, 12 Oct 2018 22:05:10 +0000 (18:05 -0400)] 
relayd: keep track of prev_index_seq in relayd_stream

The rotation and data pending checks are only performed on the
sequence number of the received data. However, it is expected
that the index of the stream (when applicable) has been written
to disk when those checks say that their respective operations
have completed.

This patch only introduces a new 'prev_index_seq' position that
is updated when an index is flushed to disk.

A follow-up fix addresses the issue mentioned above.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: session conditions not evaluated at subscription/registration
Jérémie Galarneau [Fri, 5 Oct 2018 15:55:39 +0000 (11:55 -0400)] 
Fix: session conditions not evaluated at subscription/registration

Conditions bound to sessions (session rotation ongoing/completed)
are not automatically evaluated when a notification channel client
subscribes to them or when a client is subscribed _before_ the
trigger is created.

The problematic scenario is:

- Trigger is registered to notify on session rotation ongoing for
  session 'foo',
- A rotation is launched on session foo (but not completed)
- A client subscribes to 'session rotation ongoing' notifications for
  session 'foo'

In this scenario, the client would not be notified of the 'current'
state of the session.

Whether or not a client is notified of the 'current' state at the
time of subscription/registration is defined per-condition. In
the case of 'session rotation ongoing', it is desirable for clients
to be notified that the rotation is ongoing at the time of their
subscription/registration.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRemove unnecessary check of output parameter
Jérémie Galarneau [Fri, 5 Oct 2018 16:06:37 +0000 (12:06 -0400)] 
Remove unnecessary check of output parameter

It is not necessary to check for `_notification != NULL` as it
is done at the beginning of the function. Moreover, it confuses
Coverity which warns that `notification` will be leaked if the
output parameter is NULL.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAllow get_next_notification to return when interrupted
Jérémie Galarneau [Thu, 4 Oct 2018 21:50:27 +0000 (17:50 -0400)] 
Allow get_next_notification to return when interrupted

Applications (and scripts) which consume a given set of notifications
indefinitely may fail to exit if a SIGTERM handler is registered.

lttng_notification_channel_get_next_notification() blocks indefinitely
on recvmsg() until a new notification is available. The wrapper that
is used to do so automatically restarts the recvmsg() if it is
interrupted, thus not allowing clients a change to cleanly exit.

This change causes the notification channel to wait for a message to
be available using select() before starting the actual reception of
the data and return LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUTPED if a
signal occurs during the wait.

If data is available, it is assumed that the message is well-formed
and can promptly be received in its entirety. The goal of this change
is to give a monitoring application a chance to leave the
get_next_notification() function and check if it should exit.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: register rotation thread as RCU thread
Jérémie Galarneau [Thu, 4 Oct 2018 02:05:32 +0000 (22:05 -0400)] 
Fix: register rotation thread as RCU thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoDocs: comment typo fix (accomodates -> accommodates)
Jérémie Galarneau [Thu, 4 Oct 2018 00:50:35 +0000 (20:50 -0400)] 
Docs: comment typo fix (accomodates -> accommodates)

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: uninitialized variable may be used in local rotation check
Jérémie Galarneau [Wed, 3 Oct 2018 15:28:11 +0000 (11:28 -0400)] 
Fix: uninitialized variable may be used in local rotation check

** CID 1395985:  Uninitialized variables  (UNINIT)

'ret' may be left uninitialized if no consumer daemons are
iterated-upon to perform a local rotation pending check.

In practice this wont' happen as that would mean that the
ltt_session has no user space nor kernel session action, thus
no rotation would be launched.

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoRename sessiond-timer.[hc] to timer.[hc]
Jérémie Galarneau [Tue, 2 Oct 2018 18:06:17 +0000 (14:06 -0400)] 
Rename sessiond-timer.[hc] to timer.[hc]

There is no need to namespace the timer files as they are already
contained withing the lttng-sessiond directory.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: rotation may never complete in per-PID buffering mode
Jérémie Galarneau [Fri, 21 Sep 2018 22:16:05 +0000 (18:16 -0400)] 
Fix: rotation may never complete in per-PID buffering mode

Issue
-----

The current scheme to ensure that a rotation is completed
consists in the following, from the session daemon's perspective:

Iterate on all channels:
  - Ask the consumerd to sample the current "write" positions
  - Increment a count of channels being rotated

Wait for the consumer daemon to notify the session daemon every time
a channel's streams's "read" position have all reached the sampled
"write" position.

The idea behind this is making sure that all the data that was
produced before a rotation was triggered has been consumed (i.e.
been written to a local FS or streamed to the relay daemon) before
marking the rotation as completed.

However, this assumes that the session daemon is always aware of
all channels/streams that exist at the moment at which the rotation is
initiated. This is only true for the kernel domain.

In per-PID buffer mode, it is possible for an application, and its
buffers, to be torn down at any moment. Thus the following scenario
can happen:

- The application fills its buffers, causing the consumerd to fall
  behind
- The application exits, leaving its full buffers behind to be
  extracted by the consumer daemon
- The session daemon removes anything to do with the application from
  its internal structures, including its channels
- A rotation is initiated
- The positions of the application's buffers are never sampled as the
  session daemon does not see the channels when iterating on the
  session's channels

Multiple bad things can happen from there.

First, the rotation can be marked as "completed" while the consumerd
is still exctracting the dead application's buffers, causing readers
to consume an incomplete/corrupted trace.

Second, if the session is being streamed to a relay daemon, it is
possible for the 'rename' command to be issued before the contents
of the buffers has been written causing indexes to fail to be
flushed (as the relay daemon attempts to write them to a now-defunct
location).

Solution
--------

Eliminate the pipe between the session daemon and consumer daemon that
is used to signify that a rotation is completed as the information is
unreliable.

The rotation thread now periodically asks the consumer daemon to check
for channels that have a pending rotation for a given session_id or
that belong to the ongoing rotation archive id.

Hence, for every stream:
  - If the archive id during which it was created is '>' than that of
    the ongoing rotation, we don't need to consider it
  - If the current position is '>=' than the sampled rotation position,
    we can consider its rotation 'done'
  - If it belongs to the pending rotation archive id and doesn't have
    a "target" position, it was unknown to the session daemon and the
    application associated with it is dead. We must wait for the
    stream to be flushed and torn down before assuming that the
    rotation was completed.

Drawbacks
---------

This polling approach is somewhat inefficient and can cause rotations
to take longer to complete than necessary, especially in high-latency
networking conditions.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: perform local data pending before checking data pending with relayd
Jonathan Rajotte [Tue, 11 Sep 2018 00:09:15 +0000 (20:09 -0400)] 
Fix: perform local data pending before checking data pending with relayd

Performing the data pending check in two phases, local and network,
reduces the total number network operations needed.

Doing the local check first enable early return in cases where data is
still pending locally.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: missing header breaks the cygwin build
Jérémie Galarneau [Tue, 18 Sep 2018 01:18:33 +0000 (21:18 -0400)] 
Fix: missing header breaks the cygwin build

stddef.h must be included to use ssize_t.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: double put on error path
Jonathan Rajotte [Tue, 11 Sep 2018 00:09:11 +0000 (20:09 -0400)] 
Fix: double put on error path

Let relay_index_try_flush be responsible for the self-reference put on
error path.

Code flow of relay_index_try_flush is a bit tricky but the only error
flow (via relay_index_file_write) will always mark the index as flushed
and perform the self-reference put.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
This page took 0.047575 seconds and 4 git commands to generate.