save/load: support session rotation schedule descriptors
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Aug 2018 02:41:49 +0000 (22:41 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Aug 2018 16:20:36 +0000 (12:20 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/save.c
src/bin/lttng/commands/list.c
src/common/config/config-session-abi.h
src/common/config/session-config.c
src/common/config/session.xsd

index a8f3ec79588e7bf1e09d6a39c7dd861bf400ecab..5a70fe609204a1ad1e1b3bffdf091aee40cd90b4 100644 (file)
@@ -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;
index a4ee96e9e0f2b1843a9696f28e8f822cb84c0b51..5816a05de36783f7250ed992244c20ce69399081 100644 (file)
@@ -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;
index c96adb9ebf5886c479296caf0244a5d8c494edf9..4344186aed9329e541ee6f5442d98ba3fe586f4b 100644 (file)
@@ -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 */
index ffe7b14ed59cb0cca2dd23fe4075e5bc48a637ae..bfc1bdab6decfea0938ee18fcc67b176e3386787 100644 (file)
@@ -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;
-                                       }
                                }
                        }
                }
index 1fdd03eb388c787858d72df1761f2a36c5a08276..18cb6679ad37007d499df9bc816098fec100d769 100644 (file)
@@ -280,12 +280,32 @@ by its signed 32-bit representation when converted to msec.
        </xs:all>
 </xs:complexType>
 
+<xs:complexType name="periodic_rotation_schedule_type">
+       <xs:all>
+               <xs:element name="time_us" type="uint64_type" minOccurs="0" />
+       </xs:all>
+</xs:complexType>
+
+<xs:complexType name="size_threshold_rotation_schedule_type">
+       <xs:all>
+               <xs:element name="bytes" type="uint64_type" minOccurs="0" />
+       </xs:all>
+</xs:complexType>
+
+<xs:complexType name="rotation_schedule_type">
+       <xs:sequence>
+               <xs:choice maxOccurs="unbounded">
+                       <xs:element name="periodic" type="periodic_rotation_schedule_type" maxOccurs="unbounded" />
+                       <xs:element name="size_threshold" type="size_threshold_rotation_schedule_type" maxOccurs="unbounded" />
+               </xs:choice>
+       </xs:sequence>
+</xs:complexType>
+
 <xs:complexType name="session_attributes_type">
        <xs:all>
                <xs:element name="snapshot_mode" type="xs:boolean" minOccurs="0"/>
                <xs:element name="live_timer_interval" type="uint32_type" minOccurs="0"/> <!-- usec -->
-               <xs:element name="rotation_schedule_timer_period" type="uint64_type" minOccurs="0"/> <!-- usec -->
-               <xs:element name="rotation_schedule_size" type="uint64_type" minOccurs="0"/> <!-- bytes -->
+               <xs:element name="rotation_schedules" type="rotation_schedule_type" minOccurs="0" />
        </xs:all>
 </xs:complexType>
 
This page took 0.032645 seconds and 5 git commands to generate.