From ce6176f27756b1b1453d4fef1c8f0978f02806ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 16 Aug 2018 22:41:49 -0400 Subject: [PATCH] save/load: support session rotation schedule descriptors MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/save.c | 94 +++++++++++++++++--- src/bin/lttng/commands/list.c | 20 ----- src/common/config/config-session-abi.h | 6 ++ src/common/config/session-config.c | 118 ++++++++++++++++++------- src/common/config/session.xsd | 24 ++++- 5 files changed, 192 insertions(+), 70 deletions(-) diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index a8f3ec795..5a70fe609 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1886,6 +1886,83 @@ end: return ret; } +static +int save_session_rotation_schedule(struct config_writer *writer, + enum lttng_rotation_schedule_type type, uint64_t value) +{ + int ret = 0; + const char *element_name; + const char *value_name; + + switch (type) { + case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC: + element_name = config_element_rotation_schedule_periodic; + value_name = config_element_rotation_schedule_periodic_time_us; + break; + case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD: + element_name = config_element_rotation_schedule_size_threshold; + value_name = config_element_rotation_schedule_size_threshold_bytes; + break; + default: + ret = -1; + goto end; + } + + ret = config_writer_open_element(writer, element_name); + if (ret) { + goto end; + } + + ret = config_writer_write_element_unsigned_int(writer, + value_name, value); + if (ret) { + goto end; + } + + /* Close schedule descriptor element. */ + ret = config_writer_close_element(writer); + if (ret) { + goto end; + } +end: + return ret; +} + +static +int save_session_rotation_schedules(struct config_writer *writer, + struct ltt_session *session) +{ + int ret; + + ret = config_writer_open_element(writer, + config_element_rotation_schedules); + if (session->rotate_timer_period) { + ret = save_session_rotation_schedule(writer, + LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC, + session->rotate_timer_period); + if (ret) { + goto close_schedules; + } + } + if (session->rotate_size) { + ret = save_session_rotation_schedule(writer, + LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD, + session->rotate_size); + if (ret) { + goto close_schedules; + } + } + +close_schedules: + /* Close rotation schedules element. */ + ret = config_writer_close_element(writer); + if (ret) { + goto end; + } +end: + return ret; +} + /* * Save the given session. * @@ -2061,20 +2138,9 @@ int save_session(struct ltt_session *session, goto end; } } - if (session->rotate_timer_period) { - ret = config_writer_write_element_unsigned_int(writer, - config_element_rotation_timer_interval, - session->rotate_timer_period); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } - - if (session->rotate_size) { - ret = config_writer_write_element_unsigned_int(writer, - config_element_rotation_size, - session->rotate_size); + if (session->rotate_timer_period || session->rotate_size) { + ret = save_session_rotation_schedules(writer, + session); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index a4ee96e9e..5816a05de 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -1536,16 +1536,6 @@ static enum cmd_error_code print_periodic_rotation_schedule( } MSG(" timer period: %" PRIu64" µs", value); - if (lttng_opt_mi) { - int mi_ret = mi_lttng_writer_write_element_unsigned_int(writer, - config_element_rotation_timer_interval, value); - - if (mi_ret) { - ret = CMD_ERROR; - goto end; - } - } - ret = CMD_SUCCESS; end: return ret; @@ -1567,16 +1557,6 @@ static enum cmd_error_code print_size_threshold_rotation_schedule( } MSG(" size threshold: %" PRIu64" bytes", value); - if (lttng_opt_mi) { - int mi_ret = mi_lttng_writer_write_element_unsigned_int(writer, - config_element_rotation_size, value); - - if (mi_ret) { - ret = CMD_ERROR; - goto end; - } - } - ret = CMD_SUCCESS; end: return ret; diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index c96adb9eb..4344186ae 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -135,4 +135,10 @@ extern const char * const config_event_context_migratable; extern const char * const config_event_context_callstack_user; extern const char * const config_event_context_callstack_kernel; +extern const char * const config_element_rotation_schedules; +extern const char * const config_element_rotation_schedule_periodic; +extern const char * const config_element_rotation_schedule_periodic_time_us; +extern const char * const config_element_rotation_schedule_size_threshold; +extern const char * const config_element_rotation_schedule_size_threshold_bytes; + #endif /* CONFIG_SESSION_INTERNAL_H */ diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index ffe7b14ed..bfc1bdab6 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -133,9 +133,11 @@ const char * const config_element_trackers = "trackers"; const char * const config_element_targets = "targets"; const char * const config_element_target_pid = "pid_target"; -LTTNG_HIDDEN const char * const config_element_rotation_timer_interval = "rotation_schedule_timer_period"; -LTTNG_HIDDEN const char * const config_element_rotation_size = "rotation_schedule_size"; -LTTNG_HIDDEN const char * const config_element_rotation_schedule = "rotation_schedule"; +LTTNG_HIDDEN const char * const config_element_rotation_schedules = "rotation_schedules"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic = "periodic"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic_time_us = "time_us"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_size_threshold = "size_threshold"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_size_threshold_bytes = "bytes"; const char * const config_domain_type_kernel = "KERNEL"; const char * const config_domain_type_ust = "UST"; @@ -2577,7 +2579,7 @@ int add_periodic_rotation(const char *name, uint64_t time_us) status = lttng_session_add_rotation_schedule(name, periodic); switch (status) { case LTTNG_ROTATION_STATUS_OK: - ret = LTTNG_OK; + ret = 0; break; case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET: case LTTNG_ROTATION_STATUS_INVALID: @@ -2615,7 +2617,7 @@ int add_size_rotation(const char *name, uint64_t size_bytes) status = lttng_session_add_rotation_schedule(name, size); switch (status) { case LTTNG_ROTATION_STATUS_OK: - ret = LTTNG_OK; + ret = 0; break; case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET: case LTTNG_ROTATION_STATUS_INVALID: @@ -2630,6 +2632,77 @@ error: return ret; } +static +int process_session_rotation_schedules_node( + xmlNodePtr schedules_node, + uint64_t *rotation_timer_interval, + uint64_t *rotation_size) +{ + int ret = 0; + xmlNodePtr child; + + for (child = xmlFirstElementChild(schedules_node); + child; + child = xmlNextElementSibling(child)) { + if (!strcmp((const char *) child->name, + config_element_rotation_schedule_periodic)) { + xmlChar *content; + xmlNodePtr time_us_node; + + /* periodic rotation schedule */ + time_us_node = xmlFirstElementChild(child); + if (!time_us_node || + strcmp((const char *) time_us_node->name, + config_element_rotation_schedule_periodic_time_us)) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + /* time_us child */ + content = xmlNodeGetContent(time_us_node); + if (!content) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + ret = parse_uint(content, rotation_timer_interval); + free(content); + if (ret) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + } else if (!strcmp((const char *) child->name, + config_element_rotation_schedule_size_threshold)) { + xmlChar *content; + xmlNodePtr bytes_node; + + /* size_threshold rotation schedule */ + bytes_node = xmlFirstElementChild(child); + if (!bytes_node || + strcmp((const char *) bytes_node->name, + config_element_rotation_schedule_size_threshold_bytes)) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + /* bytes child */ + content = xmlNodeGetContent(bytes_node); + if (!content) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + ret = parse_uint(content, rotation_size); + free(content); + if (ret) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + } + } + +end: + return ret; +} + static int process_session_node(xmlNodePtr session_node, const char *session_name, int overwrite, @@ -2735,40 +2808,17 @@ int process_session_node(xmlNodePtr session_node, const char *session_name, ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; goto error; } - } - if (!strcmp((const char *) attributes_child->name, - config_element_rotation_timer_interval)) { - /* rotation_timer_interval */ - xmlChar *timer_interval_content = - xmlNodeGetContent(attributes_child); - if (!timer_interval_content) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - - ret = parse_uint(timer_interval_content, &rotation_timer_interval); - free(timer_interval_content); + } else if (!strcmp((const char *) attributes_child->name, + config_element_rotation_schedules)) { + ret = process_session_rotation_schedules_node( + attributes_child, + &rotation_timer_interval, + &rotation_size); if (ret) { ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; goto error; } - } - if (!strcmp((const char *) attributes_child->name, - config_element_rotation_size)) { - /* rotation_size */ - xmlChar *rotation_size_content = - xmlNodeGetContent(attributes_child); - if (!rotation_size_content) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - ret = parse_uint(rotation_size_content, &rotation_size); - free(rotation_size_content); - if (ret) { - ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; - goto error; - } } } } diff --git a/src/common/config/session.xsd b/src/common/config/session.xsd index 1fdd03eb3..18cb6679a 100644 --- a/src/common/config/session.xsd +++ b/src/common/config/session.xsd @@ -280,12 +280,32 @@ by its signed 32-bit representation when converted to msec. + + + + + + + + + + + + + + + + + + + + + - - + -- 2.34.1