Relayd: introduce --group-output-by-session
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 5a3bcb43fbc8aea671e4cc7b0a3c15451522181e..d5720e8831e16da6d3ae0da90184ffab0b335ab8 100644 (file)
@@ -94,6 +94,8 @@ enum relay_connection_status {
 /* command line options */
 char *opt_output_path;
 static int opt_daemon, opt_background;
+int opt_group_output_by_session;
+int opt_group_output_by_host;
 
 /*
  * We need to wait for listener and live listener threads, as well as
@@ -179,6 +181,8 @@ static struct option long_options[] = {
        { "verbose", 0, 0, 'v', },
        { "config", 1, 0, 'f' },
        { "version", 0, 0, 'V' },
+       { "group-output-by-session", 0, 0, 's', },
+       { "group-output-by-host", 0, 0, 'p', },
        { NULL, 0, 0, 0, },
 };
 
@@ -300,6 +304,20 @@ static int set_option(int opt, const char *arg, const char *optname)
                        }
                }
                break;
+       case 's':
+               if (opt_group_output_by_host) {
+                       ERR("Cannot set --group-output-by-session, --group-output-by-host already defined");
+                       exit(EXIT_FAILURE);
+               }
+               opt_group_output_by_session = 1;
+               break;
+       case 'p':
+               if (opt_group_output_by_session) {
+                       ERR("Cannot set --group-output-by-host, --group-output-by-session already defined");
+                       exit(EXIT_FAILURE);
+               }
+               opt_group_output_by_host = 1;
+               break;
        default:
                /* Unknown option or other error.
                 * Error is printed by getopt, just return */
@@ -487,6 +505,11 @@ static int set_options(int argc, char **argv)
                }
        }
 
+       if (!opt_group_output_by_session && !opt_group_output_by_host) {
+               /* Group by host by default */
+               opt_group_output_by_host = 1;
+       }
+
 exit:
        free(optstring);
        return retval;
@@ -1209,16 +1232,17 @@ static int relay_add_stream(const struct lttcomm_relayd_hdr *recv_hdr,
        if (session->minor == 1) {
                /* For 2.1 */
                ret = cmd_recv_stream_2_1(payload, &path_name,
-                       &channel_name);
+                       &channel_name, session);
        } else if (session->minor > 1 && session->minor < 11) {
                /* From 2.2 to 2.10 */
                ret = cmd_recv_stream_2_2(payload, &path_name,
-                       &channel_name, &tracefile_size, &tracefile_count);
+                       &channel_name, &tracefile_size, &tracefile_count,
+                       session);
        } else {
                /* From 2.11 to ... */
                ret = cmd_recv_stream_2_11(payload, &path_name,
                        &channel_name, &tracefile_size, &tracefile_count,
-                       &stream_chunk_id.value);
+                       &stream_chunk_id.value, session);
                stream_chunk_id.is_set = true;
        }
 
@@ -2471,7 +2495,7 @@ static int relay_rotate_session_stream(const struct lttcomm_relayd_hdr *recv_hdr
         * change).
         */
        free(stream->path_name);
-       stream->path_name = create_output_path(new_path_view.data);
+       stream->path_name = create_output_path(new_path_view.data, session->session_name);
        if (!stream->path_name) {
                ERR("Failed to create a new output path");
                ret = -1;
@@ -2587,7 +2611,7 @@ static int relay_mkdir(const struct lttcomm_relayd_hdr *recv_hdr,
        path_view = lttng_buffer_view_from_view(payload, header_len,
                        path_info_header.length);
 
-       path = create_output_path(path_view.data);
+       path = create_output_path(path_view.data, session->session_name);
        if (!path) {
                ERR("Failed to create output path");
                ret = -1;
@@ -2717,14 +2741,14 @@ static int relay_rotate_rename(const struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
-       complete_old_path = create_output_path(old_path_view.data);
+       complete_old_path = create_output_path(old_path_view.data, session->session_name);
        if (!complete_old_path) {
                ERR("Failed to build old output path in rotate_rename command");
                ret = -1;
                goto end;
        }
 
-       complete_new_path = create_output_path(new_path_view.data);
+       complete_new_path = create_output_path(new_path_view.data, session->session_name);
        if (!complete_new_path) {
                ERR("Failed to build new output path in rotate_rename command");
                ret = -1;
This page took 0.026596 seconds and 5 git commands to generate.