Fix: big relayd cleanup and refactor

Due to a number of race conditions between the live feature and the data
threads, we had to refactor the relayd which mostly splits the different
objects in their own files creating APIs for each of them.

That done, we are able to remove duplicate code, centralize code path
to help with cleanup and having a flow that makes more sense when
handling multiple objects.

This commits adds a lot of fixes with the live feature and cleanup code
path of a session since some objects are shared between threads like
ctf-trace and stream.

So yeah, this is quite a BIG commit and unfortunately this work was
essential in order to fix a lof of issues and have a way more
maintainable code base for the relayd.

Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: relayd connection object refactor

Mostly rename and move the connection data structure to its own C
file/header along with functions handling the object.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Namespace lttng-viewer-abi

This header is copied to all the viewers that implement the lttng-live
protocol, we need to make sure it is properly namespaced.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: force the client to create a viewer session before attaching

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: handle session hang up in get_new_streams

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: allow attach command to multiple sessions

The attach session command can now attach to multiple session using an
ID list.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: Move static functions up in the code

When we detect that the viewer is trying to get new streams for a
session closed and for which it already got all the streams, we can
delete and destroy the session, we know it won't be useful anymore.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: check for new streams in all attached sessions

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: use uint32_t for metadata_flag in viewer's ABI

This struct is meant to be sent over the network so members should be
of exact-width.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: merge issue with thread quit pipe

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: cleanup indef guards following the rename

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: add flag to create session command and fix tests

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: don't delete ctf trace while in snapshot mode

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: add missing ctf trace delete before destroy

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: free viewer session in connection_free()

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: don't sleep(1) on the consumer ready flag

This is way too long on especially when the first command that spawn the
consumer as to wait a full second on powerful system.

Bring this down to 0.1 sec sleep by using usleep().

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: remove unused create_viewer_session option

Since it is unused for now, don't bloat the ABI with that.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Doc: live protocol clarifications

Updates about the get_new_stream, the attach procedure, the create
viewer_session and the multiple attach.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Fix: read subbuffer mmap/splice signedness issue

Signed and unsigned values were compared thus making the code path where
ret = -1 being interpreted as ret > len == true thus not cleaning up the
relayd.

This patch simplifies the read subbuffer mmap operation since
lttng_write() now provides a guarantee that the return data is either
equal to the count passed or less which the later means the endpoint has
stop working.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: fd leak when closing metadata stream

Make sure to close the metadata poll pipe when the endpoint of the
stream dies out (ex: relayd stops unexpectedly). That was causing a fd
leak when we were destroying a metadata stream without using the close
metadata code path.

Signed-off-by: David Goulet <dgoulet@efficios.com>