2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <common/common.h>
27 #include <common/kernel-ctl/kernel-ctl.h>
28 #include <common/kernel-ctl/kernel-ioctl.h>
29 #include <common/sessiond-comm/sessiond-comm.h>
33 #include "kernel-consumer.h"
34 #include "kern-modules.h"
39 * Key used to reference a channel between the sessiond and the consumer. This
40 * is only read and updated with the session_list lock held.
42 static uint64_t next_kernel_channel_key
;
45 * Add context on a kernel channel.
47 * Assumes the ownership of ctx.
49 int kernel_add_channel_context(struct ltt_kernel_channel
*chan
,
50 struct ltt_kernel_context
*ctx
)
57 DBG("Adding context to channel %s", chan
->channel
->name
);
58 ret
= kernctl_add_context(chan
->fd
, &ctx
->ctx
);
62 /* Exists but not available for this kernel */
63 ret
= LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE
;
66 /* If EEXIST, we just ignore the error */
70 PERROR("add context ioctl");
71 ret
= LTTNG_ERR_KERN_CONTEXT_FAIL
;
78 cds_list_add_tail(&ctx
->list
, &chan
->ctx_list
);
83 trace_kernel_destroy_context(ctx
);
89 * Create a new kernel session, register it to the kernel tracer and add it to
90 * the session daemon session.
92 int kernel_create_session(struct ltt_session
*session
, int tracer_fd
)
95 struct ltt_kernel_session
*lks
;
99 /* Allocate data structure */
100 lks
= trace_kernel_create_session();
106 /* Kernel tracer session creation */
107 ret
= kernctl_create_session(tracer_fd
);
109 PERROR("ioctl kernel create session");
114 /* Prevent fd duplication after execlp() */
115 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
117 PERROR("fcntl session fd");
120 lks
->id
= session
->id
;
121 lks
->consumer_fds_sent
= 0;
122 session
->kernel_session
= lks
;
124 DBG("Kernel session created (fd: %d)", lks
->fd
);
130 trace_kernel_destroy_session(lks
);
136 * Create a kernel channel, register it to the kernel tracer and add it to the
139 int kernel_create_channel(struct ltt_kernel_session
*session
,
140 struct lttng_channel
*chan
)
143 struct ltt_kernel_channel
*lkc
;
148 /* Allocate kernel channel */
149 lkc
= trace_kernel_create_channel(chan
);
154 DBG3("Kernel create channel %s with attr: %d, %" PRIu64
", %" PRIu64
", %u, %u, %d, %d",
155 chan
->name
, lkc
->channel
->attr
.overwrite
,
156 lkc
->channel
->attr
.subbuf_size
, lkc
->channel
->attr
.num_subbuf
,
157 lkc
->channel
->attr
.switch_timer_interval
, lkc
->channel
->attr
.read_timer_interval
,
158 lkc
->channel
->attr
.live_timer_interval
, lkc
->channel
->attr
.output
);
160 /* Kernel tracer channel creation */
161 ret
= kernctl_create_channel(session
->fd
, &lkc
->channel
->attr
);
163 PERROR("ioctl kernel create channel");
167 /* Setup the channel fd */
169 /* Prevent fd duplication after execlp() */
170 ret
= fcntl(lkc
->fd
, F_SETFD
, FD_CLOEXEC
);
172 PERROR("fcntl session fd");
175 /* Add channel to session */
176 cds_list_add(&lkc
->list
, &session
->channel_list
.head
);
177 session
->channel_count
++;
178 lkc
->session
= session
;
179 lkc
->key
= ++next_kernel_channel_key
;
181 DBG("Kernel channel %s created (fd: %d, key: %" PRIu64
")",
182 lkc
->channel
->name
, lkc
->fd
, lkc
->key
);
195 * Create a kernel event, enable it to the kernel tracer and add it to the
196 * channel event list of the kernel session.
197 * We own filter_expression and filter.
199 int kernel_create_event(struct lttng_event
*ev
,
200 struct ltt_kernel_channel
*channel
,
201 char *filter_expression
,
202 struct lttng_filter_bytecode
*filter
)
205 struct ltt_kernel_event
*event
;
210 /* We pass ownership of filter_expression and filter */
211 event
= trace_kernel_create_event(ev
, filter_expression
,
218 ret
= kernctl_create_event(channel
->fd
, event
->event
);
224 WARN("Event type not implemented");
227 WARN("Event %s not found!", ev
->name
);
230 PERROR("create event ioctl");
235 event
->type
= ev
->type
;
237 /* Prevent fd duplication after execlp() */
238 ret
= fcntl(event
->fd
, F_SETFD
, FD_CLOEXEC
);
240 PERROR("fcntl session fd");
244 ret
= kernctl_filter(event
->fd
, filter
);
250 ret
= kernctl_enable(event
->fd
);
254 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
257 PERROR("enable kernel event");
263 /* Add event to event list */
264 cds_list_add(&event
->list
, &channel
->events_list
.head
);
265 channel
->event_count
++;
267 DBG("Event %s created (fd: %d)", ev
->name
, event
->fd
);
276 closeret
= close(event
->fd
);
278 PERROR("close event fd");
288 * Disable a kernel channel.
290 int kernel_disable_channel(struct ltt_kernel_channel
*chan
)
296 ret
= kernctl_disable(chan
->fd
);
298 PERROR("disable chan ioctl");
303 DBG("Kernel channel %s disabled (fd: %d, key: %" PRIu64
")",
304 chan
->channel
->name
, chan
->fd
, chan
->key
);
313 * Enable a kernel channel.
315 int kernel_enable_channel(struct ltt_kernel_channel
*chan
)
321 ret
= kernctl_enable(chan
->fd
);
322 if (ret
< 0 && ret
!= -EEXIST
) {
323 PERROR("Enable kernel chan");
328 DBG("Kernel channel %s enabled (fd: %d, key: %" PRIu64
")",
329 chan
->channel
->name
, chan
->fd
, chan
->key
);
338 * Enable a kernel event.
340 int kernel_enable_event(struct ltt_kernel_event
*event
)
346 ret
= kernctl_enable(event
->fd
);
350 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
353 PERROR("enable kernel event");
360 DBG("Kernel event %s enabled (fd: %d)", event
->event
->name
, event
->fd
);
369 * Disable a kernel event.
371 int kernel_disable_event(struct ltt_kernel_event
*event
)
377 ret
= kernctl_disable(event
->fd
);
381 ret
= LTTNG_ERR_KERN_EVENT_EXIST
;
384 PERROR("disable kernel event");
391 DBG("Kernel event %s disabled (fd: %d)", event
->event
->name
, event
->fd
);
400 int kernel_track_pid(struct ltt_kernel_session
*session
, int pid
)
404 DBG("Kernel track PID %d for session id %" PRIu64
".",
406 ret
= kernctl_track_pid(session
->fd
, pid
);
412 return LTTNG_ERR_INVALID
;
414 return LTTNG_ERR_NOMEM
;
416 return LTTNG_ERR_PID_TRACKED
;
418 return LTTNG_ERR_UNK
;
422 int kernel_untrack_pid(struct ltt_kernel_session
*session
, int pid
)
426 DBG("Kernel untrack PID %d for session id %" PRIu64
".",
428 ret
= kernctl_untrack_pid(session
->fd
, pid
);
434 return LTTNG_ERR_INVALID
;
436 return LTTNG_ERR_NOMEM
;
438 return LTTNG_ERR_PID_NOT_TRACKED
;
440 return LTTNG_ERR_UNK
;
444 ssize_t
kernel_list_tracker_pids(struct ltt_kernel_session
*session
,
449 ssize_t nbmem
, count
= 0;
453 fd
= kernctl_list_tracker_pids(session
->fd
);
455 PERROR("kernel tracker pids list");
459 fp
= fdopen(fd
, "r");
461 PERROR("kernel tracker pids list fdopen");
465 nbmem
= KERNEL_TRACKER_PIDS_INIT_LIST_SIZE
;
466 pids
= zmalloc(sizeof(*pids
) * nbmem
);
468 PERROR("alloc list pids");
473 while (fscanf(fp
, "process { pid = %u; };\n", &pid
) == 1) {
474 if (count
>= nbmem
) {
478 new_nbmem
= nbmem
<< 1;
479 DBG("Reallocating pids list from %zu to %zu entries",
481 new_pids
= realloc(pids
, new_nbmem
* sizeof(*new_pids
));
482 if (new_pids
== NULL
) {
483 PERROR("realloc list events");
488 /* Zero the new memory */
489 memset(new_pids
+ nbmem
, 0,
490 (new_nbmem
- nbmem
) * sizeof(*new_pids
));
498 DBG("Kernel list tracker pids done (%zd pids)", count
);
500 ret
= fclose(fp
); /* closes both fp and fd */
516 * Create kernel metadata, open from the kernel tracer and add it to the
519 int kernel_open_metadata(struct ltt_kernel_session
*session
)
522 struct ltt_kernel_metadata
*lkm
= NULL
;
526 /* Allocate kernel metadata */
527 lkm
= trace_kernel_create_metadata();
532 /* Kernel tracer metadata creation */
533 ret
= kernctl_open_metadata(session
->fd
, &lkm
->conf
->attr
);
539 lkm
->key
= ++next_kernel_channel_key
;
540 /* Prevent fd duplication after execlp() */
541 ret
= fcntl(lkm
->fd
, F_SETFD
, FD_CLOEXEC
);
543 PERROR("fcntl session fd");
546 session
->metadata
= lkm
;
548 DBG("Kernel metadata opened (fd: %d)", lkm
->fd
);
553 trace_kernel_destroy_metadata(lkm
);
559 * Start tracing session.
561 int kernel_start_session(struct ltt_kernel_session
*session
)
567 ret
= kernctl_start_session(session
->fd
);
569 PERROR("ioctl start session");
573 DBG("Kernel session started");
582 * Make a kernel wait to make sure in-flight probe have completed.
584 void kernel_wait_quiescent(int fd
)
588 DBG("Kernel quiescent wait on %d", fd
);
590 ret
= kernctl_wait_quiescent(fd
);
592 PERROR("wait quiescent ioctl");
593 ERR("Kernel quiescent wait failed");
598 * Force flush buffer of metadata.
600 int kernel_metadata_flush_buffer(int fd
)
604 DBG("Kernel flushing metadata buffer on fd %d", fd
);
606 ret
= kernctl_buffer_flush(fd
);
608 ERR("Fail to flush metadata buffers %d (ret: %d)", fd
, ret
);
615 * Force flush buffer for channel.
617 int kernel_flush_buffer(struct ltt_kernel_channel
*channel
)
620 struct ltt_kernel_stream
*stream
;
624 DBG("Flush buffer for channel %s", channel
->channel
->name
);
626 cds_list_for_each_entry(stream
, &channel
->stream_list
.head
, list
) {
627 DBG("Flushing channel stream %d", stream
->fd
);
628 ret
= kernctl_buffer_flush(stream
->fd
);
631 ERR("Fail to flush buffer for stream %d (ret: %d)",
640 * Stop tracing session.
642 int kernel_stop_session(struct ltt_kernel_session
*session
)
648 ret
= kernctl_stop_session(session
->fd
);
653 DBG("Kernel session stopped");
662 * Open stream of channel, register it to the kernel tracer and add it
663 * to the stream list of the channel.
665 * Note: given that the streams may appear in random order wrt CPU
666 * number (e.g. cpu hotplug), the index value of the stream number in
667 * the stream name is not necessarily linked to the CPU number.
669 * Return the number of created stream. Else, a negative value.
671 int kernel_open_channel_stream(struct ltt_kernel_channel
*channel
)
674 struct ltt_kernel_stream
*lks
;
678 while ((ret
= kernctl_create_stream(channel
->fd
)) >= 0) {
679 lks
= trace_kernel_create_stream(channel
->channel
->name
,
680 channel
->stream_count
);
690 /* Prevent fd duplication after execlp() */
691 ret
= fcntl(lks
->fd
, F_SETFD
, FD_CLOEXEC
);
693 PERROR("fcntl session fd");
696 lks
->tracefile_size
= channel
->channel
->attr
.tracefile_size
;
697 lks
->tracefile_count
= channel
->channel
->attr
.tracefile_count
;
699 /* Add stream to channel stream list */
700 cds_list_add(&lks
->list
, &channel
->stream_list
.head
);
701 channel
->stream_count
++;
703 DBG("Kernel stream %s created (fd: %d, state: %d)", lks
->name
, lks
->fd
,
707 return channel
->stream_count
;
714 * Open the metadata stream and set it to the kernel session.
716 int kernel_open_metadata_stream(struct ltt_kernel_session
*session
)
722 ret
= kernctl_create_stream(session
->metadata
->fd
);
724 PERROR("kernel create metadata stream");
728 DBG("Kernel metadata stream created (fd: %d)", ret
);
729 session
->metadata_stream_fd
= ret
;
730 /* Prevent fd duplication after execlp() */
731 ret
= fcntl(session
->metadata_stream_fd
, F_SETFD
, FD_CLOEXEC
);
733 PERROR("fcntl session fd");
743 * Get the event list from the kernel tracer and return the number of elements.
745 ssize_t
kernel_list_events(int tracer_fd
, struct lttng_event
**events
)
749 size_t nbmem
, count
= 0;
751 struct lttng_event
*elist
;
755 fd
= kernctl_tracepoint_list(tracer_fd
);
757 PERROR("kernel tracepoint list");
761 fp
= fdopen(fd
, "r");
763 PERROR("kernel tracepoint list fdopen");
768 * Init memory size counter
769 * See kernel-ctl.h for explanation of this value
771 nbmem
= KERNEL_EVENT_INIT_LIST_SIZE
;
772 elist
= zmalloc(sizeof(struct lttng_event
) * nbmem
);
774 PERROR("alloc list events");
779 while (fscanf(fp
, "event { name = %m[^;]; };\n", &event
) == 1) {
780 if (count
>= nbmem
) {
781 struct lttng_event
*new_elist
;
784 new_nbmem
= nbmem
<< 1;
785 DBG("Reallocating event list from %zu to %zu bytes",
787 new_elist
= realloc(elist
, new_nbmem
* sizeof(struct lttng_event
));
788 if (new_elist
== NULL
) {
789 PERROR("realloc list events");
795 /* Zero the new memory */
796 memset(new_elist
+ nbmem
, 0,
797 (new_nbmem
- nbmem
) * sizeof(struct lttng_event
));
801 strncpy(elist
[count
].name
, event
, LTTNG_SYMBOL_NAME_LEN
);
802 elist
[count
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
803 elist
[count
].enabled
= -1;
809 DBG("Kernel list events done (%zu events)", count
);
811 ret
= fclose(fp
); /* closes both fp and fd */
827 * Get kernel version and validate it.
829 int kernel_validate_version(int tracer_fd
,
830 struct lttng_kernel_tracer_version
*version
,
831 struct lttng_kernel_tracer_abi_version
*abi_version
)
835 ret
= kernctl_tracer_version(tracer_fd
, version
);
837 ERR("Failed to retrieve the lttng-modules version");
841 /* Validate version */
842 if (version
->major
!= VERSION_MAJOR
) {
843 ERR("Kernel tracer major version (%d) is not compatible with lttng-tools major version (%d)",
844 version
->major
, VERSION_MAJOR
);
847 ret
= kernctl_tracer_abi_version(tracer_fd
, abi_version
);
849 ERR("Failed to retrieve lttng-modules ABI version");
852 if (abi_version
->major
!= LTTNG_MODULES_ABI_MAJOR_VERSION
) {
853 ERR("Kernel tracer ABI version (%d.%d) does not match the expected ABI major version (%d.*)",
854 abi_version
->major
, abi_version
->minor
,
855 LTTNG_MODULES_ABI_MAJOR_VERSION
);
858 DBG2("Kernel tracer version validated (%d.%d, ABI %d.%d)",
859 version
->major
, version
->minor
,
860 abi_version
->major
, abi_version
->minor
);
867 ERR("Kernel tracer version check failed; kernel tracing will not be available");
872 * Kernel work-arounds called at the start of sessiond main().
874 int init_kernel_workarounds(void)
880 * boot_id needs to be read once before being used concurrently
881 * to deal with a Linux kernel race. A fix is proposed for
882 * upstream, but the work-around is needed for older kernels.
884 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
891 ret
= fread(buf
, 1, sizeof(buf
), fp
);
893 /* Ignore error, we don't really care */
905 * Complete teardown of a kernel session.
907 void kernel_destroy_session(struct ltt_kernel_session
*ksess
)
910 DBG3("No kernel session when tearing down session");
914 DBG("Tearing down kernel session");
917 * Destroy channels on the consumer if at least one FD has been sent and we
918 * are in no output mode because the streams are in *no* monitor mode so we
919 * have to send a command to clean them up or else they leaked.
921 if (!ksess
->output_traces
&& ksess
->consumer_fds_sent
) {
923 struct consumer_socket
*socket
;
924 struct lttng_ht_iter iter
;
926 /* For each consumer socket. */
928 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
930 struct ltt_kernel_channel
*chan
;
932 /* For each channel, ask the consumer to destroy it. */
933 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
934 ret
= kernel_consumer_destroy_channel(socket
, chan
);
936 /* Consumer is probably dead. Use next socket. */
944 /* Close any relayd session */
945 consumer_output_send_destroy_relayd(ksess
->consumer
);
947 trace_kernel_destroy_session(ksess
);
951 * Destroy a kernel channel object. It does not do anything on the tracer side.
953 void kernel_destroy_channel(struct ltt_kernel_channel
*kchan
)
955 struct ltt_kernel_session
*ksess
= NULL
;
958 assert(kchan
->channel
);
960 DBG3("Kernel destroy channel %s", kchan
->channel
->name
);
962 /* Update channel count of associated session. */
963 if (kchan
->session
) {
964 /* Keep pointer reference so we can update it after the destroy. */
965 ksess
= kchan
->session
;
968 trace_kernel_destroy_channel(kchan
);
971 * At this point the kernel channel is not visible anymore. This is safe
972 * since in order to work on a visible kernel session, the tracing session
973 * lock (ltt_session.lock) MUST be acquired.
976 ksess
->channel_count
--;
981 * Take a snapshot for a given kernel session.
983 * Return 0 on success or else return a LTTNG_ERR code.
985 int kernel_snapshot_record(struct ltt_kernel_session
*ksess
,
986 struct snapshot_output
*output
, int wait
,
987 uint64_t nb_packets_per_stream
)
989 int err
, ret
, saved_metadata_fd
;
990 struct consumer_socket
*socket
;
991 struct lttng_ht_iter iter
;
992 struct ltt_kernel_metadata
*saved_metadata
;
995 assert(ksess
->consumer
);
998 DBG("Kernel snapshot record started");
1000 /* Save current metadata since the following calls will change it. */
1001 saved_metadata
= ksess
->metadata
;
1002 saved_metadata_fd
= ksess
->metadata_stream_fd
;
1006 ret
= kernel_open_metadata(ksess
);
1008 ret
= LTTNG_ERR_KERN_META_FAIL
;
1012 ret
= kernel_open_metadata_stream(ksess
);
1014 ret
= LTTNG_ERR_KERN_META_FAIL
;
1015 goto error_open_stream
;
1018 /* Send metadata to consumer and snapshot everything. */
1019 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
1020 socket
, node
.node
) {
1021 struct consumer_output
*saved_output
;
1022 struct ltt_kernel_channel
*chan
;
1025 * Temporarly switch consumer output for our snapshot output. As long
1026 * as the session lock is taken, this is safe.
1028 saved_output
= ksess
->consumer
;
1029 ksess
->consumer
= output
->consumer
;
1031 pthread_mutex_lock(socket
->lock
);
1032 /* This stream must not be monitored by the consumer. */
1033 ret
= kernel_consumer_add_metadata(socket
, ksess
, 0);
1034 pthread_mutex_unlock(socket
->lock
);
1035 /* Put back the saved consumer output into the session. */
1036 ksess
->consumer
= saved_output
;
1038 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1039 goto error_consumer
;
1042 /* For each channel, ask the consumer to snapshot it. */
1043 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
1044 ret
= consumer_snapshot_channel(socket
, chan
->key
, output
, 0,
1045 ksess
->uid
, ksess
->gid
,
1046 DEFAULT_KERNEL_TRACE_DIR
, wait
,
1047 nb_packets_per_stream
);
1049 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1050 (void) kernel_consumer_destroy_metadata(socket
,
1052 goto error_consumer
;
1056 /* Snapshot metadata, */
1057 ret
= consumer_snapshot_channel(socket
, ksess
->metadata
->key
, output
,
1058 1, ksess
->uid
, ksess
->gid
,
1059 DEFAULT_KERNEL_TRACE_DIR
, wait
, 0);
1061 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1062 goto error_consumer
;
1066 * The metadata snapshot is done, ask the consumer to destroy it since
1067 * it's not monitored on the consumer side.
1069 (void) kernel_consumer_destroy_metadata(socket
, ksess
->metadata
);
1075 /* Close newly opened metadata stream. It's now on the consumer side. */
1076 err
= close(ksess
->metadata_stream_fd
);
1078 PERROR("close snapshot kernel");
1082 trace_kernel_destroy_metadata(ksess
->metadata
);
1084 /* Restore metadata state.*/
1085 ksess
->metadata
= saved_metadata
;
1086 ksess
->metadata_stream_fd
= saved_metadata_fd
;
1093 * Get the syscall mask array from the kernel tracer.
1095 * Return 0 on success else a negative value. In both case, syscall_mask should
1098 int kernel_syscall_mask(int chan_fd
, char **syscall_mask
, uint32_t *nr_bits
)
1100 assert(syscall_mask
);
1103 return kernctl_syscall_mask(chan_fd
, syscall_mask
, nr_bits
);
1107 * Check for the support of the RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS via abi
1110 * Return 1 on success, 0 when feature is not supported, negative value in case
1113 int kernel_supports_ring_buffer_snapshot_sample_positions(int tracer_fd
)
1115 int ret
= 0; // Not supported by default
1116 struct lttng_kernel_tracer_abi_version abi
;
1118 ret
= kernctl_tracer_abi_version(tracer_fd
, &abi
);
1120 ERR("Failed to retrieve lttng-modules ABI version");
1125 * RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in 2.3
1127 if (abi
.major
>= 2 && abi
.minor
>= 3) {
1139 * Rotate a kernel session.
1141 * Return 0 on success or else return a LTTNG_ERR code.
1143 int kernel_rotate_session(struct ltt_session
*session
)
1146 struct consumer_socket
*socket
;
1147 struct lttng_ht_iter iter
;
1148 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
1151 assert(ksess
->consumer
);
1153 DBG("Rotate kernel session %s started (session %" PRIu64
")",
1154 session
->name
, session
->id
);
1159 * Note that this loop will end after one iteration given that there is
1160 * only one kernel consumer.
1162 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
1163 socket
, node
.node
) {
1164 struct ltt_kernel_channel
*chan
;
1167 * Account the metadata channel first to make sure the
1168 * number of channels waiting for a rotation cannot
1169 * reach 0 before we complete the iteration over all
1172 ret
= rotate_add_channel_pending(ksess
->metadata
->fd
,
1173 LTTNG_DOMAIN_KERNEL
, session
);
1175 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1179 /* For each channel, ask the consumer to rotate it. */
1180 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
1181 ret
= rotate_add_channel_pending(chan
->key
,
1182 LTTNG_DOMAIN_KERNEL
, session
);
1184 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1188 DBG("Rotate channel %" PRIu64
", session %s", chan
->key
, session
->name
);
1189 ret
= consumer_rotate_channel(socket
, chan
->key
,
1190 ksess
->uid
, ksess
->gid
, ksess
->consumer
,
1191 ksess
->consumer
->subdir
,
1192 /* is_metadata_channel */ false,
1193 session
->rotate_count
,
1194 &session
->rotate_pending_relay
);
1196 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
1202 * Rotate the metadata channel.
1204 ret
= consumer_rotate_channel(socket
, ksess
->metadata
->fd
,
1205 ksess
->uid
, ksess
->gid
, ksess
->consumer
,
1206 ksess
->consumer
->subdir
,
1207 /* is_metadata_channel */ true,
1208 session
->rotate_count
,
1209 &session
->rotate_pending_relay
);
1211 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;