Fix: reintroduce lazy kernel modules load, fix empty syscall list
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index f6c44d3be16e63096e856874344dd39e11b4d348..82d92070398119fd60fce36adb55d17eb2aafc19 100644 (file)
@@ -1038,9 +1038,10 @@ static enum lttng_error_code send_consumer_relayd_socket(
                struct consumer_output *consumer,
                struct consumer_socket *consumer_sock,
                const char *session_name, const char *hostname,
-               int session_live_timer,
+               const char *base_path, int session_live_timer,
                const uint64_t *current_chunk_id,
-               time_t session_creation_time)
+               time_t session_creation_time,
+               bool session_name_contains_creation_time)
 {
        int ret;
        struct lttcomm_relayd_sock *rsock = NULL;
@@ -1068,8 +1069,9 @@ static enum lttng_error_code send_consumer_relayd_socket(
        /* Send relayd socket to consumer. */
        ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
                        relayd_uri->stype, session_id,
-                       session_name, hostname, session_live_timer,
-                       current_chunk_id, session_creation_time);
+                       session_name, hostname, base_path,
+                       session_live_timer, current_chunk_id,
+                       session_creation_time, session_name_contains_creation_time);
        if (ret < 0) {
                status = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -1116,8 +1118,9 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                enum lttng_domain_type domain,
                unsigned int session_id, struct consumer_output *consumer,
                struct consumer_socket *sock, const char *session_name,
-               const char *hostname, int session_live_timer,
-               const uint64_t *current_chunk_id, time_t session_creation_time)
+               const char *hostname, const char *base_path, int session_live_timer,
+               const uint64_t *current_chunk_id, time_t session_creation_time,
+               bool session_name_contains_creation_time)
 {
        enum lttng_error_code status = LTTNG_OK;
 
@@ -1128,8 +1131,9 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->control_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.control, consumer, sock,
-                               session_name, hostname, session_live_timer,
-                               current_chunk_id, session_creation_time);
+                               session_name, hostname, base_path, session_live_timer,
+                               current_chunk_id, session_creation_time,
+                               session_name_contains_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1139,8 +1143,9 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->data_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.data, consumer, sock,
-                               session_name, hostname, session_live_timer,
-                               current_chunk_id, session_creation_time);
+                               session_name, hostname, base_path, session_live_timer,
+                               current_chunk_id, session_creation_time,
+                               session_name_contains_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1195,9 +1200,11 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
                                        usess->consumer, socket,
                                        session->name, session->hostname,
+                                       session->base_path,
                                        session->live_timer,
                                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
-                                       session->creation_time);
+                                       session->creation_time,
+                                       session->name_contains_creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -1219,9 +1226,11 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
                                        ksess->consumer, socket,
                                        session->name, session->hostname,
+                                       session->base_path,
                                        session->live_timer,
                                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
-                                       session->creation_time);
+                                       session->creation_time,
+                                       session->name_contains_creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -1243,7 +1252,7 @@ error:
 /*
  * Start a kernel session by opening all necessary streams.
  */
-static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
+static int start_kernel_session(struct ltt_kernel_session *ksess)
 {
        int ret;
        struct ltt_kernel_channel *kchan;
@@ -1295,7 +1304,7 @@ static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
        }
 
        /* Quiescent wait after starting trace */
-       kernel_wait_quiescent(wpipe);
+       kernel_wait_quiescent();
 
        ksess->active = 1;
 
@@ -1327,7 +1336,7 @@ int cmd_disable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -1385,7 +1394,7 @@ int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain,
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -1436,7 +1445,7 @@ int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain,
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -1516,7 +1525,7 @@ int cmd_enable_channel(struct ltt_session *session,
        switch (domain->type) {
        case LTTNG_DOMAIN_KERNEL:
        {
-               if (kernel_supports_ring_buffer_snapshot_sample_positions(kernel_tracer_fd) != 1) {
+               if (kernel_supports_ring_buffer_snapshot_sample_positions() != 1) {
                        /* Sampling position of buffer is not supported */
                        WARN("Kernel tracer does not support buffer monitoring. "
                                        "Setting the monitor interval timer to 0 "
@@ -1567,7 +1576,7 @@ int cmd_enable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -1702,7 +1711,7 @@ int cmd_disable_event(struct ltt_session *session,
                        goto error_unlock;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -2152,7 +2161,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
                break;
        }
        case LTTNG_DOMAIN_UST:
@@ -2420,7 +2429,7 @@ ssize_t cmd_list_tracepoints(enum lttng_domain_type domain,
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
-               nb_events = kernel_list_events(kernel_tracer_fd, events);
+               nb_events = kernel_list_events(events);
                if (nb_events < 0) {
                        ret = LTTNG_ERR_KERN_LIST_FAIL;
                        goto error;
@@ -2579,8 +2588,7 @@ int cmd_start_trace(struct ltt_session *session)
                goto error;
        }
 
-       if (session->output_traces && !session->current_trace_chunk &&
-                       session_output_supports_trace_chunks(session)) {
+       if (session->output_traces && !session->current_trace_chunk) {
                struct lttng_trace_chunk *trace_chunk;
 
                trace_chunk = session_create_new_trace_chunk(
@@ -2601,7 +2609,7 @@ int cmd_start_trace(struct ltt_session *session)
        /* Kernel tracing */
        if (ksession != NULL) {
                DBG("Start kernel tracing session %s", session->name);
-               ret = start_kernel_session(ksession, kernel_tracer_fd);
+               ret = start_kernel_session(ksession);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -2678,7 +2686,7 @@ int cmd_stop_trace(struct ltt_session *session)
                        goto error;
                }
 
-               kernel_wait_quiescent(kernel_tracer_fd);
+               kernel_wait_quiescent();
 
                /* Flush metadata after stopping (if exists) */
                if (ksession->metadata_stream_fd >= 0) {
@@ -2872,6 +2880,7 @@ enum lttng_error_code cmd_create_session_from_descriptor(
        const char *session_name;
        struct ltt_session *new_session = NULL;
        enum lttng_session_descriptor_status descriptor_status;
+       const char *base_path;
 
        session_lock_list();
        if (home_path) {
@@ -2894,8 +2903,13 @@ enum lttng_error_code cmd_create_session_from_descriptor(
                ret_code = LTTNG_ERR_INVALID;
                goto end;
        }
+       ret = lttng_session_descriptor_get_base_path(descriptor, &base_path);
+       if (ret) {
+               ret_code = LTTNG_ERR_INVALID;
+               goto end;
+       }
        ret_code = session_create(session_name, creds->uid, creds->gid,
-                       &new_session);
+                       base_path, &new_session);
        if (ret_code != LTTNG_OK) {
                goto end;
        }
@@ -3176,7 +3190,7 @@ int cmd_destroy_session(struct ltt_session *session,
                 * Perform a last rotation on destruction if rotations have
                 * occurred during the session's lifetime.
                 */
-               ret = cmd_rotate_session(session, NULL);
+               ret = cmd_rotate_session(session, NULL, false);
                if (ret != LTTNG_OK) {
                        ERR("Failed to perform an implicit rotation as part of the destruction of session \"%s\": %s",
                                        session->name, lttng_strerror(-ret));
@@ -3184,7 +3198,22 @@ int cmd_destroy_session(struct ltt_session *session,
                 if (reply_context) {
                        reply_context->implicit_rotation_on_destroy = true;
                 }
-        }
+        } else if (session->has_been_started && session->current_trace_chunk) {
+               /*
+                * The user has not triggered a session rotation. However, to
+                * ensure all data has been consumed, the session is rotated
+                * to a 'null' trace chunk before it is destroyed.
+                *
+                * This is a "quiet" rotation meaning that no notification is
+                * emitted and no renaming of the current trace chunk takes
+                * place.
+                */
+               ret = cmd_rotate_session(session, NULL, true);
+               if (ret != LTTNG_OK) {
+                       ERR("Failed to perform a quiet rotation as part of the destruction of session \"%s\": %s",
+                                       session->name, lttng_strerror(-ret));
+               }
+       }
 
        if (session->shm_path[0]) {
                /*
@@ -4213,6 +4242,7 @@ static enum lttng_error_code set_relayd_for_snapshot(
        struct lttng_ht_iter iter;
        struct consumer_socket *socket;
        LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
+       const char *base_path;
 
        assert(output);
        assert(session);
@@ -4239,6 +4269,16 @@ static enum lttng_error_code set_relayd_for_snapshot(
                goto error;
        }
 
+       /*
+        * The snapshot record URI base path overrides the session
+        * base path.
+        */
+       if (output->dst.net.control.subdir[0] != '\0') {
+               base_path = output->dst.net.control.subdir;
+       } else {
+               base_path = session->base_path;
+       }
+
        /*
         * For each consumer socket, create and send the relayd object of the
         * snapshot output.
@@ -4250,9 +4290,11 @@ static enum lttng_error_code set_relayd_for_snapshot(
                status = send_consumer_relayd_sockets(0, session->id,
                                output, socket,
                                session->name, session->hostname,
+                               base_path,
                                session->live_timer,
                                current_chunk_id.is_set ? &current_chunk_id.value : NULL,
-                               session->creation_time);
+                               session->creation_time,
+                               session->name_contains_creation_time);
                pthread_mutex_unlock(socket->lock);
                if (status != LTTNG_OK) {
                        rcu_read_unlock();
@@ -4434,6 +4476,8 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
                                session->kernel_session->consumer;
                snapshot_kernel_consumer_output =
                                consumer_copy_output(snapshot_output->consumer);
+               strcpy(snapshot_kernel_consumer_output->chunk_path,
+                       snapshot_chunk_name);
                ret = consumer_copy_sockets(snapshot_kernel_consumer_output,
                                original_kernel_consumer_output);
                if (ret < 0) {
@@ -4454,6 +4498,8 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
                original_ust_consumer_output = session->ust_session->consumer;
                snapshot_ust_consumer_output =
                                consumer_copy_output(snapshot_output->consumer);
+               strcpy(snapshot_ust_consumer_output->chunk_path,
+                       snapshot_chunk_name);
                ret = consumer_copy_sockets(snapshot_ust_consumer_output,
                                original_ust_consumer_output);
                if (ret < 0) {
@@ -4520,7 +4566,7 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
        }
 
        if (session_close_trace_chunk(
-                           session, session->current_trace_chunk, NULL)) {
+                           session, session->current_trace_chunk, NULL, NULL)) {
                /*
                 * Don't goto end; make sure the chunk is closed for the session
                 * to allow future snapshots.
@@ -4713,7 +4759,8 @@ int cmd_set_session_shm_path(struct ltt_session *session,
  * Returns LTTNG_OK on success or else a negative LTTng error code.
  */
 int cmd_rotate_session(struct ltt_session *session,
-               struct lttng_rotate_session_return *rotate_return)
+               struct lttng_rotate_session_return *rotate_return,
+               bool quiet_rotation)
 {
        int ret;
        uint64_t ongoing_rotation_chunk_id;
@@ -4729,13 +4776,20 @@ int cmd_rotate_session(struct ltt_session *session,
                goto end;
        }
 
-       if (session->live_timer || !session->output_traces) {
+       /*
+        * Explicit rotation is not supported for live sessions.
+        * However, live sessions can perform a quiet rotation on
+        * destroy.
+        * Rotation is not supported for snapshot traces (no output).
+        */
+       if ((!quiet_rotation && session->live_timer) ||
+                       !session->output_traces) {
                cmd_ret = LTTNG_ERR_ROTATION_NOT_AVAILABLE;
                goto end;
        }
 
        /* Unsupported feature in lttng-relayd before 2.11. */
-       if (session->consumer->type == CONSUMER_DST_NET &&
+       if (!quiet_rotation && session->consumer->type == CONSUMER_DST_NET &&
                        (session->consumer->relay_major_version == 2 &&
                        session->consumer->relay_minor_version < 11)) {
                cmd_ret = LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY;
@@ -4798,13 +4852,17 @@ int cmd_rotate_session(struct ltt_session *session,
        }
 
        ret = session_close_trace_chunk(session, chunk_being_archived,
-                       &((enum lttng_trace_chunk_command_type) {
-                                       LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED}));
+                       quiet_rotation ?
+                                       NULL :
+                                       &((enum lttng_trace_chunk_command_type){
+                                                       LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED}),
+                       session->last_chunk_path);
        if (ret) {
                cmd_ret = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER;
                goto error;
        }
 
+       session->quiet_rotation = quiet_rotation;
        ret = timer_session_rotation_pending_check_start(session,
                        DEFAULT_ROTATE_PENDING_TIMER);
        if (ret) {
@@ -4822,14 +4880,16 @@ int cmd_rotate_session(struct ltt_session *session,
 
        session->chunk_being_archived = chunk_being_archived;
        chunk_being_archived = NULL;
-       ret = notification_thread_command_session_rotation_ongoing(
-                       notification_thread_handle,
-                       session->name, session->uid, session->gid,
-                       ongoing_rotation_chunk_id);
-       if (ret != LTTNG_OK) {
-               ERR("Failed to notify notification thread that a session rotation is ongoing for session %s",
-                               session->name);
-               cmd_ret = ret;
+       if (!quiet_rotation) {
+               ret = notification_thread_command_session_rotation_ongoing(
+                               notification_thread_handle,
+                               session->name, session->uid, session->gid,
+                               ongoing_rotation_chunk_id);
+               if (ret != LTTNG_OK) {
+                       ERR("Failed to notify notification thread that a session rotation is ongoing for session %s",
+                                       session->name);
+                       cmd_ret = ret;
+               }
        }
 
        DBG("Cmd rotate session %s, archive_id %" PRIu64 " sent",
@@ -4917,6 +4977,16 @@ int cmd_rotate_get_info(struct ltt_session *session,
                                        sizeof(info_return->location.local.absolute_path);
                        info_return->location_type =
                                        (int8_t) LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL;
+                       fmt_ret = asprintf(&chunk_path,
+                                       "%s/" DEFAULT_ARCHIVED_TRACE_CHUNKS_DIRECTORY "/%s",
+                                       session_get_base_path(session),
+                                       session->last_archived_chunk_name);
+                       if (fmt_ret == -1) {
+                               PERROR("Failed to format the path of the last archived trace chunk");
+                               info_return->status = LTTNG_ROTATION_STATUS_ERROR;
+                               cmd_ret = LTTNG_ERR_UNK;
+                               goto end;
+                       }
                        break;
                case CONSUMER_DST_NET:
                        current_tracing_path_reply =
@@ -4942,20 +5012,17 @@ int cmd_rotate_get_info(struct ltt_session *session,
                                        &info_return->location.relay.ports.data);
                        info_return->location_type =
                                        (int8_t) LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY;
+                       chunk_path = strdup(session->last_chunk_path);
+                       if (!chunk_path) {
+                               ERR("Failed to allocate the path of the last archived trace chunk");
+                               info_return->status = LTTNG_ROTATION_STATUS_ERROR;
+                               cmd_ret = LTTNG_ERR_UNK;
+                               goto end;
+                       }
                        break;
                default:
                        abort();
                }
-               fmt_ret = asprintf(&chunk_path,
-                               "%s/" DEFAULT_ARCHIVED_TRACE_CHUNKS_DIRECTORY "/%s",
-                               session_get_base_path(session),
-                               session->last_archived_chunk_name);
-               if (fmt_ret == -1) {
-                       PERROR("Failed to format the path of the last archived trace chunk");
-                       info_return->status = LTTNG_ROTATION_STATUS_ERROR;
-                       cmd_ret = LTTNG_ERR_UNK;
-                       goto end;
-               }
 
                fmt_ret = lttng_strncpy(current_tracing_path_reply,
                                chunk_path, current_tracing_path_reply_len);
This page took 0.030409 seconds and 4 git commands to generate.