From 0883d500afc63b5ee78de8ed7d69150e21dd60a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 28 Feb 2017 22:03:13 -0500 Subject: [PATCH] Add deserialization of buffer-usage condition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- .../lttng/condition/buffer-usage-internal.h | 8 ++ src/lib/lttng-ctl/buffer-usage.c | 117 ++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/include/lttng/condition/buffer-usage-internal.h b/include/lttng/condition/buffer-usage-internal.h index b8cb50ccc..bac144bc6 100644 --- a/include/lttng/condition/buffer-usage-internal.h +++ b/include/lttng/condition/buffer-usage-internal.h @@ -67,4 +67,12 @@ LTTNG_HIDDEN struct lttng_evaluation *lttng_evaluation_buffer_usage_create(uint64_t use, uint64_t capacity); +LTTNG_HIDDEN +ssize_t lttng_condition_buffer_usage_low_create_from_buffer(const char *buf, + struct lttng_condition **condition); + +LTTNG_HIDDEN +ssize_t lttng_condition_buffer_usage_high_create_from_buffer(const char *buf, + struct lttng_condition **condition); + #endif /* LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H */ diff --git a/src/lib/lttng-ctl/buffer-usage.c b/src/lib/lttng-ctl/buffer-usage.c index 233aa8ed1..eed921a56 100644 --- a/src/lib/lttng-ctl/buffer-usage.c +++ b/src/lib/lttng-ctl/buffer-usage.c @@ -155,6 +155,123 @@ struct lttng_condition *lttng_condition_buffer_usage_high_create(void) LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH); } +static +ssize_t init_from_buffer(struct lttng_condition *condition, const char *buf) +{ + ssize_t ret, condition_size; + enum lttng_condition_status status; + enum lttng_domain_type domain_type; + struct lttng_condition_buffer_usage_comm *condition_comm = + (struct lttng_condition_buffer_usage_comm *) buf; + const char *session_name, *channel_name; + + if (condition_comm->threshold_set_in_bytes) { + status = lttng_condition_buffer_usage_set_threshold(condition, + condition_comm->threshold.bytes); + } else { + status = lttng_condition_buffer_usage_set_threshold_percentage( + condition, condition_comm->threshold.percent); + } + if (status != LTTNG_CONDITION_STATUS_OK) { + ret = -1; + goto end; + } + + if (condition_comm->domain_type <= LTTNG_DOMAIN_NONE || + condition_comm->domain_type > LTTNG_DOMAIN_PYTHON) { + /* Invalid domain value. */ + ret = -1; + goto end; + } + + domain_type = (enum lttng_domain_type) condition_comm->domain_type; + status = lttng_condition_buffer_usage_set_domain_type(condition, + domain_type); + if (status != LTTNG_CONDITION_STATUS_OK) { + ret = -1; + goto end; + } + + session_name = buf + sizeof(struct lttng_condition_buffer_usage_comm); + channel_name = session_name + condition_comm->session_name_len; + + status = lttng_condition_buffer_usage_set_session_name(condition, + session_name); + if (status != LTTNG_CONDITION_STATUS_OK) { + ret = -1; + goto end; + } + + status = lttng_condition_buffer_usage_set_channel_name(condition, + channel_name); + if (status != LTTNG_CONDITION_STATUS_OK) { + ret = -1; + goto end; + } + + if (!lttng_condition_validate(condition)) { + ret = -1; + goto end; + } + + condition_size = sizeof(*condition_comm); + condition_size += (ssize_t) condition_comm->session_name_len; + condition_size += (ssize_t) condition_comm->channel_name_len; + ret = condition_size; +end: + return ret; +} + +LTTNG_HIDDEN +ssize_t lttng_condition_buffer_usage_low_create_from_buffer(const char *buf, + struct lttng_condition **_condition) +{ + ssize_t ret; + struct lttng_condition *condition = + lttng_condition_buffer_usage_low_create(); + + if (!_condition || !condition) { + ret = -1; + goto error; + } + + ret = init_from_buffer(condition, buf); + if (ret < 0) { + goto error; + } + + *_condition = condition; + return ret; +error: + lttng_condition_destroy(condition); + return ret; +} + +LTTNG_HIDDEN +ssize_t lttng_condition_buffer_usage_high_create_from_buffer(const char *buf, + struct lttng_condition **_condition) +{ + ssize_t ret; + struct lttng_condition *condition = + lttng_condition_buffer_usage_high_create(); + + if (!_condition || !condition) { + ret = -1; + goto error; + } + + ret = init_from_buffer(condition, buf); + if (ret < 0) { + goto error; + } + + *_condition = condition; + return ret; +error: + lttng_condition_destroy(condition); + return ret; +} + enum lttng_condition_status lttng_condition_buffer_usage_get_threshold_percentage( struct lttng_condition *condition, double *threshold_percent) -- 2.34.1