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(struct ltt_session
*session
)
169 struct ltt_kernel_session
*lks
;
171 LTTNG_ASSERT(session
);
173 /* Allocate data structure */
174 lks
= trace_kernel_create_session();
175 if (lks
== nullptr) {
180 /* Kernel tracer session creation */
181 ret
= kernctl_create_session(kernel_tracer_fd
);
183 PERROR("ioctl kernel create session");
188 /* Prevent fd duplication after execlp() */
189 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
191 PERROR("fcntl session fd");
194 lks
->id
= session
->id
;
195 lks
->consumer_fds_sent
= 0;
196 session
->kernel_session
= lks
;
198 DBG("Kernel session created (fd: %d)", lks
->fd
);
201 * This is necessary since the creation time is present in the session
202 * name when it is generated.
204 if (session
->has_auto_generated_name
) {
205 ret
= kernctl_session_set_name(lks
->fd
, DEFAULT_SESSION_NAME
);
207 ret
= kernctl_session_set_name(lks
->fd
, session
->name
);
210 WARN("Could not set kernel session name for session %" PRIu64
" name: %s",
215 ret
= kernctl_session_set_creation_time(lks
->fd
, session
->creation_time
);
217 WARN("Could not set kernel session creation time for session %" PRIu64
" name: %s",
226 trace_kernel_destroy_session(lks
);
227 trace_kernel_free_session(lks
);
233 * Create a kernel channel, register it to the kernel tracer and add it to the
236 int kernel_create_channel(struct ltt_kernel_session
*session
, struct lttng_channel
*chan
)
239 struct ltt_kernel_channel
*lkc
;
241 LTTNG_ASSERT(session
);
244 /* Allocate kernel channel */
245 lkc
= trace_kernel_create_channel(chan
);
246 if (lkc
== nullptr) {
250 DBG3("Kernel create channel %s with attr: %d, %" PRIu64
", %" PRIu64
", %u, %u, %d, %d",
252 lkc
->channel
->attr
.overwrite
,
253 lkc
->channel
->attr
.subbuf_size
,
254 lkc
->channel
->attr
.num_subbuf
,
255 lkc
->channel
->attr
.switch_timer_interval
,
256 lkc
->channel
->attr
.read_timer_interval
,
257 lkc
->channel
->attr
.live_timer_interval
,
258 lkc
->channel
->attr
.output
);
260 /* Kernel tracer channel creation */
261 ret
= kernctl_create_channel(session
->fd
, &lkc
->channel
->attr
);
263 PERROR("ioctl kernel create channel");
267 /* Setup the channel fd */
269 /* Prevent fd duplication after execlp() */
270 ret
= fcntl(lkc
->fd
, F_SETFD
, FD_CLOEXEC
);
272 PERROR("fcntl session fd");
275 /* Add channel to session */
276 cds_list_add(&lkc
->list
, &session
->channel_list
.head
);
277 session
->channel_count
++;
278 lkc
->session
= session
;
279 lkc
->key
= ++next_kernel_channel_key
;
281 DBG("Kernel channel %s created (fd: %d, key: %" PRIu64
")",
297 * Create a kernel event notifier group, register it to the kernel tracer and
298 * add it to the kernel session.
300 static int kernel_create_event_notifier_group(int *event_notifier_group_fd
)
305 LTTNG_ASSERT(event_notifier_group_fd
);
307 /* Kernel event notifier group creation. */
308 ret
= kernctl_create_event_notifier_group(kernel_tracer_fd
);
310 PERROR("Failed to create kernel event notifier group");
317 /* Prevent fd duplication after execlp(). */
318 ret
= fcntl(local_fd
, F_SETFD
, FD_CLOEXEC
);
320 PERROR("Failed to set FD_CLOEXEC on kernel event notifier group file descriptor: fd = %d",
325 DBG("Created kernel event notifier group: fd = %d", local_fd
);
326 *event_notifier_group_fd
= local_fd
;
331 ret
= close(local_fd
);
333 PERROR("Failed to close kernel event notifier group file descriptor: fd = %d",
342 * Compute the offset of the instrumentation byte in the binary based on the
343 * function probe location using the ELF lookup method.
345 * Returns 0 on success and set the offset out parameter to the offset of the
347 * Returns -1 on error
349 static int extract_userspace_probe_offset_function_elf(
350 const struct lttng_userspace_probe_location
*probe_location
,
357 const char *symbol
= nullptr;
358 const struct lttng_userspace_probe_location_lookup_method
*lookup
= nullptr;
359 enum lttng_userspace_probe_location_lookup_method_type lookup_method_type
;
361 LTTNG_ASSERT(lttng_userspace_probe_location_get_type(probe_location
) ==
362 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
364 lookup
= lttng_userspace_probe_location_get_lookup_method(probe_location
);
370 lookup_method_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup
);
372 LTTNG_ASSERT(lookup_method_type
==
373 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
);
375 symbol
= lttng_userspace_probe_location_function_get_function_name(probe_location
);
381 fd
= lttng_userspace_probe_location_function_get_binary_fd(probe_location
);
387 ret
= run_as_extract_elf_symbol_offset(fd
, symbol
, uid
, gid
, offset
);
389 DBG("userspace probe offset calculation failed for "
395 DBG("userspace probe elf offset for %s is 0x%jd", symbol
, (intmax_t) (*offset
));
401 * Compute the offsets of the instrumentation bytes in the binary based on the
402 * tracepoint probe location using the SDT lookup method. This function
403 * allocates the offsets buffer, the caller must free it.
405 * Returns 0 on success and set the offset out parameter to the offsets of the
407 * Returns -1 on error.
409 static int extract_userspace_probe_offset_tracepoint_sdt(
410 const struct lttng_userspace_probe_location
*probe_location
,
414 uint32_t *offsets_count
)
416 enum lttng_userspace_probe_location_lookup_method_type lookup_method_type
;
417 const struct lttng_userspace_probe_location_lookup_method
*lookup
= nullptr;
418 const char *probe_name
= nullptr, *provider_name
= nullptr;
422 LTTNG_ASSERT(lttng_userspace_probe_location_get_type(probe_location
) ==
423 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
425 lookup
= lttng_userspace_probe_location_get_lookup_method(probe_location
);
431 lookup_method_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup
);
433 LTTNG_ASSERT(lookup_method_type
==
434 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
);
436 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(probe_location
);
442 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(probe_location
);
443 if (!provider_name
) {
448 fd
= lttng_userspace_probe_location_tracepoint_get_binary_fd(probe_location
);
454 ret
= run_as_extract_sdt_probe_offsets(
455 fd
, provider_name
, probe_name
, uid
, gid
, offsets
, offsets_count
);
457 DBG("userspace probe offset calculation failed for sdt "
464 if (*offsets_count
== 0) {
465 DBG("no userspace probe offset found");
469 DBG("%u userspace probe SDT offsets found for %s:%s at:",
473 for (i
= 0; i
< *offsets_count
; i
++) {
474 DBG("\t0x%jd", (intmax_t) ((*offsets
)[i
]));
480 static int userspace_probe_add_callsite(const struct lttng_userspace_probe_location
*location
,
485 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
= nullptr;
486 enum lttng_userspace_probe_location_lookup_method_type type
;
489 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
490 if (!lookup_method
) {
495 type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
497 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
499 struct lttng_kernel_abi_event_callsite callsite
;
502 ret
= extract_userspace_probe_offset_function_elf(location
, uid
, gid
, &offset
);
504 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
508 callsite
.u
.uprobe
.offset
= sanitize_uprobe_offset(offset
);
509 ret
= kernctl_add_callsite(fd
, &callsite
);
511 WARN("Failed to add callsite to ELF userspace probe.");
512 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
517 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
520 uint64_t *offsets
= nullptr;
521 uint32_t offsets_count
;
522 struct lttng_kernel_abi_event_callsite callsite
;
525 * This call allocates the offsets buffer. This buffer must be freed
528 ret
= extract_userspace_probe_offset_tracepoint_sdt(
529 location
, uid
, gid
, &offsets
, &offsets_count
);
531 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
534 for (i
= 0; i
< offsets_count
; i
++) {
535 callsite
.u
.uprobe
.offset
= sanitize_uprobe_offset(offsets
[i
]);
536 ret
= kernctl_add_callsite(fd
, &callsite
);
538 WARN("Failed to add callsite to SDT userspace probe");
539 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
548 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
556 * Extract the offsets of the instrumentation point for the different lookup
559 static int userspace_probe_event_add_callsites(struct lttng_event
*ev
,
560 struct ltt_kernel_session
*session
,
564 const struct lttng_userspace_probe_location
*location
= nullptr;
567 LTTNG_ASSERT(ev
->type
== LTTNG_EVENT_USERSPACE_PROBE
);
569 location
= lttng_event_get_userspace_probe_location(ev
);
575 ret
= userspace_probe_add_callsite(location
, session
->uid
, session
->gid
, fd
);
577 WARN("Failed to add callsite to userspace probe event '%s'", ev
->name
);
585 * Extract the offsets of the instrumentation point for the different look-up
588 static int userspace_probe_event_rule_add_callsites(const struct lttng_event_rule
*rule
,
589 const struct lttng_credentials
*creds
,
593 enum lttng_event_rule_status status
;
594 enum lttng_event_rule_type event_rule_type
;
595 const struct lttng_userspace_probe_location
*location
= nullptr;
600 event_rule_type
= lttng_event_rule_get_type(rule
);
601 LTTNG_ASSERT(event_rule_type
== LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
);
603 status
= lttng_event_rule_kernel_uprobe_get_location(rule
, &location
);
604 if (status
!= LTTNG_EVENT_RULE_STATUS_OK
|| !location
) {
609 ret
= userspace_probe_add_callsite(
610 location
, lttng_credentials_get_uid(creds
), lttng_credentials_get_gid(creds
), fd
);
612 WARN("Failed to add callsite to user space probe object: fd = %d", fd
);
620 * Create a kernel event, enable it to the kernel tracer and add it to the
621 * channel event list of the kernel session.
622 * We own filter_expression and filter.
624 int kernel_create_event(struct lttng_event
*ev
,
625 struct ltt_kernel_channel
*channel
,
626 char *filter_expression
,
627 struct lttng_bytecode
*filter
)
630 enum lttng_error_code ret
;
631 struct ltt_kernel_event
*event
;
634 LTTNG_ASSERT(channel
);
636 /* We pass ownership of filter_expression and filter */
637 ret
= trace_kernel_create_event(ev
, filter_expression
, filter
, &event
);
638 if (ret
!= LTTNG_OK
) {
642 fd
= kernctl_create_event(channel
->fd
, event
->event
);
646 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
649 WARN("Event type not implemented");
650 ret
= LTTNG_ERR_KERN_EVENT_ENOSYS
;
653 WARN("Event %s not found!", ev
->name
);
654 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
657 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
658 PERROR("create event ioctl");
663 event
->type
= ev
->type
;
665 /* Prevent fd duplication after execlp() */
666 err
= fcntl(event
->fd
, F_SETFD
, FD_CLOEXEC
);
668 PERROR("fcntl session fd");
672 err
= kernctl_filter(event
->fd
, filter
);
676 ret
= LTTNG_ERR_FILTER_NOMEM
;
679 ret
= LTTNG_ERR_FILTER_INVAL
;
686 if (ev
->type
== LTTNG_EVENT_USERSPACE_PROBE
) {
687 ret
= (lttng_error_code
) userspace_probe_event_add_callsites(
688 ev
, channel
->session
, event
->fd
);
690 goto add_callsite_error
;
694 err
= kernctl_enable(event
->fd
);
698 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
701 PERROR("enable kernel event");
702 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
708 /* Add event to event list */
709 cds_list_add(&event
->list
, &channel
->events_list
.head
);
710 channel
->event_count
++;
712 DBG("Event %s created (fd: %d)", ev
->name
, event
->fd
);
722 closeret
= close(event
->fd
);
724 PERROR("close event fd");
734 * Disable a kernel channel.
736 int kernel_disable_channel(struct ltt_kernel_channel
*chan
)
742 ret
= kernctl_disable(chan
->fd
);
744 PERROR("disable chan ioctl");
748 chan
->enabled
= false;
749 DBG("Kernel channel %s disabled (fd: %d, key: %" PRIu64
")",
761 * Enable a kernel channel.
763 int kernel_enable_channel(struct ltt_kernel_channel
*chan
)
769 ret
= kernctl_enable(chan
->fd
);
770 if (ret
< 0 && ret
!= -EEXIST
) {
771 PERROR("Enable kernel chan");
775 chan
->enabled
= true;
776 DBG("Kernel channel %s enabled (fd: %d, key: %" PRIu64
")",
788 * Enable a kernel event.
790 int kernel_enable_event(struct ltt_kernel_event
*event
)
796 ret
= kernctl_enable(event
->fd
);
800 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
803 PERROR("enable kernel event");
809 event
->enabled
= true;
810 DBG("Kernel event %s enabled (fd: %d)", event
->event
->name
, event
->fd
);
819 * Disable a kernel event.
821 int kernel_disable_event(struct ltt_kernel_event
*event
)
827 ret
= kernctl_disable(event
->fd
);
829 PERROR("Failed to disable kernel event: name = '%s', fd = %d",
835 event
->enabled
= false;
836 DBG("Kernel event %s disabled (fd: %d)", event
->event
->name
, event
->fd
);
845 * Disable a kernel event notifier.
847 static int kernel_disable_event_notifier_rule(struct ltt_kernel_event_notifier_rule
*event
)
853 lttng::urcu::read_lock_guard read_lock
;
854 cds_lfht_del(kernel_token_to_event_notifier_rule_ht
, &event
->ht_node
);
856 ret
= kernctl_disable(event
->fd
);
858 PERROR("Failed to disable kernel event notifier: fd = %d, token = %" PRIu64
,
864 event
->enabled
= false;
865 DBG("Disabled kernel event notifier: fd = %d, token = %" PRIu64
, event
->fd
, event
->token
);
871 static struct process_attr_tracker
*
872 _kernel_get_process_attr_tracker(struct ltt_kernel_session
*session
,
873 enum lttng_process_attr process_attr
)
875 switch (process_attr
) {
876 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
877 return session
->tracker_pid
;
878 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
879 return session
->tracker_vpid
;
880 case LTTNG_PROCESS_ATTR_USER_ID
:
881 return session
->tracker_uid
;
882 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
883 return session
->tracker_vuid
;
884 case LTTNG_PROCESS_ATTR_GROUP_ID
:
885 return session
->tracker_gid
;
886 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
887 return session
->tracker_vgid
;
893 const struct process_attr_tracker
*
894 kernel_get_process_attr_tracker(struct ltt_kernel_session
*session
,
895 enum lttng_process_attr process_attr
)
897 return (const struct process_attr_tracker
*) _kernel_get_process_attr_tracker(session
,
901 enum lttng_error_code
902 kernel_process_attr_tracker_set_tracking_policy(struct ltt_kernel_session
*session
,
903 enum lttng_process_attr process_attr
,
904 enum lttng_tracking_policy policy
)
907 enum lttng_error_code ret_code
= LTTNG_OK
;
908 struct process_attr_tracker
*tracker
=
909 _kernel_get_process_attr_tracker(session
, process_attr
);
910 enum lttng_tracking_policy previous_policy
;
913 ret_code
= LTTNG_ERR_INVALID
;
917 previous_policy
= process_attr_tracker_get_tracking_policy(tracker
);
918 ret
= process_attr_tracker_set_tracking_policy(tracker
, policy
);
920 ret_code
= LTTNG_ERR_UNK
;
924 if (previous_policy
== policy
) {
929 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
930 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
932 * Maintain a special case for the process ID process
933 * attribute tracker as it was the only supported
934 * attribute prior to 2.12.
936 ret
= kernctl_track_pid(session
->fd
, -1);
938 ret
= kernctl_track_id(session
->fd
, process_attr
, -1);
941 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
942 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
944 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
946 * Maintain a special case for the process ID process
947 * attribute tracker as it was the only supported
948 * attribute prior to 2.12.
950 ret
= kernctl_untrack_pid(session
->fd
, -1);
952 ret
= kernctl_untrack_id(session
->fd
, process_attr
, -1);
958 /* kern-ctl error handling */
964 ret_code
= LTTNG_ERR_INVALID
;
967 ret_code
= LTTNG_ERR_NOMEM
;
970 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
973 ret_code
= LTTNG_ERR_UNK
;
980 enum lttng_error_code
981 kernel_process_attr_tracker_inclusion_set_add_value(struct ltt_kernel_session
*session
,
982 enum lttng_process_attr process_attr
,
983 const struct process_attr_value
*value
)
985 int ret
, integral_value
;
986 enum lttng_error_code ret_code
;
987 struct process_attr_tracker
*tracker
;
988 enum process_attr_tracker_status status
;
991 * Convert process attribute tracker value to the integral
992 * representation required by the kern-ctl API.
994 switch (process_attr
) {
995 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
996 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
997 integral_value
= (int) value
->value
.pid
;
999 case LTTNG_PROCESS_ATTR_USER_ID
:
1000 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1001 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
) {
1004 ret_code
= utils_user_id_from_name(value
->value
.user_name
, &uid
);
1005 if (ret_code
!= LTTNG_OK
) {
1008 integral_value
= (int) uid
;
1010 integral_value
= (int) value
->value
.uid
;
1013 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1014 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1015 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
) {
1018 ret_code
= utils_group_id_from_name(value
->value
.group_name
, &gid
);
1019 if (ret_code
!= LTTNG_OK
) {
1022 integral_value
= (int) gid
;
1024 integral_value
= (int) value
->value
.gid
;
1028 ret_code
= LTTNG_ERR_INVALID
;
1032 tracker
= _kernel_get_process_attr_tracker(session
, process_attr
);
1034 ret_code
= LTTNG_ERR_INVALID
;
1038 status
= process_attr_tracker_inclusion_set_add_value(tracker
, value
);
1039 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1041 case PROCESS_ATTR_TRACKER_STATUS_EXISTS
:
1042 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
1044 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY
:
1045 ret_code
= LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY
;
1047 case PROCESS_ATTR_TRACKER_STATUS_ERROR
:
1049 ret_code
= LTTNG_ERR_UNK
;
1055 DBG("Kernel track %s %d for session id %" PRIu64
,
1056 lttng_process_attr_to_string(process_attr
),
1059 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
1061 * Maintain a special case for the process ID process attribute
1062 * tracker as it was the only supported attribute prior to 2.12.
1064 ret
= kernctl_track_pid(session
->fd
, integral_value
);
1066 ret
= kernctl_track_id(session
->fd
, process_attr
, integral_value
);
1069 ret_code
= LTTNG_OK
;
1073 kernel_wait_quiescent();
1075 /* kern-ctl error handling */
1078 ret_code
= LTTNG_OK
;
1081 ret_code
= LTTNG_ERR_INVALID
;
1084 ret_code
= LTTNG_ERR_NOMEM
;
1087 ret_code
= LTTNG_ERR_PROCESS_ATTR_EXISTS
;
1090 ret_code
= LTTNG_ERR_UNK
;
1094 /* Attempt to remove the value from the tracker. */
1095 status
= process_attr_tracker_inclusion_set_remove_value(tracker
, value
);
1096 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1097 ERR("Failed to roll-back the tracking of kernel %s process attribute %d while handling a kern-ctl error",
1098 lttng_process_attr_to_string(process_attr
),
1105 enum lttng_error_code
1106 kernel_process_attr_tracker_inclusion_set_remove_value(struct ltt_kernel_session
*session
,
1107 enum lttng_process_attr process_attr
,
1108 const struct process_attr_value
*value
)
1110 int ret
, integral_value
;
1111 enum lttng_error_code ret_code
;
1112 struct process_attr_tracker
*tracker
;
1113 enum process_attr_tracker_status status
;
1116 * Convert process attribute tracker value to the integral
1117 * representation required by the kern-ctl API.
1119 switch (process_attr
) {
1120 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1121 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1122 integral_value
= (int) value
->value
.pid
;
1124 case LTTNG_PROCESS_ATTR_USER_ID
:
1125 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1126 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
) {
1129 ret_code
= utils_user_id_from_name(value
->value
.user_name
, &uid
);
1130 if (ret_code
!= LTTNG_OK
) {
1133 integral_value
= (int) uid
;
1135 integral_value
= (int) value
->value
.uid
;
1138 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1139 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1140 if (value
->type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
) {
1143 ret_code
= utils_group_id_from_name(value
->value
.group_name
, &gid
);
1144 if (ret_code
!= LTTNG_OK
) {
1147 integral_value
= (int) gid
;
1149 integral_value
= (int) value
->value
.gid
;
1153 ret_code
= LTTNG_ERR_INVALID
;
1157 tracker
= _kernel_get_process_attr_tracker(session
, process_attr
);
1159 ret_code
= LTTNG_ERR_INVALID
;
1163 status
= process_attr_tracker_inclusion_set_remove_value(tracker
, value
);
1164 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1166 case PROCESS_ATTR_TRACKER_STATUS_MISSING
:
1167 ret_code
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
1169 case PROCESS_ATTR_TRACKER_STATUS_INVALID_TRACKING_POLICY
:
1170 ret_code
= LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY
;
1172 case PROCESS_ATTR_TRACKER_STATUS_ERROR
:
1174 ret_code
= LTTNG_ERR_UNK
;
1180 DBG("Kernel track %s %d for session id %" PRIu64
,
1181 lttng_process_attr_to_string(process_attr
),
1184 if (process_attr
== LTTNG_PROCESS_ATTR_PROCESS_ID
) {
1186 * Maintain a special case for the process ID process attribute
1187 * tracker as it was the only supported attribute prior to 2.12.
1189 ret
= kernctl_untrack_pid(session
->fd
, integral_value
);
1191 ret
= kernctl_untrack_id(session
->fd
, process_attr
, integral_value
);
1194 ret_code
= LTTNG_OK
;
1197 kernel_wait_quiescent();
1199 /* kern-ctl error handling */
1202 ret_code
= LTTNG_OK
;
1205 ret_code
= LTTNG_ERR_INVALID
;
1208 ret_code
= LTTNG_ERR_NOMEM
;
1211 ret_code
= LTTNG_ERR_PROCESS_ATTR_MISSING
;
1214 ret_code
= LTTNG_ERR_UNK
;
1218 /* Attempt to add the value to the tracker. */
1219 status
= process_attr_tracker_inclusion_set_add_value(tracker
, value
);
1220 if (status
!= PROCESS_ATTR_TRACKER_STATUS_OK
) {
1221 ERR("Failed to roll-back the tracking of kernel %s process attribute %d while handling a kern-ctl error",
1222 lttng_process_attr_to_string(process_attr
),
1230 * Create kernel metadata, open from the kernel tracer and add it to the
1233 int kernel_open_metadata(struct ltt_kernel_session
*session
)
1236 struct ltt_kernel_metadata
*lkm
= nullptr;
1238 LTTNG_ASSERT(session
);
1240 /* Allocate kernel metadata */
1241 lkm
= trace_kernel_create_metadata();
1242 if (lkm
== nullptr) {
1246 /* Kernel tracer metadata creation */
1247 ret
= kernctl_open_metadata(session
->fd
, &lkm
->conf
->attr
);
1253 lkm
->key
= ++next_kernel_channel_key
;
1254 /* Prevent fd duplication after execlp() */
1255 ret
= fcntl(lkm
->fd
, F_SETFD
, FD_CLOEXEC
);
1257 PERROR("fcntl session fd");
1260 session
->metadata
= lkm
;
1262 DBG("Kernel metadata opened (fd: %d)", lkm
->fd
);
1267 trace_kernel_destroy_metadata(lkm
);
1273 * Start tracing session.
1275 int kernel_start_session(struct ltt_kernel_session
*session
)
1279 LTTNG_ASSERT(session
);
1281 ret
= kernctl_start_session(session
->fd
);
1283 PERROR("ioctl start session");
1287 DBG("Kernel session started");
1296 * Make a kernel wait to make sure in-flight probe have completed.
1298 void kernel_wait_quiescent()
1301 int fd
= kernel_tracer_fd
;
1303 DBG("Kernel quiescent wait on %d", fd
);
1305 ret
= kernctl_wait_quiescent(fd
);
1307 PERROR("wait quiescent ioctl");
1308 ERR("Kernel quiescent wait failed");
1313 * Force flush buffer of metadata.
1315 int kernel_metadata_flush_buffer(int fd
)
1319 DBG("Kernel flushing metadata buffer on fd %d", fd
);
1321 ret
= kernctl_buffer_flush(fd
);
1323 ERR("Fail to flush metadata buffers %d (ret: %d)", fd
, ret
);
1330 * Force flush buffer for channel.
1332 int kernel_flush_buffer(struct ltt_kernel_channel
*channel
)
1335 struct ltt_kernel_stream
*stream
;
1337 LTTNG_ASSERT(channel
);
1339 DBG("Flush buffer for channel %s", channel
->channel
->name
);
1341 cds_list_for_each_entry (stream
, &channel
->stream_list
.head
, list
) {
1342 DBG("Flushing channel stream %d", stream
->fd
);
1343 ret
= kernctl_buffer_flush(stream
->fd
);
1346 ERR("Fail to flush buffer for stream %d (ret: %d)", stream
->fd
, ret
);
1354 * Stop tracing session.
1356 int kernel_stop_session(struct ltt_kernel_session
*session
)
1360 LTTNG_ASSERT(session
);
1362 ret
= kernctl_stop_session(session
->fd
);
1367 DBG("Kernel session stopped");
1376 * Open stream of channel, register it to the kernel tracer and add it
1377 * to the stream list of the channel.
1379 * Note: given that the streams may appear in random order wrt CPU
1380 * number (e.g. cpu hotplug), the index value of the stream number in
1381 * the stream name is not necessarily linked to the CPU number.
1383 * Return the number of created stream. Else, a negative value.
1385 int kernel_open_channel_stream(struct ltt_kernel_channel
*channel
)
1388 struct ltt_kernel_stream
*lks
;
1390 LTTNG_ASSERT(channel
);
1392 while ((ret
= kernctl_create_stream(channel
->fd
)) >= 0) {
1393 lks
= trace_kernel_create_stream(channel
->channel
->name
, channel
->stream_count
);
1394 if (lks
== nullptr) {
1403 /* Prevent fd duplication after execlp() */
1404 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
1406 PERROR("fcntl session fd");
1409 lks
->tracefile_size
= channel
->channel
->attr
.tracefile_size
;
1410 lks
->tracefile_count
= channel
->channel
->attr
.tracefile_count
;
1412 /* Add stream to channel stream list */
1413 cds_list_add(&lks
->list
, &channel
->stream_list
.head
);
1414 channel
->stream_count
++;
1416 DBG("Kernel stream %s created (fd: %d, state: %d)", lks
->name
, lks
->fd
, lks
->state
);
1419 return channel
->stream_count
;
1426 * Open the metadata stream and set it to the kernel session.
1428 int kernel_open_metadata_stream(struct ltt_kernel_session
*session
)
1432 LTTNG_ASSERT(session
);
1434 ret
= kernctl_create_stream(session
->metadata
->fd
);
1436 PERROR("kernel create metadata stream");
1440 DBG("Kernel metadata stream created (fd: %d)", ret
);
1441 session
->metadata_stream_fd
= ret
;
1442 /* Prevent fd duplication after execlp() */
1443 ret
= fcntl(session
->metadata_stream_fd
, F_SETFD
, FD_CLOEXEC
);
1445 PERROR("fcntl session fd");
1455 * Get the event list from the kernel tracer and return the number of elements.
1457 ssize_t
kernel_list_events(struct lttng_event
**events
)
1461 size_t nbmem
, count
= 0;
1463 struct lttng_event
*elist
;
1465 LTTNG_ASSERT(events
);
1467 fd
= kernctl_tracepoint_list(kernel_tracer_fd
);
1469 PERROR("kernel tracepoint list");
1473 fp
= fdopen(fd
, "r");
1474 if (fp
== nullptr) {
1475 PERROR("kernel tracepoint list fdopen");
1480 * Init memory size counter
1481 * See kernel-ctl.h for explanation of this value
1483 nbmem
= KERNEL_EVENT_INIT_LIST_SIZE
;
1484 elist
= calloc
<lttng_event
>(nbmem
);
1485 if (elist
== nullptr) {
1486 PERROR("alloc list events");
1491 while (fscanf(fp
, "event { name = %m[^;]; };\n", &event
) == 1) {
1492 if (count
>= nbmem
) {
1493 struct lttng_event
*new_elist
;
1496 new_nbmem
= nbmem
<< 1;
1497 DBG("Reallocating event list from %zu to %zu bytes", nbmem
, new_nbmem
);
1498 new_elist
= (lttng_event
*) realloc(elist
,
1499 new_nbmem
* sizeof(struct lttng_event
));
1500 if (new_elist
== nullptr) {
1501 PERROR("realloc list events");
1507 /* Zero the new memory */
1508 memset(new_elist
+ nbmem
,
1510 (new_nbmem
- nbmem
) * sizeof(struct lttng_event
));
1514 strncpy(elist
[count
].name
, event
, LTTNG_SYMBOL_NAME_LEN
);
1515 elist
[count
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1516 elist
[count
].enabled
= -1;
1522 DBG("Kernel list events done (%zu events)", count
);
1524 ret
= fclose(fp
); /* closes both fp and fd */
1540 * Get kernel version and validate it.
1542 int kernel_validate_version(struct lttng_kernel_abi_tracer_version
*version
,
1543 struct lttng_kernel_abi_tracer_abi_version
*abi_version
)
1547 ret
= kernctl_tracer_version(kernel_tracer_fd
, version
);
1549 ERR("Failed to retrieve the lttng-modules version");
1553 /* Validate version */
1554 if (version
->major
!= VERSION_MAJOR
) {
1555 ERR("Kernel tracer major version (%d) is not compatible with lttng-tools major version (%d)",
1560 ret
= kernctl_tracer_abi_version(kernel_tracer_fd
, abi_version
);
1562 ERR("Failed to retrieve lttng-modules ABI version");
1565 if (abi_version
->major
!= LTTNG_KERNEL_ABI_MAJOR_VERSION
) {
1566 ERR("Kernel tracer ABI version (%d.%d) does not match the expected ABI major version (%d.*)",
1569 LTTNG_KERNEL_ABI_MAJOR_VERSION
);
1572 DBG2("Kernel tracer version validated (%d.%d, ABI %d.%d)",
1576 abi_version
->minor
);
1583 ERR("Kernel tracer version check failed; kernel tracing will not be available");
1588 * Kernel work-arounds called at the start of sessiond main().
1590 int init_kernel_workarounds()
1596 * boot_id needs to be read once before being used concurrently
1597 * to deal with a Linux kernel race. A fix is proposed for
1598 * upstream, but the work-around is needed for older kernels.
1600 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
1607 ret
= fread(buf
, 1, sizeof(buf
), fp
);
1609 /* Ignore error, we don't really care */
1621 * Teardown of a kernel session, keeping data required by destroy notifiers.
1623 void kernel_destroy_session(struct ltt_kernel_session
*ksess
)
1625 struct lttng_trace_chunk
*trace_chunk
;
1627 if (ksess
== nullptr) {
1628 DBG3("No kernel session when tearing down session");
1632 DBG("Tearing down kernel session");
1633 trace_chunk
= ksess
->current_trace_chunk
;
1636 * Destroy channels on the consumer if at least one FD has been sent and we
1637 * are in no output mode because the streams are in *no* monitor mode so we
1638 * have to send a command to clean them up or else they leaked.
1640 if (!ksess
->output_traces
&& ksess
->consumer_fds_sent
) {
1642 struct consumer_socket
*socket
;
1643 struct lttng_ht_iter iter
;
1645 /* For each consumer socket. */
1646 lttng::urcu::read_lock_guard read_lock
;
1648 cds_lfht_for_each_entry (
1649 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1650 struct ltt_kernel_channel
*chan
;
1652 /* For each channel, ask the consumer to destroy it. */
1653 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1654 ret
= kernel_consumer_destroy_channel(socket
, chan
);
1656 /* Consumer is probably dead. Use next socket. */
1663 /* Close any relayd session */
1664 consumer_output_send_destroy_relayd(ksess
->consumer
);
1666 trace_kernel_destroy_session(ksess
);
1667 lttng_trace_chunk_put(trace_chunk
);
1670 /* Teardown of data required by destroy notifiers. */
1671 void kernel_free_session(struct ltt_kernel_session
*ksess
)
1673 if (ksess
== nullptr) {
1676 trace_kernel_free_session(ksess
);
1680 * Destroy a kernel channel object. It does not do anything on the tracer side.
1682 void kernel_destroy_channel(struct ltt_kernel_channel
*kchan
)
1684 struct ltt_kernel_session
*ksess
= nullptr;
1686 LTTNG_ASSERT(kchan
);
1687 LTTNG_ASSERT(kchan
->channel
);
1689 DBG3("Kernel destroy channel %s", kchan
->channel
->name
);
1691 /* Update channel count of associated session. */
1692 if (kchan
->session
) {
1693 /* Keep pointer reference so we can update it after the destroy. */
1694 ksess
= kchan
->session
;
1697 trace_kernel_destroy_channel(kchan
);
1700 * At this point the kernel channel is not visible anymore. This is safe
1701 * since in order to work on a visible kernel session, the tracing session
1702 * lock (ltt_session.lock) MUST be acquired.
1705 ksess
->channel_count
--;
1710 * Take a snapshot for a given kernel session.
1712 * Return LTTNG_OK on success or else return a LTTNG_ERR code.
1714 enum lttng_error_code
kernel_snapshot_record(struct ltt_kernel_session
*ksess
,
1715 const struct consumer_output
*output
,
1716 uint64_t nb_packets_per_stream
)
1718 int err
, ret
, saved_metadata_fd
;
1719 enum lttng_error_code status
= LTTNG_OK
;
1720 struct consumer_socket
*socket
;
1721 struct lttng_ht_iter iter
;
1722 struct ltt_kernel_metadata
*saved_metadata
;
1723 char *trace_path
= nullptr;
1724 size_t consumer_path_offset
= 0;
1726 LTTNG_ASSERT(ksess
);
1727 LTTNG_ASSERT(ksess
->consumer
);
1728 LTTNG_ASSERT(output
);
1730 DBG("Kernel snapshot record started");
1732 /* Save current metadata since the following calls will change it. */
1733 saved_metadata
= ksess
->metadata
;
1734 saved_metadata_fd
= ksess
->metadata_stream_fd
;
1736 ret
= kernel_open_metadata(ksess
);
1738 status
= LTTNG_ERR_KERN_META_FAIL
;
1742 ret
= kernel_open_metadata_stream(ksess
);
1744 status
= LTTNG_ERR_KERN_META_FAIL
;
1745 goto error_open_stream
;
1748 trace_path
= setup_channel_trace_path(ksess
->consumer
, "", &consumer_path_offset
);
1750 status
= LTTNG_ERR_INVALID
;
1755 /* Send metadata to consumer and snapshot everything. */
1756 lttng::urcu::read_lock_guard read_lock
;
1758 cds_lfht_for_each_entry (output
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1759 struct ltt_kernel_channel
*chan
;
1761 pthread_mutex_lock(socket
->lock
);
1762 /* This stream must not be monitored by the consumer. */
1763 ret
= kernel_consumer_add_metadata(socket
, ksess
, 0);
1764 pthread_mutex_unlock(socket
->lock
);
1766 status
= LTTNG_ERR_KERN_META_FAIL
;
1767 goto error_consumer
;
1770 /* For each channel, ask the consumer to snapshot it. */
1771 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1773 consumer_snapshot_channel(socket
,
1777 &trace_path
[consumer_path_offset
],
1778 nb_packets_per_stream
);
1779 if (status
!= LTTNG_OK
) {
1780 (void) kernel_consumer_destroy_metadata(socket
,
1782 goto error_consumer
;
1786 /* Snapshot metadata, */
1787 status
= consumer_snapshot_channel(socket
,
1788 ksess
->metadata
->key
,
1791 &trace_path
[consumer_path_offset
],
1793 if (status
!= LTTNG_OK
) {
1794 goto error_consumer
;
1798 * The metadata snapshot is done, ask the consumer to destroy it since
1799 * it's not monitored on the consumer side.
1801 (void) kernel_consumer_destroy_metadata(socket
, ksess
->metadata
);
1806 /* Close newly opened metadata stream. It's now on the consumer side. */
1807 err
= close(ksess
->metadata_stream_fd
);
1809 PERROR("close snapshot kernel");
1813 trace_kernel_destroy_metadata(ksess
->metadata
);
1815 /* Restore metadata state.*/
1816 ksess
->metadata
= saved_metadata
;
1817 ksess
->metadata_stream_fd
= saved_metadata_fd
;
1823 * Get the syscall mask array from the kernel tracer.
1825 * Return 0 on success else a negative value. In both case, syscall_mask should
1828 int kernel_syscall_mask(int chan_fd
, char **syscall_mask
, uint32_t *nr_bits
)
1830 LTTNG_ASSERT(syscall_mask
);
1831 LTTNG_ASSERT(nr_bits
);
1833 return kernctl_syscall_mask(chan_fd
, syscall_mask
, nr_bits
);
1836 static int kernel_tracer_abi_greater_or_equal(unsigned int major
, unsigned int minor
)
1839 struct lttng_kernel_abi_tracer_abi_version abi
;
1841 ret
= kernctl_tracer_abi_version(kernel_tracer_fd
, &abi
);
1843 ERR("Failed to retrieve lttng-modules ABI version");
1847 ret
= abi
.major
> major
|| (abi
.major
== major
&& abi
.minor
>= minor
);
1853 * Check for the support of the RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS via abi
1856 * Return 1 on success, 0 when feature is not supported, negative value in case
1859 int kernel_supports_ring_buffer_snapshot_sample_positions()
1862 * RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in 2.3
1864 return kernel_tracer_abi_greater_or_equal(2, 3);
1868 * Check for the support of the packet sequence number via abi version number.
1870 * Return 1 on success, 0 when feature is not supported, negative value in case
1873 int kernel_supports_ring_buffer_packet_sequence_number()
1876 * Packet sequence number was introduced in LTTng 2.8,
1877 * lttng-modules ABI 2.1.
1879 return kernel_tracer_abi_greater_or_equal(2, 1);
1883 * Check for the support of event notifiers via abi version number.
1885 * Return 1 on success, 0 when feature is not supported, negative value in case
1888 int kernel_supports_event_notifiers()
1891 * Event notifiers were introduced in LTTng 2.13, lttng-modules ABI 2.6.
1893 return kernel_tracer_abi_greater_or_equal(2, 6);
1897 * Rotate a kernel session.
1899 * Return LTTNG_OK on success or else an LTTng error code.
1901 enum lttng_error_code
kernel_rotate_session(struct ltt_session
*session
)
1904 enum lttng_error_code status
= LTTNG_OK
;
1905 struct consumer_socket
*socket
;
1906 struct lttng_ht_iter iter
;
1907 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
1909 LTTNG_ASSERT(ksess
);
1910 LTTNG_ASSERT(ksess
->consumer
);
1912 DBG("Rotate kernel session %s started (session %" PRIu64
")", session
->name
, session
->id
);
1916 * Note that this loop will end after one iteration given that there is
1917 * only one kernel consumer.
1919 lttng::urcu::read_lock_guard read_lock
;
1921 cds_lfht_for_each_entry (
1922 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
1923 struct ltt_kernel_channel
*chan
;
1925 /* For each channel, ask the consumer to rotate it. */
1926 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
1927 DBG("Rotate kernel channel %" PRIu64
", session %s",
1930 ret
= consumer_rotate_channel(socket
,
1933 /* is_metadata_channel */ false);
1935 status
= LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1941 * Rotate the metadata channel.
1943 ret
= consumer_rotate_channel(socket
,
1944 ksess
->metadata
->key
,
1946 /* is_metadata_channel */ true);
1948 status
= LTTNG_ERR_ROTATION_FAIL_CONSUMER
;
1958 enum lttng_error_code
kernel_create_channel_subdirectories(const struct ltt_kernel_session
*ksess
)
1960 enum lttng_error_code ret
= LTTNG_OK
;
1961 enum lttng_trace_chunk_status chunk_status
;
1963 lttng::urcu::read_lock_guard read_lock
;
1964 LTTNG_ASSERT(ksess
->current_trace_chunk
);
1967 * Create the index subdirectory which will take care
1968 * of implicitly creating the channel's path.
1970 chunk_status
= lttng_trace_chunk_create_subdirectory(
1971 ksess
->current_trace_chunk
, DEFAULT_KERNEL_TRACE_DIR
"/" DEFAULT_INDEX_DIR
);
1972 if (chunk_status
!= LTTNG_TRACE_CHUNK_STATUS_OK
) {
1973 ret
= LTTNG_ERR_CREATE_DIR_FAIL
;
1981 * Get current kernel tracer status
1983 enum lttng_kernel_tracer_status
get_kernel_tracer_status()
1985 if (!kernel_tracer_status
) {
1986 return LTTNG_KERNEL_TRACER_STATUS_ERR_UNKNOWN
;
1989 return *kernel_tracer_status
;
1993 * Sets the kernel tracer status based on the positive errno code
1995 void set_kernel_tracer_status_from_modules_ret(int code
)
2000 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2001 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_MISSING
);
2009 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2010 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_SIGNATURE
);
2015 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2016 LTTNG_KERNEL_TRACER_STATUS_ERR_MODULES_UNKNOWN
);
2023 * Setup necessary data for kernel tracer action.
2025 int init_kernel_tracer()
2028 bool is_root
= !getuid();
2030 const auto log_status_on_exit
= lttng::make_scope_exit([]() noexcept
{
2031 DBG_FMT("Kernel tracer status set to `{}`",
2032 kernel_tracer_status_to_str(*kernel_tracer_status
));
2035 /* Modprobe lttng kernel modules */
2036 ret
= modprobe_lttng_control();
2038 set_kernel_tracer_status_from_modules_ret(-ret
);
2042 /* Open debugfs lttng */
2043 kernel_tracer_fd
= open(module_proc_lttng
, O_RDWR
);
2044 if (kernel_tracer_fd
< 0) {
2045 DBG("Failed to open %s", module_proc_lttng
);
2046 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2047 LTTNG_KERNEL_TRACER_STATUS_ERR_OPEN_PROC_LTTNG
);
2051 /* Validate kernel version */
2052 ret
= kernel_validate_version(&the_kernel_tracer_version
, &the_kernel_tracer_abi_version
);
2054 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2055 LTTNG_KERNEL_TRACER_STATUS_ERR_VERSION_MISMATCH
);
2059 ret
= modprobe_lttng_data();
2061 set_kernel_tracer_status_from_modules_ret(-ret
);
2065 ret
= kernel_supports_ring_buffer_snapshot_sample_positions();
2070 WARN("Kernel tracer does not support buffer monitoring. "
2071 "The monitoring timer of channels in the kernel domain "
2072 "will be set to 0 (disabled).");
2075 ret
= kernel_supports_event_notifiers();
2077 ERR("Failed to check for kernel tracer event notifier support");
2078 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2079 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2082 ret
= kernel_create_event_notifier_group(&kernel_tracer_event_notifier_group_fd
);
2084 /* This is not fatal. */
2085 WARN("Failed to create kernel event notifier group");
2086 kernel_tracer_event_notifier_group_fd
= -1;
2088 enum event_notifier_error_accounting_status error_accounting_status
;
2089 enum lttng_error_code error_code_ret
=
2090 kernel_create_event_notifier_group_notification_fd(
2091 &kernel_tracer_event_notifier_group_notification_fd
);
2093 if (error_code_ret
!= LTTNG_OK
) {
2094 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2095 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2099 error_accounting_status
= event_notifier_error_accounting_register_kernel(
2100 kernel_tracer_event_notifier_group_fd
);
2101 if (error_accounting_status
!= EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK
) {
2102 ERR("Failed to initialize event notifier error accounting for kernel tracer");
2103 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING
;
2104 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2105 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2109 kernel_token_to_event_notifier_rule_ht
= cds_lfht_new(
2110 DEFAULT_HT_SIZE
, 1, 0, CDS_LFHT_AUTO_RESIZE
| CDS_LFHT_ACCOUNTING
, nullptr);
2111 if (!kernel_token_to_event_notifier_rule_ht
) {
2112 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2113 LTTNG_KERNEL_TRACER_STATUS_ERR_NOTIFIER
);
2114 goto error_token_ht
;
2118 DBG("Kernel tracer initialized: kernel tracer fd = %d, event notifier group fd = %d, event notifier group notification fd = %d",
2120 kernel_tracer_event_notifier_group_fd
,
2121 kernel_tracer_event_notifier_group_notification_fd
);
2123 ret
= syscall_init_table(kernel_tracer_fd
);
2125 ERR("Unable to populate syscall table. Syscall tracing won't "
2126 "work for this session daemon.");
2129 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2130 LTTNG_KERNEL_TRACER_STATUS_INITIALIZED
);
2134 modprobe_remove_lttng_control();
2135 ret
= close(kernel_tracer_fd
);
2137 PERROR("Failed to close kernel tracer file descriptor: fd = %d", kernel_tracer_fd
);
2140 kernel_tracer_fd
= -1;
2141 return LTTNG_ERR_KERN_VERSION
;
2144 ret
= close(kernel_tracer_event_notifier_group_notification_fd
);
2146 PERROR("Failed to close kernel tracer event notifier group notification file descriptor: fd = %d",
2147 kernel_tracer_event_notifier_group_notification_fd
);
2150 kernel_tracer_event_notifier_group_notification_fd
= -1;
2153 ret
= close(kernel_tracer_event_notifier_group_fd
);
2155 PERROR("Failed to close kernel tracer event notifier group file descriptor: fd = %d",
2156 kernel_tracer_event_notifier_group_fd
);
2159 kernel_tracer_event_notifier_group_fd
= -1;
2161 ret
= close(kernel_tracer_fd
);
2163 PERROR("Failed to close kernel tracer file descriptor: fd = %d", kernel_tracer_fd
);
2166 kernel_tracer_fd
= -1;
2169 modprobe_remove_lttng_control();
2172 WARN("No kernel tracer available");
2173 kernel_tracer_fd
= -1;
2175 kernel_tracer_status
= nonstd::optional
<enum lttng_kernel_tracer_status
>(
2176 LTTNG_KERNEL_TRACER_STATUS_ERR_NEED_ROOT
);
2177 return LTTNG_ERR_NEED_ROOT_SESSIOND
;
2179 return LTTNG_ERR_KERN_NA
;
2183 void cleanup_kernel_tracer()
2185 DBG2("Closing kernel event notifier group notification file descriptor");
2186 if (kernel_tracer_event_notifier_group_notification_fd
>= 0) {
2187 int ret
= notification_thread_command_remove_tracer_event_source(
2188 the_notification_thread_handle
,
2189 kernel_tracer_event_notifier_group_notification_fd
);
2190 if (ret
!= LTTNG_OK
) {
2191 ERR("Failed to remove kernel event notifier notification from notification thread");
2194 ret
= close(kernel_tracer_event_notifier_group_notification_fd
);
2196 PERROR("Failed to close kernel event notifier group notification file descriptor: fd = %d",
2197 kernel_tracer_event_notifier_group_notification_fd
);
2200 kernel_tracer_event_notifier_group_notification_fd
= -1;
2203 if (kernel_token_to_event_notifier_rule_ht
) {
2204 const int ret
= cds_lfht_destroy(kernel_token_to_event_notifier_rule_ht
, nullptr);
2205 LTTNG_ASSERT(ret
== 0);
2208 DBG2("Closing kernel event notifier group file descriptor");
2209 if (kernel_tracer_event_notifier_group_fd
>= 0) {
2210 const int ret
= close(kernel_tracer_event_notifier_group_fd
);
2213 PERROR("Failed to close kernel event notifier group file descriptor: fd = %d",
2214 kernel_tracer_event_notifier_group_fd
);
2217 kernel_tracer_event_notifier_group_fd
= -1;
2220 DBG2("Closing kernel fd");
2221 if (kernel_tracer_fd
>= 0) {
2222 const int ret
= close(kernel_tracer_fd
);
2225 PERROR("Failed to close kernel tracer file descriptor: fd = %d",
2229 kernel_tracer_fd
= -1;
2232 kernel_tracer_status
= nonstd::nullopt
;
2233 free(syscall_table
);
2236 bool kernel_tracer_is_initialized()
2238 return kernel_tracer_fd
>= 0;
2242 * Clear a kernel session.
2244 * Return LTTNG_OK on success or else an LTTng error code.
2246 enum lttng_error_code
kernel_clear_session(struct ltt_session
*session
)
2249 enum lttng_error_code status
= LTTNG_OK
;
2250 struct consumer_socket
*socket
;
2251 struct lttng_ht_iter iter
;
2252 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2254 LTTNG_ASSERT(ksess
);
2255 LTTNG_ASSERT(ksess
->consumer
);
2257 DBG("Clear kernel session %s (session %" PRIu64
")", session
->name
, session
->id
);
2259 if (ksess
->active
) {
2260 ERR("Expecting inactive session %s (%" PRIu64
")", session
->name
, session
->id
);
2261 status
= LTTNG_ERR_FATAL
;
2267 * Note that this loop will end after one iteration given that there is
2268 * only one kernel consumer.
2270 lttng::urcu::read_lock_guard read_lock
;
2272 cds_lfht_for_each_entry (
2273 ksess
->consumer
->socks
->ht
, &iter
.iter
, socket
, node
.node
) {
2274 struct ltt_kernel_channel
*chan
;
2276 /* For each channel, ask the consumer to clear it. */
2277 cds_list_for_each_entry (chan
, &ksess
->channel_list
.head
, list
) {
2278 DBG("Clear kernel channel %" PRIu64
", session %s",
2281 ret
= consumer_clear_channel(socket
, chan
->key
);
2287 if (!ksess
->metadata
) {
2289 * Nothing to do for the metadata.
2290 * This is a snapshot session.
2291 * The metadata is genererated on the fly.
2297 * Clear the metadata channel.
2298 * Metadata channel is not cleared per se but we still need to
2299 * perform a rotation operation on it behind the scene.
2301 ret
= consumer_clear_channel(socket
, ksess
->metadata
->key
);
2311 case LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED
:
2312 status
= LTTNG_ERR_CLEAR_RELAY_DISALLOWED
;
2315 status
= LTTNG_ERR_CLEAR_FAIL_CONSUMER
;
2322 enum lttng_error_code
2323 kernel_create_event_notifier_group_notification_fd(int *event_notifier_group_notification_fd
)
2325 int local_fd
= -1, ret
;
2326 enum lttng_error_code error_code_ret
;
2328 LTTNG_ASSERT(event_notifier_group_notification_fd
);
2330 ret
= kernctl_create_event_notifier_group_notification_fd(
2331 kernel_tracer_event_notifier_group_fd
);
2333 PERROR("Failed to create kernel event notifier group notification file descriptor");
2334 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
;
2340 /* Prevent fd duplication after execlp(). */
2341 ret
= fcntl(local_fd
, F_SETFD
, FD_CLOEXEC
);
2343 PERROR("Failed to set FD_CLOEXEC on kernel event notifier group notification file descriptor: fd = %d",
2345 error_code_ret
= LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
;
2349 DBG("Created kernel notifier group notification file descriptor: fd = %d", local_fd
);
2350 error_code_ret
= LTTNG_OK
;
2351 *event_notifier_group_notification_fd
= local_fd
;
2355 if (local_fd
>= 0) {
2356 ret
= close(local_fd
);
2358 PERROR("Failed to close kernel event notifier group notification file descriptor: fd = %d",
2363 return error_code_ret
;
2366 enum lttng_error_code
2367 kernel_destroy_event_notifier_group_notification_fd(int event_notifier_group_notification_fd
)
2369 enum lttng_error_code ret_code
= LTTNG_OK
;
2371 DBG("Closing event notifier group notification file descriptor: fd = %d",
2372 event_notifier_group_notification_fd
);
2373 if (event_notifier_group_notification_fd
>= 0) {
2374 const int ret
= close(event_notifier_group_notification_fd
);
2376 PERROR("Failed to close event notifier group notification file descriptor: fd = %d",
2377 event_notifier_group_notification_fd
);
2384 static unsigned long hash_trigger(const struct lttng_trigger
*trigger
)
2386 const struct lttng_condition
*condition
= lttng_trigger_get_const_condition(trigger
);
2388 return lttng_condition_hash(condition
);
2391 static int match_trigger(struct cds_lfht_node
*node
, const void *key
)
2393 const struct ltt_kernel_event_notifier_rule
*event_notifier_rule
;
2394 const struct lttng_trigger
*trigger
= (lttng_trigger
*) key
;
2396 event_notifier_rule
=
2397 caa_container_of(node
, const struct ltt_kernel_event_notifier_rule
, ht_node
);
2399 return lttng_trigger_is_equal(trigger
, event_notifier_rule
->trigger
);
2402 static enum lttng_error_code
kernel_create_event_notifier_rule(
2403 struct lttng_trigger
*trigger
, const struct lttng_credentials
*creds
, uint64_t token
)
2405 int err
, fd
, ret
= 0;
2406 enum lttng_error_code error_code_ret
;
2407 enum lttng_condition_status condition_status
;
2408 enum lttng_condition_type condition_type
;
2409 enum lttng_event_rule_type event_rule_type
;
2410 struct ltt_kernel_event_notifier_rule
*event_notifier_rule
;
2411 struct lttng_kernel_abi_event_notifier kernel_event_notifier
= {};
2412 unsigned int capture_bytecode_count
= 0, i
;
2413 const struct lttng_condition
*condition
= nullptr;
2414 const struct lttng_event_rule
*event_rule
= nullptr;
2415 enum lttng_condition_status cond_status
;
2417 LTTNG_ASSERT(trigger
);
2419 condition
= lttng_trigger_get_const_condition(trigger
);
2420 LTTNG_ASSERT(condition
);
2422 condition_type
= lttng_condition_get_type(condition
);
2423 LTTNG_ASSERT(condition_type
== LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
);
2425 /* Does not acquire a reference. */
2426 condition_status
= lttng_condition_event_rule_matches_get_rule(condition
, &event_rule
);
2427 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
2428 LTTNG_ASSERT(event_rule
);
2430 event_rule_type
= lttng_event_rule_get_type(event_rule
);
2431 LTTNG_ASSERT(event_rule_type
!= LTTNG_EVENT_RULE_TYPE_UNKNOWN
);
2433 error_code_ret
= trace_kernel_create_event_notifier_rule(
2436 lttng_condition_event_rule_matches_get_error_counter_index(condition
),
2437 &event_notifier_rule
);
2438 if (error_code_ret
!= LTTNG_OK
) {
2442 error_code_ret
= trace_kernel_init_event_notifier_from_event_rule(event_rule
,
2443 &kernel_event_notifier
);
2444 if (error_code_ret
!= LTTNG_OK
) {
2448 kernel_event_notifier
.event
.token
= event_notifier_rule
->token
;
2449 kernel_event_notifier
.error_counter_idx
=
2450 lttng_condition_event_rule_matches_get_error_counter_index(condition
);
2452 fd
= kernctl_create_event_notifier(kernel_tracer_event_notifier_group_fd
,
2453 &kernel_event_notifier
);
2457 error_code_ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
2460 WARN("Failed to create kernel event notifier: not notifier type not implemented");
2461 error_code_ret
= LTTNG_ERR_KERN_EVENT_ENOSYS
;
2464 WARN("Failed to create kernel event notifier: not found: name = '%s'",
2465 kernel_event_notifier
.event
.name
);
2466 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2469 PERROR("Failed to create kernel event notifier: error code = %d, name = '%s'",
2471 kernel_event_notifier
.event
.name
);
2472 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2477 event_notifier_rule
->fd
= fd
;
2478 /* Prevent fd duplication after execlp(). */
2479 err
= fcntl(event_notifier_rule
->fd
, F_SETFD
, FD_CLOEXEC
);
2481 PERROR("Failed to set FD_CLOEXEC on kernel event notifier file descriptor: fd = %d",
2483 error_code_ret
= LTTNG_ERR_FATAL
;
2484 goto set_cloexec_error
;
2487 if (event_notifier_rule
->filter
) {
2488 err
= kernctl_filter(event_notifier_rule
->fd
, event_notifier_rule
->filter
);
2492 error_code_ret
= LTTNG_ERR_FILTER_NOMEM
;
2495 error_code_ret
= LTTNG_ERR_FILTER_INVAL
;
2502 if (lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
) {
2503 ret
= userspace_probe_event_rule_add_callsites(
2504 event_rule
, creds
, event_notifier_rule
->fd
);
2506 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2507 goto add_callsite_error
;
2511 /* Set the capture bytecode if any. */
2512 cond_status
= lttng_condition_event_rule_matches_get_capture_descriptor_count(
2513 condition
, &capture_bytecode_count
);
2514 LTTNG_ASSERT(cond_status
== LTTNG_CONDITION_STATUS_OK
);
2516 for (i
= 0; i
< capture_bytecode_count
; i
++) {
2517 const struct lttng_bytecode
*capture_bytecode
=
2518 lttng_condition_event_rule_matches_get_capture_bytecode_at_index(condition
,
2521 if (capture_bytecode
== nullptr) {
2522 ERR("Unexpected NULL capture bytecode on condition");
2523 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2527 ret
= kernctl_capture(event_notifier_rule
->fd
, capture_bytecode
);
2529 ERR("Failed to set capture bytecode on event notifier rule fd: fd = %d",
2530 event_notifier_rule
->fd
);
2531 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2536 err
= kernctl_enable(event_notifier_rule
->fd
);
2540 error_code_ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
2543 PERROR("enable kernel event notifier");
2544 error_code_ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2550 /* Add trigger to kernel token mapping in the hash table. */
2552 lttng::urcu::read_lock_guard read_lock
;
2553 cds_lfht_add(kernel_token_to_event_notifier_rule_ht
,
2554 hash_trigger(trigger
),
2555 &event_notifier_rule
->ht_node
);
2558 DBG("Created kernel event notifier: name = '%s', fd = %d",
2559 kernel_event_notifier
.event
.name
,
2560 event_notifier_rule
->fd
);
2570 const int close_ret
= close(event_notifier_rule
->fd
);
2573 PERROR("Failed to close kernel event notifier file descriptor: fd = %d",
2574 event_notifier_rule
->fd
);
2578 free(event_notifier_rule
);
2580 return error_code_ret
;
2583 enum lttng_error_code
kernel_register_event_notifier(struct lttng_trigger
*trigger
,
2584 const struct lttng_credentials
*cmd_creds
)
2586 enum lttng_error_code ret
;
2587 enum lttng_condition_status status
;
2588 enum lttng_domain_type domain_type
;
2589 const struct lttng_event_rule
*event_rule
;
2590 const struct lttng_condition
*const condition
= lttng_trigger_get_const_condition(trigger
);
2591 const uint64_t token
= lttng_trigger_get_tracer_token(trigger
);
2593 LTTNG_ASSERT(condition
);
2595 /* Does not acquire a reference to the event rule. */
2596 status
= lttng_condition_event_rule_matches_get_rule(condition
, &event_rule
);
2597 LTTNG_ASSERT(status
== LTTNG_CONDITION_STATUS_OK
);
2599 domain_type
= lttng_event_rule_get_domain_type(event_rule
);
2600 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2602 ret
= kernel_create_event_notifier_rule(trigger
, cmd_creds
, token
);
2603 if (ret
!= LTTNG_OK
) {
2604 ERR("Failed to create kernel event notifier rule");
2610 enum lttng_error_code
kernel_unregister_event_notifier(const struct lttng_trigger
*trigger
)
2612 struct ltt_kernel_event_notifier_rule
*token_event_rule_element
;
2613 struct cds_lfht_node
*node
;
2614 struct cds_lfht_iter iter
;
2615 enum lttng_error_code error_code_ret
;
2618 lttng::urcu::read_lock_guard read_lock
;
2620 cds_lfht_lookup(kernel_token_to_event_notifier_rule_ht
,
2621 hash_trigger(trigger
),
2626 node
= cds_lfht_iter_get_node(&iter
);
2628 error_code_ret
= LTTNG_ERR_TRIGGER_NOT_FOUND
;
2632 token_event_rule_element
=
2633 caa_container_of(node
, struct ltt_kernel_event_notifier_rule
, ht_node
);
2635 ret
= kernel_disable_event_notifier_rule(token_event_rule_element
);
2637 error_code_ret
= LTTNG_ERR_FATAL
;
2641 trace_kernel_destroy_event_notifier_rule(token_event_rule_element
);
2642 error_code_ret
= LTTNG_OK
;
2646 return error_code_ret
;
2649 int kernel_get_notification_fd()
2651 return kernel_tracer_event_notifier_group_notification_fd
;