Fix: hash table cleanup call_rcu deadlock
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index f803f7b0553c19c0458d387ae8b03a73a1969417..2e20878856fd1ee1ab1637b6ff297044bda58d77 100644 (file)
@@ -32,6 +32,7 @@
 #include "consumer.h"
 #include "health.h"
 #include "ust-app.h"
+#include "utils.h"
 
 /*
  * Receive a reply command status message from the consumer. Consumer socket
@@ -407,6 +408,8 @@ error:
 
 /*
  * Delete the consumer_output object from the list and free the ptr.
+ *
+ * Should *NOT* be called with RCU read-side lock held.
  */
 void consumer_destroy_output(struct consumer_output *obj)
 {
@@ -426,7 +429,7 @@ void consumer_destroy_output(struct consumer_output *obj)
                rcu_read_unlock();
 
                /* Finally destroy HT */
-               lttng_ht_destroy(obj->socks);
+               ht_cleanup_push(obj->socks);
        }
 
        free(obj);
@@ -434,6 +437,8 @@ void consumer_destroy_output(struct consumer_output *obj)
 
 /*
  * Copy consumer output and returned the newly allocated copy.
+ *
+ * Should *NOT* be called with RCU read-side lock held.
  */
 struct consumer_output *consumer_copy_output(struct consumer_output *obj)
 {
@@ -504,6 +509,12 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_CONTROL_PORT;
+               } else {
+                       if (obj->dst.net.data_isset && uri->port ==
+                                       obj->dst.net.data.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer control URI set with port %d", uri->port);
                break;
@@ -513,11 +524,18 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_DATA_PORT;
+               } else {
+                       if (obj->dst.net.control_isset && uri->port ==
+                                       obj->dst.net.control.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer data URI set with port %d", uri->port);
                break;
        default:
                ERR("Set network uri type unknown %d", uri->stype);
+               ret = -LTTNG_ERR_INVALID;
                goto error;
        }
 
@@ -553,6 +571,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
                }
                if (ret < 0) {
                        PERROR("snprintf set consumer uri subdir");
+                       ret = -LTTNG_ERR_NOMEM;
                        goto error;
                }
 
@@ -564,7 +583,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
 equal:
        return 1;
 error:
-       return -1;
+       return ret;
 }
 
 /*
@@ -805,14 +824,14 @@ error:
  * On success return positive value. On error, negative value.
  */
 int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
-               struct lttcomm_sock *sock, struct consumer_output *consumer,
+               struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
                enum lttng_stream_type type, uint64_t session_id)
 {
        int ret;
        struct lttcomm_consumer_msg msg;
 
        /* Code flow error. Safety net. */
-       assert(sock);
+       assert(rsock);
        assert(consumer);
        assert(consumer_sock);
 
@@ -831,13 +850,13 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
        msg.u.relayd_sock.net_index = consumer->net_seq_index;
        msg.u.relayd_sock.type = type;
        msg.u.relayd_sock.session_id = session_id;
-       memcpy(&msg.u.relayd_sock.sock, sock, sizeof(msg.u.relayd_sock.sock));
+       memcpy(&msg.u.relayd_sock.sock, rsock, sizeof(msg.u.relayd_sock.sock));
 
        DBG3("Sending relayd sock info to consumer on %d", consumer_sock->fd);
        ret = lttcomm_send_unix_sock(consumer_sock->fd, &msg, sizeof(msg));
        if (ret < 0) {
                /* The above call will print a PERROR on error. */
-               DBG("Error when sending relayd sockets on sock %d", sock->fd);
+               DBG("Error when sending relayd sockets on sock %d", rsock->sock.fd);
                goto error;
        }
 
@@ -847,7 +866,7 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
        }
 
        DBG3("Sending relayd socket file descriptor to consumer");
-       ret = consumer_send_fds(consumer_sock, &sock->fd, 1);
+       ret = consumer_send_fds(consumer_sock, &rsock->sock.fd, 1);
        if (ret < 0) {
                goto error;
        }
@@ -1107,7 +1126,7 @@ int consumer_push_metadata(struct consumer_socket *socket,
                goto end;
        }
 
-       DBG3("Consumer pushing metadata on sock %d of len %lu", socket->fd, len);
+       DBG3("Consumer pushing metadata on sock %d of len %zu", socket->fd, len);
 
        ret = lttcomm_send_unix_sock(socket->fd, metadata_str, len);
        if (ret < 0) {
This page took 0.027834 seconds and 5 git commands to generate.