Save/load: support session trace format
[lttng-tools.git] / src / bin / lttng / commands / create.cpp
index 68a1020a892ef53cdb8379fc5266fcccc8b60b2a..5841013d646814bc57c77bcafca579e74cae494f 100644 (file)
@@ -307,6 +307,7 @@ struct lttng_session_descriptor *create_session_descriptor(void)
                        goto error;
                }
        }
+
 end:
        free(uris);
        return descriptor;
@@ -316,6 +317,77 @@ error:
        goto end;
 }
 
+static int trace_format_check(struct lttng_session_descriptor& descriptor)
+{
+       int ret = 0;
+       enum lttng_error_code ret_code;
+       const lttng_trace_format_descriptor *trace_format_descriptor = nullptr;
+       enum lttng_session_descriptor_status status;
+       std::string destination;
+
+       status = lttng_session_descriptor_get_trace_format_descriptor(
+                       &descriptor, &trace_format_descriptor);
+       if (status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) {
+               ret_code = LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       /*
+        * Only check kernel domain since only the kernel tracer can lag behind
+        * in term of feature.
+        */
+
+       ret_code = lttng_domain_supports_trace_format(lttng_session_daemon_command_endpoint,
+                       LTTNG_DOMAIN_KERNEL, trace_format_descriptor);
+       if (ret_code == LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_KERNEL_TRACER) {
+               WARN("%s", lttng_strerror(ret_code));
+       } else if (ret_code == LTTNG_ERR_KERN_NA || ret_code == LTTNG_ERR_NEED_ROOT_SESSIOND) {
+               /*
+                * Not an error, kernel tracers is simply not available at that
+                * time. Next operation will fail as necessary.
+                */
+               DBG("Kernel tracer not available for trace format support check");
+       } else if (ret_code != LTTNG_OK) {
+               ERR("Failed to validate trace format support: %s", lttng_strerror(ret_code));
+               ret = -1;
+               goto end;
+       }
+
+       if (opt_output_path) {
+               char *tmp = utils_expand_path(opt_output_path);
+               if (!tmp) {
+                       ret = -1;
+                       goto end;
+               }
+               destination = tmp;
+               free(tmp);
+       } else if (opt_url || opt_ctrl_url) {
+               destination = opt_ctrl_url ? opt_ctrl_url : opt_url;
+       } else if (opt_live_timer) {
+               destination = "tcp://127.0.0.1";
+       }
+
+       if (!destination.empty()) {
+               ret_code = lttng_destination_supports_trace_format(
+                               lttng_session_daemon_command_endpoint, destination.c_str(),
+                               trace_format_descriptor);
+               if (ret_code == LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_RELAY_DAEMON) {
+                       WARN("%s", lttng_strerror(ret_code));
+               } else if (ret_code == LTTNG_ERR_RELAYD_CONNECT_FAIL) {
+                       DBG("Could not validate trace format support: %s",
+                                       lttng_strerror(ret_code));
+               } else if (ret_code != LTTNG_OK) {
+                       ERR("Failed to validate trace format support: %s",
+                                       lttng_strerror(ret_code));
+                       ret = -1;
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
 /*
  *  Create a tracing session.
  *  If no name is specified, a default name is generated.
@@ -375,6 +447,7 @@ static int create_session(void)
                ret = CMD_ERROR;
                goto error;
        }
+
        ret_code = lttng_create_session_ext(session_descriptor);
        if (ret_code != LTTNG_OK) {
                ERR("%s", lttng_strerror(-ret_code));
@@ -382,8 +455,14 @@ static int create_session(void)
                goto error;
        }
 
+       ret = trace_format_check(*session_descriptor);
+       if (ret < 0) {
+               ret = CMD_ERROR;
+               goto error;
+       }
+
        descriptor_status = lttng_session_descriptor_get_session_name(
-               session_descriptor, &created_session_name);
+                       session_descriptor, &created_session_name);
        if (descriptor_status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) {
                ERR("Failed to obtain created session name");
                ret = CMD_ERROR;
This page took 0.029777 seconds and 5 git commands to generate.