Move completed trace archive chunks to an "archives" sub-folder
[lttng-tools.git] / src / bin / lttng-sessiond / rotate.c
index 17d3c51fdbf0823adb32d4bd3aab8606058df2f7..c3413a2cab7b2e0d89ae2853a9773447de87572c 100644 (file)
@@ -218,7 +218,7 @@ int rename_completed_chunk(struct ltt_session *session, time_t ts)
                 * session_root_path, so we need to create the chunk folder
                 * and move the domain-specific folders inside it.
                 */
-               ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64,
+               ret = snprintf(new_path, sizeof(new_path), "%s/archives/%s-%s-%" PRIu64,
                                session->rotation_chunk.current_rotate_path,
                                start_time,
                                datetime, session->current_archive_id);
@@ -275,7 +275,7 @@ int rename_completed_chunk(struct ltt_session *session, time_t ts)
                        ret = -1;
                        goto end;
                }
-               ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64,
+               ret = snprintf(new_path, sizeof(new_path), "%s/archives/%s-%s-%" PRIu64,
                                session_get_base_path(session),
                                start_datetime,
                                datetime, session->current_archive_id);
@@ -320,6 +320,47 @@ end:
        return ret;
 }
 
+int rename_active_chunk(struct ltt_session *session)
+{
+       int ret;
+
+       session->current_archive_id++;
+
+       /*
+        * The currently active tracing path is now the folder we
+        * want to rename.
+        */
+       ret = lttng_strncpy(session->rotation_chunk.current_rotate_path,
+                       session->rotation_chunk.active_tracing_path,
+                       sizeof(session->rotation_chunk.current_rotate_path));
+       if (ret) {
+               ERR("Failed to copy active tracing path");
+               goto end;
+       }
+
+       ret = rename_completed_chunk(session, time(NULL));
+       if (ret < 0) {
+               ERR("Failed to rename current rotation's path");
+               goto end;
+       }
+
+       /*
+        * We just renamed, the folder, we didn't do an actual rotation, so
+        * the active tracing path is now the renamed folder and we have to
+        * restore the rotate count.
+        */
+       ret = lttng_strncpy(session->rotation_chunk.active_tracing_path,
+                       session->rotation_chunk.current_rotate_path,
+                       sizeof(session->rotation_chunk.active_tracing_path));
+       if (ret) {
+               ERR("Failed to rename active session chunk tracing path");
+               goto end;
+       }
+end:
+       session->current_archive_id--;
+       return ret;
+}
+
 int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64_t size,
                struct notification_thread_handle *notification_thread_handle)
 {
This page took 0.024357 seconds and 4 git commands to generate.