From 07a5d4b54470787744777d4cf93eaaad8f4612cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 5 Dec 2023 14:51:25 -0500 Subject: [PATCH] sessiond: kernel: log kernel tracer status on change MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Log the value of newly-introduced the kernel tracer status when it is set. This will make it easier to confirm that the lttng_get_kernel_tracer_status API returns a given value given the logs of the session daemon. Signed-off-by: Jérémie Galarneau Change-Id: I7a49493d05bf34868acd32f7f7fba301a41f69d5 --- src/bin/lttng-sessiond/kernel.cpp | 60 +++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/bin/lttng-sessiond/kernel.cpp b/src/bin/lttng-sessiond/kernel.cpp index 1bb8f80b8..1d2f8aeda 100644 --- a/src/bin/lttng-sessiond/kernel.cpp +++ b/src/bin/lttng-sessiond/kernel.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,46 @@ #include namespace { +/* + * Key used to reference a channel between the sessiond and the consumer. This + * is only read and updated with the session_list lock held. + */ +uint64_t next_kernel_channel_key; + +const char *module_proc_lttng = "/proc/lttng"; + +int kernel_tracer_fd = -1; +nonstd::optional kernel_tracer_status = nonstd::nullopt; +int kernel_tracer_event_notifier_group_fd = -1; +int kernel_tracer_event_notifier_group_notification_fd = -1; +struct cds_lfht *kernel_token_to_event_notifier_rule_ht; + +const char *kernel_tracer_status_to_str(lttng_kernel_tracer_status status) +{ + switch (status) { + case LTTNG_KERNEL_TRACER_STATUS_INITIALIZED: + return "LTTNG_KERNEL_TRACER_STATUS_INITIALIZED"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING"; + case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE: + return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE"; + } + + abort(); +} + /* * On some architectures, calling convention details are embedded in the symbol * addresses. Uprobe requires a "clean" symbol offset (or at least, an address @@ -73,20 +114,6 @@ static inline uint64_t sanitize_uprobe_offset(uint64_t raw_offset) return raw_offset; } #endif - -/* - * Key used to reference a channel between the sessiond and the consumer. This - * is only read and updated with the session_list lock held. - */ -uint64_t next_kernel_channel_key; - -const char *module_proc_lttng = "/proc/lttng"; - -int kernel_tracer_fd = -1; -nonstd::optional kernel_tracer_status = nonstd::nullopt; -int kernel_tracer_event_notifier_group_fd = -1; -int kernel_tracer_event_notifier_group_notification_fd = -1; -struct cds_lfht *kernel_token_to_event_notifier_rule_ht; } /* namespace */ /* @@ -2000,6 +2027,11 @@ int init_kernel_tracer() int ret; bool is_root = !getuid(); + const auto log_status_on_exit = lttng::make_scope_exit([]() noexcept { + DBG_FMT("Kernel tracer status set to `{}`", + kernel_tracer_status_to_str(*kernel_tracer_status)); + }); + /* Modprobe lttng kernel modules */ ret = modprobe_lttng_control(); if (ret < 0) { -- 2.34.1