Apply the overrides attributes during configuration load
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 12 Sep 2016 22:09:09 +0000 (18:09 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 7 Oct 2016 04:44:05 +0000 (00:44 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/load-internal.h
src/bin/lttng-sessiond/load-session-thread.c
src/common/config/session-config.c
src/common/config/session-config.h
src/lib/lttng-ctl/load.c

index b644717ce39a08e8646f154e815a207c3b9a28b0..43dc3326216e93489abe2db732aac93657247b09 100644 (file)
@@ -45,7 +45,7 @@ struct lttng_load_session_attr {
        /* The raw override data url for getter */
        char *raw_override_data_url;
        /* Override struct */
-       struct config_load_session_override_attr override_attr;
+       struct config_load_session_override_attr *override_attr;
 } LTTNG_PACKED;
 
 #endif /* LTTNG_LOAD_INTERNAL_ABI_H */
index 4c08791f10f045aa6069c64d99893d88a5991820..b95764d6693a76cd902187955362979ccb3c651c 100644 (file)
@@ -97,7 +97,7 @@ void *thread_load_session(void *data)
        }
 
        /* Override existing session and autoload also. */
-       ret = config_load_session(info->path, NULL, 1, 1);
+       ret = config_load_session(info->path, NULL, 1, 1, NULL);
        if (ret) {
                ERR("Session load failed: %s", error_get_str(ret));
        }
index d53ec0aa530ae88201932675c2bcb7e6b6dff719..adb49bd08ee94b68c9cea8ef46b93b9d93898a15 100644 (file)
@@ -1188,7 +1188,8 @@ end:
 }
 
 static
-int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
+int create_snapshot_session(const char *session_name, xmlNodePtr output_node,
+               const struct config_load_session_override_attr *overrides)
 {
        int ret;
        xmlNodePtr node = NULL;
@@ -1218,6 +1219,9 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
                uint64_t max_size = UINT64_MAX;
                struct consumer_output output = { 0 };
                struct lttng_snapshot_output *snapshot_output = NULL;
+               const char *control_uri = NULL;
+               const char *data_uri = NULL;
+               const char *path = NULL;
 
                for (node = xmlFirstElementChild(snapshot_output_node); node;
                                node = xmlNextElementSibling(node)) {
@@ -1253,6 +1257,26 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
                        }
                }
 
+               if (overrides) {
+                       if (overrides->path_url) {
+                               /* Control/data_uri are null */
+                               path = overrides->path_url;
+                       } else {
+                               if (overrides->ctrl_url) {
+                                       /* path is null */
+                                       control_uri = overrides->ctrl_url;
+                               }
+                               if (overrides->data_url) {
+                                       /* path is null */
+                                       data_uri = overrides->data_url;
+                               }
+                       }
+               } else {
+                       control_uri = output.control_uri;
+                       data_uri = output.data_uri;
+                       path = output.path;
+               }
+
                snapshot_output = lttng_snapshot_output_create();
                if (!snapshot_output) {
                        ret = -LTTNG_ERR_NOMEM;
@@ -1269,23 +1293,23 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
                        goto error_snapshot_output;
                }
 
-               if (output.path) {
-                       ret = lttng_snapshot_output_set_ctrl_url(output.path,
+               if (path) {
+                       ret = lttng_snapshot_output_set_ctrl_url(path,
                                        snapshot_output);
                        if (ret) {
                                goto error_snapshot_output;
                        }
                } else {
-                       if (output.control_uri) {
-                               ret = lttng_snapshot_output_set_ctrl_url(output.control_uri,
+                       if (control_uri) {
+                               ret = lttng_snapshot_output_set_ctrl_url(control_uri,
                                                snapshot_output);
                                if (ret) {
                                        goto error_snapshot_output;
                                }
                        }
 
-                       if (output.data_uri) {
-                               ret = lttng_snapshot_output_set_data_url(output.data_uri,
+                       if (data_uri) {
+                               ret = lttng_snapshot_output_set_data_url(data_uri,
                                                snapshot_output);
                                if (ret) {
                                        goto error_snapshot_output;
@@ -1315,11 +1339,15 @@ int create_session(const char *name,
        struct lttng_domain *jul_domain,
        struct lttng_domain *log4j_domain,
        xmlNodePtr output_node,
-       uint64_t live_timer_interval)
+       uint64_t live_timer_interval,
+       const struct config_load_session_override_attr *overrides)
 {
        int ret;
        struct consumer_output output = { 0 };
        xmlNodePtr consumer_output_node;
+       const char *control_uri = NULL;
+       const char *data_uri = NULL;
+       const char *path = NULL;
 
        assert(name);
 
@@ -1344,13 +1372,33 @@ int create_session(const char *name,
                }
        }
 
-       if (live_timer_interval != UINT64_MAX &&
-               !output.control_uri && !output.data_uri) {
+       /* Check for override and apply them */
+       if (overrides) {
+               if (overrides->path_url) {
+                       /* control/data_uri are null */;
+                       path = overrides->path_url;
+               } else {
+                       if (overrides->ctrl_url) {
+                               /* path is null */
+                               control_uri = overrides->ctrl_url;
+                       }
+                       if (overrides->data_url) {
+                               /* path is null */
+                               data_uri = overrides->data_url;
+                       }
+               }
+       } else {
+               control_uri = output.control_uri;
+               data_uri = output.data_uri;
+               path = output.path;
+       }
+
+       if (live_timer_interval != UINT64_MAX && !control_uri && !data_uri) {
                ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
                goto end;
        }
 
-       if (output.control_uri || output.data_uri) {
+       if (control_uri || data_uri) {
                /* network destination */
                if (live_timer_interval && live_timer_interval != UINT64_MAX) {
                        /*
@@ -1366,15 +1414,14 @@ int create_session(const char *name,
                        goto end;
                }
 
-               ret = create_session_net_output(name, output.control_uri,
-                               output.data_uri);
+               ret = create_session_net_output(name, control_uri, data_uri);
                if (ret) {
                        goto end;
                }
 
        } else {
                /* either local output or no output */
-               ret = lttng_create_session(name, output.path);
+               ret = lttng_create_session(name, path);
                if (ret) {
                        goto end;
                }
@@ -2395,7 +2442,8 @@ end:
 
 static
 int process_session_node(xmlNodePtr session_node, const char *session_name,
-               int overwrite)
+               int overwrite,
+               const struct config_load_session_override_attr *overrides)
 {
        int ret, started = -1, snapshot_mode = -1;
        uint64_t live_timer_interval = UINT64_MAX;
@@ -2581,17 +2629,18 @@ domain_init_error:
 
        /* Create session type depending on output type */
        if (snapshot_mode && snapshot_mode != -1) {
-               ret = create_snapshot_session((const char *) name, output_node);
+               ret = create_snapshot_session((const char *) name, output_node,
+                               overrides);
        } else if (live_timer_interval &&
                live_timer_interval != UINT64_MAX) {
                ret = create_session((const char *) name, kernel_domain,
                                ust_domain, jul_domain, log4j_domain,
-                               output_node, live_timer_interval);
+                               output_node, live_timer_interval, overrides);
        } else {
                /* regular session */
                ret = create_session((const char *) name, kernel_domain,
                                ust_domain, jul_domain, log4j_domain,
-                               output_node, UINT64_MAX);
+                               output_node, UINT64_MAX, overrides);
        }
        if (ret) {
                goto error;
@@ -2665,7 +2714,8 @@ valid:
 
 static
 int load_session_from_file(const char *path, const char *session_name,
-       struct session_config_validation_ctx *validation_ctx, int overwrite)
+       struct session_config_validation_ctx *validation_ctx, int overwrite,
+       const struct config_load_session_override_attr *overrides)
 {
        int ret, session_found = !session_name;
        xmlDocPtr doc = NULL;
@@ -2707,7 +2757,7 @@ int load_session_from_file(const char *path, const char *session_name,
                session_node; session_node =
                        xmlNextElementSibling(session_node)) {
                ret = process_session_node(session_node,
-                       session_name, overwrite);
+                       session_name, overwrite, overrides);
                if (session_name && ret == 0) {
                        /* Target session found and loaded */
                        session_found = 1;
@@ -2741,7 +2791,8 @@ struct dirent *alloc_dirent(const char *path)
 
 static
 int load_session_from_path(const char *path, const char *session_name,
-       struct session_config_validation_ctx *validation_ctx, int overwrite)
+       struct session_config_validation_ctx *validation_ctx, int overwrite,
+       const struct config_load_session_override_attr *overrides)
 {
        int ret, session_found = !session_name;
        DIR *directory = NULL;
@@ -2816,7 +2867,7 @@ int load_session_from_path(const char *path, const char *session_name,
                        file_path[path_len + file_name_len] = '\0';
 
                        ret = load_session_from_file(file_path, session_name,
-                               validation_ctx, overwrite);
+                               validation_ctx, overwrite, overrides);
                        if (session_name && !ret) {
                                session_found = 1;
                                break;
@@ -2827,7 +2878,7 @@ int load_session_from_path(const char *path, const char *session_name,
                free(file_path);
        } else {
                ret = load_session_from_file(path, session_name,
-                       validation_ctx, overwrite);
+                       validation_ctx, overwrite, overrides);
                if (ret) {
                        goto end;
                } else {
@@ -2885,7 +2936,8 @@ invalid:
 
 LTTNG_HIDDEN
 int config_load_session(const char *path, const char *session_name,
-               int overwrite, unsigned int autoload)
+               int overwrite, unsigned int autoload,
+               const struct config_load_session_override_attr *overrides)
 {
        int ret;
        bool session_loaded = false;
@@ -2939,7 +2991,7 @@ int config_load_session(const char *path, const char *session_name,
                        }
                        if (path_ptr) {
                                ret = load_session_from_path(path_ptr, session_name,
-                                               &validation_ctx, overwrite);
+                                               &validation_ctx, overwrite, overrides);
                                if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) {
                                        goto end;
                                }
@@ -2969,7 +3021,7 @@ int config_load_session(const char *path, const char *session_name,
 
                if (path_ptr) {
                        ret = load_session_from_path(path_ptr, session_name,
-                                       &validation_ctx, overwrite);
+                                       &validation_ctx, overwrite, overrides);
                        if (!ret) {
                                session_loaded = true;
                        }
@@ -2994,7 +3046,7 @@ int config_load_session(const char *path, const char *session_name,
                }
 
                ret = load_session_from_path(path, session_name,
-                       &validation_ctx, overwrite);
+                       &validation_ctx, overwrite, overrides);
        }
 end:
        fini_session_config_validation_ctx(&validation_ctx);
index cb006f18e6824b6406c3469b246330a06ff03039..55b8de3dc5fe0df2bc114b4f3ac709f0264b0eac 100644 (file)
@@ -223,12 +223,14 @@ int config_writer_write_element_string(struct config_writer *writer,
  *
  * overwrite Overwrite current session configuration if it exists.
  * autoload Tell to load the auto session(s).
+ * overrides The override attribute structure specifying override parameters.
  *
  * Returns zero if the session could be loaded successfully. Returns
  * a negative LTTNG_ERR code on error.
  */
 LTTNG_HIDDEN
 int config_load_session(const char *path, const char *session_name,
-               int overwrite, unsigned int autoload);
+               int overwrite, unsigned int autoload,
+               const struct config_load_session_override_attr *overrides);
 
 #endif /* _CONFIG_H */
index be236f242b25b9fb0096ba42e73167d6400fb38b..0bebdc094514cdd48d651a6f666b006dfe1cc8d2 100644 (file)
@@ -43,15 +43,18 @@ void reset_load_session_attr_urls(struct lttng_load_session_attr *attr)
        free(attr->raw_override_path_url);
        free(attr->raw_override_ctrl_url);
        free(attr->raw_override_data_url);
-       free(attr->override_attr.path_url);
-       free(attr->override_attr.ctrl_url);
-       free(attr->override_attr.data_url);
+       if (attr->override_attr) {
+               free(attr->override_attr->path_url);
+               free(attr->override_attr->ctrl_url);
+               free(attr->override_attr->data_url);
+       }
 }
 
 void lttng_load_session_attr_destroy(struct lttng_load_session_attr *attr)
 {
        if (attr) {
                reset_load_session_attr_urls(attr);
+               free(attr->override_attr);
                free(attr);
        }
 }
@@ -91,7 +94,7 @@ const char *lttng_load_session_attr_get_override_path_url(
 {
        const char *ret = NULL;
 
-       if (attr && attr->override_attr.path_url) {
+       if (attr && attr->override_attr->path_url) {
                ret = attr->raw_override_path_url;
        }
 
@@ -103,7 +106,7 @@ const char *lttng_load_session_attr_get_override_ctrl_url(
 {
        const char *ret = NULL;
 
-       if (attr && attr->override_attr.ctrl_url) {
+       if (attr && attr->override_attr->ctrl_url) {
                ret = attr->raw_override_ctrl_url;
        }
 
@@ -115,7 +118,7 @@ const char *lttng_load_session_attr_get_override_data_url(
 {
        const char *ret = NULL;
 
-       if (attr && attr->override_attr.data_url) {
+       if (attr && attr->override_attr->data_url) {
                ret = attr->raw_override_data_url;
        }
 
@@ -127,9 +130,9 @@ const char *lttng_load_session_attr_get_override_url(
 {
        const char *ret = NULL;
 
-       if (attr && (attr->override_attr.path_url ||
-               (attr->override_attr.ctrl_url &&
-                attr->override_attr.data_url))) {
+       if (attr && (attr->override_attr->path_url ||
+               (attr->override_attr->ctrl_url &&
+                attr->override_attr->data_url))) {
                ret = attr->raw_override_url;
        }
 
@@ -233,12 +236,19 @@ int lttng_load_session_attr_set_override_ctrl_url(
                goto end;
        }
 
-       if (attr->override_attr.path_url) {
+       if (!attr->override_attr) {
+               attr->override_attr = zmalloc(
+                       sizeof(struct config_load_session_override_attr));
+               if (!attr->override_attr) {
+                       ret = -LTTNG_ERR_NOMEM;
+                       goto end;
+               }
+       }
+
+       if (attr->override_attr->path_url) {
                /*
-                * FIXME: return a more meaningful error.
-                * Setting a ctrl override after a path override make no
-                * sense.
-                * */
+                * Setting a ctrl override after a path override makes no sense.
+                */
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
@@ -279,11 +289,11 @@ int lttng_load_session_attr_set_override_ctrl_url(
        }
 
        /* Squash old value if any */
-       free(attr->override_attr.ctrl_url);
+       free(attr->override_attr->ctrl_url);
        free(attr->raw_override_ctrl_url);
 
        /* Populate the object */
-       attr->override_attr.ctrl_url = url_str;
+       attr->override_attr->ctrl_url = url_str;
        attr->raw_override_ctrl_url = raw_str;
 
        /* Ownership passed to attr. */
@@ -311,7 +321,19 @@ int lttng_load_session_attr_set_override_data_url(
                goto end;
        }
 
-       if (attr->override_attr.path_url) {
+       if (!attr->override_attr) {
+               attr->override_attr = zmalloc(
+                       sizeof(struct config_load_session_override_attr));
+               if (!attr->override_attr) {
+                       ret = -LTTNG_ERR_NOMEM;
+                       goto end;
+               }
+       }
+
+       if (attr->override_attr->path_url) {
+               /*
+                * Setting a data override after a path override makes no sense.
+                */
                ret = -LTTNG_ERR_INVALID;
                goto end;
        }
@@ -351,11 +373,11 @@ int lttng_load_session_attr_set_override_data_url(
        }
 
        /* Squash old value if any */
-       free(attr->override_attr.data_url);
+       free(attr->override_attr->data_url);
        free(attr->raw_override_data_url);
 
        /* Populate the object */
-       attr->override_attr.data_url = url_str;
+       attr->override_attr->data_url = url_str;
        attr->raw_override_data_url = raw_str;
 
        /* Ownership passed to attr. */
@@ -388,6 +410,15 @@ int lttng_load_session_attr_set_override_url(
                goto end;
        }
 
+       if (!attr->override_attr) {
+               attr->override_attr = zmalloc(
+                       sizeof(struct config_load_session_override_attr));
+               if (!attr->override_attr) {
+                       ret = -LTTNG_ERR_NOMEM;
+                       goto end;
+               }
+       }
+
        /*
         * FIXME: uri_parse should be able to take as parameter the protocol
         * type to validate "url". For now only check the parsing goes through;
@@ -475,9 +506,9 @@ int lttng_load_session_attr_set_override_url(
 
        reset_load_session_attr_urls(attr);
 
-       attr->override_attr.path_url = path_str;
-       attr->override_attr.ctrl_url = ctrl_str;
-       attr->override_attr.data_url = data_str;
+       attr->override_attr->path_url = path_str;
+       attr->override_attr->ctrl_url = ctrl_str;
+       attr->override_attr->data_url = data_str;
 
        attr->raw_override_url = raw_url_str;
        attr->raw_override_path_url = raw_path_str;
@@ -519,7 +550,8 @@ int lttng_load_session(struct lttng_load_session_attr *attr)
        session_name = attr->session_name[0] != '\0' ?
                        attr->session_name : NULL;
 
-       ret = config_load_session(url, session_name, attr->overwrite, 0);
+       ret = config_load_session(url, session_name, attr->overwrite, 0,
+                       attr->override_attr);
 
 end:
        return ret;
This page took 0.064756 seconds and 4 git commands to generate.