X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel-consumer.c;h=044b1a81f58f19540a527370beadade74a6f297c;hp=2a9bf9983d937223e5131ed5c0d374599c052000;hb=6dc3064a30b0cc7cfa9fdd22da1963525dfb7388;hpb=f50f23d9f80ed9fae7fe5c49aee65e813e0031c8 diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.c index 2a9bf9983..044b1a81f 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.c +++ b/src/bin/lttng-sessiond/kernel-consumer.c @@ -26,37 +26,87 @@ #include #include "consumer.h" +#include "health.h" #include "kernel-consumer.h" /* * Sending a single channel to the consumer with command ADD_CHANNEL. */ int kernel_consumer_add_channel(struct consumer_socket *sock, - struct ltt_kernel_channel *channel) + struct ltt_kernel_channel *channel, struct ltt_kernel_session *session) { int ret; + char tmp_path[PATH_MAX]; + const char *pathname; struct lttcomm_consumer_msg lkm; + struct consumer_output *consumer; /* Safety net */ assert(channel); + assert(session); + assert(session->consumer); + + consumer = session->consumer; DBG("Kernel consumer adding channel %s to kernel consumer", channel->channel->name); + /* Get the right path name destination */ + if (consumer->type == CONSUMER_DST_LOCAL) { + /* Set application path to the destination path */ + ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s", + consumer->dst.trace_path, consumer->subdir); + if (ret < 0) { + PERROR("snprintf metadata path"); + goto error; + } + pathname = tmp_path; + + /* Create directory */ + ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG, + session->uid, session->gid); + if (ret < 0) { + if (ret != -EEXIST) { + ERR("Trace directory creation error"); + goto error; + } + } + DBG3("Kernel local consumer tracefile path: %s", pathname); + } else { + ret = snprintf(tmp_path, sizeof(tmp_path), "%s", consumer->subdir); + if (ret < 0) { + PERROR("snprintf metadata path"); + goto error; + } + pathname = tmp_path; + DBG3("Kernel network consumer subdir path: %s", pathname); + } + /* Prep channel message structure */ consumer_init_channel_comm_msg(&lkm, LTTNG_CONSUMER_ADD_CHANNEL, channel->fd, - channel->channel->attr.subbuf_size, - 0, /* Kernel */ + session->id, + pathname, + session->uid, + session->gid, + consumer->net_seq_index, channel->channel->name, - channel->stream_count); + channel->stream_count, + channel->channel->attr.output, + CONSUMER_CHANNEL_TYPE_DATA, + channel->channel->attr.tracefile_size, + channel->channel->attr.tracefile_count); + + health_code_update(); ret = consumer_send_channel(sock, &lkm); if (ret < 0) { goto error; } + health_code_update(); + error: return ret; } @@ -65,7 +115,7 @@ error: * Sending metadata to the consumer with command ADD_CHANNEL and ADD_STREAM. */ int kernel_consumer_add_metadata(struct consumer_socket *sock, - struct ltt_kernel_session *session) + struct ltt_kernel_session *session, int no_monitor) { int ret; char tmp_path[PATH_MAX]; @@ -86,7 +136,7 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock, /* Get the right path name destination */ if (consumer->type == CONSUMER_DST_LOCAL) { /* Set application path to the destination path */ - ret = snprintf(tmp_path, sizeof(tmp_path), "%s/%s", + ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s", consumer->dst.trace_path, consumer->subdir); if (ret < 0) { PERROR("snprintf metadata path"); @@ -118,31 +168,42 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock, consumer_init_channel_comm_msg(&lkm, LTTNG_CONSUMER_ADD_CHANNEL, session->metadata->fd, - session->metadata->conf->attr.subbuf_size, - 0, /* for kernel */ - "metadata", - 1); + session->id, + pathname, + session->uid, + session->gid, + consumer->net_seq_index, + DEFAULT_METADATA_NAME, + 1, + DEFAULT_KERNEL_CHANNEL_OUTPUT, + CONSUMER_CHANNEL_TYPE_METADATA, + 0, 0); + + health_code_update(); ret = consumer_send_channel(sock, &lkm); if (ret < 0) { goto error; } + health_code_update(); + /* Prep stream message structure */ consumer_init_stream_comm_msg(&lkm, LTTNG_CONSUMER_ADD_STREAM, session->metadata->fd, session->metadata_stream_fd, - LTTNG_CONSUMER_ACTIVE_STREAM, - DEFAULT_KERNEL_CHANNEL_OUTPUT, - 0, /* Kernel */ - session->uid, - session->gid, - consumer->net_seq_index, - 1, /* Metadata flag set */ - "metadata", - pathname, - session->id); + 0); /* CPU: 0 for metadata. */ + + /* + * Set the no monitor flag. If set to 1, it indicates the consumer to NOT + * monitor the stream but rather add it to a special list in the associated + * channel. This is used to handle ephemeral stream used by the snapshot + * command or store streams for the flight recorder mode. + */ + lkm.u.stream.no_monitor = no_monitor; + + health_code_update(); /* Send stream and file descriptor */ ret = consumer_send_stream(sock, consumer, &lkm, @@ -151,6 +212,8 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock, goto error; } + health_code_update(); + error: return ret; } @@ -163,8 +226,6 @@ int kernel_consumer_add_stream(struct consumer_socket *sock, struct ltt_kernel_session *session) { int ret; - char tmp_path[PATH_MAX]; - const char *pathname; struct lttcomm_consumer_msg lkm; struct consumer_output *consumer; @@ -180,41 +241,14 @@ int kernel_consumer_add_stream(struct consumer_socket *sock, /* Get consumer output pointer */ consumer = session->consumer; - /* Get the right path name destination */ - if (consumer->type == CONSUMER_DST_LOCAL) { - /* Set application path to the destination path */ - ret = snprintf(tmp_path, sizeof(tmp_path), "%s/%s", - consumer->dst.trace_path, consumer->subdir); - if (ret < 0) { - PERROR("snprintf stream path"); - goto error; - } - pathname = tmp_path; - DBG3("Kernel local consumer tracefile path: %s", pathname); - } else { - ret = snprintf(tmp_path, sizeof(tmp_path), "%s", consumer->subdir); - if (ret < 0) { - PERROR("snprintf stream path"); - goto error; - } - pathname = tmp_path; - DBG3("Kernel network consumer subdir path: %s", pathname); - } - /* Prep stream consumer message */ - consumer_init_stream_comm_msg(&lkm, LTTNG_CONSUMER_ADD_STREAM, + consumer_init_stream_comm_msg(&lkm, + LTTNG_CONSUMER_ADD_STREAM, channel->fd, stream->fd, - stream->state, - channel->channel->attr.output, - 0, /* Kernel */ - session->uid, - session->gid, - consumer->net_seq_index, - 0, /* Metadata flag unset */ - stream->name, - pathname, - session->id); + stream->cpu); + + health_code_update(); /* Send stream and file descriptor */ ret = consumer_send_stream(sock, consumer, &lkm, &stream->fd, 1); @@ -222,6 +256,8 @@ int kernel_consumer_add_stream(struct consumer_socket *sock, goto error; } + health_code_update(); + error: return ret; } @@ -250,7 +286,7 @@ int kernel_consumer_send_channel_stream(struct consumer_socket *sock, DBG("Sending streams of channel %s to kernel consumer", channel->channel->name); - ret = kernel_consumer_add_channel(sock, channel); + ret = kernel_consumer_add_channel(sock, channel, session); if (ret < 0) { goto error; } @@ -295,7 +331,7 @@ int kernel_consumer_send_session(struct consumer_socket *sock, DBG("Sending session stream to kernel consumer"); if (session->metadata_stream_fd >= 0) { - ret = kernel_consumer_add_metadata(sock, session); + ret = kernel_consumer_add_metadata(sock, session, 0); if (ret < 0) { goto error; }