Move to kernel style SPDX license identifiers The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. See https://spdx.org/ids-how for details. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: I62e7038e191a061286abcef5550b58f5ee67149d Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Refactoring: introduce lttng_tracker_ids data structure This data structure is opaque to allow for back-end implementation change in the future. For now, only the following functions concerning lttng_tracker_ids are public: lttng_list_tracker_ids lttng_tracker_ids_get_count lttng_tracker_ids_get_at_index lttng_tracker_ids_destroy Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Change-Id: Iae1c10d0b578b402ab91378dd49f69f605b316b2 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Refactoring: use an opaque lttng_tracker_id type Move the tracker and tracker id related API to tracker.h and tracker-internal.h. The use of an opaque object mimics the new API for rotation and trigger etc. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Change-Id: I00b876c618d7dcb0dd940189e5250c3f3d64c7e0 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: cmd_rotate_session: introduce command argument Add a command type argument to cmd_rotate_session(). Change the internal session_close_trace_chunk() API to introduce the LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION command rather than rely on a NULL pointer, which facilitates passing of command argument across cmd_rotate_session. This introduces the LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE command, which is required for the clear feature. Its implementation will follow in a separate commit. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: Ic1d8cbab1f98b93f1f6d27a2c6624ac2780932e2 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: refactoring: introduce start/stop_kernel_session The clear feature will need to stop kernel session as well, so move this code to its own function rather than duplicate it. start_kernel_session already exists, but is static. Expose it so it can be used from a separate compile unit. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I68da1ee2e51105278265866590734c320a9789bd Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: sessiond cmd.h: include missing lttng-sessiond.h lttng-sessiond.h declares struct command_ctx which is used in cmd.h prototypes. It typically does not generate a compilation error because all compile units including cmd.h also include lttng-sessiond.h, but it is cleaner to include dependencies directly in cmd.h. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: If3106291309cd543a886b2aecda7d4f9d4b290b3 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: fix: possible unaligned access in packed structure A number of (potentially) unaligned pointers are used in client command handlers to pass command parameters to other internal functions. Fixing those forces a number of const-correctness changes where contexts are passed as arguments. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: perform a rotation to a null trace chunk on session destruction In order to guarantee the consumption of all data by the time a session's destruction completes, a rotation to a "null" trace chunk is performed as part of a session's destruction. This ensures that a session is only reclaimed when all of its streams (on both the consumers and the relay daemon) have been destroyed. The notion of a "quiet" rotation is introduced in order to re-use the session rotation infrastructure, but without the rotation being visible to external users through either the notification system or a rename of the trace output folder. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: wait for the completion of implicit session rotations A session that has been rotated within its lifetime will be rotated during its destruction to rename the last trace chunk. Currently, the liblttng-ctl library's session destruction function only waits for the data pending to indicate that all data has been consumed. This used to be sufficient, but it is now necessary to wait for the implicit session rotation to complete. The "wait" variant of the session destruction function will wait for any implicit session rotation to compete. A new lttng_destruction_handle class is introduced to allow a client to wait for the destruction of a session and obtain the location of the last trace archive produced by the implicit session rotation. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Generate session name and default output on sessiond's end The lttng client currently generates the default session name and output parameters. This has, over time, resulted in a number of problems. Notably, it is possible for scripts to create session too quickly using automatically-generated session names that would clash since the session's creation timestamp is the only variable part of a session "automatic" name. Hence, sessions created in the same second would clash and result in spurious session creation failures. More importantly, generating session names and outputs on the client end makes it impossible to reliably differentiate output locations that were automatically generated vs. those that were explicitly provided. This causes destinations to be "opaque" to the LTTng daemons as the subdir, session name, and session's creation timestamp are all "cooked" as part of the output destination path/subdir. Keeping these path components separate will make it easier to implement output path configurations that allow the grouping of session outputs by name, by host, etc. Since a session's creation time is used as part of its shm-path, an accessor to the session's creation time is added to the public API: lttng_session_get_creation_time(). This creation time attribute can be accessed when an lttng_session structure is created using the session listing API. Note that existing session creation functions are preserved to maintain the binary compatibility with existing liblttng-ctl users. The session creation functions are reimplemented on top of this newly-introduced API. The only function for which compatibility is dropped is the hidden _lttng_create_session_ext(). Overhaul of path separation --- Not generating paths on the client-end has uncovered a number of problems in the path handling of the session daemon, especially when a network output was used. A lot of code presumed that a network session would be created with a URL containing a sub-directory of the form "session_name-timestamp". While this is true for remote sessions created by the lttng client, a sub-directory is not required when liblttng-ctl is used directly. Hence, this commit ensures that session directories are split as base path, chunk directory, domain directory, application directory. A number of changes in this fix ensure that a session's base path contains everything up to the "session" path element _or_ up to the user-specified output directory. For example, creating a local session using default output settings, the session base output is: /home/user/lttng-traces/session-timestamp Creating a remote session using default output settings, the session base output path is: /hostname/session-timestamp/ Using custom output directories, whether locally or remotely, causes the session base path to be set to that custom output directory. For example, using a local output path of /tmp/my_path will result in a session base path of the form: /tmp/my_path Whereas creating a session with a network output of net://localhost/my_path will result in a session base path of the form: /hostname/my_path Another problematic element is the subdir of the kernel_session and ust_session consumer output which in different scenarios contained chunk names and arbitrary parts of the path hierarchy. The consumer output subdir has been renamed to 'domain_subdir' and now only ever contains: "kernel/", "ust/", or "". Finally, the chunk_path session attribute only contains the name of the current chunk directory being produced. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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>
Remove unused session current_archive_location accessor This function was replaced by lttng_rotation_handle_get_archive_location() which requires an lttng_rotation_handle to be used, making its use less error-prone. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
rotation-api: introduce rotation schedule descriptors The current rotation API is limited in that it imposes two types of automatic rotation. This change introduces rotation schedules, a more generic concept, that will eventually allow an arbitrary number of rotation schedules to be set on a session. Moreover, the API's design is now more aligned with the APIs that were recently added (i.e. use of opaque descriptors for commands that may require more parameters at some point). Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: check for removal of session's shm_path in destroy() When a session is created with an explicit shm_path, the consumer daemon will create its shared memory files at that location and will *not* unlink them. This is normal as the intention of that feature is to make it possible to retrieve the content of those files should a crash occur. To ensure the content of those files can be used, the sessiond daemon will replicate the content of the metadata cache in a metadata file. On clean-up, it is expected that the consumer daemon will unlink the shared memory files and that the session daemon will unlink the metadata file. Then, the session's directory in the shm path can be removed. Unfortunately, a flaw in the design of the sessiond's and consumerd's tear down of channels makes it impossible to determine when the sessiond _and_ the consumerd have both destroyed their representation of a channel. For one, the unlinking, close, and rmdir happen in deferred 'call_rcu' callbacks in both daemons. However, it is also impossible for the sessiond to know when the consumer daemon is done destroying its channel(s) since it occurs as a reaction to the closing of the channel's file descriptor. There is no resulting communication initiated from the consumerd to the sessiond to confirm that the operation is completed (and was successful). Until this is all fixed, the session daemon checks for the removal of the session's shm path which makes it possible to safely advertise a session as having been destroyed. Prior to this fix, it was not possible to reliably save a session making use of the --shm-path option, destroy it, and load it again. This is because the creation of the session would fail upon seeing the session's shm path already in existence. Note that none of the error paths in the check for the directory's existence return an error. This is normal as there isn't much that can be done. The session will be destroyed properly, except that we can't offer the guarantee that the same session can be re-created. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Size-based rotation The user can now configure the desired size of each chunk, every time a chunk is bigger than the specified size, a rotation is automatically started. The size of a chunk is measured by polling from the monitoring thread, so the accuracy depends on the monitoring sampling rate. Signed-off-by: Julien Desfossez <jdesfossez@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Rotate timer Allow the user to configure a timer to rotate a session periodically. The user can configure this setting with the API or the new enable-rotation/disable-rotation commands: lttng enable-rotation --timer 10s lttng disable-rotation --timer Signed-off-by: Julien Desfossez <jdesfossez@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Rotate command This is the core of the session rotation command in the session daemon, no client interface for now. For each channel in the session, we send a request to the related consumer to rotate the channel and add that channel key and domain in the channel_pending_rotate_ht HT. When the consumer has finished the rotation of all the streams in the channel, it sends back a notification. The rotation thread in the session daemon looks up the channel information in the HT and finds the corresponding session. When all channels of a session have finished, the rotation thread asks the consumer to rename the chunk folder to append the timestamp of the end of the rotation. On the first rotation, we have an extra step to change the session directory layout from "<session-name>/<domain>" to "<session-name>/<session-start-time>-<rotate-end-time>-1/<domain>". When the rotation starts, the new chunk folder is created immediately in: "<session-name>/<previous-rotate-start-time>-2/<domain>" so we won't have to move the domain folder(s) after the next rotate has finished, just rename the chunk folder. The "mkdir" and "rename" commands are all propagated to the relay if needed, only the rotate_pending check on the relay is not part of this patch. Signed-off-by: Julien Desfossez <jdesfossez@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>