sessiond: Extract condition hashing functions
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 9 Sep 2020 21:36:12 +0000 (17:36 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 14 Dec 2020 20:40:06 +0000 (15:40 -0500)
Extract these functions so it can be used by other files.

The lttng_condition hashing code is kept in this (rather than
common/condition/condition.c) since it makes use of GPLv2 code
(hashtable utils), which we don't want to link in liblttng-ctl.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iaafe1402b2d198a00920d939502004038e78fff0

src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/condition-internal.c [new file with mode: 0644]
src/bin/lttng-sessiond/condition-internal.h [new file with mode: 0644]
src/bin/lttng-sessiond/notification-thread-events.c
tests/unit/Makefile.am

index d8e3b715d7b7926b550b4c5f973ae5bc7c7080ff..1d3741c6129e550c0edc45da929f07e066b703c2 100644 (file)
@@ -16,6 +16,7 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        lttng-ust-ctl.h lttng-ust-abi.h lttng-ust-error.h \
                        ust-ctl-internal.h ust-abi-internal.h ust-error-internal.h \
                        ust-registry.h \
+                       condition-internal.c condition-internal.h \
                        context.c context.h \
                        channel.c channel.h \
                        event.c event.h \
diff --git a/src/bin/lttng-sessiond/condition-internal.c b/src/bin/lttng-sessiond/condition-internal.c
new file mode 100644 (file)
index 0000000..dc21ca3
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <common/hashtable/utils.h>
+#include <common/hashtable/hashtable.h>
+
+#include <lttng/condition/condition.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/condition/buffer-usage-internal.h>
+#include <lttng/condition/session-consumed-size-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
+#include <lttng/condition/event-rule-internal.h>
+#include <lttng/condition/event-rule.h>
+#include <lttng/event-rule/event-rule-internal.h>
+#include "condition-internal.h"
+
+static
+unsigned long lttng_condition_buffer_usage_hash(
+       const struct lttng_condition *_condition)
+{
+       unsigned long hash;
+       unsigned long condition_type;
+       struct lttng_condition_buffer_usage *condition;
+
+       condition = container_of(_condition,
+                       struct lttng_condition_buffer_usage, parent);
+
+       condition_type = (unsigned long) condition->parent.type;
+       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
+       if (condition->session_name) {
+               hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
+       }
+       if (condition->channel_name) {
+               hash ^= hash_key_str(condition->channel_name, lttng_ht_seed);
+       }
+       if (condition->domain.set) {
+               hash ^= hash_key_ulong(
+                               (void *) condition->domain.type,
+                               lttng_ht_seed);
+       }
+       if (condition->threshold_ratio.set) {
+               uint64_t val;
+
+               val = condition->threshold_ratio.value * (double) UINT32_MAX;
+               hash ^= hash_key_u64(&val, lttng_ht_seed);
+       } else if (condition->threshold_bytes.set) {
+               uint64_t val;
+
+               val = condition->threshold_bytes.value;
+               hash ^= hash_key_u64(&val, lttng_ht_seed);
+       }
+       return hash;
+}
+
+static
+unsigned long lttng_condition_session_consumed_size_hash(
+       const struct lttng_condition *_condition)
+{
+       unsigned long hash;
+       unsigned long condition_type =
+                       (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE;
+       struct lttng_condition_session_consumed_size *condition;
+       uint64_t val;
+
+       condition = container_of(_condition,
+                       struct lttng_condition_session_consumed_size, parent);
+
+       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
+       if (condition->session_name) {
+               hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
+       }
+       val = condition->consumed_threshold_bytes.value;
+       hash ^= hash_key_u64(&val, lttng_ht_seed);
+       return hash;
+}
+
+static
+unsigned long lttng_condition_session_rotation_hash(
+       const struct lttng_condition *_condition)
+{
+       unsigned long hash, condition_type;
+       struct lttng_condition_session_rotation *condition;
+
+       condition = container_of(_condition,
+                       struct lttng_condition_session_rotation, parent);
+       condition_type = (unsigned long) condition->parent.type;
+       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
+       assert(condition->session_name);
+       hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
+       return hash;
+}
+
+static
+unsigned long lttng_condition_event_rule_hash(
+       const struct lttng_condition *condition)
+{
+       unsigned long hash, condition_type;
+       enum lttng_condition_status condition_status;
+       const struct lttng_event_rule *event_rule;
+
+       condition_type = (unsigned long) condition->type;
+
+       condition_status = lttng_condition_event_rule_get_rule(condition,
+                       &event_rule);
+       assert(condition_status == LTTNG_CONDITION_STATUS_OK);
+
+       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
+       return hash ^ lttng_event_rule_hash(event_rule);
+}
+
+/*
+ * The lttng_condition hashing code is kept in this file (rather than
+ * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
+ * don't want to link in liblttng-ctl.
+ */
+unsigned long lttng_condition_hash(const struct lttng_condition *condition)
+{
+       switch (condition->type) {
+       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
+       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
+               return lttng_condition_buffer_usage_hash(condition);
+       case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
+               return lttng_condition_session_consumed_size_hash(condition);
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               return lttng_condition_session_rotation_hash(condition);
+       case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
+               return lttng_condition_event_rule_hash(condition);
+       default:
+               //ERR("[notification-thread] Unexpected condition type caught");
+               abort();
+       }
+}
diff --git a/src/bin/lttng-sessiond/condition-internal.h b/src/bin/lttng-sessiond/condition-internal.h
new file mode 100644 (file)
index 0000000..2863f7b
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_SESSIOND_CONDITION_INTERNAL_H
+#define LTTNG_SESSIOND_CONDITION_INTERNAL_H
+
+#include <lttng/condition/condition.h>
+
+/*
+ * The lttng_condition hashing code is kept in this file (rather than
+ * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
+ * don't want to link in liblttng-ctl.
+ */
+unsigned long lttng_condition_hash(const struct lttng_condition *condition);
+
+#endif /* LTTNG_SESSIOND_CONDITION_INTERNAL_H */
index 5956d53ca9e6f0c4e3006ac456979a621bf5f7e6..d5a3f95026f0d3b4af2ed83c74751e9b41a645e3 100644 (file)
@@ -37,6 +37,7 @@
 #include <inttypes.h>
 #include <fcntl.h>
 
+#include "condition-internal.h"
 #include "notification-thread.h"
 #include "notification-thread-events.h"
 #include "notification-thread-commands.h"
@@ -370,125 +371,6 @@ unsigned long hash_trigger_by_name_uid(const struct lttng_trigger *trigger)
        return hash;
 }
 
-static
-unsigned long lttng_condition_buffer_usage_hash(
-       const struct lttng_condition *_condition)
-{
-       unsigned long hash;
-       unsigned long condition_type;
-       struct lttng_condition_buffer_usage *condition;
-
-       condition = container_of(_condition,
-                       struct lttng_condition_buffer_usage, parent);
-
-       condition_type = (unsigned long) condition->parent.type;
-       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
-       if (condition->session_name) {
-               hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
-       }
-       if (condition->channel_name) {
-               hash ^= hash_key_str(condition->channel_name, lttng_ht_seed);
-       }
-       if (condition->domain.set) {
-               hash ^= hash_key_ulong(
-                               (void *) condition->domain.type,
-                               lttng_ht_seed);
-       }
-       if (condition->threshold_ratio.set) {
-               uint64_t val;
-
-               val = condition->threshold_ratio.value * (double) UINT32_MAX;
-               hash ^= hash_key_u64(&val, lttng_ht_seed);
-       } else if (condition->threshold_bytes.set) {
-               uint64_t val;
-
-               val = condition->threshold_bytes.value;
-               hash ^= hash_key_u64(&val, lttng_ht_seed);
-       }
-       return hash;
-}
-
-static
-unsigned long lttng_condition_session_consumed_size_hash(
-       const struct lttng_condition *_condition)
-{
-       unsigned long hash;
-       unsigned long condition_type =
-                       (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE;
-       struct lttng_condition_session_consumed_size *condition;
-       uint64_t val;
-
-       condition = container_of(_condition,
-                       struct lttng_condition_session_consumed_size, parent);
-
-       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
-       if (condition->session_name) {
-               hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
-       }
-       val = condition->consumed_threshold_bytes.value;
-       hash ^= hash_key_u64(&val, lttng_ht_seed);
-       return hash;
-}
-
-static
-unsigned long lttng_condition_session_rotation_hash(
-       const struct lttng_condition *_condition)
-{
-       unsigned long hash, condition_type;
-       struct lttng_condition_session_rotation *condition;
-
-       condition = container_of(_condition,
-                       struct lttng_condition_session_rotation, parent);
-       condition_type = (unsigned long) condition->parent.type;
-       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
-       assert(condition->session_name);
-       hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
-       return hash;
-}
-
-static
-unsigned long lttng_condition_event_rule_hash(
-       const struct lttng_condition *condition)
-{
-       unsigned long hash, condition_type;
-       enum lttng_condition_status condition_status;
-       const struct lttng_event_rule *event_rule;
-
-       condition_type = (unsigned long) condition->type;
-
-       condition_status = lttng_condition_event_rule_get_rule(condition,
-                                                              &event_rule);
-       assert(condition_status == LTTNG_CONDITION_STATUS_OK);
-
-       hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
-       return hash ^ lttng_event_rule_hash(event_rule);
-}
-
-/*
- * The lttng_condition hashing code is kept in this file (rather than
- * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
- * don't want to link in liblttng-ctl.
- */
-static
-unsigned long lttng_condition_hash(const struct lttng_condition *condition)
-{
-       switch (condition->type) {
-       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
-       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
-               return lttng_condition_buffer_usage_hash(condition);
-       case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
-               return lttng_condition_session_consumed_size_hash(condition);
-       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
-       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
-               return lttng_condition_session_rotation_hash(condition);
-       case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
-               return lttng_condition_event_rule_hash(condition);
-       default:
-               ERR("[notification-thread] Unexpected condition type caught");
-               abort();
-       }
-}
-
 static
 unsigned long hash_channel_key(struct channel_key *key)
 {
index 8ce735890241c65574c4a14ed1cf75416951bcda..5963292bc3d996002d462bb44289f05971443169 100644 (file)
@@ -65,6 +65,7 @@ test_uri_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBHASHTABLE) $(DL_LIBS)
 # Sessiond objects
 SESSIOND_OBJS = $(top_builddir)/src/bin/lttng-sessiond/buffer-registry.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/cmd.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/condition-internal.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/save.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/notification-thread-commands.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/shm.$(OBJEXT) \
This page took 0.029477 seconds and 4 git commands to generate.