From: Philippe Proulx Date: Wed, 7 Jun 2017 20:24:13 +0000 (-0400) Subject: Refuse to add port to component when parent graph is canceled X-Git-Tag: v2.0.0-pre1~43 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=bd7cc15bddddb727ea02fb44bde2d9f15cd82847 Refuse to add port to component when parent graph is canceled The objects owned by a graph should not be able to perform any useless action. Having those constraints promise that certain contained objects remain within certain states when the graph is canceled. In this case, it is useless for a component to add a port, since this port cannot be connected to another one within the same graph because bt_graph_connect_ports() is not permitted when the graph is canceled. We still allow ports to be removed when the graph is canceled for symetric teardowns, for example. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index d67dd54f..f78c468b 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -170,6 +170,8 @@ const char *bt_component_status_string(enum bt_component_status status) return "BT_COMPONENT_STATUS_NOMEM"; case BT_COMPONENT_STATUS_NOT_FOUND: return "BT_COMPONENT_STATUS_NOT_FOUND"; + case BT_COMPONENT_STATUS_GRAPH_IS_CANCELED: + return "BT_COMPONENT_STATUS_GRAPH_IS_CANCELED"; default: return "(unknown)"; } diff --git a/include/babeltrace/graph/component-status.h b/include/babeltrace/graph/component-status.h index 2425c5ee..fe1d59ab 100644 --- a/include/babeltrace/graph/component-status.h +++ b/include/babeltrace/graph/component-status.h @@ -56,6 +56,7 @@ enum bt_component_status { BT_COMPONENT_STATUS_NOMEM = -12, /** Element not found. */ BT_COMPONENT_STATUS_NOT_FOUND = -19, + BT_COMPONENT_STATUS_GRAPH_IS_CANCELED = 125, }; #ifdef __cplusplus diff --git a/lib/graph/filter.c b/lib/graph/filter.c index 4e6db19f..6cae9b3b 100644 --- a/lib/graph/filter.c +++ b/lib/graph/filter.c @@ -36,6 +36,7 @@ #include #include #include +#include BT_HIDDEN void bt_component_filter_destroy(struct bt_component *component) @@ -251,6 +252,7 @@ enum bt_component_status bt_private_component_filter_add_input_private_port( struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; if (!component) { BT_LOGW_STR("Invalid parameter: component is NULL."); @@ -267,6 +269,17 @@ enum bt_component_status bt_private_component_filter_add_input_private_port( goto end; } + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add output port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + /* bt_component_add_input_port() logs details/errors */ port = bt_component_add_input_port(component, name, user_data); if (!port) { @@ -315,6 +328,7 @@ enum bt_component_status bt_private_component_filter_add_output_private_port( struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; if (!component) { BT_LOGW_STR("Invalid parameter: component is NULL."); @@ -331,6 +345,17 @@ enum bt_component_status bt_private_component_filter_add_output_private_port( goto end; } + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add output port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + /* bt_component_add_output_port() logs details/errors */ port = bt_component_add_output_port(component, name, user_data); if (!port) { diff --git a/lib/graph/sink.c b/lib/graph/sink.c index b2088139..063539f2 100644 --- a/lib/graph/sink.c +++ b/lib/graph/sink.c @@ -34,6 +34,7 @@ #include #include #include +#include BT_HIDDEN void bt_component_sink_destroy(struct bt_component *component) @@ -205,6 +206,7 @@ enum bt_component_status bt_private_component_sink_add_input_private_port( struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; if (!component) { BT_LOGW_STR("Invalid parameter: component is NULL."); @@ -221,6 +223,17 @@ enum bt_component_status bt_private_component_sink_add_input_private_port( goto end; } + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add output port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + /* bt_component_add_input_port() logs details/errors */ port = bt_component_add_input_port(component, name, user_data); if (!port) { diff --git a/lib/graph/source.c b/lib/graph/source.c index 57244c06..b09494f2 100644 --- a/lib/graph/source.c +++ b/lib/graph/source.c @@ -36,6 +36,7 @@ #include #include #include +#include BT_HIDDEN void bt_component_source_destroy(struct bt_component *component) @@ -170,6 +171,7 @@ enum bt_component_status bt_private_component_source_add_output_private_port( struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; if (!component) { BT_LOGW_STR("Invalid parameter: component is NULL."); @@ -186,6 +188,17 @@ enum bt_component_status bt_private_component_source_add_output_private_port( goto end; } + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add output port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + /* bt_component_add_output_port() logs details and errors */ port = bt_component_add_output_port(component, name, user_data); if (!port) {