Fix: filter attach vs event enable race

In order to correctly handle the use-case where events are enabled
_after_ trace is started, and _after_ applications are already being
traced, the event should be created in a "disabled" state, so that it
does not trace events until its filter is attached.

This fix needs to be done both in lttng-tools and lttng-ust. In order to
keep ABI compatibility between tools and ust within a stable release
cycle, we introduce a new "disabled" within struct lttng_ust_event
padding (previously zeroed). Newer LTTng-UST checks this flag, and
fallback on the old racy behavior (enabling the event on creation) if it
is unset.

Therefore, old session daemon works with newer lttng-ust of the same
stable release, and vice-versa. However, building lttng-tools requires
an upgraded lttng-ust, which contains the communication protocol with
the new "disabled" field.

This patch should be backported to stable-2.4, stable-2.5, stable-2.6
branches.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: missing rcu_read_lock in cmd_start_trace()

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: missing rcu_read_lock when calling trace_ust_find_agent()

Added a comment to note that this function is assumed to be
called with the rcu_read_lock held.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: missing rcu_read_lock in trace_ust_destroy_session()

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: agent events HT should be destroyed from the cleanup thread

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: HT must not be destroyed with a rcu_read_lock held

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: filter bytecode and string memory leak on error

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: Ambiguous agent event filter bytecode ownership

A shared ownership of the filter bytecode between UST events
and Agent event led to a leak in cmd_enable_event() which was
fixed previously. However, that fix introduced a bug which
passed NULL to the agent event creation function.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: removed useless key from relay_index

This field was never used except in debug messages (instead of using the
good value that is part of index_n).

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: empty indexes_ht before destroying it.

Fixes: #722

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: check userspace perf counter name when looking up contexts

create_ust_app_channel_context() looks for a context's existance
in a channel before adding it. However, it only checks for
context types. This is valid for all context types except for
LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER since multiple perf
thread counters may be enabled at the same time.

This fix ensures that the perf counter name is taken into
consideration when checking for a context's presence in a
channel.

Reported-by: Alexander Grigoriev <alexgri@tbricks.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Note find_ust_app_context must be called with RCU read lock

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: return EINVAL if agent registration fails

The errno value might be 0 thus not returning an error if so. It has
been seen with an unstable python agent code base which means it could
happen in the future if a third part decides to create an agent.

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