sessiond: kernel: log kernel tracer status on change
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 5 Dec 2023 19:51:25 +0000 (14:51 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Feb 2024 15:39:04 +0000 (10:39 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: I7a49493d05bf34868acd32f7f7fba301a41f69d5

src/bin/lttng-sessiond/kernel.cpp

index 1bb8f80b8853d4599926981d7149bceccea25fb8..1d2f8aeda10de3ba9057c658aa6f953129f89d64 100644 (file)
@@ -24,6 +24,7 @@
 #include <common/hashtable/utils.hpp>
 #include <common/kernel-ctl/kernel-ctl.hpp>
 #include <common/kernel-ctl/kernel-ioctl.hpp>
+#include <common/scope-exit.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
 #include <common/trace-chunk.hpp>
 #include <common/tracker.hpp>
 #include <unistd.h>
 
 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<enum lttng_kernel_tracer_status> 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<enum lttng_kernel_tracer_status> 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) {
This page took 0.027463 seconds and 4 git commands to generate.