From: Mathieu Desnoyers Date: Wed, 11 Dec 2019 18:46:11 +0000 (-0500) Subject: sessiond: cmd_rotate_session: introduce command argument X-Git-Tag: v2.12.0-rc1~139 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=343defc2671db532be8a9eed84907fd2e4044f0e;p=lttng-tools.git sessiond: cmd_rotate_session: introduce command argument Add a command type argument to cmd_rotate_session(). Change the internal session_close_trace_chunk() API to introduce the LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION command rather than rely on a NULL pointer, which facilitates passing of command argument across cmd_rotate_session. This introduces the LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE command, which is required for the clear feature. Its implementation will follow in a separate commit. Signed-off-by: Mathieu Desnoyers Change-Id: Ic1d8cbab1f98b93f1f6d27a2c6624ac2780932e2 Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c index 327c1fe17..551295efb 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.c @@ -1850,7 +1850,8 @@ error_add_context: } ret = cmd_rotate_session(cmd_ctx->session, &rotate_return, - false); + false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); if (ret < 0) { ret = -ret; goto error; diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 1977353e9..7af855eac 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -2715,7 +2715,8 @@ int cmd_start_trace(struct ltt_session *session) * was produced as the session was stopped, so the * rotation should happen on reception of the command. */ - ret = cmd_rotate_session(session, NULL, true); + ret = cmd_rotate_session(session, NULL, true, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION); if (ret != LTTNG_OK) { goto error; } @@ -3329,7 +3330,8 @@ 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, false); + ret = cmd_rotate_session(session, NULL, false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); 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)); @@ -3348,7 +3350,8 @@ int cmd_destroy_session(struct ltt_session *session, * emitted and no renaming of the current trace chunk takes * place. */ - ret = cmd_rotate_session(session, NULL, true); + ret = cmd_rotate_session(session, NULL, true, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION); 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)); @@ -4707,8 +4710,8 @@ enum lttng_error_code snapshot_record(struct ltt_session *session, } } - if (session_close_trace_chunk( - session, session->current_trace_chunk, NULL, NULL)) { + if (session_close_trace_chunk(session, session->current_trace_chunk, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION, NULL)) { /* * Don't goto end; make sure the chunk is closed for the session * to allow future snapshots. @@ -4902,7 +4905,8 @@ int cmd_set_session_shm_path(struct ltt_session *session, */ int cmd_rotate_session(struct ltt_session *session, struct lttng_rotate_session_return *rotate_return, - bool quiet_rotation) + bool quiet_rotation, + enum lttng_trace_chunk_command_type command) { int ret; uint64_t ongoing_rotation_chunk_id; @@ -5022,11 +5026,7 @@ int cmd_rotate_session(struct ltt_session *session, assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); ret = session_close_trace_chunk(session, chunk_being_archived, - quiet_rotation ? - NULL : - &((enum lttng_trace_chunk_command_type){ - LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED}), - session->last_chunk_path); + command, session->last_chunk_path); if (ret) { cmd_ret = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER; goto error; diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h index 87a40c884..2f9d9cdf7 100644 --- a/src/bin/lttng-sessiond/cmd.h +++ b/src/bin/lttng-sessiond/cmd.h @@ -135,7 +135,8 @@ int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock, int cmd_rotate_session(struct ltt_session *session, struct lttng_rotate_session_return *rotate_return, - bool quiet_rotation); + bool quiet_rotation, + enum lttng_trace_chunk_command_type command); int cmd_rotate_get_info(struct ltt_session *session, struct lttng_rotation_get_info_return *info_return, uint64_t rotate_id); diff --git a/src/bin/lttng-sessiond/rotation-thread.c b/src/bin/lttng-sessiond/rotation-thread.c index 659d8431d..54a3cc62d 100644 --- a/src/bin/lttng-sessiond/rotation-thread.c +++ b/src/bin/lttng-sessiond/rotation-thread.c @@ -537,7 +537,8 @@ int launch_session_rotation(struct ltt_session *session) DBG("[rotation-thread] Launching scheduled time-based rotation on session \"%s\"", session->name); - ret = cmd_rotate_session(session, &rotation_return, false); + ret = cmd_rotate_session(session, &rotation_return, false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); if (ret == LTTNG_OK) { DBG("[rotation-thread] Scheduled time-based rotation successfully launched on session \"%s\"", session->name); @@ -684,7 +685,8 @@ int handle_condition(const struct lttng_condition *condition, goto end_unlock; } - ret = cmd_rotate_session(session, NULL, false); + ret = cmd_rotate_session(session, NULL, false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); if (ret == -LTTNG_ERR_ROTATION_PENDING) { DBG("Rotate already pending, subscribe to the next threshold value"); } else if (ret != LTTNG_OK) { diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index ee71533f9..3a537e49e 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -662,9 +662,9 @@ error: goto end; } -int session_close_trace_chunk(const struct ltt_session *session, +int session_close_trace_chunk(struct ltt_session *session, struct lttng_trace_chunk *trace_chunk, - const enum lttng_trace_chunk_command_type *close_command, + enum lttng_trace_chunk_command_type close_command, char *closed_trace_chunk_path) { int ret = 0; @@ -674,13 +674,11 @@ int session_close_trace_chunk(const struct ltt_session *session, enum lttng_trace_chunk_status chunk_status; const time_t chunk_close_timestamp = time(NULL); - if (close_command) { - chunk_status = lttng_trace_chunk_set_close_command( - trace_chunk, *close_command); - if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) { - ret = -1; - goto end; - } + chunk_status = lttng_trace_chunk_set_close_command( + trace_chunk, close_command); + if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) { + ret = -1; + goto end; } if (chunk_close_timestamp == (time_t) -1) { diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index 20a7fcbc8..3625ece6d 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -251,9 +251,9 @@ int session_set_trace_chunk(struct ltt_session *session, * Close a chunk on the remote peers of a session. Has no effect on the * ltt_session itself. */ -int session_close_trace_chunk(const struct ltt_session *session, +int session_close_trace_chunk(struct ltt_session *session, struct lttng_trace_chunk *trace_chunk, - const enum lttng_trace_chunk_command_type *close_command, + enum lttng_trace_chunk_command_type close_command, char *path); bool session_output_supports_trace_chunks(const struct ltt_session *session); diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c index aadb40f6f..bba90f1ac 100644 --- a/src/common/trace-chunk.c +++ b/src/common/trace-chunk.c @@ -111,6 +111,10 @@ static const char *close_command_names[] = { [LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED] = "move to completed chunk folder", + [LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION] = + "no operation", + [LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE] = + "delete", }; static const @@ -1078,7 +1082,15 @@ enum lttng_trace_chunk_status lttng_trace_chunk_set_close_command( DBG("Setting trace chunk close command to \"%s\"", close_command_names[close_command]); } - LTTNG_OPTIONAL_SET(&chunk->close_command, close_command); + /* + * Unset close command for no-op for backward compatibility with relayd + * 2.11. + */ + if (close_command != LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION) { + LTTNG_OPTIONAL_SET(&chunk->close_command, close_command); + } else { + LTTNG_OPTIONAL_UNSET(&chunk->close_command); + } pthread_mutex_unlock(&chunk->lock); end: return status; @@ -1091,6 +1103,10 @@ const char *lttng_trace_chunk_command_type_get_name( switch (command) { case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED: return "move to completed trace chunk folder"; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION: + return "no operation"; + case LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE: + return "delete"; default: abort(); } diff --git a/src/common/trace-chunk.h b/src/common/trace-chunk.h index b90daf8ae..202a20ae2 100644 --- a/src/common/trace-chunk.h +++ b/src/common/trace-chunk.h @@ -73,7 +73,9 @@ enum lttng_trace_chunk_status { enum lttng_trace_chunk_command_type { LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED = 0, - LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX + LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION = 1, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_DELETE = 2, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MAX, }; LTTNG_HIDDEN