Save, restore and list the rotation parameters
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 21 Dec 2017 19:32:32 +0000 (14:32 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 Apr 2018 16:12:28 +0000 (12:12 -0400)
Add the support to save, restore and list the automatic rotation
parameters.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/rotate-internal.h
include/lttng/rotation.h
src/bin/lttng-sessiond/main.c
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
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/rotate.c

index 00a348ff793673842145c9d0c02c49cd271e698f..29ea8c8359f7e6513b81a7583927f001bcac8efa 100644 (file)
@@ -95,4 +95,14 @@ struct lttng_session_get_current_output_return {
        char path[LTTNG_PATH_MAX];
 } LTTNG_PACKED;
 
+/* For the LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD command. */
+struct lttng_rotation_schedule_get_timer_period {
+       uint64_t rotate_timer;
+} LTTNG_PACKED;
+
+/* For the LTTNG_ROTATION_SCHEDULE_GET_SIZE command. */
+struct lttng_rotation_schedule_get_size {
+       uint64_t rotate_size;
+} LTTNG_PACKED;
+
 #endif /* LTTNG_ROTATE_INTERNAL_ABI_H */
index 9b797ac11c2783256c420f1cd70b22da08c835bd..186cbd6f6464f7bd761e8d593a2b390083f711db 100644 (file)
@@ -188,6 +188,26 @@ extern int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr,
 extern int lttng_rotation_set_schedule(
                struct lttng_rotation_schedule_attr *attr);
 
+/*
+ * Ask the sessiond for the value of the rotate timer (in micro-seconds) of the
+ * session.
+ *
+ * On success, return 0 and set the value or rotate_timer, on error return a
+ * negative value.
+ */
+extern int lttng_rotation_schedule_get_timer_period(const char *session_name,
+               uint64_t *rotate_timer);
+
+/*
+ * Ask the sessiond for the value of the rotate size (in micro-seconds) of the
+ * session.
+ *
+ * On success, return 0 and set the value or rotate_size, on error return
+ * a negative value.
+ */
+extern int lttng_rotation_schedule_get_size(const char *session_name,
+               uint64_t *rotate_size);
+
 #ifdef __cplusplus
 }
 #endif
index 5e4148fb6e707fc653dfa3cea4f0c883c8bd0f7f..cec3a504a01371aed72f81f419f43a66539ba162 100644 (file)
@@ -2967,6 +2967,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_ROTATION_GET_INFO:
        case LTTNG_SESSION_GET_CURRENT_OUTPUT:
        case LTTNG_ROTATION_SET_SCHEDULE:
+       case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD:
+       case LTTNG_ROTATION_SCHEDULE_GET_SIZE:
                need_domain = 0;
                break;
        default:
@@ -3011,6 +3013,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_DATA_PENDING:
        case LTTNG_ROTATE_SESSION:
        case LTTNG_ROTATION_GET_INFO:
+       case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD:
+       case LTTNG_ROTATION_SCHEDULE_GET_SIZE:
                break;
        default:
                /* Setup lttng message with no payload */
@@ -4205,6 +4209,50 @@ error_add_context:
                ret = LTTNG_OK;
                break;
        }
+       case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD:
+       {
+               struct lttng_rotation_schedule_get_timer_period *get_timer;
+
+               get_timer = zmalloc(sizeof(struct lttng_rotation_schedule_get_timer_period));
+               if (!get_timer) {
+                       ret = ENOMEM;
+                       goto error;
+               }
+               get_timer->rotate_timer = cmd_ctx->session->rotate_timer_period;
+
+               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_timer,
+                               sizeof(struct lttng_rotation_schedule_get_timer_period));
+               free(get_timer);
+               if (ret < 0) {
+                       ret = -ret;
+                       goto error;
+               }
+
+               ret = LTTNG_OK;
+               break;
+       }
+       case LTTNG_ROTATION_SCHEDULE_GET_SIZE:
+       {
+               struct lttng_rotation_schedule_get_size *get_size;
+
+               get_size = zmalloc(sizeof(struct lttng_rotation_schedule_get_size));
+               if (!get_size) {
+                       ret = ENOMEM;
+                       goto error;
+               }
+               get_size->rotate_size = cmd_ctx->session->rotate_size;
+
+               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_size,
+                               sizeof(struct lttng_rotation_schedule_get_size));
+               free(get_size);
+               if (ret < 0) {
+                       ret = -ret;
+                       goto error;
+               }
+
+               ret = LTTNG_OK;
+               break;
+       }
        default:
                ret = LTTNG_ERR_UND;
                break;
index af01654cd450f4aa54c46bd9d0914982a22b62d1..ea4feb0c314696e4742a68aae7beea86944dbaec 100644 (file)
@@ -2033,7 +2033,8 @@ int save_session(struct ltt_session *session,
                goto end;
        }
 
-       if (session->snapshot_mode || session->live_timer) {
+       if (session->snapshot_mode || session->live_timer ||
+                       session->rotate_timer_period || session->rotate_size) {
                ret = config_writer_open_element(writer, config_element_attributes);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
@@ -2047,7 +2048,7 @@ int save_session(struct ltt_session *session,
                                ret = LTTNG_ERR_SAVE_IO_FAIL;
                                goto end;
                        }
-               } else {
+               } else if (session->live_timer) {
                        ret = config_writer_write_element_unsigned_int(writer,
                                        config_element_live_timer_interval, session->live_timer);
                        if (ret) {
@@ -2055,6 +2056,25 @@ 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 (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
+               }
 
                /* /attributes */
                ret = config_writer_close_element(writer);
index 898c0de6a02e1a2735d9ce5f59067fe10fe788fb..e05134cbb2d518f6f1dbfcea9ffa0fc151fd71e8 100644 (file)
@@ -1520,6 +1520,57 @@ end:
        return ret;
 }
 
+/*
+ * List the rotate settings (timer/size if any).
+ */
+static int list_rotate_settings(const char *session_name)
+{
+       int ret;
+       uint64_t size, timer;
+
+       ret = lttng_rotation_schedule_get_timer_period(session_name, &timer);
+       if (ret) {
+               goto end;
+       }
+
+       ret = lttng_rotation_schedule_get_size(session_name, &size);
+       if (ret) {
+               goto end;
+       }
+
+       if (!timer && !size) {
+               ret = 0;
+               goto end;
+       }
+
+       _MSG("Automatic rotation schedule settings:\n");
+
+       if (timer) {
+               _MSG("    timer period: %" PRIu64" µs\n", timer);
+               if (lttng_opt_mi) {
+                       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                                       config_element_rotation_timer_interval, timer);
+                       if (ret) {
+                               goto end;
+                       }
+               }
+       }
+       if (size) {
+               _MSG("    size threshold:  %" PRIu64" bytes\n", size);
+               if (lttng_opt_mi) {
+                       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                                       config_element_rotation_size, size);
+                       if (ret) {
+                               goto end;
+                       }
+               }
+       }
+       _MSG("\n");
+
+end:
+       return ret;
+}
+
 /*
  * Machine interface
  * Find the session with session_name as name
@@ -1925,6 +1976,11 @@ int cmd_list(int argc, const char **argv)
                        goto end;
                }
 
+               ret = list_rotate_settings(session_name);
+               if (ret) {
+                       goto end;
+               }
+
                /* Domain listing */
                if (opt_domain) {
                        ret = list_domains(session_name);
index 65589f83e1e737bce77bad144900ea67fca9ea7c..2746c378c1301a04e2a52ce9d0e45151967ad218 100644 (file)
@@ -81,6 +81,7 @@ extern const char * const config_element_trackers;
 extern const char * const config_element_targets;
 extern const char * const config_element_target_pid;
 extern const char * const config_element_rotation_timer_interval;
+extern const char * const config_element_rotation_size;
 extern const char * const config_element_rotation_schedule;
 
 extern const char * const config_domain_type_kernel;
index 4d5045f09237bf068f6fba08d13643c1acf17d12..49047b1d6acc9f573aa5fb537dd9a6826bae8ede 100644 (file)
@@ -133,6 +133,7 @@ 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";
 
 const char * const config_domain_type_kernel = "KERNEL";
index 7f4592f1eb36b78fdf3e3a15a5e6ab1a268c9f27..2c51ebec702cb40404ba2e90ff455e451d25b6b5 100644 (file)
@@ -278,7 +278,8 @@ by its signed 32-bit representation when converted to msec.
        <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_timer_interval" type="uint64_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:all>
 </xs:complexType>
 
index 8f08d9904a16a05713edf20ae21b20d7b003af83..b8278bbe0a2abb542d6945b3e0eee70631458e46 100644 (file)
@@ -105,6 +105,8 @@ enum lttcomm_sessiond_command {
        LTTNG_ROTATION_GET_INFO             = 46,
        LTTNG_ROTATION_SET_SCHEDULE         = 47,
        LTTNG_SESSION_GET_CURRENT_OUTPUT    = 48,
+       LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD = 49,
+       LTTNG_ROTATION_SCHEDULE_GET_SIZE    = 50,
 };
 
 enum lttcomm_relayd_command {
index d0e1274976be2cc6759cee884e55953c8bf5390f..9ad32f962c035a90429bef225edc75919aa73b41 100644 (file)
@@ -329,3 +329,57 @@ int lttng_rotation_set_schedule(
 end:
        return ret;
 }
+
+int lttng_rotation_schedule_get_timer_period(const char *session_name,
+               uint64_t *rotate_timer)
+{
+       struct lttcomm_session_msg lsm;
+       struct lttng_rotation_schedule_get_timer_period *get_timer = NULL;
+       int ret;
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD;
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+
+       ret = lttng_ctl_ask_sessiond(&lsm, (void **) &get_timer);
+       if (ret < 0) {
+               ret = -1;
+               goto end;
+       }
+
+       *rotate_timer = get_timer->rotate_timer;
+
+       ret = 0;
+
+end:
+       free(get_timer);
+       return ret;
+}
+
+int lttng_rotation_schedule_get_size(const char *session_name,
+               uint64_t *rotate_size)
+{
+       struct lttcomm_session_msg lsm;
+       struct lttng_rotation_schedule_get_size *get_size = NULL;
+       int ret;
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_ROTATION_SCHEDULE_GET_SIZE;
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+
+       ret = lttng_ctl_ask_sessiond(&lsm, (void **) &get_size);
+       if (ret < 0) {
+               ret = -1;
+               goto end;
+       }
+
+       *rotate_size = get_size->rotate_size;
+
+       ret = 0;
+
+end:
+       free(get_size);
+       return ret;
+}
This page took 0.050288 seconds and 4 git commands to generate.