sessiond: cmd_rotate_session: introduce command argument
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 11 Dec 2019 18:46:11 +0000 (13:46 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Dec 2019 22:38:52 +0000 (17:38 -0500)
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 <mathieu.desnoyers@efficios.com>
Change-Id: Ic1d8cbab1f98b93f1f6d27a2c6624ac2780932e2
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/client.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/cmd.h
src/bin/lttng-sessiond/rotation-thread.c
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/session.h
src/common/trace-chunk.c
src/common/trace-chunk.h

index 327c1fe1706efabaefdf9dd2a3c5dc7fb4865c3e..551295efbe6d5d7194b8e2d59d4346e712a43ef3 100644 (file)
@@ -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;
index 1977353e9f6bec04c7fc74fc8eaaf84584bb017a..7af855eacb14e13b204730cdd2848f888c3bc352 100644 (file)
@@ -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;
index 87a40c884afda432bc393ae1fd18e1fa1c007747..2f9d9cdf74f4e81ce14766613bb505646d68d94c 100644 (file)
@@ -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);
index 659d8431dd39aec39dbcd7cba7eac3d4927b1ace..54a3cc62db9f8bd407561c1b465dde61f6c9eb0d 100644 (file)
@@ -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) {
index ee71533f9ff790e60e11fac522ac2c82c2f4e3c6..3a537e49e2179357298cb43813dfa17a6f63927d 100644 (file)
@@ -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) {
index 20a7fcbc86ed0d4ab2057b5364515734325e8546..3625ece6d4ce5196586c632025cc6567ab06557f 100644 (file)
@@ -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);
index aadb40f6f68383a174304cc912c2beb2880a86fd..bba90f1ac6b8026e1886aef4fbf28a3c1426f9a4 100644 (file)
@@ -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();
        }
index b90daf8ae823798c9ff8ae3b439afd73c674fed2..202a20ae2ebca328b39a859c492dd48a106137cc 100644 (file)
@@ -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
This page took 0.037428 seconds and 4 git commands to generate.