Implement the relayd live features
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index f2043df9cb9c25bf364fb96b08b86340cadc7b1a..85f396f1c0e2329938e50690d919309f239bef6c 100644 (file)
@@ -462,9 +462,6 @@ static int init_kernel_tracing(struct ltt_kernel_session *session)
        if (session->consumer_fds_sent == 0 && session->consumer != NULL) {
                cds_lfht_for_each_entry(session->consumer->socks->ht, &iter.iter,
                                socket, node.node) {
-                       /* Code flow error */
-                       assert(socket->fd >= 0);
-
                        pthread_mutex_lock(socket->lock);
                        ret = kernel_consumer_send_session(socket, session);
                        pthread_mutex_unlock(socket->lock);
@@ -550,7 +547,8 @@ error:
  */
 static int send_consumer_relayd_socket(int domain, unsigned int session_id,
                struct lttng_uri *relayd_uri, struct consumer_output *consumer,
-               struct consumer_socket *consumer_sock)
+               struct consumer_socket *consumer_sock,
+               char *session_name, char *hostname, int session_live_timer)
 {
        int ret;
        struct lttcomm_relayd_sock *rsock = NULL;
@@ -576,7 +574,8 @@ static int send_consumer_relayd_socket(int domain, unsigned int session_id,
 
        /* Send relayd socket to consumer. */
        ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
-                       relayd_uri->stype, session_id);
+                       relayd_uri->stype, session_id,
+                       session_name, hostname, session_live_timer);
        if (ret < 0) {
                ret = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -618,7 +617,8 @@ error:
  * session.
  */
 static int send_consumer_relayd_sockets(int domain, unsigned int session_id,
-               struct consumer_output *consumer, struct consumer_socket *sock)
+               struct consumer_output *consumer, struct consumer_socket *sock,
+               char *session_name, char *hostname, int session_live_timer)
 {
        int ret = LTTNG_OK;
 
@@ -628,7 +628,8 @@ static int send_consumer_relayd_sockets(int domain, unsigned int session_id,
        /* Sending control relayd socket. */
        if (!sock->control_sock_sent) {
                ret = send_consumer_relayd_socket(domain, session_id,
-                               &consumer->dst.net.control, consumer, sock);
+                               &consumer->dst.net.control, consumer, sock,
+                               session_name, hostname, session_live_timer);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -637,7 +638,8 @@ static int send_consumer_relayd_sockets(int domain, unsigned int session_id,
        /* Sending data relayd socket. */
        if (!sock->data_sock_sent) {
                ret = send_consumer_relayd_socket(domain, session_id,
-                               &consumer->dst.net.data, consumer, sock);
+                               &consumer->dst.net.data, consumer, sock,
+                               session_name, hostname, session_live_timer);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -674,12 +676,11 @@ int cmd_setup_relayd(struct ltt_session *session)
                /* For each consumer socket, send relayd sockets */
                cds_lfht_for_each_entry(usess->consumer->socks->ht, &iter.iter,
                                socket, node.node) {
-                       /* Code flow error */
-                       assert(socket->fd >= 0);
-
                        pthread_mutex_lock(socket->lock);
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
-                                       usess->consumer, socket);
+                                       usess->consumer, socket,
+                                       session->name, session->hostname,
+                                       session->live_timer);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -693,12 +694,11 @@ int cmd_setup_relayd(struct ltt_session *session)
                        && ksess->consumer->enabled) {
                cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter,
                                socket, node.node) {
-                       /* Code flow error */
-                       assert(socket->fd >= 0);
-
                        pthread_mutex_lock(socket->lock);
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
-                                       ksess->consumer, socket);
+                                       ksess->consumer, socket,
+                                       session->name, session->hostname,
+                                       session->live_timer);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -859,6 +859,25 @@ int cmd_enable_channel(struct ltt_session *session,
 
        rcu_read_lock();
 
+       /*
+        * Don't try to enable a channel if the session has been started at
+        * some point in time before. The tracer does not allow it.
+        */
+       if (session->started) {
+               ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
+               goto error;
+       }
+
+       /*
+        * If the session is a live session, remove the switch timer, the
+        * live timer does the same thing but sends also synchronisation
+        * beacons for inactive streams.
+        */
+       if (session->live_timer > 0) {
+               attr->attr.live_timer_interval = session->live_timer;
+               attr->attr.switch_timer_interval = 0;
+       }
+
        switch (domain->type) {
        case LTTNG_DOMAIN_KERNEL:
        {
@@ -1124,17 +1143,6 @@ int cmd_add_context(struct ltt_session *session, int domain,
        case LTTNG_DOMAIN_KERNEL:
                assert(session->kernel_session);
 
-               /*
-                * If a non-default channel has been created in the
-                * session, explicitely require that -c chan_name needs
-                * to be provided.
-                */
-               if (session->kernel_session->has_non_default_channel
-                               && channel_name[0] == '\0') {
-                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
-                       goto error;
-               }
-
                if (session->kernel_session->channel_count == 0) {
                        /* Create default channel */
                        ret = channel_kernel_create(session->kernel_session, NULL, kwpipe);
@@ -1156,16 +1164,6 @@ int cmd_add_context(struct ltt_session *session, int domain,
 
                assert(usess);
 
-               /*
-                * If a non-default channel has been created in the
-                * session, explicitely require that -c chan_name needs
-                * to be provided.
-                */
-               if (usess->has_non_default_channel && channel_name[0] == '\0') {
-                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
-                       goto error;
-               }
-
                chan_count = lttng_ht_get_count(usess->domain_global.channels);
                if (chan_count == 0) {
                        struct lttng_channel *attr;
@@ -1794,7 +1792,7 @@ error:
  * Command LTTNG_CREATE_SESSION processed by the client thread.
  */
 int cmd_create_session_uri(char *name, struct lttng_uri *uris,
-               size_t nb_uri, lttng_sock_cred *creds)
+               size_t nb_uri, lttng_sock_cred *creds, unsigned int live_timer)
 {
        int ret;
        struct ltt_session *session;
@@ -1832,6 +1830,7 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris,
        session = session_find_by_name(name);
        assert(session);
 
+       session->live_timer = live_timer;
        /* Create default consumer output for the session not yet created. */
        session->consumer = consumer_create_output(CONSUMER_DST_LOCAL);
        if (session->consumer == NULL) {
@@ -1878,7 +1877,7 @@ int cmd_create_session_snapshot(char *name, struct lttng_uri *uris,
         * Create session in no output mode with URIs set to NULL. The uris we've
         * received are for a default snapshot output if one.
         */
-       ret = cmd_create_session_uri(name, NULL, 0, creds);
+       ret = cmd_create_session_uri(name, NULL, 0, creds, -1);
        if (ret != LTTNG_OK) {
                goto error;
        }
@@ -2048,13 +2047,15 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
                        ret = LTTNG_ERR_CONNECT_FAIL;
                        goto error;
                }
+               cdata->cmd_sock = sock;
 
-               socket = consumer_allocate_socket(sock);
+               socket = consumer_allocate_socket(&cdata->cmd_sock);
                if (socket == NULL) {
                        ret = close(sock);
                        if (ret < 0) {
                                PERROR("close register consumer");
                        }
+                       cdata->cmd_sock = -1;
                        ret = LTTNG_ERR_FATAL;
                        goto error;
                }
@@ -2547,7 +2548,9 @@ static int set_relayd_for_snapshot(struct consumer_output *consumer,
        cds_lfht_for_each_entry(snap_output->consumer->socks->ht, &iter.iter,
                        socket, node.node) {
                ret = send_consumer_relayd_sockets(0, session->id,
-                               snap_output->consumer, socket);
+                               snap_output->consumer, socket,
+                               session->name, session->hostname,
+                               session->live_timer);
                if (ret != LTTNG_OK) {
                        rcu_read_unlock();
                        goto error;
@@ -2598,13 +2601,7 @@ static int record_kernel_snapshot(struct ltt_kernel_session *ksess,
        }
 
        ret = kernel_snapshot_record(ksess, output, wait, nb_streams);
-       if (ret < 0) {
-               if (ret == -EINVAL) {
-                       ret = LTTNG_ERR_INVALID;
-                       goto error_snapshot;
-               }
-
-               ret = LTTNG_ERR_SNAPSHOT_FAIL;
+       if (ret != LTTNG_OK) {
                goto error_snapshot;
        }
 
@@ -2857,6 +2854,8 @@ int cmd_snapshot_record(struct ltt_session *session,
 
        if (snapshot_success) {
                session->snapshot.nb_snapshot++;
+       } else {
+               ret = LTTNG_ERR_SNAPSHOT_FAIL;
        }
 
 error:
This page took 0.029458 seconds and 5 git commands to generate.