2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include "condition-internal.hpp"
10 #include "consumer.hpp"
11 #include "event-notifier-error-accounting.hpp"
12 #include "kern-modules.hpp"
13 #include "kernel-consumer.hpp"
15 #include "lttng-sessiond.hpp"
16 #include "lttng-syscall.hpp"
17 #include "modprobe.hpp"
18 #include "notification-thread-commands.hpp"
19 #include "sessiond-config.hpp"
20 #include "tracker.hpp"
23 #include <common/common.hpp>
24 #include <common/hashtable/utils.hpp>
25 #include <common/kernel-ctl/kernel-ctl.hpp>
26 #include <common/kernel-ctl/kernel-ioctl.hpp>
27 #include <common/scope-exit.hpp>
28 #include <common/sessiond-comm/sessiond-comm.hpp>
29 #include <common/trace-chunk.hpp>
30 #include <common/tracker.hpp>
31 #include <common/urcu.hpp>
32 #include <common/utils.hpp>
34 #include <lttng/condition/event-rule-matches-internal.hpp>
35 #include <lttng/condition/event-rule-matches.h>
36 #include <lttng/event-rule/event-rule-internal.hpp>
37 #include <lttng/event-rule/event-rule.h>
38 #include <lttng/event-rule/kernel-uprobe-internal.hpp>
39 #include <lttng/event.h>
40 #include <lttng/lttng-error.h>
41 #include <lttng/tracker.h>
42 #include <lttng/userspace-probe-internal.hpp>
43 #include <lttng/userspace-probe.h>
50 #include <sys/types.h>
55 * Key used to reference a channel between the sessiond and the consumer. This
56 * is only read and updated with the session_list lock held.
58 uint64_t next_kernel_channel_key
;
60 const char *module_proc_lttng
= "/proc/lttng";
62 int kernel_tracer_fd
= -1;
63 nonstd::optional
<enum lttng_kernel_tracer_status
> kernel_tracer_status
= nonstd::nullopt
;
64 int kernel_tracer_event_notifier_group_fd
= -1;
65 int kernel_tracer_event_notifier_group_notification_fd
= -1;
66 struct cds_lfht
*kernel_token_to_event_notifier_rule_ht
;
68 const char *kernel_tracer_status_to_str(lttng_kernel_tracer_status status
)
71 case LTTNG_KERNEL_TRACER_STATUS_INITIALIZED
:
72 return "LTTNG_KERNEL_TRACER_STATUS_INITIALIZED";
73 case LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN
:
74 return "LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN";
75 case LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT
:
76 return "LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT";
77 case LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
:
78 return "LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER";
79 case LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG
:
80 return "LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG";
81 case LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH
:
82 return "LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH";
83 case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN
:
84 return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN";
85 case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING
:
86 return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING";
87 case LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE
:
88 return "LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE";
95 * On some architectures, calling convention details are embedded in the symbol
96 * addresses. Uprobe requires a "clean" symbol offset (or at least, an address
97 * where an instruction boundary would be legal) to add
98 * instrumentation. sanitize_uprobe_offset implements that sanitization logic on
99 * a per-architecture basis.
101 #if defined(__arm__) || defined(__aarch64__)
102 static inline uint64_t sanitize_uprobe_offset(uint64_t raw_offset
)
105 * The least significant bit is used when branching to switch to thumb
106 * ISA. However, it's an invalid address for us; mask the least
109 return raw_offset
&= ~0b1;
111 #else /* defined(__arm__) || defined(__aarch64__) */
112 static inline uint64_t sanitize_uprobe_offset(uint64_t raw_offset
)
120 * Add context on a kernel channel.
122 * Assumes the ownership of ctx.
124 int kernel_add_channel_context(struct ltt_kernel_channel
*chan
, struct ltt_kernel_context
*ctx
)
131 DBG("Adding context to channel %s", chan
->channel
->name
);
132 ret
= kernctl_add_context(chan
->fd
, &ctx
->ctx
);
136 /* Exists but not available for this kernel */
137 ret
= LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE
;
140 /* If EEXIST, we just ignore the error */
144 PERROR("add context ioctl");
145 ret
= LTTNG_ERR_KERN_CONTEXT_FAIL
;
152 cds_list_add_tail(&ctx
->list
, &chan
->ctx_list
);
157 trace_kernel_destroy_context(ctx
);
163 * Create a new kernel session, register it to the kernel tracer and add it to
164 * the session daemon session.
166 int kernel_create_session(const ltt_session::locked_ref
& session
)
169 struct ltt_kernel_session
*lks
;
171 /* Allocate data structure */
172 lks
= trace_kernel_create_session();
173 if (lks
== nullptr) {
178 /* Kernel tracer session creation */
179 ret
= kernctl_create_session(kernel_tracer_fd
);
181 PERROR("ioctl kernel create session");
186 /* Prevent fd duplication after execlp() */
187 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
189 PERROR("fcntl session fd");
192 lks
->id
= session
->id
;
193 lks
->consumer_fds_sent
= 0;
194 session
->kernel_session
= lks
;
196 DBG("Kernel session created (fd: %d)", lks
->fd
);
199 * This is necessary since the creation time is present in the session
200 * name when it is generated.
202 if (session
->has_auto_generated_name
) {
203 ret
= kernctl_session_set_name(lks
->fd
, DEFAULT_SESSION_NAME
);
205 ret
= kernctl_session_set_name(lks
->fd
, session
->name
);
208 WARN("Could not set kernel session name for session %" PRIu64
" name: %s",
213 ret
= kernctl_session_set_creation_time(lks
->fd
, session
->creation_time
);
215 WARN("Could not set kernel session creation time for session %" PRIu64
" name: %s",
224 trace_kernel_destroy_session(lks
);
225 trace_kernel_free_session(lks
);
231 * Create a kernel channel, register it to the kernel tracer and add it to the
234 int kernel_create_channel(struct ltt_kernel_session
*session
, struct lttng_channel
*chan
)
237 struct ltt_kernel_channel
*lkc
;
239 LTTNG_ASSERT(session
);
242 /* Allocate kernel channel */
243 lkc
= trace_kernel_create_channel(chan
);
244 if (lkc
== nullptr) {
248 DBG3("Kernel create channel %s with attr: %d, %" PRIu64
", %" PRIu64
", %u, %u, %d, %d",
250 lkc
->channel
->attr
.overwrite
,
251 lkc
->channel
->attr
.subbuf_size
,
252 lkc
->channel
->attr
.num_subbuf
,
253 lkc
->channel
->attr
.switch_timer_interval
,
254 lkc
->channel
->attr
.read_timer_interval
,
255 lkc
->channel
->attr
.live_timer_interval
,
256 lkc
->channel
->attr
.output
);
258 /* Kernel tracer channel creation */
259 ret
= kernctl_create_channel(session
->fd
, &lkc
->channel
->attr
);
261 PERROR("ioctl kernel create channel");
265 /* Setup the channel fd */
267 /* Prevent fd duplication after execlp() */
268 ret
= fcntl(lkc
->fd
, F_SETFD
, FD_CLOEXEC
);
270 PERROR("fcntl session fd");
273 /* Add channel to session */
274 cds_list_add(&lkc
->list
, &session
->channel_list
.head
);
275 session
->channel_count
++;
276 lkc
->session
= session
;
277 lkc
->key
= ++next_kernel_channel_key
;
279 DBG("Kernel channel %s created (fd: %d, key: %" PRIu64
")",
295 * Create a kernel event notifier group, register it to the kernel tracer and
296 * add it to the kernel session.
298 static int kernel_create_event_notifier_group(int *event_notifier_group_fd
)
303 LTTNG_ASSERT(event_notifier_group_fd
);
305 /* Kernel event notifier group creation. */
306 ret
= kernctl_create_event_notifier_group(kernel_tracer_fd
);
308 PERROR("Failed to create kernel event notifier group");
315 /* Prevent fd duplication after execlp(). */
316 ret
= fcntl(local_fd
, F_SETFD
, FD_CLOEXEC
);
318 PERROR("Failed to set FD_CLOEXEC on kernel event notifier group file descriptor: fd = %d",
323 DBG("Created kernel event notifier group: fd = %d", local_fd
);
324 *event_notifier_group_fd
= local_fd
;
329 ret
= close(local_fd
);
331 PERROR("Failed to close kernel event notifier group file descriptor: fd = %d",
340 * Compute the offset of the instrumentation byte in the binary based on the
341 * function probe location using the ELF lookup method.
343 * Returns 0 on success and set the offset out parameter to the offset of the
345 * Returns -1 on error
347 static int extract_userspace_probe_offset_function_elf(
348 const struct lttng_userspace_probe_location
*probe_location
,
355 const char *symbol
= nullptr;
356 const struct lttng_userspace_probe_location_lookup_method
*lookup
= nullptr;
357 enum lttng_userspace_probe_location_lookup_method_type lookup_method_type
;
359 LTTNG_ASSERT(lttng_userspace_probe_location_get_type(probe_location
) ==
360 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
362 lookup
= lttng_userspace_probe_location_get_lookup_method(probe_location
);
368 lookup_method_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup
);
370 LTTNG_ASSERT(lookup_method_type
==
371 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
);
373 symbol
= lttng_userspace_probe_location_function_get_function_name(probe_location
);
379 fd
= lttng_userspace_probe_location_function_get_binary_fd(probe_location
);
385 ret
= run_as_extract_elf_symbol_offset(fd
, symbol
, uid
, gid
, offset
);
387 DBG("userspace probe offset calculation failed for "
393 DBG("userspace probe elf offset for %s is 0x%jd", symbol
, (intmax_t) (*offset
));
399 * Compute the offsets of the instrumentation bytes in the binary based on the
400 * tracepoint probe location using the SDT lookup method. This function
401 * allocates the offsets buffer, the caller must free it.
403 * Returns 0 on success and set the offset out parameter to the offsets of the
405 * Returns -1 on error.
407 static int extract_userspace_probe_offset_tracepoint_sdt(
408 const struct lttng_userspace_probe_location
*probe_location
,
412 uint32_t *offsets_count
)
414 enum lttng_userspace_probe_location_lookup_method_type lookup_method_type
;
415 const struct lttng_userspace_probe_location_lookup_method
*lookup
= nullptr;
416 const char *probe_name
= nullptr, *provider_name
= nullptr;
420 LTTNG_ASSERT(lttng_userspace_probe_location_get_type(probe_location
) ==
421 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
423 lookup
= lttng_userspace_probe_location_get_lookup_method(probe_location
);
429 lookup_method_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup
);
431 LTTNG_ASSERT(lookup_method_type
==
432 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
);
434 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(probe_location
);
440 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(probe_location
);
441 if (!provider_name
) {
446 fd
= lttng_userspace_probe_location_tracepoint_get_binary_fd(probe_location
);
452 ret
= run_as_extract_sdt_probe_offsets(
453 fd
, provider_name
, probe_name
, uid
, gid
, offsets
, offsets_count
);
455 DBG("userspace probe offset calculation failed for sdt "
462 if (*offsets_count
== 0) {
463 DBG("no userspace probe offset found");
467 DBG("%u userspace probe SDT offsets found for %s:%s at:",
471 for (i
= 0; i
< *offsets_count
; i
++) {
472 DBG("\t0x%jd", (intmax_t) ((*offsets
)[i
]));
478 static int userspace_probe_add_callsite(const struct lttng_userspace_probe_location
*location
,
483 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
= nullptr;
484 enum lttng_userspace_probe_location_lookup_method_type type
;
487 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
488 if (!lookup_method
) {
493 type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
495 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
497 struct lttng_kernel_abi_event_callsite callsite
;
500 ret
= extract_userspace_probe_offset_function_elf(location
, uid
, gid
, &offset
);
502 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
506 callsite
.u
.uprobe
.offset
= sanitize_uprobe_offset(offset
);
507 ret
= kernctl_add_callsite(fd
, &callsite
);
509 WARN("Failed to add callsite to ELF userspace probe.");
510 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
515 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
518 uint64_t *offsets
= nullptr;
519 uint32_t offsets_count
;
520 struct lttng_kernel_abi_event_callsite callsite
;
523 * This call allocates the offsets buffer. This buffer must be freed
526 ret
= extract_userspace_probe_offset_tracepoint_sdt(
527 location
, uid
, gid
, &offsets
, &offsets_count
);
529 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
532 for (i
= 0; i
< offsets_count
; i
++) {
533 callsite
.u
.uprobe
.offset
= sanitize_uprobe_offset(offsets
[i
]);
534 ret
= kernctl_add_callsite(fd
, &callsite
);
536 WARN("Failed to add callsite to SDT userspace probe");
537 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
546 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
554 * Extract the offsets of the instrumentation point for the different lookup
557 static int userspace_probe_event_add_callsites(struct lttng_event
*ev
,
558 struct ltt_kernel_session
*session
,
562 const struct lttng_userspace_probe_location
*location
= nullptr;
565 LTTNG_ASSERT(ev
->type
== LTTNG_EVENT_USERSPACE_PROBE
);
567 location
= lttng_event_get_userspace_probe_location(ev
);
573 ret
= userspace_probe_add_callsite(location
, session
->uid
, session
->gid
, fd
);
575 WARN("Failed to add callsite to userspace probe event '%s'", ev
->name
);
583 * Extract the offsets of the instrumentation point for the different look-up
586 static int userspace_probe_event_rule_add_callsites(const struct lttng_event_rule
*rule
,
587 const struct lttng_credentials
*creds
,
591 enum lttng_event_rule_status status
;
592 enum lttng_event_rule_type event_rule_type
;
593 const struct lttng_userspace_probe_location
*location
= nullptr;
598 event_rule_type
= lttng_event_rule_get_type(rule
);
599 LTTNG_ASSERT(event_rule_type
== LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
);
601 status
= lttng_event_rule_kernel_uprobe_get_location(rule
, &location
);
602 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
|| !location
) {
607 ret
= userspace_probe_add_callsite(
608 location
, lttng_credentials_get_uid(creds
), lttng_credentials_get_gid(creds
), fd
);
610 WARN("Failed to add callsite to user space probe object: fd = %d", fd
);
618 * Create a kernel event, enable it to the kernel tracer and add it to the
619 * channel event list of the kernel session.
620 * We own filter_expression and filter.
622 int kernel_create_event(struct lttng_event
*ev
,
623 struct ltt_kernel_channel
*channel
,
624 char *filter_expression
,
625 struct lttng_bytecode
*filter
)
628 enum lttng_error_code ret
;
629 struct ltt_kernel_event
*event
;
632 LTTNG_ASSERT(channel
);
634 /* We pass ownership of filter_expression and filter */
635 ret
= trace_kernel_create_event(ev
, filter_expression
, filter
, &event
);
636 if (ret
!= LTTNG_OK
) {
640 fd
= kernctl_create_event(channel
->fd
, event
->event
);
644 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
647 WARN("Event type not implemented");
648 ret
= LTTNG_ERR_KERN_EVENT_ENOSYS
;
651 WARN("Event %s not found!", ev
->name
);
652 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
655 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
656 PERROR("create event ioctl");
661 event
->type
= ev
->type
;
663 /* Prevent fd duplication after execlp() */
664 err
= fcntl(event
->fd
, F_SETFD
, FD_CLOEXEC
);
666 PERROR("fcntl session fd");
670 err
= kernctl_filter(event
->fd
, filter
);
674 ret
= LTTNG_ERR_FILTER_NOMEM
;
677 ret
= LTTNG_ERR_FILTER_INVAL
;
684 if (ev
->type
== LTTNG_EVENT_USERSPACE_PROBE
) {
685 ret
= (lttng_error_code
) userspace_probe_event_add_callsites(
686 ev
, channel
->session
, event
->fd
);
688 goto add_callsite_error
;
692 err
= kernctl_enable(event
->fd
);
696 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
699 PERROR("enable kernel event");
700 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
706 /* Add event to event list */
707 cds_list_add(&event
->list
, &channel
->events_list
.head
);
708 channel
->event_count
++;
710 DBG("Event %s created (fd: %d)", ev
->name
, event
->fd
);
720 closeret
= close(event
->fd
);
722 PERROR("close event fd");
732 * Disable a kernel channel.
734 int kernel_disable_channel(struct ltt_kernel_channel
*chan
)
740 ret
= kernctl_disable(chan
->fd
);
742 PERROR("disable chan ioctl");
746 chan
->enabled
= false;
747 DBG("Kernel channel %s disabled (fd: %d, key: %" PRIu64
")",
759 * Enable a kernel channel.
761 int kernel_enable_channel(struct ltt_kernel_channel
*chan
)
767 ret
= kernctl_enable(chan
->fd
);
768 if (ret
< 0 && ret
!= -EEXIST
) {
769 PERROR("Enable kernel chan");
773 chan
->enabled
= true;
774 DBG("Kernel channel %s enabled (fd: %d, key: %" PRIu64
")",
786 * Enable a kernel event.
788 int kernel_enable_event(struct ltt_kernel_event
*event
)
794 ret
= kernctl_enable(event
->fd
);
798 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
801 PERROR("enable kernel event");
807 event
->enabled
= true;
808 DBG("Kernel event %s enabled (fd: %d)", event
->event
->name
, event
->fd
);
817 * Disable a kernel event.
819 int kernel_disable_event(struct ltt_kernel_event
*event
)
825 ret
= kernctl_disable(event
->fd
);
827 PERROR("Failed to disable kernel event: name = '%s', fd = %d",
833 event
->enabled
= false;
834 DBG("Kernel event %s disabled (fd: %d)", event
->event
->name
, event
->fd
);
843 * Disable a kernel event notifier.
845 static int kernel_disable_event_notifier_rule(struct ltt_kernel_event_notifier_rule
*event
)
851 lttng::urcu::read_lock_guard read_lock
;
852 cds_lfht_del(kernel_token_to_event_notifier_rule_ht
, &event
->ht_node
);
854 ret
= kernctl_disable(event
->fd
);
856 PERROR("Failed to disable kernel event notifier: fd = %d, token = %" PRIu64
,
862 event
->enabled
= false;
863 DBG("Disabled kernel event notifier: fd = %d, token = %" PRIu64
, event
->fd
, event
->token
);
869 static struct process_attr_tracker
*
870 _kernel_get_process_attr_tracker(struct ltt_kernel_session
*session
,
871 enum lttng_process_attr process_attr
)
873 switch (process_attr
) {
874 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
875 return session
->tracker_pid
;
876 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
877 return session
->tracker_vpid
;
878 case LTTNG_PROCESS_ATTR_USER_ID
:
879 return session
->tracker_uid
;
880 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
881 return session
->tracker_vuid
;
882 case LTTNG_PROCESS_ATTR_GROUP_ID
:
883 return session
->tracker_gid
;
884 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
885 return session
->tracker_vgid
;
891 const struct process_attr_tracker
*
892 kernel_get_process_attr_tracker(struct ltt_kernel_session
*session
,
893 enum lttng_process_attr process_attr
)
895 return (const struct process_attr_tracker
*) _kernel_get_process_attr_tracker(session
,
899 enum lttng_error_code
900 kernel_process_attr_tracker_set_tracking_policy(struct ltt_kernel_session
*session
,
901 enum lttng_process_attr process_attr
,
902 enum lttng_tracking_policy policy
)
905 enum lttng_error_code ret_code
= LTTNG_OK
;
906 struct process_attr_tracker
*tracker
=
907 _kernel_get_process_attr_tracker(session
, process_attr
);
908 enum lttng_tracking_policy previous_policy
;
911 ret_code
= LTTNG_ERR_INVALID
;
915 previous_policy
= process_attr_tracker_get_tracking_policy(tracker
);
916 ret
= process_attr_tracker_set_tracking_policy(tracker
, policy
);
918 ret_code
= LTTNG_ERR_UNK
;
922 if (previous_policy
== policy
) {
927 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
928 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
930 * Maintain a special case for the process ID process
931 * attribute tracker as it was the only supported
932 * attribute prior to 2.12.
934 ret
= kernctl_track_pid(session
->fd
, -1);
936 ret
= kernctl_track_id(session
->fd
, process_attr
, -1);
939 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
940 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
942 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
944 * Maintain a special case for the process ID process
945 * attribute tracker as it was the only supported
946 * attribute prior to 2.12.
948 ret
= kernctl_untrack_pid(session
->fd
, -1);
950 ret
= kernctl_untrack_id(session
->fd
, process_attr
, -1);
956 /* kern-ctl error handling */
962 ret_code
= LTTNG_ERR_INVALID
;
965 ret_code
= LTTNG_ERR_NOMEM
;
968 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
971 ret_code
= LTTNG_ERR_UNK
;
978 enum lttng_error_code
979 kernel_process_attr_tracker_inclusion_set_add_value(struct ltt_kernel_session
*session
,
980 enum lttng_process_attr process_attr
,
981 const struct process_attr_value
*value
)
983 int ret
, integral_value
;
984 enum lttng_error_code ret_code
;
985 struct process_attr_tracker
*tracker
;
986 enum process_attr_tracker_status status
;
989 * Convert process attribute tracker value to the integral
990 * representation required by the kern-ctl API.
992 switch (process_attr
) {
993 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
994 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
995 integral_value
= (int) value
->value
.pid
;
997 case LTTNG_PROCESS_ATTR_USER_ID
:
998 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
999 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
) {
1002 ret_code
= utils_user_id_from_name(value
->value
.user_name
, &uid
);
1003 if (ret_code
!= LTTNG_OK
) {
1006 integral_value
= (int) uid
;
1008 integral_value
= (int) value
->value
.uid
;
1011 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1012 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1013 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
) {
1016 ret_code
= utils_group_id_from_name(value
->value
.group_name
, &gid
);
1017 if (ret_code
!= LTTNG_OK
) {
1020 integral_value
= (int) gid
;
1022 integral_value
= (int) value
->value
.gid
;
1026 ret_code
= LTTNG_ERR_INVALID
;
1030 tracker
= _kernel_get_process_attr_tracker(session
, process_attr
);
1032 ret_code
= LTTNG_ERR_INVALID
;
1036 status
= process_attr_tracker_inclusion_set_add_value(tracker
, value
);
1037 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1039 case PROCESS_ATTR_TRACKER_STATUS_EXISTS
:
1040 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
1042 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY
:
1043 ret_code
= LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY
;
1045 case PROCESS_ATTR_TRACKER_STATUS_ERROR
:
1047 ret_code
= LTTNG_ERR_UNK
;
1053 DBG("Kernel track %s %d for session id %" PRIu64
,
1054 lttng_process_attr_to_string(process_attr
),
1057 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
1059 * Maintain a special case for the process ID process attribute
1060 * tracker as it was the only supported attribute prior to 2.12.
1062 ret
= kernctl_track_pid(session
->fd
, integral_value
);
1064 ret
= kernctl_track_id(session
->fd
, process_attr
, integral_value
);
1067 ret_code
= LTTNG_OK
;
1071 kernel_wait_quiescent();
1073 /* kern-ctl error handling */
1076 ret_code
= LTTNG_OK
;
1079 ret_code
= LTTNG_ERR_INVALID
;
1082 ret_code
= LTTNG_ERR_NOMEM
;
1085 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
1088 ret_code
= LTTNG_ERR_UNK
;
1092 /* Attempt to remove the value from the tracker. */
1093 status
= process_attr_tracker_inclusion_set_remove_value(tracker
, value
);
1094 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1095 ERR("Failed to roll-back the tracking of kernel %s process attribute %d while handling a kern-ctl error",
1096 lttng_process_attr_to_string(process_attr
),
1103 enum lttng_error_code
1104 kernel_process_attr_tracker_inclusion_set_remove_value(struct ltt_kernel_session
*session
,
1105 enum lttng_process_attr process_attr
,
1106 const struct process_attr_value
*value
)
1108 int ret
, integral_value
;
1109 enum lttng_error_code ret_code
;
1110 struct process_attr_tracker
*tracker
;
1111 enum process_attr_tracker_status status
;
1114 * Convert process attribute tracker value to the integral
1115 * representation required by the kern-ctl API.
1117 switch (process_attr
) {
1118 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1119 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1120 integral_value
= (int) value
->value
.pid
;
1122 case LTTNG_PROCESS_ATTR_USER_ID
:
1123 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1124 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
) {
1127 ret_code
= utils_user_id_from_name(value
->value
.user_name
, &uid
);
1128 if (ret_code
!= LTTNG_OK
) {
1131 integral_value
= (int) uid
;
1133 integral_value
= (int) value
->value
.uid
;
1136 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1137 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1138 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
) {
1141 ret_code
= utils_group_id_from_name(value
->value
.group_name
, &gid
);
1142 if (ret_code
!= LTTNG_OK
) {
1145 integral_value
= (int) gid
;
1147 integral_value
= (int) value
->value
.gid
;
1151 ret_code
= LTTNG_ERR_INVALID
;
1155 tracker
= _kernel_get_process_attr_tracker(session
, process_attr
);
1157 ret_code
= LTTNG_ERR_INVALID
;
1161 status
= process_attr_tracker_inclusion_set_remove_value(tracker
, value
);
1162 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1164 case PROCESS_ATTR_TRACKER_STATUS_MISSING
:
1165 ret_code
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
1167 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY
:
1168 ret_code
= LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY
;
1170 case PROCESS_ATTR_TRACKER_STATUS_ERROR
:
1172 ret_code
= LTTNG_ERR_UNK
;
1178 DBG("Kernel track %s %d for session id %" PRIu64
,
1179 lttng_process_attr_to_string(process_attr
),
1182 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
1184 * Maintain a special case for the process ID process attribute
1185 * tracker as it was the only supported attribute prior to 2.12.
1187 ret
= kernctl_untrack_pid(session
->fd
, integral_value
);
1189 ret
= kernctl_untrack_id(session
->fd
, process_attr
, integral_value
);
1192 ret_code
= LTTNG_OK
;
1195 kernel_wait_quiescent();
1197 /* kern-ctl error handling */
1200 ret_code
= LTTNG_OK
;
1203 ret_code
= LTTNG_ERR_INVALID
;
1206 ret_code
= LTTNG_ERR_NOMEM
;
1209 ret_code
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
1212 ret_code
= LTTNG_ERR_UNK
;
1216 /* Attempt to add the value to the tracker. */
1217 status
= process_attr_tracker_inclusion_set_add_value(tracker
, value
);
1218 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1219 ERR("Failed to roll-back the tracking of kernel %s process attribute %d while handling a kern-ctl error",
1220 lttng_process_attr_to_string(process_attr
),
1228 * Create kernel metadata, open from the kernel tracer and add it to the
1231 int kernel_open_metadata(struct ltt_kernel_session
*session
)
1234 struct ltt_kernel_metadata
*lkm
= nullptr;
1236 LTTNG_ASSERT(session
);
1238 /* Allocate kernel metadata */
1239 lkm
= trace_kernel_create_metadata();
1240 if (lkm
== nullptr) {
1244 /* Kernel tracer metadata creation */
1245 ret
= kernctl_open_metadata(session
->fd
, &lkm
->conf
->attr
);
1251 lkm
->key
= ++next_kernel_channel_key
;
1252 /* Prevent fd duplication after execlp() */
1253 ret
= fcntl(lkm
->fd
, F_SETFD
, FD_CLOEXEC
);
1255 PERROR("fcntl session fd");
1258 session
->metadata
= lkm
;
1260 DBG("Kernel metadata opened (fd: %d)", lkm
->fd
);
1265 trace_kernel_destroy_metadata(lkm
);
1271 * Start tracing session.
1273 int kernel_start_session(struct ltt_kernel_session
*session
)
1277 LTTNG_ASSERT(session
);
1279 ret
= kernctl_start_session(session
->fd
);
1281 PERROR("ioctl start session");
1285 DBG("Kernel session started");
1294 * Make a kernel wait to make sure in-flight probe have completed.
1296 void kernel_wait_quiescent()
1299 int fd
= kernel_tracer_fd
;
1301 DBG("Kernel quiescent wait on %d", fd
);
1303 ret
= kernctl_wait_quiescent(fd
);
1305 PERROR("wait quiescent ioctl");
1306 ERR("Kernel quiescent wait failed");
1311 * Force flush buffer of metadata.
1313 int kernel_metadata_flush_buffer(int fd
)
1317 DBG("Kernel flushing metadata buffer on fd %d", fd
);
1319 ret
= kernctl_buffer_flush(fd
);
1321 ERR("Fail to flush metadata buffers %d (ret: %d)", fd
, ret
);
1328 * Force flush buffer for channel.
1330 int kernel_flush_buffer(struct ltt_kernel_channel
*channel
)
1333 struct ltt_kernel_stream
*stream
;
1335 LTTNG_ASSERT(channel
);
1337 DBG("Flush buffer for channel %s", channel
->channel
->name
);
1339 cds_list_for_each_entry (stream
, &channel
->stream_list
.head
, list
) {
1340 DBG("Flushing channel stream %d", stream
->fd
);
1341 ret
= kernctl_buffer_flush(stream
->fd
);
1344 ERR("Fail to flush buffer for stream %d (ret: %d)", stream
->fd
, ret
);
1352 * Stop tracing session.
1354 int kernel_stop_session(struct ltt_kernel_session
*session
)
1358 LTTNG_ASSERT(session
);
1360 ret
= kernctl_stop_session(session
->fd
);
1365 DBG("Kernel session stopped");
1374 * Open stream of channel, register it to the kernel tracer and add it
1375 * to the stream list of the channel.
1377 * Note: given that the streams may appear in random order wrt CPU
1378 * number (e.g. cpu hotplug), the index value of the stream number in
1379 * the stream name is not necessarily linked to the CPU number.
1381 * Return the number of created stream. Else, a negative value.
1383 int kernel_open_channel_stream(struct ltt_kernel_channel
*channel
)
1386 struct ltt_kernel_stream
*lks
;
1388 LTTNG_ASSERT(channel
);
1390 while ((ret
= kernctl_create_stream(channel
->fd
)) >= 0) {
1391 lks
= trace_kernel_create_stream(channel
->channel
->name
, channel
->stream_count
);
1392 if (lks
== nullptr) {
1401 /* Prevent fd duplication after execlp() */
1402 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
1404 PERROR("fcntl session fd");
1407 lks
->tracefile_size
= channel
->channel
->attr
.tracefile_size
;
1408 lks
->tracefile_count
= channel
->channel
->attr
.tracefile_count
;
1410 /* Add stream to channel stream list */
1411 cds_list_add(&lks
->list
, &channel
->stream_list
.head
);
1412 channel
->stream_count
++;
1414 DBG("Kernel stream %s created (fd: %d, state: %d)", lks
->name
, lks
->fd
, lks
->state
);
1417 return channel
->stream_count
;
1424 * Open the metadata stream and set it to the kernel session.
1426 int kernel_open_metadata_stream(struct ltt_kernel_session
*session
)
1430 LTTNG_ASSERT(session
);
1432 ret
= kernctl_create_stream(session
->metadata
->fd
);
1434 PERROR("kernel create metadata stream");
1438 DBG("Kernel metadata stream created (fd: %d)", ret
);
1439 session
->metadata_stream_fd
= ret
;
1440 /* Prevent fd duplication after execlp() */
1441 ret
= fcntl(session
->metadata_stream_fd
, F_SETFD
, FD_CLOEXEC
);
1443 PERROR("fcntl session fd");
1453 * Get the event list from the kernel tracer and return the number of elements.
1455 ssize_t
kernel_list_events(struct lttng_event
**events
)
1459 size_t nbmem
, count
= 0;
1461 struct lttng_event
*elist
;
1463 LTTNG_ASSERT(events
);
1465 fd
= kernctl_tracepoint_list(kernel_tracer_fd
);
1467 PERROR("kernel tracepoint list");
1471 fp
= fdopen(fd
, "r");
1472 if (fp
== nullptr) {
1473 PERROR("kernel tracepoint list fdopen");
1478 * Init memory size counter
1479 * See kernel-ctl.h for explanation of this value
1481 nbmem
= KERNEL_EVENT_INIT_LIST_SIZE
;
1482 elist
= calloc
<lttng_event
>(nbmem
);
1483 if (elist
== nullptr) {
1484 PERROR("alloc list events");
1489 while (fscanf(fp
, "event { name = %m[^;]; };\n", &event
) == 1) {
1490 if (count
>= nbmem
) {
1491 struct lttng_event
*new_elist
;
1494 new_nbmem
= nbmem
<< 1;
1495 DBG("Reallocating event list from %zu to %zu bytes", nbmem
, new_nbmem
);
1496 new_elist
= (lttng_event
*) realloc(elist
,
1497 new_nbmem
* sizeof(struct lttng_event
));
1498 if (new_elist
== nullptr) {
1499 PERROR("realloc list events");
1505 /* Zero the new memory */
1506 memset(new_elist
+ nbmem
,
1508 (new_nbmem
- nbmem
) * sizeof(struct lttng_event
));
1512 strncpy(elist
[count
].name
, event
, LTTNG_SYMBOL_NAME_LEN
);
1513 elist
[count
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1514 elist
[count
].enabled
= -1;
1520 DBG("Kernel list events done (%zu events)", count
);
1522 ret
= fclose(fp
); /* closes both fp and fd */
1538 * Get kernel version and validate it.
1540 int kernel_validate_version(struct lttng_kernel_abi_tracer_version
*version
,
1541 struct lttng_kernel_abi_tracer_abi_version
*abi_version
)
1545 ret
= kernctl_tracer_version(kernel_tracer_fd
, version
);
1547 ERR("Failed to retrieve the lttng-modules version");
1551 /* Validate version */
1552 if (version
->major
!= VERSION_MAJOR
) {
1553 ERR("Kernel tracer major version (%d) is not compatible with lttng-tools major version (%d)",
1558 ret
= kernctl_tracer_abi_version(kernel_tracer_fd
, abi_version
);
1560 ERR("Failed to retrieve lttng-modules ABI version");
1563 if (abi_version
->major
!= LTTNG_KERNEL_ABI_MAJOR_VERSION
) {
1564 ERR("Kernel tracer ABI version (%d.%d) does not match the expected ABI major version (%d.*)",
1567 LTTNG_KERNEL_ABI_MAJOR_VERSION
);
1570 DBG2("Kernel tracer version validated (%d.%d, ABI %d.%d)",
1574 abi_version
->minor
);
1581 ERR("Kernel tracer version check failed; kernel tracing will not be available");
1586 * Kernel work-arounds called at the start of sessiond main().
1588 int init_kernel_workarounds()
1594 * boot_id needs to be read once before being used concurrently
1595 * to deal with a Linux kernel race. A fix is proposed for
1596 * upstream, but the work-around is needed for older kernels.
1598 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
1605 ret
= fread(buf
, 1, sizeof(buf
), fp
);
1607 /* Ignore error, we don't really care */
1619 * Teardown of a kernel session, keeping data required by destroy notifiers.
1621 void kernel_destroy_session(struct ltt_kernel_session
*ksess
)
1623 struct lttng_trace_chunk
*trace_chunk
;
1625 if (ksess
== nullptr) {
1626 DBG3("No kernel session when tearing down session");
1630 DBG("Tearing down kernel session");
1631 trace_chunk
= ksess
->current_trace_chunk
;
1634 * Destroy channels on the consumer if at least one FD has been sent and we
1635 * are in no output mode because the streams are in *no* monitor mode so we
1636 * have to send a command to clean them up or else they leaked.
1638 if (!ksess
->output_traces
&& ksess
->consumer_fds_sent
) {
1640 struct consumer_socket
*socket
;
1641 struct lttng_ht_iter iter
;
1643 /* For each consumer socket. */
1644 lttng::urcu::read_lock_guard read_lock
;
1646 cds_lfht_for_each_entry (
1647 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1648 struct ltt_kernel_channel
*chan
;
1650 /* For each channel, ask the consumer to destroy it. */
1651 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1652 ret
= kernel_consumer_destroy_channel(socket
, chan
);
1654 /* Consumer is probably dead. Use next socket. */
1661 /* Close any relayd session */
1662 consumer_output_send_destroy_relayd(ksess
->consumer
);
1664 trace_kernel_destroy_session(ksess
);
1665 lttng_trace_chunk_put(trace_chunk
);
1668 /* Teardown of data required by destroy notifiers. */
1669 void kernel_free_session(struct ltt_kernel_session
*ksess
)
1671 if (ksess
== nullptr) {
1674 trace_kernel_free_session(ksess
);
1678 * Destroy a kernel channel object. It does not do anything on the tracer side.
1680 void kernel_destroy_channel(struct ltt_kernel_channel
*kchan
)
1682 struct ltt_kernel_session
*ksess
= nullptr;
1684 LTTNG_ASSERT(kchan
);
1685 LTTNG_ASSERT(kchan
->channel
);
1687 DBG3("Kernel destroy channel %s", kchan
->channel
->name
);
1689 /* Update channel count of associated session. */
1690 if (kchan
->session
) {
1691 /* Keep pointer reference so we can update it after the destroy. */
1692 ksess
= kchan
->session
;
1695 trace_kernel_destroy_channel(kchan
);
1698 * At this point the kernel channel is not visible anymore. This is safe
1699 * since in order to work on a visible kernel session, the tracing session
1700 * lock (ltt_session.lock) MUST be acquired.
1703 ksess
->channel_count
--;
1708 * Take a snapshot for a given kernel session.
1710 * Return LTTNG_OK on success or else return a LTTNG_ERR code.
1712 enum lttng_error_code
kernel_snapshot_record(struct ltt_kernel_session
*ksess
,
1713 const struct consumer_output
*output
,
1714 uint64_t nb_packets_per_stream
)
1716 int err
, ret
, saved_metadata_fd
;
1717 enum lttng_error_code status
= LTTNG_OK
;
1718 struct consumer_socket
*socket
;
1719 struct lttng_ht_iter iter
;
1720 struct ltt_kernel_metadata
*saved_metadata
;
1721 char *trace_path
= nullptr;
1722 size_t consumer_path_offset
= 0;
1724 LTTNG_ASSERT(ksess
);
1725 LTTNG_ASSERT(ksess
->consumer
);
1726 LTTNG_ASSERT(output
);
1728 DBG("Kernel snapshot record started");
1730 /* Save current metadata since the following calls will change it. */
1731 saved_metadata
= ksess
->metadata
;
1732 saved_metadata_fd
= ksess
->metadata_stream_fd
;
1734 ret
= kernel_open_metadata(ksess
);
1736 status
= LTTNG_ERR_KERN_META_FAIL
;
1740 ret
= kernel_open_metadata_stream(ksess
);
1742 status
= LTTNG_ERR_KERN_META_FAIL
;
1743 goto error_open_stream
;
1746 trace_path
= setup_channel_trace_path(ksess
->consumer
, "", &consumer_path_offset
);
1748 status
= LTTNG_ERR_INVALID
;
1753 /* Send metadata to consumer and snapshot everything. */
1754 lttng::urcu::read_lock_guard read_lock
;
1756 cds_lfht_for_each_entry (output
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1757 struct ltt_kernel_channel
*chan
;
1759 pthread_mutex_lock(socket
->lock
);
1760 /* This stream must not be monitored by the consumer. */
1761 ret
= kernel_consumer_add_metadata(socket
, ksess
, 0);
1762 pthread_mutex_unlock(socket
->lock
);
1764 status
= LTTNG_ERR_KERN_META_FAIL
;
1765 goto error_consumer
;
1768 /* For each channel, ask the consumer to snapshot it. */
1769 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1771 consumer_snapshot_channel(socket
,
1775 &trace_path
[consumer_path_offset
],
1776 nb_packets_per_stream
);
1777 if (status
!= LTTNG_OK
) {
1778 (void) kernel_consumer_destroy_metadata(socket
,
1780 goto error_consumer
;
1784 /* Snapshot metadata, */
1785 status
= consumer_snapshot_channel(socket
,
1786 ksess
->metadata
->key
,
1789 &trace_path
[consumer_path_offset
],
1791 if (status
!= LTTNG_OK
) {
1792 goto error_consumer
;
1796 * The metadata snapshot is done, ask the consumer to destroy it since
1797 * it's not monitored on the consumer side.
1799 (void) kernel_consumer_destroy_metadata(socket
, ksess
->metadata
);
1804 /* Close newly opened metadata stream. It's now on the consumer side. */
1805 err
= close(ksess
->metadata_stream_fd
);
1807 PERROR("close snapshot kernel");
1811 trace_kernel_destroy_metadata(ksess
->metadata
);
1813 /* Restore metadata state.*/
1814 ksess
->metadata
= saved_metadata
;
1815 ksess
->metadata_stream_fd
= saved_metadata_fd
;
1821 * Get the syscall mask array from the kernel tracer.
1823 * Return 0 on success else a negative value. In both case, syscall_mask should
1826 int kernel_syscall_mask(int chan_fd
, char **syscall_mask
, uint32_t *nr_bits
)
1828 LTTNG_ASSERT(syscall_mask
);
1829 LTTNG_ASSERT(nr_bits
);
1831 return kernctl_syscall_mask(chan_fd
, syscall_mask
, nr_bits
);
1834 static int kernel_tracer_abi_greater_or_equal(unsigned int major
, unsigned int minor
)
1837 struct lttng_kernel_abi_tracer_abi_version abi
;
1839 ret
= kernctl_tracer_abi_version(kernel_tracer_fd
, &abi
);
1841 ERR("Failed to retrieve lttng-modules ABI version");
1845 ret
= abi
.major
> major
|| (abi
.major
== major
&& abi
.minor
>= minor
);
1851 * Check for the support of the RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS via abi
1854 * Return 1 on success, 0 when feature is not supported, negative value in case
1857 int kernel_supports_ring_buffer_snapshot_sample_positions()
1860 * RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in 2.3
1862 return kernel_tracer_abi_greater_or_equal(2, 3);
1866 * Check for the support of the packet sequence number via abi version number.
1868 * Return 1 on success, 0 when feature is not supported, negative value in case
1871 int kernel_supports_ring_buffer_packet_sequence_number()
1874 * Packet sequence number was introduced in LTTng 2.8,
1875 * lttng-modules ABI 2.1.
1877 return kernel_tracer_abi_greater_or_equal(2, 1);
1881 * Check for the support of event notifiers via abi version number.
1883 * Return 1 on success, 0 when feature is not supported, negative value in case
1886 int kernel_supports_event_notifiers()
1889 * Event notifiers were introduced in LTTng 2.13, lttng-modules ABI 2.6.
1891 return kernel_tracer_abi_greater_or_equal(2, 6);
1895 * Rotate a kernel session.
1897 * Return LTTNG_OK on success or else an LTTng error code.
1899 enum lttng_error_code
kernel_rotate_session(const ltt_session::locked_ref
& session
)
1902 enum lttng_error_code status
= LTTNG_OK
;
1903 struct consumer_socket
*socket
;
1904 struct lttng_ht_iter iter
;
1905 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
1907 LTTNG_ASSERT(ksess
);
1908 LTTNG_ASSERT(ksess
->consumer
);
1910 DBG("Rotate kernel session %s started (session %" PRIu64
")", session
->name
, session
->id
);
1914 * Note that this loop will end after one iteration given that there is
1915 * only one kernel consumer.
1917 lttng::urcu::read_lock_guard read_lock
;
1919 cds_lfht_for_each_entry (
1920 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1921 struct ltt_kernel_channel
*chan
;
1923 /* For each channel, ask the consumer to rotate it. */
1924 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1925 DBG("Rotate kernel channel %" PRIu64
", session %s",
1928 ret
= consumer_rotate_channel(socket
,
1931 /* is_metadata_channel */ false);
1933 status
= LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1939 * Rotate the metadata channel.
1941 ret
= consumer_rotate_channel(socket
,
1942 ksess
->metadata
->key
,
1944 /* is_metadata_channel */ true);
1946 status
= LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1956 enum lttng_error_code
kernel_create_channel_subdirectories(const struct ltt_kernel_session
*ksess
)
1958 enum lttng_error_code ret
= LTTNG_OK
;
1959 enum lttng_trace_chunk_status chunk_status
;
1961 lttng::urcu::read_lock_guard read_lock
;
1962 LTTNG_ASSERT(ksess
->current_trace_chunk
);
1965 * Create the index subdirectory which will take care
1966 * of implicitly creating the channel's path.
1968 chunk_status
= lttng_trace_chunk_create_subdirectory(
1969 ksess
->current_trace_chunk
, DEFAULT_KERNEL_TRACE_DIR
"/" DEFAULT_INDEX_DIR
);
1970 if (chunk_status
!= LTTNG_TRACE_CHUNK_STATUS_OK
) {
1971 ret
= LTTNG_ERR_CREATE_DIR_FAIL
;
1979 * Get current kernel tracer status
1981 enum lttng_kernel_tracer_status
get_kernel_tracer_status()
1983 if (!kernel_tracer_status
) {
1984 return LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN
;
1987 return *kernel_tracer_status
;
1991 * Sets the kernel tracer status based on the positive errno code
1993 void set_kernel_tracer_status_from_modules_ret(int code
)
1998 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
1999 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING
);
2007 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2008 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE
);
2013 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2014 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN
);
2021 * Setup necessary data for kernel tracer action.
2023 int init_kernel_tracer()
2026 bool is_root
= !getuid();
2028 const auto log_status_on_exit
= lttng::make_scope_exit([]() noexcept
{
2029 DBG_FMT("Kernel tracer status set to `{}`",
2030 kernel_tracer_status_to_str(*kernel_tracer_status
));
2033 /* Modprobe lttng kernel modules */
2034 ret
= modprobe_lttng_control();
2036 set_kernel_tracer_status_from_modules_ret(-ret
);
2040 /* Open debugfs lttng */
2041 kernel_tracer_fd
= open(module_proc_lttng
, O_RDWR
);
2042 if (kernel_tracer_fd
< 0) {
2043 DBG("Failed to open %s", module_proc_lttng
);
2044 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2045 LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG
);
2049 /* Validate kernel version */
2050 ret
= kernel_validate_version(&the_kernel_tracer_version
, &the_kernel_tracer_abi_version
);
2052 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2053 LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH
);
2057 ret
= modprobe_lttng_data();
2059 set_kernel_tracer_status_from_modules_ret(-ret
);
2063 ret
= kernel_supports_ring_buffer_snapshot_sample_positions();
2068 WARN("Kernel tracer does not support buffer monitoring. "
2069 "The monitoring timer of channels in the kernel domain "
2070 "will be set to 0 (disabled).");
2073 ret
= kernel_supports_event_notifiers();
2075 ERR("Failed to check for kernel tracer event notifier support");
2076 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2077 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2080 ret
= kernel_create_event_notifier_group(&kernel_tracer_event_notifier_group_fd
);
2082 /* This is not fatal. */
2083 WARN("Failed to create kernel event notifier group");
2084 kernel_tracer_event_notifier_group_fd
= -1;
2086 enum event_notifier_error_accounting_status error_accounting_status
;
2087 enum lttng_error_code error_code_ret
=
2088 kernel_create_event_notifier_group_notification_fd(
2089 &kernel_tracer_event_notifier_group_notification_fd
);
2091 if (error_code_ret
!= LTTNG_OK
) {
2092 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2093 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2097 error_accounting_status
= event_notifier_error_accounting_register_kernel(
2098 kernel_tracer_event_notifier_group_fd
);
2099 if (error_accounting_status
!= EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK
) {
2100 ERR("Failed to initialize event notifier error accounting for kernel tracer");
2101 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING
;
2102 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2103 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2107 kernel_token_to_event_notifier_rule_ht
= cds_lfht_new(
2108 DEFAULT_HT_SIZE
, 1, 0, CDS_LFHT_AUTO_RESIZE
| CDS_LFHT_ACCOUNTING
, nullptr);
2109 if (!kernel_token_to_event_notifier_rule_ht
) {
2110 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2111 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2112 goto error_token_ht
;
2116 DBG("Kernel tracer initialized: kernel tracer fd = %d, event notifier group fd = %d, event notifier group notification fd = %d",
2118 kernel_tracer_event_notifier_group_fd
,
2119 kernel_tracer_event_notifier_group_notification_fd
);
2121 ret
= syscall_init_table(kernel_tracer_fd
);
2123 ERR("Unable to populate syscall table. Syscall tracing won't "
2124 "work for this session daemon.");
2127 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2128 LTTNG_KERNEL_TRACER_STATUS_INITIALIZED
);
2132 modprobe_remove_lttng_control();
2133 ret
= close(kernel_tracer_fd
);
2135 PERROR("Failed to close kernel tracer file descriptor: fd = %d", kernel_tracer_fd
);
2138 kernel_tracer_fd
= -1;
2139 return LTTNG_ERR_KERN_VERSION
;
2142 ret
= close(kernel_tracer_event_notifier_group_notification_fd
);
2144 PERROR("Failed to close kernel tracer event notifier group notification file descriptor: fd = %d",
2145 kernel_tracer_event_notifier_group_notification_fd
);
2148 kernel_tracer_event_notifier_group_notification_fd
= -1;
2151 ret
= close(kernel_tracer_event_notifier_group_fd
);
2153 PERROR("Failed to close kernel tracer event notifier group file descriptor: fd = %d",
2154 kernel_tracer_event_notifier_group_fd
);
2157 kernel_tracer_event_notifier_group_fd
= -1;
2159 ret
= close(kernel_tracer_fd
);
2161 PERROR("Failed to close kernel tracer file descriptor: fd = %d", kernel_tracer_fd
);
2164 kernel_tracer_fd
= -1;
2167 modprobe_remove_lttng_control();
2170 WARN("No kernel tracer available");
2171 kernel_tracer_fd
= -1;
2173 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2174 LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT
);
2175 return LTTNG_ERR_NEED_ROOT_SESSIOND
;
2177 return LTTNG_ERR_KERN_NA
;
2181 void cleanup_kernel_tracer()
2183 DBG2("Closing kernel event notifier group notification file descriptor");
2184 if (kernel_tracer_event_notifier_group_notification_fd
>= 0) {
2185 int ret
= notification_thread_command_remove_tracer_event_source(
2186 the_notification_thread_handle
,
2187 kernel_tracer_event_notifier_group_notification_fd
);
2188 if (ret
!= LTTNG_OK
) {
2189 ERR("Failed to remove kernel event notifier notification from notification thread");
2192 ret
= close(kernel_tracer_event_notifier_group_notification_fd
);
2194 PERROR("Failed to close kernel event notifier group notification file descriptor: fd = %d",
2195 kernel_tracer_event_notifier_group_notification_fd
);
2198 kernel_tracer_event_notifier_group_notification_fd
= -1;
2201 if (kernel_token_to_event_notifier_rule_ht
) {
2202 const int ret
= cds_lfht_destroy(kernel_token_to_event_notifier_rule_ht
, nullptr);
2203 LTTNG_ASSERT(ret
== 0);
2206 DBG2("Closing kernel event notifier group file descriptor");
2207 if (kernel_tracer_event_notifier_group_fd
>= 0) {
2208 const int ret
= close(kernel_tracer_event_notifier_group_fd
);
2211 PERROR("Failed to close kernel event notifier group file descriptor: fd = %d",
2212 kernel_tracer_event_notifier_group_fd
);
2215 kernel_tracer_event_notifier_group_fd
= -1;
2218 DBG2("Closing kernel fd");
2219 if (kernel_tracer_fd
>= 0) {
2220 const int ret
= close(kernel_tracer_fd
);
2223 PERROR("Failed to close kernel tracer file descriptor: fd = %d",
2227 kernel_tracer_fd
= -1;
2230 kernel_tracer_status
= nonstd::nullopt
;
2231 free(syscall_table
);
2234 bool kernel_tracer_is_initialized()
2236 return kernel_tracer_fd
>= 0;
2240 * Clear a kernel session.
2242 * Return LTTNG_OK on success or else an LTTng error code.
2244 enum lttng_error_code
kernel_clear_session(const ltt_session::locked_ref
& session
)
2247 enum lttng_error_code status
= LTTNG_OK
;
2248 struct consumer_socket
*socket
;
2249 struct lttng_ht_iter iter
;
2250 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2252 LTTNG_ASSERT(ksess
);
2253 LTTNG_ASSERT(ksess
->consumer
);
2255 DBG("Clear kernel session %s (session %" PRIu64
")", session
->name
, session
->id
);
2257 if (ksess
->active
) {
2258 ERR("Expecting inactive session %s (%" PRIu64
")", session
->name
, session
->id
);
2259 status
= LTTNG_ERR_FATAL
;
2265 * Note that this loop will end after one iteration given that there is
2266 * only one kernel consumer.
2268 lttng::urcu::read_lock_guard read_lock
;
2270 cds_lfht_for_each_entry (
2271 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
2272 struct ltt_kernel_channel
*chan
;
2274 /* For each channel, ask the consumer to clear it. */
2275 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
2276 DBG("Clear kernel channel %" PRIu64
", session %s",
2279 ret
= consumer_clear_channel(socket
, chan
->key
);
2285 if (!ksess
->metadata
) {
2287 * Nothing to do for the metadata.
2288 * This is a snapshot session.
2289 * The metadata is genererated on the fly.
2295 * Clear the metadata channel.
2296 * Metadata channel is not cleared per se but we still need to
2297 * perform a rotation operation on it behind the scene.
2299 ret
= consumer_clear_channel(socket
, ksess
->metadata
->key
);
2309 case LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED
:
2310 status
= LTTNG_ERR_CLEAR_RELAY_DISALLOWED
;
2313 status
= LTTNG_ERR_CLEAR_FAIL_CONSUMER
;
2320 enum lttng_error_code
2321 kernel_create_event_notifier_group_notification_fd(int *event_notifier_group_notification_fd
)
2323 int local_fd
= -1, ret
;
2324 enum lttng_error_code error_code_ret
;
2326 LTTNG_ASSERT(event_notifier_group_notification_fd
);
2328 ret
= kernctl_create_event_notifier_group_notification_fd(
2329 kernel_tracer_event_notifier_group_fd
);
2331 PERROR("Failed to create kernel event notifier group notification file descriptor");
2332 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
;
2338 /* Prevent fd duplication after execlp(). */
2339 ret
= fcntl(local_fd
, F_SETFD
, FD_CLOEXEC
);
2341 PERROR("Failed to set FD_CLOEXEC on kernel event notifier group notification file descriptor: fd = %d",
2343 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
;
2347 DBG("Created kernel notifier group notification file descriptor: fd = %d", local_fd
);
2348 error_code_ret
= LTTNG_OK
;
2349 *event_notifier_group_notification_fd
= local_fd
;
2353 if (local_fd
>= 0) {
2354 ret
= close(local_fd
);
2356 PERROR("Failed to close kernel event notifier group notification file descriptor: fd = %d",
2361 return error_code_ret
;
2364 enum lttng_error_code
2365 kernel_destroy_event_notifier_group_notification_fd(int event_notifier_group_notification_fd
)
2367 enum lttng_error_code ret_code
= LTTNG_OK
;
2369 DBG("Closing event notifier group notification file descriptor: fd = %d",
2370 event_notifier_group_notification_fd
);
2371 if (event_notifier_group_notification_fd
>= 0) {
2372 const int ret
= close(event_notifier_group_notification_fd
);
2374 PERROR("Failed to close event notifier group notification file descriptor: fd = %d",
2375 event_notifier_group_notification_fd
);
2382 static unsigned long hash_trigger(const struct lttng_trigger
*trigger
)
2384 const struct lttng_condition
*condition
= lttng_trigger_get_const_condition(trigger
);
2386 return lttng_condition_hash(condition
);
2389 static int match_trigger(struct cds_lfht_node
*node
, const void *key
)
2391 const struct ltt_kernel_event_notifier_rule
*event_notifier_rule
;
2392 const struct lttng_trigger
*trigger
= (lttng_trigger
*) key
;
2394 event_notifier_rule
=
2395 caa_container_of(node
, const struct ltt_kernel_event_notifier_rule
, ht_node
);
2397 return lttng_trigger_is_equal(trigger
, event_notifier_rule
->trigger
);
2400 static enum lttng_error_code
kernel_create_event_notifier_rule(
2401 struct lttng_trigger
*trigger
, const struct lttng_credentials
*creds
, uint64_t token
)
2403 int err
, fd
, ret
= 0;
2404 enum lttng_error_code error_code_ret
;
2405 enum lttng_condition_status condition_status
;
2406 enum lttng_condition_type condition_type
;
2407 enum lttng_event_rule_type event_rule_type
;
2408 struct ltt_kernel_event_notifier_rule
*event_notifier_rule
;
2409 struct lttng_kernel_abi_event_notifier kernel_event_notifier
= {};
2410 unsigned int capture_bytecode_count
= 0, i
;
2411 const struct lttng_condition
*condition
= nullptr;
2412 const struct lttng_event_rule
*event_rule
= nullptr;
2413 enum lttng_condition_status cond_status
;
2415 LTTNG_ASSERT(trigger
);
2417 condition
= lttng_trigger_get_const_condition(trigger
);
2418 LTTNG_ASSERT(condition
);
2420 condition_type
= lttng_condition_get_type(condition
);
2421 LTTNG_ASSERT(condition_type
== LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
);
2423 /* Does not acquire a reference. */
2424 condition_status
= lttng_condition_event_rule_matches_get_rule(condition
, &event_rule
);
2425 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
2426 LTTNG_ASSERT(event_rule
);
2428 event_rule_type
= lttng_event_rule_get_type(event_rule
);
2429 LTTNG_ASSERT(event_rule_type
!= LTTNG_EVENT_RULE_TYPE_UNKNOWN
);
2431 error_code_ret
= trace_kernel_create_event_notifier_rule(
2434 lttng_condition_event_rule_matches_get_error_counter_index(condition
),
2435 &event_notifier_rule
);
2436 if (error_code_ret
!= LTTNG_OK
) {
2440 error_code_ret
= trace_kernel_init_event_notifier_from_event_rule(event_rule
,
2441 &kernel_event_notifier
);
2442 if (error_code_ret
!= LTTNG_OK
) {
2446 kernel_event_notifier
.event
.token
= event_notifier_rule
->token
;
2447 kernel_event_notifier
.error_counter_idx
=
2448 lttng_condition_event_rule_matches_get_error_counter_index(condition
);
2450 fd
= kernctl_create_event_notifier(kernel_tracer_event_notifier_group_fd
,
2451 &kernel_event_notifier
);
2455 error_code_ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
2458 WARN("Failed to create kernel event notifier: not notifier type not implemented");
2459 error_code_ret
= LTTNG_ERR_KERN_EVENT_ENOSYS
;
2462 WARN("Failed to create kernel event notifier: not found: name = '%s'",
2463 kernel_event_notifier
.event
.name
);
2464 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2467 PERROR("Failed to create kernel event notifier: error code = %d, name = '%s'",
2469 kernel_event_notifier
.event
.name
);
2470 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2475 event_notifier_rule
->fd
= fd
;
2476 /* Prevent fd duplication after execlp(). */
2477 err
= fcntl(event_notifier_rule
->fd
, F_SETFD
, FD_CLOEXEC
);
2479 PERROR("Failed to set FD_CLOEXEC on kernel event notifier file descriptor: fd = %d",
2481 error_code_ret
= LTTNG_ERR_FATAL
;
2482 goto set_cloexec_error
;
2485 if (event_notifier_rule
->filter
) {
2486 err
= kernctl_filter(event_notifier_rule
->fd
, event_notifier_rule
->filter
);
2490 error_code_ret
= LTTNG_ERR_FILTER_NOMEM
;
2493 error_code_ret
= LTTNG_ERR_FILTER_INVAL
;
2500 if (lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
) {
2501 ret
= userspace_probe_event_rule_add_callsites(
2502 event_rule
, creds
, event_notifier_rule
->fd
);
2504 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2505 goto add_callsite_error
;
2509 /* Set the capture bytecode if any. */
2510 cond_status
= lttng_condition_event_rule_matches_get_capture_descriptor_count(
2511 condition
, &capture_bytecode_count
);
2512 LTTNG_ASSERT(cond_status
== LTTNG_CONDITION_STATUS_OK
);
2514 for (i
= 0; i
< capture_bytecode_count
; i
++) {
2515 const struct lttng_bytecode
*capture_bytecode
=
2516 lttng_condition_event_rule_matches_get_capture_bytecode_at_index(condition
,
2519 if (capture_bytecode
== nullptr) {
2520 ERR("Unexpected NULL capture bytecode on condition");
2521 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2525 ret
= kernctl_capture(event_notifier_rule
->fd
, capture_bytecode
);
2527 ERR("Failed to set capture bytecode on event notifier rule fd: fd = %d",
2528 event_notifier_rule
->fd
);
2529 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2534 err
= kernctl_enable(event_notifier_rule
->fd
);
2538 error_code_ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
2541 PERROR("enable kernel event notifier");
2542 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2548 /* Add trigger to kernel token mapping in the hash table. */
2550 lttng::urcu::read_lock_guard read_lock
;
2551 cds_lfht_add(kernel_token_to_event_notifier_rule_ht
,
2552 hash_trigger(trigger
),
2553 &event_notifier_rule
->ht_node
);
2556 DBG("Created kernel event notifier: name = '%s', fd = %d",
2557 kernel_event_notifier
.event
.name
,
2558 event_notifier_rule
->fd
);
2568 const int close_ret
= close(event_notifier_rule
->fd
);
2571 PERROR("Failed to close kernel event notifier file descriptor: fd = %d",
2572 event_notifier_rule
->fd
);
2576 free(event_notifier_rule
);
2578 return error_code_ret
;
2581 enum lttng_error_code
kernel_register_event_notifier(struct lttng_trigger
*trigger
,
2582 const struct lttng_credentials
*cmd_creds
)
2584 enum lttng_error_code ret
;
2585 enum lttng_condition_status status
;
2586 enum lttng_domain_type domain_type
;
2587 const struct lttng_event_rule
*event_rule
;
2588 const struct lttng_condition
*const condition
= lttng_trigger_get_const_condition(trigger
);
2589 const uint64_t token
= lttng_trigger_get_tracer_token(trigger
);
2591 LTTNG_ASSERT(condition
);
2593 /* Does not acquire a reference to the event rule. */
2594 status
= lttng_condition_event_rule_matches_get_rule(condition
, &event_rule
);
2595 LTTNG_ASSERT(status
== LTTNG_CONDITION_STATUS_OK
);
2597 domain_type
= lttng_event_rule_get_domain_type(event_rule
);
2598 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2600 ret
= kernel_create_event_notifier_rule(trigger
, cmd_creds
, token
);
2601 if (ret
!= LTTNG_OK
) {
2602 ERR("Failed to create kernel event notifier rule");
2608 enum lttng_error_code
kernel_unregister_event_notifier(const struct lttng_trigger
*trigger
)
2610 struct ltt_kernel_event_notifier_rule
*token_event_rule_element
;
2611 struct cds_lfht_node
*node
;
2612 struct cds_lfht_iter iter
;
2613 enum lttng_error_code error_code_ret
;
2616 lttng::urcu::read_lock_guard read_lock
;
2618 cds_lfht_lookup(kernel_token_to_event_notifier_rule_ht
,
2619 hash_trigger(trigger
),
2624 node
= cds_lfht_iter_get_node(&iter
);
2626 error_code_ret
= LTTNG_ERR_TRIGGER_NOT_FOUND
;
2630 token_event_rule_element
=
2631 caa_container_of(node
, struct ltt_kernel_event_notifier_rule
, ht_node
);
2633 ret
= kernel_disable_event_notifier_rule(token_event_rule_element
);
2635 error_code_ret
= LTTNG_ERR_FATAL
;
2639 trace_kernel_destroy_event_notifier_rule(token_event_rule_element
);
2640 error_code_ret
= LTTNG_OK
;
2644 return error_code_ret
;
2647 int kernel_get_notification_fd()
2649 return kernel_tracer_event_notifier_group_notification_fd
;