CUSTOM: liver timer: immediate liver timer control on data pending and destroy
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 8290b5faf05944fdae379a6b812f0a622020903e..76572a075c9afca920d782a8b7639c11396c9896 100644 (file)
@@ -731,6 +731,8 @@ error:
 
 /*
  * Send file descriptor to consumer via sock.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd)
 {
@@ -739,6 +741,7 @@ int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd)
        assert(fds);
        assert(sock);
        assert(nb_fd > 0);
+       assert(pthread_mutex_trylock(sock->lock) == EBUSY);
 
        ret = lttcomm_send_fds_unix_sock(*sock->fd_ptr, fds, nb_fd);
        if (ret < 0) {
@@ -755,6 +758,8 @@ error:
 
 /*
  * Consumer send communication message structure to consumer.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_msg(struct consumer_socket *sock,
                struct lttcomm_consumer_msg *msg)
@@ -778,6 +783,8 @@ error:
 
 /*
  * Consumer send channel communication message structure to consumer.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_channel(struct consumer_socket *sock,
                struct lttcomm_consumer_msg *msg)
@@ -807,6 +814,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                unsigned int switch_timer_interval,
                unsigned int read_timer_interval,
                unsigned int live_timer_interval,
+               bool is_in_live_session,
                int output,
                int type,
                uint64_t session_id,
@@ -838,6 +846,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.ask_channel.switch_timer_interval = switch_timer_interval;
        msg->u.ask_channel.read_timer_interval = read_timer_interval;
        msg->u.ask_channel.live_timer_interval = live_timer_interval;
+       msg->u.ask_channel.is_live = is_in_live_session;
        msg->u.ask_channel.output = output;
        msg->u.ask_channel.type = type;
        msg->u.ask_channel.session_id = session_id;
@@ -893,7 +902,8 @@ void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                uint64_t tracefile_size,
                uint64_t tracefile_count,
                unsigned int monitor,
-               unsigned int live_timer_interval)
+               unsigned int live_timer_interval,
+               bool is_in_live_session)
 {
        assert(msg);
 
@@ -914,6 +924,7 @@ void consumer_init_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.channel.tracefile_count = tracefile_count;
        msg->u.channel.monitor = monitor;
        msg->u.channel.live_timer_interval = live_timer_interval;
+       msg->u.channel.is_live = is_in_live_session;
 
        strncpy(msg->u.channel.pathname, pathname,
                        sizeof(msg->u.channel.pathname));
@@ -986,6 +997,8 @@ error:
 /*
  * Send relayd socket to consumer associated with a session name.
  *
+ * The consumer socket lock must be held by the caller.
+ *
  * On success return positive value. On error, negative value.
  */
 int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
@@ -1192,6 +1205,69 @@ end:
        return ret;
 }
 
+/*
+ * Stop live timer.
+ *
+ * Return 0 on success else a negative value.
+ */
+int consumer_channel_stop_live_timer(struct consumer_socket *socket, uint64_t key)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG2("Consumer stop live timer for channel key %" PRIu64, key);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_CHANNEL_STOP_LIVE_TIMER;
+       msg.u.stop_live_timer.key = key;
+
+       pthread_mutex_lock(socket->lock);
+       health_code_update();
+
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto end;
+       }
+
+end:
+       health_code_update();
+       pthread_mutex_unlock(socket->lock);
+       return ret;
+}
+
+/*
+ * Start live timer.
+ *
+ * Return 0 on success else a negative value.
+ */
+int consumer_channel_start_live_timer(struct consumer_socket *socket, uint64_t key)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG2("Consumer start live timer for channel key %" PRIu64, key);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_CHANNEL_START_LIVE_TIMER;
+       msg.u.start_live_timer.key = key;
+
+       pthread_mutex_lock(socket->lock);
+       health_code_update();
+
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto end;
+       }
+
+end:
+       health_code_update();
+       pthread_mutex_unlock(socket->lock);
+       return ret;
+}
 /*
  * Send a clear quiescent command to consumer using the given channel key.
  *
@@ -1403,7 +1479,9 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
        }
 
        health_code_update();
+       pthread_mutex_lock(socket->lock);
        ret = consumer_send_msg(socket, &msg);
+       pthread_mutex_unlock(socket->lock);
        if (ret < 0) {
                goto error;
        }
This page took 0.02742 seconds and 5 git commands to generate.