rotation-api: introduce rotation schedule descriptors
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 9c2458eb1a15a1bee49d1a1babe3d0390418390e..e8f05cecf2694dc8048c4540950611d265097145 100644 (file)
@@ -858,7 +858,7 @@ error:
  *
  * Useful for CPU hotplug feature.
  */
-static int update_kernel_stream(struct consumer_data *consumer_data, int fd)
+static int update_kernel_stream(int fd)
 {
        int ret = 0;
        struct ltt_session *session;
@@ -1092,7 +1092,7 @@ static void *thread_manage_kernel(void *data)
                                         * New CPU detected by the kernel. Adding kernel stream to
                                         * kernel session and updating the kernel consumer
                                         */
-                                       ret = update_kernel_stream(&kconsumer_data, pollfd);
+                                       ret = update_kernel_stream(pollfd);
                                        if (ret < 0) {
                                                continue;
                                        }
@@ -3000,8 +3000,7 @@ 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:
+       case LTTNG_SESSION_LIST_ROTATION_SCHEDULES:
                need_domain = 0;
                break;
        default:
@@ -3046,8 +3045,7 @@ 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:
+       case LTTNG_SESSION_LIST_ROTATION_SCHEDULES:
                break;
        default:
                /* Setup lttng message with no payload */
@@ -4226,15 +4224,24 @@ error_add_context:
        }
        case LTTNG_ROTATION_SET_SCHEDULE:
        {
+               bool set_schedule;
+               enum lttng_rotation_schedule_type schedule_type;
+               uint64_t value;
+
                if (cmd_ctx->session->kernel_session && !check_rotate_compatible()) {
                        DBG("Kernel tracer version does not support session rotations");
                        ret = LTTNG_ERR_ROTATION_WRONG_VERSION;
                        goto error;
                }
 
+               set_schedule = cmd_ctx->lsm->u.rotation_set_schedule.set == 1;
+               schedule_type = (enum lttng_rotation_schedule_type) cmd_ctx->lsm->u.rotation_set_schedule.type;
+               value = cmd_ctx->lsm->u.rotation_set_schedule.value;
+
                ret = cmd_rotation_set_schedule(cmd_ctx->session,
-                               cmd_ctx->lsm->u.rotate_setup.timer_us,
-                               cmd_ctx->lsm->u.rotate_setup.size,
+                               set_schedule,
+                               schedule_type,
+                               value,
                                notification_thread_handle);
                if (ret != LTTNG_OK) {
                        goto error;
@@ -4242,42 +4249,17 @@ error_add_context:
 
                break;
        }
-       case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD:
+       case LTTNG_SESSION_LIST_ROTATION_SCHEDULES:
        {
-               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);
+               struct lttng_session_list_schedules_return schedules = {
+                       .periodic.set = !!cmd_ctx->session->rotate_timer_period,
+                       .periodic.value = cmd_ctx->session->rotate_timer_period,
+                       .size.set = !!cmd_ctx->session->rotate_size,
+                       .size.value = cmd_ctx->session->rotate_size,
+               };
+
+               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, &schedules,
+                               sizeof(schedules));
                if (ret < 0) {
                        ret = -ret;
                        goto error;
@@ -4574,8 +4556,17 @@ static void *thread_manage_clients(void *data)
                if (ret > 0 || (ret < 0 && errno != EINTR)) {
                        goto exit;
                }
-               cmm_smp_rmb();
        }
+       /*
+        * This barrier is paired with the one in sessiond_notify_ready() to
+        * ensure that loads accessing data initialized by the other threads,
+        * on which this thread was waiting, are not performed before this point.
+        *
+        * Note that this could be a 'read' memory barrier, but a full barrier
+        * is used in case the code changes. The performance implications of
+        * this choice are minimal since this is a slow path.
+        */
+       cmm_smp_mb();
 
        /* This testpoint is after we signal readiness to the parent. */
        if (testpoint(sessiond_thread_manage_clients)) {
@@ -4589,6 +4580,8 @@ static void *thread_manage_clients(void *data)
        health_code_update();
 
        while (1) {
+               const struct cmd_completion_handler *cmd_completion_handler;
+
                DBG("Accepting client command ...");
 
                /* Inifinite blocking call, waiting for transmission */
@@ -4731,6 +4724,18 @@ static void *thread_manage_clients(void *data)
                        continue;
                }
 
+               cmd_completion_handler = cmd_pop_completion_handler();
+               if (cmd_completion_handler) {
+                       enum lttng_error_code completion_code;
+
+                       completion_code = cmd_completion_handler->run(
+                                       cmd_completion_handler->data);
+                       if (completion_code != LTTNG_OK) {
+                               clean_command_ctx(&cmd_ctx);
+                               continue;
+                       }
+               }
+
                health_code_update();
 
                DBG("Sending response (size: %d, retcode: %s (%d))",
@@ -5821,6 +5826,12 @@ int main(int argc, char **argv)
                goto exit_set_signal_handler;
        }
 
+       /*
+        * Init config from environment variables.
+        * Command line option override env configuration per-doc. Do env first.
+        */
+       sessiond_config_apply_env_config(&config);
+
        /*
         * Parse arguments and load the daemon configuration file.
         *
@@ -5835,9 +5846,6 @@ int main(int argc, char **argv)
                goto exit_options;
        }
 
-       /* Init config from environment variables. */
-       sessiond_config_apply_env_config(&config);
-
        /*
         * Resolve all paths received as arguments, configuration option, or
         * through environment variable as absolute paths. This is necessary
This page took 0.028147 seconds and 5 git commands to generate.