Cleanup: rotation-thread: enforce conding standard following fix A fix introducing rotate_notification_channel_subscription_change_eventfd didn't follow the current coding standard so as to make it easier to backport to the stable branches. Clean-up the affected code to follow the current standard: - Replace the use of a raw eventfd to use the eventfd utility, - Subscribe and unsubscribe functions made use of global variables to communicate with the rotation thread: replace that with the rotation_thread class to centralize the interface, - Make the code using eventfd exception-safe (automatic memory management, use of various RAII utils), - Replacement of non-null pointers by references. Change-Id: I7e363e21b829fd0939a336aca2570fdbcc346967 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: add a CTF 2-generating trace class visitor The enumeration_type class is modified to guarantee that a mapping is present. Implicit (or auto) mappings provided by the tracer are converted to an explicit mapping. This results in a slightly more verbose TSDL output which can be fixed later. Change-Id: I4372ad528384c1b7d9321dd5183525e3bd60ded4 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Clean-up: sessiond: move ust_registry_session under lttng::sessiond::ust The ust_registry_session* class hierarchy is namespaced under lttng::sessiond::ust. The registry session classes are also moved to their own headers. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I3be5aa3239bbff9b385ab942f749748b4d6cb352
sessiond: transition from lttng-ust to tracer agnostic API Refactor the session daemon's user space tracer management to use the tracer-agnostic trace hierarchy description API. Since the API introduced under lttng::sessiond::trace is closer to idiomatic C++, some changes are needed to make use of it. The biggest changes make the ust_registry* structures inherit from the trace descriptions classes (trace_class, stream_class, event_class, clock_class). This effectively isolates the members of the `ust_registry` structures that describe their corresponding CTF class to a base class and leaves only the implementation guts in the `ust_registry` objects (moved under lttng::sessiond::ust). Since the generation of TSDL metadata directly used the lttng_ust_ctl API, it is replaced by a new implementation that is based around a trace class visitor that serializes the tracer agnostic trace description objects. The TSDL environment visitor is moved under the TSDL implementation of the trace class visitor. Some little changes are also made to the existing code to make it exception-safe, as needed. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I6562ef12e85afa91780337e8c6fdbb13568d9ece
sessiond: add tracer-agnostic trace hierarchy classes The session daemon receives the fields present in events from the instrumented applications in the form of an array of lttng_ust_ctl_field structures and uses them directly in a number of code paths. This makes it impossible to extend the structures which makes a number of features harder to implement than they should be. The session daemon also implements various CTF concepts (clock, trace, event, stream classes) as part of various structures defined under `ust_registry*`. This makes it hard to isolate which attributes are "internal" and which are visible to the external world through the traces. Tracer-agnostic trace hierachy classes are introduced under the lttng::sessiond::trace namespace. Those classes don't cover the full functionality of CTF: they expose what the tracers can currently express. The top-level elements of the trace hierarchy -- trace, event, stream, clock classes -- are visited using the trace_class_visitor interface. Seperate field and type visitor interfaces are used to make it easier to visit this subset of the trace hierarchy. This will be useful to implement the listing of event fields through liblttng-ctl, for example. In the short term, these classes will be used to implement the serialization of the layout descriptions of CTF 1.8 and 2. Change-Id: I6d99f0ec93082259bf64434c440a720ed9a49bf8 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: Move trace_ust_clock to a clock_attributes_sample class Move trace clock functions to a class that samples the clock's attributes on creation. This makes it easier to implement trace format agnostic serialization facilities in follow-up patches. Change-Id: Id75b2c6e00779710e02691da107b2e93bf33ff12 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
sessiond: Split ust_registry_session into per-type classes This is a preliminary refactoring step to implement support for the conditional generation of CTF 1.8/2.0 stream description layouts. Splitting the registry session will simplify the implementation of a serialization visitor by segregating per-type environment attributes. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ia95dd0c67f2ff41ce4f771ce776ff84a214098b9
Rename C++ header files to .hpp Rename all C++ header files (include/**/*-internal.h, src/**/*.h except argpar and msgpack, some headers in tests) to have the .hpp extension. Doing so highlights that we include some C++ header files in some test files still compiled as C. This is ok for now, as the files they include don't actually contain C++ code incompatible with C yet, but they could eventually. This is something we can fix later. Change-Id: I8bf326b6b2946a3e26704f3ef3ac5831bbe9bc26 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common: use single Makefile for parallel builds Use a single Makefile in 'src/common' as it contains multiple subdirectories with a small number of objects to compile. This allows faster parallel builds since parallelism in automake is applied per Makefile. There is anectodal evidence of a 25 seconds improvement to the build process on a 36 core machine. Change-Id: If2ce266050e345d58b00bf65b574ccf5168f28f1 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Remove ht-cleanup thread The hashtable cleanup thread was introduced to prevent deadlocks happening when the `cds_lfht_destroy()` function was called concurrently with userspace-rcu hashtable resizes. This was fixed in the userspace-rcu project in commit: commit d0ec0ed2fcb5d67a28587dcb778606e64f5b7b83 Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Date: Tue May 30 15:51:45 2017 -0400 Use workqueue in rculfhash That commit makes it so that the `cds_lfht_destroy()` function can safely be called within RCU read-side critical sections. This commit is included in the 0.10 release of urcu. The LTTng-Tools project now has a minimum version dependency on urcu 0.11. Because it's now safe to call `cds_lfht_destroy()` within RCU critical sections, the need for the hash table cleanup thread disappears. This commit replaces all uses of `ht_cleanup_push()` by `lttng_ht_destroy()` and remove all uses and mentions of the ht_cleanup thread. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I163a281b64a6b3eed62c58515932f71f3b52fea6
Introduce libcommon-lgpl for liblttng-ctl liblttng-ctl is a LGPLv2.1 library should should not use GPLv2 code. Introduce libcommon-lgpl as a static archive containing only LGPLv2.1 compatible code. This also removes the dependency from liblttng-ctl to liburcu. Include some source files in libcommon-lgpl.a which are indirectly needed by source files required in libcommon-lgpl.a: - endpoint.cpp, - lttng-elf.cpp, - lttng-elf.h. Include some source files in libcommon-lgpl.a which are only needed to link the lttng executable: - domain.cpp, - spawn-viewer.cpp, spawn-viewer.h. Introduce the new source file hashtable/seed.cpp to move the lttng_ht_seed symbol in a source file which does not require liburcu-cds, so it can be present in libcommon-lgpl. This allows building compile units which are needed in the lgpl common library which also contain functions which directly refer to lttng_ht_seed. Programs and libraries which use libhashtable.la are changed to use libcommon-gpl.la instead. libhashtable becomes internal to libcommon. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I27d2acb823a6d951692a5da88ce32bbe6bafb072
Rename libcommon.so to libcommon-gpl.so libcommon is a static library is currently used by both liblttng-ctl (LGPLv2.1) and all lttng-tools executables (GPLv2). Given that some code in libcommon depends on liburcu, this introduces an indirect dependency from liblttng-ctl to liburcu, which is unwanted. This first step renames libcommon.so to libcommon-gpl.so. Following steps will introduce a more lightweight libcommon-lgpl.so which only contains LGPLv2.1 code, and removes the dependency on liburcu. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ia8f37ea229f68550200cbb1528216a505bbbd45f
bin: compile lttng-sessiond as C++ Same as commit 48a400056134 ("bin: compile lttng as C++"), but change lttng-sessiond to be a C++ program. In addition to the categories of changes already mentioned in that commit's message, here are some interesting changes: - Add an include in trigger.h, an exported header, to fix: CXX notification-thread.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/notification-thread.cpp:9: /home/simark/src/lttng-tools/include/lttng/trigger/trigger.h:142:13: error: use of enum ‘lttng_error_code’ without previous declaration 142 | extern enum lttng_error_code lttng_register_trigger_with_name( | ^~~~~~~~~~~~~~~~ - We get this with clang: CXX lttng-conf.o In file included from /home/simark/src/lttng-tools/src/bin/lttng/conf.cpp:18: In file included from /home/simark/src/lttng-tools/src/common/common.h:14: In file included from /home/simark/src/lttng-tools/src/common/runas.h:17: In file included from /home/simark/src/lttng-tools/src/common/sessiond-comm/sessiond-comm.h:38: In file included from /home/simark/src/lttng-tools/src/common/unix.h:17: /home/simark/src/lttng-tools/src/common/payload-view.h:82:27: error: 'lttng_payload_view_from_payload' has C-linkage specified, but returns user-defined type 'struct lttng_payload_view' which is incompatible with C [-Werror,-Wreturn-type-c-linkage] struct lttng_payload_view lttng_payload_view_from_payload( ^ Turns out that because of the "const" field in lttng_payload_view, clang doesn't consider that type incompatible with C. I don't really want to remove the "const" for C code using that API, so conditionally remove it if we are compiling with clang in C++. - clang gives: CXX event.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/event.cpp:19: /home/simark/src/lttng-tools/src/common/bytecode/bytecode.h:50:1: error: struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] struct literal_string { ^ It looks like that type isn't even used? Remove it. - it's not possible to initialize some union members, for example with lttcomm_consumer_msg, in consumer.cpp. Initialize it in a separate statement. - It's not possible to use the transparent union trick when calling urcu function, for example in thread_application_registration, in register.cpp. We need to instantiate a cds_wfcq_head_ptr_t object, assign the appropriate field, and pass that object to the function. - the ALIGNED_CONST_PTR trick does not work in C++: CXX consumer.lo In file included from /home/simark/src/lttng-tools/src/common/error.h:19, from /home/simark/src/lttng-tools/src/common/common.h:12, from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:19: /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp: In function ‘int consumer_send_relayd_socket(consumer_socket*, lttcomm_relayd_sock*, consumer_output*, lttng_stream_type, uint64_t, const char*, const char*, const char*, int, const uint64_t*, time_t, bool)’: /home/simark/src/lttng-tools/src/common/macros.h:116:58: error: expected primary-expression before ‘]’ token 116 | #define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value })) | ^ /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:1192:48: note: in expansion of macro ‘ALIGNED_CONST_PTR’ 1192 | ret = consumer_send_fds(consumer_sock, ALIGNED_CONST_PTR(rsock->sock.fd), 1); | ^~~~~~~~~~~~~~~~~ Replace uses with copying the data in a local variable (which is properly aligned), and pass the address to that variable to the function. - In consumer.h, an array field in a structure is defined using the max macro. It can't be replaced with std::max, since std::max isn't constexpr in C++11. Define a max_constexpr function locally and use it. - g++ 7 doesn't support non-trivial designated initializers, leading to errors like: CXX globals.lo /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/globals.cpp:44:1: sorry, unimplemented: non-trivial designated initializers not supported }; ^ Change consumer_data to have a constructor instead. Change initializations of some structures, such as lttcomm_lttng_msg, to initialize the fields separate from the variable declaration. This requires making these variable non-const which is not ideal. But once everything is C++, these types could get a fancy constructor, and then they can be made const again. - When compiling without UST support the stub versions of functions ust_app_rotate_session & co, in ust-app.h, are used. Some of them have the return type "enum lttng_error_code", but return 0, an invalid value, causing: CXX main.o In file included from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/lttng-sessiond.h:22:0, from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/main.cpp:45: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h: In function ‘lttng_error_code ust_app_snapshot_record(ltt_ust_session*, const consumer_output*, int, uint64_t)’: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h:575:9: error: invalid conversion from ‘int’ to ‘lttng_error_code’ [-fpermissive] return 0; ^ Change these functions to return LTTNG_ERR_UNK. These functions are not supposed to be called if UST support is not included. But even if they were: all their callers check that the return value is not LTTNG_OK. The value 0 would be considered an error, so will be LTTNG_ERR_UNK. Change-Id: I2cdd34459a54b1943087b43843ef20b35b7bf7d8 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
build: Add the liblttng-sessiond-comm.la convenience library This allows correctly linking test_kernel_data with slibtool. Signed-off-by: orbea <orbea@riseup.net> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ib076854dc2a4f0234ad3fb04ea1c3c7c4d4a2b7e
Fix: Handle SIGBUS in sessiond and consumerd There is an issue with the security model of lib ring buffer (lttng-ust) vs SIGBUS handling by consumer daemon. We do not handle SIGBUS in the consumer daemon. An application using ftruncate on a ring buffer shm could cause the consumer to be killed with SIGBUS. Wire up SIGBUS handling in the session daemon as well given that it also uses liblttng-ust-ctl. This depends on "liblttng-ust-ctl: Implement SIGBUS handling" in lttng-ust, which extends the API of liblttng-ust-ctl, which requires the user application to define the TLS sigbus state with DEFINE_LTTNG_UST_SIGBUS_STATE(). It therefore needs to be introduced in locked-step between lttng-ust and lttng-tools. Considering that this change in liblttng-ust-ctl modifies the ABI, it is done with a major soname version bump of the library, so it is allowed to break the API. Depends-on: lttng-ust: I7ade988e3e68a87930fbcee3e14e59c3fb66e755 Fixes: #1284 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I76a91616bd35b21c5e891c8306c73ed5e8725ebb
Cleanup: Move `create_posix_shm()` to common/shm.c * This function will be used for trigger error accounting. * This function is renamed to `shm_create_anonymous()` and now takes one parameter for the owner of the shared memory area. Again this is code reuse. * Remove erroneous comment about the `name` parameter for the `shm_open()` function. It's the absence (and not its presence) of the '/' at the beginning of the name that makes the behaviour implementation defined. * Move the bin/lttng-sessiond/shm.c to common/shm.c so that all shm related functions are in one location. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I690b38801ffb4772e7c5069c4cccf470b0671f63
sessiond: Extract condition hashing functions Extract these functions so it can be used by other files. The lttng_condition hashing code is kept in this (rather than common/condition/condition.c) since it makes use of GPLv2 code (hashtable utils), which we don't want to link in liblttng-ctl. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Iaafe1402b2d198a00920d939502004038e78fff0