sessiond: open_packets: use user_space_consumer_channel_keys util
[lttng-tools.git] / src / bin / lttng-sessiond / condition-internal.cpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#include "condition-internal.hpp"
9
10#include <common/hashtable/hashtable.hpp>
11#include <common/hashtable/utils.hpp>
12
13#include <lttng/condition/buffer-usage-internal.hpp>
14#include <lttng/condition/condition-internal.hpp>
15#include <lttng/condition/condition.h>
16#include <lttng/condition/event-rule-matches-internal.hpp>
17#include <lttng/condition/event-rule-matches.h>
18#include <lttng/condition/session-consumed-size-internal.hpp>
19#include <lttng/condition/session-rotation-internal.hpp>
20#include <lttng/event-rule/event-rule-internal.hpp>
21
22static unsigned long lttng_condition_buffer_usage_hash(const struct lttng_condition *_condition)
23{
24 unsigned long hash;
25 unsigned long condition_type;
26 struct lttng_condition_buffer_usage *condition;
27
28 condition = lttng::utils::container_of(_condition, &lttng_condition_buffer_usage::parent);
29
30 condition_type = (unsigned long) condition->parent.type;
31 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
32 if (condition->session_name) {
33 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
34 }
35 if (condition->channel_name) {
36 hash ^= hash_key_str(condition->channel_name, lttng_ht_seed);
37 }
38 if (condition->domain.set) {
39 hash ^= hash_key_ulong((void *) condition->domain.type, lttng_ht_seed);
40 }
41 if (condition->threshold_ratio.set) {
42 hash ^= hash_key_u64(&condition->threshold_ratio.value, lttng_ht_seed);
43 } else if (condition->threshold_bytes.set) {
44 uint64_t val;
45
46 val = condition->threshold_bytes.value;
47 hash ^= hash_key_u64(&val, lttng_ht_seed);
48 }
49 return hash;
50}
51
52static unsigned long
53lttng_condition_session_consumed_size_hash(const struct lttng_condition *_condition)
54{
55 unsigned long hash;
56 const unsigned long condition_type =
57 (unsigned long) LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE;
58 struct lttng_condition_session_consumed_size *condition;
59 uint64_t val;
60
61 condition = lttng::utils::container_of(_condition,
62 &lttng_condition_session_consumed_size::parent);
63
64 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
65 if (condition->session_name) {
66 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
67 }
68 val = condition->consumed_threshold_bytes.value;
69 hash ^= hash_key_u64(&val, lttng_ht_seed);
70 return hash;
71}
72
73static unsigned long lttng_condition_session_rotation_hash(const struct lttng_condition *_condition)
74{
75 unsigned long hash, condition_type;
76 struct lttng_condition_session_rotation *condition;
77
78 condition =
79 lttng::utils::container_of(_condition, &lttng_condition_session_rotation::parent);
80 condition_type = (unsigned long) condition->parent.type;
81 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
82 LTTNG_ASSERT(condition->session_name);
83 hash ^= hash_key_str(condition->session_name, lttng_ht_seed);
84 return hash;
85}
86
87static unsigned long
88lttng_condition_event_rule_matches_hash(const struct lttng_condition *condition)
89{
90 unsigned long hash, condition_type;
91 enum lttng_condition_status condition_status;
92 const struct lttng_event_rule *event_rule;
93
94 condition_type = (unsigned long) condition->type;
95 condition_status = lttng_condition_event_rule_matches_get_rule(condition, &event_rule);
96 LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
97
98 hash = hash_key_ulong((void *) condition_type, lttng_ht_seed);
99 return hash ^ lttng_event_rule_hash(event_rule);
100}
101
102/*
103 * The lttng_condition hashing code is kept in this file (rather than
104 * condition.c) since it makes use of GPLv2 code (hashtable utils), which we
105 * don't want to link in liblttng-ctl.
106 */
107unsigned long lttng_condition_hash(const struct lttng_condition *condition)
108{
109 switch (condition->type) {
110 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
111 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
112 return lttng_condition_buffer_usage_hash(condition);
113 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
114 return lttng_condition_session_consumed_size_hash(condition);
115 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
116 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
117 return lttng_condition_session_rotation_hash(condition);
118 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES:
119 return lttng_condition_event_rule_matches_hash(condition);
120 default:
121 abort();
122 }
123}
124
125struct lttng_condition *lttng_condition_copy(const struct lttng_condition *condition)
126{
127 int ret;
128 struct lttng_payload copy_buffer;
129 struct lttng_condition *copy = nullptr;
130
131 lttng_payload_init(&copy_buffer);
132
133 ret = lttng_condition_serialize(condition, &copy_buffer);
134 if (ret < 0) {
135 goto end;
136 }
137
138 {
139 struct lttng_payload_view view =
140 lttng_payload_view_from_payload(&copy_buffer, 0, -1);
141
142 ret = lttng_condition_create_from_payload(&view, &copy);
143 if (ret < 0) {
144 copy = nullptr;
145 goto end;
146 }
147 }
148
149end:
150 lttng_payload_reset(&copy_buffer);
151 return copy;
152}
This page took 0.025283 seconds and 5 git commands to generate.