X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=869215b8d920cb7d2a0bd33d22129c34024e199e;hp=5a122d8d3c8dcf7e7f361b34f69f46c4680c0d22;hb=4dbe187595e8dc40516d6d9ce8a6a9c285f48a5e;hpb=1f4962443f25c371e4b54e97f9eb867d67cbf88e diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 5a122d8d3..869215b8d 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1185,6 +1185,7 @@ int cmd_setup_relayd(struct ltt_session *session) DBG("Setting relayd for session %s", session->name); + rcu_read_lock(); if (session->current_trace_chunk) { enum lttng_trace_chunk_status status = lttng_trace_chunk_get_id( session->current_trace_chunk, ¤t_chunk_id.value); @@ -1198,8 +1199,6 @@ int cmd_setup_relayd(struct ltt_session *session) } } - rcu_read_lock(); - if (usess && usess->consumer && usess->consumer->type == CONSUMER_DST_NET && usess->consumer->enabled) { /* For each consumer socket, send relayd sockets */ @@ -1261,7 +1260,7 @@ error: /* * Start a kernel session by opening all necessary streams. */ -static int start_kernel_session(struct ltt_kernel_session *ksess) +int start_kernel_session(struct ltt_kernel_session *ksess) { int ret; struct ltt_kernel_channel *kchan; @@ -1323,6 +1322,53 @@ error: return ret; } +int stop_kernel_session(struct ltt_kernel_session *ksess) +{ + struct ltt_kernel_channel *kchan; + bool error_occurred = false; + int ret; + + if (!ksess || !ksess->active) { + return LTTNG_OK; + } + DBG("Stopping kernel tracing"); + + ret = kernel_stop_session(ksess); + if (ret < 0) { + ret = LTTNG_ERR_KERN_STOP_FAIL; + goto error; + } + + kernel_wait_quiescent(); + + /* Flush metadata after stopping (if exists) */ + if (ksess->metadata_stream_fd >= 0) { + ret = kernel_metadata_flush_buffer(ksess->metadata_stream_fd); + if (ret < 0) { + ERR("Kernel metadata flush failed"); + error_occurred = true; + } + } + + /* Flush all buffers after stopping */ + cds_list_for_each_entry(kchan, &ksess->channel_list.head, list) { + ret = kernel_flush_buffer(kchan); + if (ret < 0) { + ERR("Kernel flush buffer error"); + error_occurred = true; + } + } + + ksess->active = 0; + if (error_occurred) { + ret = LTTNG_ERR_UNK; + } else { + ret = LTTNG_OK; + } +error: + return ret; +} + /* * Command LTTNG_DISABLE_CHANNEL processed by the client thread. */ @@ -2717,14 +2763,12 @@ error: int cmd_stop_trace(struct ltt_session *session) { int ret; - struct ltt_kernel_channel *kchan; struct ltt_kernel_session *ksession; struct ltt_ust_session *usess; - bool error_occurred = false; assert(session); - DBG("Begin stop session %s (id %" PRIu64 ")", session->name, session->id); + DBG("Begin stop session \"%s\" (id %" PRIu64 ")", session->name, session->id); /* Short cut */ ksession = session->kernel_session; usess = session->ust_session; @@ -2735,39 +2779,9 @@ int cmd_stop_trace(struct ltt_session *session) goto error; } - /* Kernel tracer */ - if (ksession && ksession->active) { - DBG("Stop kernel tracing"); - - ret = kernel_stop_session(ksession); - if (ret < 0) { - ret = LTTNG_ERR_KERN_STOP_FAIL; - goto error; - } - - kernel_wait_quiescent(); - - /* Flush metadata after stopping (if exists) */ - if (ksession->metadata_stream_fd >= 0) { - ret = kernel_metadata_flush_buffer(ksession->metadata_stream_fd); - if (ret < 0) { - ERR("Kernel metadata flush failed"); - error_occurred = true; - } - } - - /* Flush all buffers after stopping */ - cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) { - ret = kernel_flush_buffer(kchan); - if (ret < 0) { - ERR("Kernel flush buffer error"); - error_occurred = true; - } - } - - ksession->active = 0; - DBG("Kernel session stopped %s (id %" PRIu64 ")", session->name, - session->id); + ret = stop_kernel_session(ksession); + if (ret != LTTNG_OK) { + goto error; } if (usess && usess->active) { @@ -2778,9 +2792,11 @@ int cmd_stop_trace(struct ltt_session *session) } } + DBG("Completed stop session \"%s\" (id %" PRIu64 ")", session->name, + session->id); /* Flag inactive after a successful stop. */ session->active = 0; - ret = !error_occurred ? LTTNG_OK : LTTNG_ERR_UNK; + ret = LTTNG_OK; error: return ret; @@ -4908,6 +4924,12 @@ int cmd_rotate_session(struct ltt_session *session, goto end; } + /* Unsupported feature in lttng-modules before 2.8 (lack of sequence number). */ + if (session->kernel_session && !kernel_supports_ring_buffer_packet_sequence_number()) { + cmd_ret = LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL; + goto end; + } + if (session->rotation_state == LTTNG_ROTATION_STATE_ONGOING) { DBG("Refusing to launch a rotation; a rotation is already in progress for session %s", session->name); @@ -4925,9 +4947,6 @@ int cmd_rotate_session(struct ltt_session *session, cmd_ret = LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP; goto end; } - - session->rotation_state = LTTNG_ROTATION_STATE_ONGOING; - if (session->active) { new_trace_chunk = session_create_new_trace_chunk(session, NULL, NULL, NULL); @@ -4951,11 +4970,6 @@ int cmd_rotate_session(struct ltt_session *session, goto error; } - assert(chunk_being_archived); - chunk_status = lttng_trace_chunk_get_id(chunk_being_archived, - &ongoing_rotation_chunk_id); - assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); - if (session->kernel_session) { cmd_ret = kernel_rotate_session(session); if (cmd_ret != LTTNG_OK) { @@ -4971,6 +4985,26 @@ int cmd_rotate_session(struct ltt_session *session, } } + if (!session->active) { + session->rotated_after_last_stop = true; + } + + if (!chunk_being_archived) { + DBG("Rotating session \"%s\" from a \"NULL\" trace chunk to a new trace chunk, skipping completion check", + session->name); + if (failed_to_rotate) { + cmd_ret = rotation_fail_code; + goto error; + } + cmd_ret = LTTNG_OK; + goto end; + } + + session->rotation_state = LTTNG_ROTATION_STATE_ONGOING; + chunk_status = lttng_trace_chunk_get_id(chunk_being_archived, + &ongoing_rotation_chunk_id); + assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); + ret = session_close_trace_chunk(session, chunk_being_archived, quiet_rotation ? NULL : @@ -4995,10 +5029,6 @@ int cmd_rotate_session(struct ltt_session *session, goto error; } - if (!session->active) { - session->rotated_after_last_stop = true; - } - if (rotate_return) { rotate_return->rotation_id = ongoing_rotation_chunk_id; }