X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fcondition.c;h=cffe6cf5e2b7408034781f23063681bebe9f2f7c;hp=9a9e9babdfa19a7145f22508bc81b863f1406078;hb=fbc9f37df245d544a7705ba576297df791220b44;hpb=3647288fe42b25340f905046f3bd9aef21e12aaa diff --git a/src/common/condition.c b/src/common/condition.c index 9a9e9babd..cffe6cf5e 100644 --- a/src/common/condition.c +++ b/src/common/condition.c @@ -1,23 +1,14 @@ /* - * Copyright (C) 2017 - Jérémie Galarneau + * Copyright (C) 2017 Jérémie Galarneau * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include +#include #include #include #include @@ -32,15 +23,36 @@ enum lttng_condition_type lttng_condition_get_type( } void lttng_condition_destroy(struct lttng_condition *condition) +{ + lttng_condition_put(condition); +} + +static void condition_destroy_ref(struct urcu_ref *ref) +{ + struct lttng_condition *condition = + container_of(ref, struct lttng_condition, ref); + + condition->destroy(condition); +} + +LTTNG_HIDDEN +void lttng_condition_get(struct lttng_condition *condition) +{ + urcu_ref_get(&condition->ref); +} + +LTTNG_HIDDEN +void lttng_condition_put(struct lttng_condition *condition) { if (!condition) { return; } assert(condition->destroy); - condition->destroy(condition); + urcu_ref_put(&condition->ref, condition_destroy_ref); } + LTTNG_HIDDEN bool lttng_condition_validate(const struct lttng_condition *condition) { @@ -64,10 +76,10 @@ end: LTTNG_HIDDEN int lttng_condition_serialize(const struct lttng_condition *condition, - struct lttng_dynamic_buffer *buf) + struct lttng_payload *payload) { int ret; - struct lttng_condition_comm condition_comm = { 0 }; + struct lttng_condition_comm condition_comm = {}; if (!condition) { ret = -1; @@ -76,13 +88,13 @@ int lttng_condition_serialize(const struct lttng_condition *condition, condition_comm.condition_type = (int8_t) condition->type; - ret = lttng_dynamic_buffer_append(buf, &condition_comm, + ret = lttng_dynamic_buffer_append(&payload->buffer, &condition_comm, sizeof(condition_comm)); if (ret) { goto end; } - ret = condition->serialize(condition, buf); + ret = condition->serialize(condition, payload); if (ret) { goto end; } @@ -104,38 +116,58 @@ bool lttng_condition_is_equal(const struct lttng_condition *a, goto end; } + if (a == b) { + is_equal = true; + goto end; + } + is_equal = a->equal ? a->equal(a, b) : true; end: return is_equal; } LTTNG_HIDDEN -ssize_t lttng_condition_create_from_buffer( - const struct lttng_buffer_view *buffer, +ssize_t lttng_condition_create_from_payload( + struct lttng_payload_view *view, struct lttng_condition **condition) { ssize_t ret, condition_size = 0; + condition_create_from_payload_cb create_from_payload = NULL; const struct lttng_condition_comm *condition_comm; - condition_create_from_buffer_cb create_from_buffer = NULL; + const struct lttng_payload_view condition_comm_view = + lttng_payload_view_from_view( + view, 0, sizeof(*condition_comm)); - if (!buffer || !condition) { + if (!view || !condition) { + ret = -1; + goto end; + } + + if (!lttng_payload_view_is_valid(&condition_comm_view)) { + /* Payload not large enough to contain the header. */ ret = -1; goto end; } DBG("Deserializing condition from buffer"); - condition_comm = (const struct lttng_condition_comm *) buffer->data; + condition_comm = (typeof(condition_comm)) condition_comm_view.buffer.data; condition_size += sizeof(*condition_comm); switch ((enum lttng_condition_type) condition_comm->condition_type) { case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: - create_from_buffer = lttng_condition_buffer_usage_low_create_from_buffer; + create_from_payload = lttng_condition_buffer_usage_low_create_from_payload; break; case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: - create_from_buffer = lttng_condition_buffer_usage_high_create_from_buffer; + create_from_payload = lttng_condition_buffer_usage_high_create_from_payload; break; case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: - create_from_buffer = lttng_condition_session_consumed_size_create_from_buffer; + create_from_payload = lttng_condition_session_consumed_size_create_from_payload; + break; + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: + create_from_payload = lttng_condition_session_rotation_ongoing_create_from_payload; + break; + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: + create_from_payload = lttng_condition_session_rotation_completed_create_from_payload; break; default: ERR("Attempted to create condition of unknown type (%i)", @@ -144,12 +176,12 @@ ssize_t lttng_condition_create_from_buffer( goto end; } - if (create_from_buffer) { - const struct lttng_buffer_view view = - lttng_buffer_view_from_view(buffer, + if (create_from_payload) { + struct lttng_payload_view condition_view = + lttng_payload_view_from_view(view, sizeof(*condition_comm), -1); - ret = create_from_buffer(&view, condition); + ret = create_from_payload(&condition_view, condition); if (ret < 0) { goto end; } @@ -169,4 +201,5 @@ void lttng_condition_init(struct lttng_condition *condition, enum lttng_condition_type type) { condition->type = type; + urcu_ref_init(&condition->ref); }