Cleanup: enforce const-correctness in notification thread
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Aug 2018 17:25:51 +0000 (13:25 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 01:15:03 +0000 (21:15 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/action/action-internal.h
include/lttng/condition/evaluation-internal.h
include/lttng/notification/notification-internal.h
include/lttng/trigger/trigger-internal.h
src/bin/lttng-sessiond/notification-thread-events.c
src/common/action.c
src/common/buffer-usage.c
src/common/evaluation.c
src/common/notification.c
src/common/session-consumed-size.c
src/common/trigger.c

index 0c862a3a2c4831634c2eccb2fde971d15f227efd..df400d5a3527588ddea04d928a0041785dae5022 100644 (file)
@@ -53,4 +53,8 @@ LTTNG_HIDDEN
 ssize_t lttng_action_create_from_buffer(const struct lttng_buffer_view *view,
                struct lttng_action **action);
 
+LTTNG_HIDDEN
+enum lttng_action_type lttng_action_get_type_const(
+               const struct lttng_action *action);
+
 #endif /* LTTNG_ACTION_INTERNAL_H */
index b88a0f712ab69aa9e0b508653fbb456f74db62a0..45a72daa0401a5ec920d19a9991f46b21719c8e6 100644 (file)
@@ -26,7 +26,8 @@
 #include <sys/types.h>
 
 typedef void (*evaluation_destroy_cb)(struct lttng_evaluation *evaluation);
-typedef int (*evaluation_serialize_cb)(struct lttng_evaluation *evaluation,
+typedef int (*evaluation_serialize_cb)(
+               const struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf);
 
 struct lttng_evaluation_comm {
@@ -50,7 +51,7 @@ ssize_t lttng_evaluation_create_from_buffer(const struct lttng_buffer_view *view
                struct lttng_evaluation **evaluation);
 
 LTTNG_HIDDEN
-int lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
+int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf);
 
 #endif /* LTTNG_EVALUATION_INTERNAL_H */
index 648977f3378ff804ba542ddccd83cb07a74134c2..65b03672295f638250e90ce93edb5c31ef8a0e83 100644 (file)
 struct lttng_notification {
        struct lttng_condition *condition;
        struct lttng_evaluation *evaluation;
-       /*
-        * The ownership of the notification's inner-elements depends
-        * on the way it was created. The notification owns both
-        * the condition and evaluation if it was obtained from a notification
-        * channel (i.e. created using lttng_notification_create_from_buffer)
-        * as the user may never access the condition and evaluation,
-        * thus never getting a chance to free them.
-        *
-        * However, when the _private_ lttng_notification_create() function
-        * is used, no ownership of condition and evaluation is assumed by
-        * the notification object. The main reason for this change in
-        * behavior is that internal users of this API only use the object
-        * to use its serialization facilities.
-        */
-       bool owns_elements;
 };
 
 struct lttng_notification_comm {
@@ -59,7 +44,7 @@ struct lttng_notification *lttng_notification_create(
                struct lttng_evaluation *evaluation);
 
 LTTNG_HIDDEN
-int lttng_notification_serialize(struct lttng_notification *notification,
+int lttng_notification_serialize(const struct lttng_notification *notification,
                struct lttng_dynamic_buffer *buf);
 
 LTTNG_HIDDEN
index 22975bf41d96136ca64e0488b497ff8cf0acfbcb..8c44f5cdf1113b0cb93940c703c3534bcffc67a4 100644 (file)
@@ -46,6 +46,14 @@ LTTNG_HIDDEN
 int lttng_trigger_serialize(struct lttng_trigger *trigger,
                struct lttng_dynamic_buffer *buf);
 
+LTTNG_HIDDEN
+const struct lttng_condition *lttng_trigger_get_const_condition(
+               const struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+const struct lttng_action *lttng_trigger_get_const_action(
+               const struct lttng_trigger *trigger);
+
 LTTNG_HIDDEN
 bool lttng_trigger_validate(struct lttng_trigger *trigger);
 
index 0f43e380b20a0799e0e3c3a37a83d1fe4518e7d4..98757737dbfd2d13357d62f0c2a20a5b45683163 100644 (file)
@@ -28,7 +28,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/macros.h>
 #include <lttng/condition/condition.h>
-#include <lttng/action/action.h>
+#include <lttng/action/action-internal.h>
 #include <lttng/notification/notification-internal.h>
 #include <lttng/condition/condition-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
@@ -166,8 +166,8 @@ static int evaluate_condition(const struct lttng_condition *condition,
                uint64_t latest_session_consumed_total,
                struct channel_info *channel_info);
 static
-int send_evaluation_to_clients(struct lttng_trigger *trigger,
-               struct lttng_evaluation *evaluation,
+int send_evaluation_to_clients(const struct lttng_trigger *trigger,
+               const struct lttng_evaluation *evaluation,
                struct notification_client_list *client_list,
                struct notification_thread_state *state,
                uid_t channel_uid, gid_t channel_gid);
@@ -292,7 +292,7 @@ int match_client_list_condition(struct cds_lfht_node *node, const void *key)
 
 static
 unsigned long lttng_condition_buffer_usage_hash(
-       struct lttng_condition *_condition)
+       const struct lttng_condition *_condition)
 {
        unsigned long hash = 0;
        struct lttng_condition_buffer_usage *condition;
@@ -327,7 +327,7 @@ unsigned long lttng_condition_buffer_usage_hash(
 
 static
 unsigned long lttng_condition_session_consumed_size_hash(
-       struct lttng_condition *_condition)
+       const struct lttng_condition *_condition)
 {
        unsigned long hash = 0;
        struct lttng_condition_session_consumed_size *condition;
@@ -350,7 +350,7 @@ unsigned long lttng_condition_session_consumed_size_hash(
  * don't want to link in liblttng-ctl.
  */
 static
-unsigned long lttng_condition_hash(struct lttng_condition *condition)
+unsigned long lttng_condition_hash(const struct lttng_condition *condition)
 {
        switch (condition->type) {
        case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
@@ -547,8 +547,8 @@ int evaluate_condition_for_client(struct lttng_trigger *trigger,
                struct lttng_trigger_list_element *element;
 
                cds_list_for_each_entry(element, &channel_trigger_list->list, node) {
-                       struct lttng_condition *current_condition =
-                               lttng_trigger_get_condition(
+                       const struct lttng_condition *current_condition =
+                               lttng_trigger_get_const_condition(
                                                element->trigger);
 
                        assert(current_condition);
@@ -1027,7 +1027,7 @@ struct session_info *find_or_create_session_info(
        }
 
        cds_lfht_add(state->sessions_ht, hash_key_str(name, lttng_ht_seed),
-                       &sessions->sessions_ht_node);
+                       &session->sessions_ht_node);
 end:
        rcu_read_unlock();
        return session;
@@ -1494,8 +1494,8 @@ int handle_notification_thread_command_unregister_trigger(
 
                cds_list_for_each_entry_safe(trigger_element, tmp,
                                &trigger_list->list, node) {
-                       struct lttng_condition *current_condition =
-                                       lttng_trigger_get_condition(
+                       const struct lttng_condition *current_condition =
+                                       lttng_trigger_get_const_condition(
                                                trigger_element->trigger);
 
                        assert(current_condition);
@@ -2378,8 +2378,8 @@ int client_enqueue_dropped_notification(struct notification_client *client,
 }
 
 static
-int send_evaluation_to_clients(struct lttng_trigger *trigger,
-               struct lttng_evaluation *evaluation,
+int send_evaluation_to_clients(const struct lttng_trigger *trigger,
+               const struct lttng_evaluation *evaluation,
                struct notification_client_list* client_list,
                struct notification_thread_state *state,
                uid_t channel_uid, gid_t channel_gid)
@@ -2387,30 +2387,23 @@ int send_evaluation_to_clients(struct lttng_trigger *trigger,
        int ret = 0;
        struct lttng_dynamic_buffer msg_buffer;
        struct notification_client_list_element *client_list_element, *tmp;
-       struct lttng_notification *notification;
-       struct lttng_condition *condition;
+       const struct lttng_notification notification = {
+               .condition = (struct lttng_condition *) lttng_trigger_get_const_condition(trigger),
+               .evaluation = (struct lttng_evaluation *) evaluation,
+       };
        struct lttng_notification_channel_message msg_header = {
                .type = (int8_t) LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION,
        };
 
        lttng_dynamic_buffer_init(&msg_buffer);
 
-       condition = lttng_trigger_get_condition(trigger);
-       assert(condition);
-
-       notification = lttng_notification_create(condition, evaluation);
-       if (!notification) {
-               ret = -1;
-               goto end;
-       }
-
        ret = lttng_dynamic_buffer_append(&msg_buffer, &msg_header,
                        sizeof(msg_header));
        if (ret) {
                goto end;
        }
 
-       ret = lttng_notification_serialize(notification, &msg_buffer);
+       ret = lttng_notification_serialize(&notification, &msg_buffer);
        if (ret) {
                ERR("[notification-thread] Failed to serialize notification");
                ret = -1;
@@ -2470,7 +2463,6 @@ int send_evaluation_to_clients(struct lttng_trigger *trigger,
        }
        ret = 0;
 end:
-       lttng_notification_destroy(notification);
        lttng_dynamic_buffer_reset(&msg_buffer);
        return ret;
 }
@@ -2611,19 +2603,19 @@ int handle_notification_thread_channel_sample(
                        channel_triggers_ht_node);
        cds_list_for_each_entry(trigger_list_element, &trigger_list->list,
                        node) {
-               struct lttng_condition *condition;
-               struct lttng_action *action;
-               struct lttng_trigger *trigger;
+               const struct lttng_condition *condition;
+               const struct lttng_action *action;
+               const struct lttng_trigger *trigger;
                struct notification_client_list *client_list;
                struct lttng_evaluation *evaluation = NULL;
 
                trigger = trigger_list_element->trigger;
-               condition = lttng_trigger_get_condition(trigger);
+               condition = lttng_trigger_get_const_condition(trigger);
                assert(condition);
-               action = lttng_trigger_get_action(trigger);
+               action = lttng_trigger_get_const_action(trigger);
 
                /* Notify actions are the only type currently supported. */
-               assert(lttng_action_get_type(action) ==
+               assert(lttng_action_get_type_const(action) ==
                                LTTNG_ACTION_TYPE_NOTIFY);
 
                /*
index 0ce93c8529c05cda73714306ed63f22f439ff593..617bc2806a55afc7dd2e1e93adedddfd7f7046ca 100644 (file)
@@ -25,6 +25,13 @@ enum lttng_action_type lttng_action_get_type(struct lttng_action *action)
        return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN;
 }
 
+LTTNG_HIDDEN
+enum lttng_action_type lttng_action_get_type_const(
+               const struct lttng_action *action)
+{
+       return action->type;
+}
+
 void lttng_action_destroy(struct lttng_action *action)
 {
        if (!action) {
index dbfae89c8630b7886873892dd0222b75e870b953..e19a875c9b96ccd1e3f3d395f03787dc03d8b32e 100644 (file)
@@ -739,7 +739,7 @@ end:
 
 static
 int lttng_evaluation_buffer_usage_serialize(
-               struct lttng_evaluation *evaluation,
+               const struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf)
 {
        struct lttng_evaluation_buffer_usage *usage;
index 91d5c0b1d8de7edbe397449784a264c873f9b923..e239193025f6e7abfe64273e92a1b199288e84ef 100644 (file)
@@ -32,7 +32,7 @@ void lttng_evaluation_init(struct lttng_evaluation *evaluation,
 }
 
 LTTNG_HIDDEN
-int lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
+int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf)
 {
        int ret;
index 3826534cda89e3833e75cba2311020388744adb3..674429692aafd25199bf9008287b7d37cc50784d 100644 (file)
@@ -40,13 +40,12 @@ struct lttng_notification *lttng_notification_create(
 
        notification->condition = condition;
        notification->evaluation = evaluation;
-       notification->owns_elements = false;
 end:
        return notification;
 }
 
 LTTNG_HIDDEN
-int lttng_notification_serialize(struct lttng_notification *notification,
+int lttng_notification_serialize(const struct lttng_notification *notification,
                struct lttng_dynamic_buffer *buf)
 {
        int ret;
@@ -134,7 +133,6 @@ ssize_t lttng_notification_create_from_buffer(
                goto error;
        }
        ret = notification_size;
-       (*notification)->owns_elements = true;
 end:
        return ret;
 error:
@@ -149,10 +147,8 @@ void lttng_notification_destroy(struct lttng_notification *notification)
                return;
        }
 
-       if (notification->owns_elements) {
-               lttng_condition_destroy(notification->condition);
-               lttng_evaluation_destroy(notification->evaluation);
-       }
+       lttng_condition_destroy(notification->condition);
+       lttng_evaluation_destroy(notification->evaluation);
        free(notification);
 }
 
index 28bc7ff3b3bef772f98225d3db8d371ecc292ab5..6ba64249d8cf77566eb4c0be9a072100df4c9403 100644 (file)
@@ -402,7 +402,7 @@ end:
 
 static
 int lttng_evaluation_session_consumed_size_serialize(
-               struct lttng_evaluation *evaluation,
+               const struct lttng_evaluation *evaluation,
                struct lttng_dynamic_buffer *buf)
 {
        struct lttng_evaluation_session_consumed_size *consumed;
index 1de1b3b490328c05dc4d7e1f5bc2acc4d88ba692..a4130ec312ff293460834849a92556680fb2f730 100644 (file)
@@ -64,12 +64,26 @@ struct lttng_condition *lttng_trigger_get_condition(
        return trigger ? trigger->condition : NULL;
 }
 
+LTTNG_HIDDEN
+const struct lttng_condition *lttng_trigger_get_const_condition(
+               const struct lttng_trigger *trigger)
+{
+       return trigger->condition;
+}
+
 struct lttng_action *lttng_trigger_get_action(
                struct lttng_trigger *trigger)
 {
        return trigger ? trigger->action : NULL;
 }
 
+LTTNG_HIDDEN
+const struct lttng_action *lttng_trigger_get_const_action(
+               const struct lttng_trigger *trigger)
+{
+       return trigger->action;
+}
+
 void lttng_trigger_destroy(struct lttng_trigger *trigger)
 {
        if (!trigger) {
This page took 0.033271 seconds and 4 git commands to generate.