return ret;
}
-int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
- int pipe)
+static
+int consumer_send_pipe(struct consumer_socket *consumer_sock,
+ enum lttng_consumer_command cmd, int pipe)
{
int ret;
struct lttcomm_consumer_msg msg;
+ const char *pipe_name;
+ const char *command_name;
+
+ switch (cmd) {
+ case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE:
+ pipe_name = "channel monitor";
+ command_name = "SET_CHANNEL_MONITOR_PIPE";
+ break;
+ case LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE:
+ pipe_name = "channel rotate";
+ command_name = "SET_CHANNEL_ROTATE_PIPE";
+ break;
+ default:
+ ERR("Unexpected command received in %s (cmd = %d)", __func__,
+ (int) cmd);
+ abort();
+ }
/* Code flow error. Safety net. */
memset(&msg, 0, sizeof(msg));
- msg.cmd_type = LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE;
+ msg.cmd_type = cmd;
pthread_mutex_lock(consumer_sock->lock);
- DBG3("Sending set_channel_monitor_pipe command to consumer");
+ DBG3("Sending %s command to consumer", command_name);
ret = consumer_send_msg(consumer_sock, &msg);
if (ret < 0) {
goto error;
}
- DBG3("Sending channel monitoring pipe %d to consumer on socket %d",
+ DBG3("Sending %s pipe %d to consumer on socket %d",
+ pipe_name,
pipe, *consumer_sock->fd_ptr);
ret = consumer_send_fds(consumer_sock, &pipe, 1);
if (ret < 0) {
goto error;
}
- DBG2("Channel monitoring pipe successfully sent");
+ DBG2("%s pipe successfully sent", pipe_name);
error:
pthread_mutex_unlock(consumer_sock->lock);
return ret;
}
+int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
+ int pipe)
+{
+ return consumer_send_pipe(consumer_sock,
+ LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE, pipe);
+}
+
+int consumer_send_channel_rotate_pipe(struct consumer_socket *consumer_sock,
+ int pipe)
+{
+ return consumer_send_pipe(consumer_sock,
+ LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE, pipe);
+}
+
/*
* Set consumer subdirectory using the session name and a generated datetime if
* needed. This is appended to the current subdirectory.
* consumer.
*/
int channel_monitor_pipe;
+ /*
+ * Write-end of the channel rotation pipe to be passed to the
+ * consumer.
+ */
+ int channel_rotate_pipe;
/*
* The metadata socket object is handled differently and only created
* locally in this object thus it's the only reference available in the
char *session_name, char *hostname, int session_live_timer);
int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
int pipe);
+int consumer_send_channel_rotate_pipe(struct consumer_socket *consumer_sock,
+ int pipe);
int consumer_send_destroy_relayd(struct consumer_socket *sock,
struct consumer_output *consumer);
int consumer_recv_status_reply(struct consumer_socket *sock);
.err_sock = -1,
.cmd_sock = -1,
.channel_monitor_pipe = -1,
+ .channel_rotate_pipe = -1,
.pid_mutex = PTHREAD_MUTEX_INITIALIZER,
.lock = PTHREAD_MUTEX_INITIALIZER,
.cond = PTHREAD_COND_INITIALIZER,
.err_sock = -1,
.cmd_sock = -1,
.channel_monitor_pipe = -1,
+ .channel_rotate_pipe = -1,
.pid_mutex = PTHREAD_MUTEX_INITIALIZER,
.lock = PTHREAD_MUTEX_INITIALIZER,
.cond = PTHREAD_COND_INITIALIZER,
.err_sock = -1,
.cmd_sock = -1,
.channel_monitor_pipe = -1,
+ .channel_rotate_pipe = -1,
.pid_mutex = PTHREAD_MUTEX_INITIALIZER,
.lock = PTHREAD_MUTEX_INITIALIZER,
.cond = PTHREAD_COND_INITIALIZER,
PERROR("UST consumerd64 channel monitor pipe close");
}
}
+ if (kconsumer_data.channel_rotate_pipe >= 0) {
+ ret = close(kconsumer_data.channel_rotate_pipe);
+ if (ret < 0) {
+ PERROR("kernel consumer channel rotate pipe close");
+ }
+ }
+ if (ustconsumer32_data.channel_rotate_pipe >= 0) {
+ ret = close(ustconsumer32_data.channel_rotate_pipe);
+ if (ret < 0) {
+ PERROR("UST consumerd32 channel rotate pipe close");
+ }
+ }
+ if (ustconsumer64_data.channel_rotate_pipe >= 0) {
+ ret = close(ustconsumer64_data.channel_rotate_pipe);
+ if (ret < 0) {
+ PERROR("UST consumerd64 channel rotate pipe close");
+ }
+ }
}
/*
health_code_update();
/*
- * Transfer the write-end of the channel monitoring pipe to the
- * by issuing a SET_CHANNEL_MONITOR_PIPE command.
+ * Transfer the write-end of the channel monitoring and rotate pipe
+ * to the consumer by issuing a SET_CHANNEL_MONITOR_PIPE and
+ * SET_CHANNEL_ROTATE_PIPE commands.
*/
cmd_socket_wrapper = consumer_allocate_socket(&consumer_data->cmd_sock);
if (!cmd_socket_wrapper) {
if (ret) {
goto error;
}
+
+ ret = consumer_send_channel_rotate_pipe(cmd_socket_wrapper,
+ consumer_data->channel_rotate_pipe);
+ if (ret) {
+ goto error;
+ }
+
/* Discard the socket wrapper as it is no longer needed. */
consumer_destroy_socket(cmd_socket_wrapper);
cmd_socket_wrapper = NULL;
*ust64_channel_monitor_pipe = NULL,
*kernel_channel_monitor_pipe = NULL;
bool notification_thread_running = false;
+ struct lttng_pipe *ust32_channel_rotate_pipe = NULL,
+ *ust64_channel_rotate_pipe = NULL,
+ *kernel_channel_rotate_pipe = NULL;
init_kernel_workarounds();
retval = -1;
goto exit_init_data;
}
+ kernel_channel_rotate_pipe = lttng_pipe_open(0);
+ if (!kernel_channel_rotate_pipe) {
+ ERR("Failed to create kernel consumer channel rotate pipe");
+ retval = -1;
+ goto exit_init_data;
+ }
+ kconsumer_data.channel_rotate_pipe =
+ lttng_pipe_release_writefd(
+ kernel_channel_rotate_pipe);
+ if (kconsumer_data.channel_rotate_pipe < 0) {
+ retval = -1;
+ goto exit_init_data;
+ }
}
lockfile_fd = create_lockfile();
retval = -1;
goto exit_init_data;
}
+ ust32_channel_rotate_pipe = lttng_pipe_open(0);
+ if (!ust32_channel_rotate_pipe) {
+ ERR("Failed to create 32-bit user space consumer channel rotate pipe");
+ retval = -1;
+ goto exit_init_data;
+ }
+ ustconsumer32_data.channel_rotate_pipe = lttng_pipe_release_writefd(
+ ust32_channel_rotate_pipe);
+ if (ustconsumer32_data.channel_rotate_pipe < 0) {
+ retval = -1;
+ goto exit_init_data;
+ }
+
ust64_channel_monitor_pipe = lttng_pipe_open(0);
if (!ust64_channel_monitor_pipe) {
retval = -1;
goto exit_init_data;
}
+ ust64_channel_rotate_pipe = lttng_pipe_open(0);
+ if (!ust64_channel_rotate_pipe) {
+ ERR("Failed to create 64-bit user space consumer channel rotate pipe");
+ retval = -1;
+ goto exit_init_data;
+ }
+ ustconsumer64_data.channel_rotate_pipe = lttng_pipe_release_writefd(
+ ust64_channel_rotate_pipe);
+ if (ustconsumer64_data.channel_rotate_pipe < 0) {
+ retval = -1;
+ goto exit_init_data;
+ }
/*
* See if daemon already exist.
lttng_pipe_destroy(ust32_channel_monitor_pipe);
lttng_pipe_destroy(ust64_channel_monitor_pipe);
lttng_pipe_destroy(kernel_channel_monitor_pipe);
+ lttng_pipe_destroy(ust32_channel_rotate_pipe);
+ lttng_pipe_destroy(ust64_channel_rotate_pipe);
+ lttng_pipe_destroy(kernel_channel_rotate_pipe);
exit_ht_cleanup:
health_app_destroy(health_sessiond);
LTTNG_CONSUMER_LOST_PACKETS,
LTTNG_CONSUMER_CLEAR_QUIESCENT_CHANNEL,
LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE,
+ LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE,
LTTNG_CONSUMER_ROTATE_RENAME,
LTTNG_CONSUMER_MKDIR,
};
* to the session daemon (write-only).
*/
int channel_monitor_pipe;
+ /*
+ * Pipe used to inform the session daemon that a stream has finished
+ * its rotation (write-only).
+ */
+ int channel_rotate_pipe;
};
/*
}
break;
}
+ case LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE:
+ {
+ int channel_rotate_pipe;
+ int flags;
+
+ ret_code = LTTCOMM_CONSUMERD_SUCCESS;
+ /* Successfully received the command's type. */
+ ret = consumer_send_status_msg(sock, ret_code);
+ if (ret < 0) {
+ goto error_fatal;
+ }
+
+ ret = lttcomm_recv_fds_unix_sock(sock, &channel_rotate_pipe, 1);
+ if (ret != (ssize_t) sizeof(channel_rotate_pipe)) {
+ ERR("Failed to receive channel rotate pipe");
+ goto error_fatal;
+ }
+
+ DBG("Received channel rotate pipe (%d)", channel_rotate_pipe);
+ ctx->channel_rotate_pipe = channel_rotate_pipe;
+ /* Set the pipe as non-blocking. */
+ ret = fcntl(channel_rotate_pipe, F_GETFL, 0);
+ if (ret == -1) {
+ PERROR("fcntl get flags of the channel rotate pipe");
+ goto error_fatal;
+ }
+ flags = ret;
+
+ ret = fcntl(channel_rotate_pipe, F_SETFL, flags | O_NONBLOCK);
+ if (ret == -1) {
+ PERROR("fcntl set O_NONBLOCK flag of the channel rotate pipe");
+ goto error_fatal;
+ }
+ DBG("Channel rotate pipe set as non-blocking");
+ ret_code = LTTCOMM_CONSUMERD_SUCCESS;
+ ret = consumer_send_status_msg(sock, ret_code);
+ if (ret < 0) {
+ goto error_fatal;
+ }
+ break;
+ }
case LTTNG_CONSUMER_ROTATE_RENAME:
{
DBG("Consumer rename session %" PRIu64 " after rotation, old path = \"%s\", new path = \"%s\"",
}
goto end_msg_sessiond;
}
+ case LTTNG_CONSUMER_SET_CHANNEL_ROTATE_PIPE:
+ {
+ int channel_rotate_pipe;
+ int flags;
+
+ ret_code = LTTCOMM_CONSUMERD_SUCCESS;
+ /* Successfully received the command's type. */
+ ret = consumer_send_status_msg(sock, ret_code);
+ if (ret < 0) {
+ goto error_fatal;
+ }
+
+ ret = lttcomm_recv_fds_unix_sock(sock, &channel_rotate_pipe, 1);
+ if (ret != sizeof(channel_rotate_pipe)) {
+ ERR("Failed to receive channel rotate pipe");
+ goto error_fatal;
+ }
+
+ DBG("Received channel rotate pipe (%d)", channel_rotate_pipe);
+ ctx->channel_rotate_pipe = channel_rotate_pipe;
+ /* Set the pipe as non-blocking. */
+ ret = fcntl(channel_rotate_pipe, F_GETFL, 0);
+ if (ret == -1) {
+ PERROR("fcntl get flags of the channel rotate pipe");
+ goto error_fatal;
+ }
+ flags = ret;
+
+ ret = fcntl(channel_rotate_pipe, F_SETFL, flags | O_NONBLOCK);
+ if (ret == -1) {
+ PERROR("fcntl set O_NONBLOCK flag of the channel rotate pipe");
+ goto error_fatal;
+ }
+ DBG("Channel rotate pipe set as non-blocking");
+ ret_code = LTTCOMM_CONSUMERD_SUCCESS;
+ ret = consumer_send_status_msg(sock, ret_code);
+ if (ret < 0) {
+ goto error_fatal;
+ }
+ break;
+ }
case LTTNG_CONSUMER_ROTATE_RENAME:
{
DBG("Consumer rename session %" PRIu64 " after rotation",