Prepare for '-Wunused-parameter'
[lttng-tools.git] / src / common / consumer / consumer.cpp
index 0585b7d50ee149d28243697f46cca6dc427b9f4a..f26ccd71a9ff57bc3eda8c2b97cc58ae5ec0a414 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "common/index/ctf-index.h"
+#include <stdint.h>
 #define _LGPL_SOURCE
 #include <poll.h>
 #include <pthread.h>
@@ -173,7 +174,6 @@ static void clean_channel_stream_list(struct lttng_consumer_channel *channel)
        /* Delete streams that might have been left in the stream list. */
        cds_list_for_each_entry_safe(stream, stmp, &channel->streams.head,
                        send_node) {
-               cds_list_del(&stream->send_node);
                /*
                 * Once a stream is added to this list, the buffers were created so we
                 * have a guarantee that this call will succeed. Setting the monitor
@@ -3404,7 +3404,7 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
         */
        if (stream->rotate_ready) {
                DBG("Rotate stream before consuming data");
-               ret = lttng_consumer_rotate_stream(ctx, stream);
+               ret = lttng_consumer_rotate_stream(stream);
                if (ret < 0) {
                        ERR("Stream rotation error before consuming data");
                        goto end;
@@ -3460,7 +3460,7 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
         */
        rotation_ret = lttng_consumer_stream_is_rotate_ready(stream);
        if (rotation_ret == 1) {
-               rotation_ret = lttng_consumer_rotate_stream(ctx, stream);
+               rotation_ret = lttng_consumer_rotate_stream(stream);
                if (rotation_ret < 0) {
                        ret = rotation_ret;
                        ERR("Stream rotation error after consuming data");
@@ -3564,18 +3564,23 @@ error:
  * This will create a relayd socket pair and add it to the relayd hash table.
  * The caller MUST acquire a RCU read side lock before calling it.
  */
- void consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
-               struct lttng_consumer_local_data *ctx, int sock,
+void consumer_add_relayd_socket(uint64_t net_seq_idx,
+               int sock_type,
+               struct lttng_consumer_local_data *ctx,
+               int sock,
                struct pollfd *consumer_sockpoll,
-               struct lttcomm_relayd_sock *relayd_sock, uint64_t sessiond_id,
-               uint64_t relayd_session_id)
+               uint64_t sessiond_id,
+               uint64_t relayd_session_id,
+               uint32_t relayd_version_major,
+               uint32_t relayd_version_minor,
+               enum lttcomm_sock_proto relayd_socket_protocol)
 {
        int fd = -1, ret = -1, relayd_created = 0;
        enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS;
        struct consumer_relayd_sock_pair *relayd = NULL;
 
        LTTNG_ASSERT(ctx);
-       LTTNG_ASSERT(relayd_sock);
+       LTTNG_ASSERT(sock >= 0);
        ASSERT_RCU_READ_LOCKED();
 
        DBG("Consumer adding relayd socket (idx: %" PRIu64 ")", net_seq_idx);
@@ -3645,54 +3650,25 @@ error:
        switch (sock_type) {
        case LTTNG_STREAM_CONTROL:
                /* Copy received lttcomm socket */
-               lttcomm_copy_sock(&relayd->control_sock.sock, &relayd_sock->sock);
-               ret = lttcomm_create_sock(&relayd->control_sock.sock);
-               /* Handle create_sock error. */
-               if (ret < 0) {
-                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
-                       goto error;
-               }
-               /*
-                * Close the socket created internally by
-                * lttcomm_create_sock, so we can replace it by the one
-                * received from sessiond.
-                */
-               if (close(relayd->control_sock.sock.fd)) {
-                       PERROR("close");
-               }
+               ret = lttcomm_populate_sock_from_open_socket(
+                               &relayd->control_sock.sock, fd,
+                               relayd_socket_protocol);
 
-               /* Assign new file descriptor */
-               relayd->control_sock.sock.fd = fd;
                /* Assign version values. */
-               relayd->control_sock.major = relayd_sock->major;
-               relayd->control_sock.minor = relayd_sock->minor;
+               relayd->control_sock.major = relayd_version_major;
+               relayd->control_sock.minor = relayd_version_minor;
 
                relayd->relayd_session_id = relayd_session_id;
 
                break;
        case LTTNG_STREAM_DATA:
                /* Copy received lttcomm socket */
-               lttcomm_copy_sock(&relayd->data_sock.sock, &relayd_sock->sock);
-               ret = lttcomm_create_sock(&relayd->data_sock.sock);
-               /* Handle create_sock error. */
-               if (ret < 0) {
-                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
-                       goto error;
-               }
-               /*
-                * Close the socket created internally by
-                * lttcomm_create_sock, so we can replace it by the one
-                * received from sessiond.
-                */
-               if (close(relayd->data_sock.sock.fd)) {
-                       PERROR("close");
-               }
-
-               /* Assign new file descriptor */
-               relayd->data_sock.sock.fd = fd;
+               ret = lttcomm_populate_sock_from_open_socket(
+                               &relayd->data_sock.sock, fd,
+                               relayd_socket_protocol);
                /* Assign version values. */
-               relayd->data_sock.major = relayd_sock->major;
-               relayd->data_sock.minor = relayd_sock->minor;
+               relayd->data_sock.major = relayd_version_major;
+               relayd->data_sock.minor = relayd_version_minor;
                break;
        default:
                ERR("Unknown relayd socket type (%d)", sock_type);
@@ -3700,6 +3676,11 @@ error:
                goto error;
        }
 
+       if (ret < 0) {
+               ret_code = LTTCOMM_CONSUMERD_FATAL;
+               goto error;
+       }
+
        DBG("Consumer %s socket created successfully with net idx %" PRIu64 " (fd: %d)",
                        sock_type == LTTNG_STREAM_CONTROL ? "control" : "data",
                        relayd->net_seq_idx, fd);
@@ -4005,8 +3986,7 @@ end:
  * Returns 0 on success, < 0 on error
  */
 int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel,
-               uint64_t key, uint64_t relayd_id, uint32_t metadata,
-               struct lttng_consumer_local_data *ctx)
+               uint64_t key, uint64_t relayd_id)
 {
        int ret;
        struct lttng_consumer_stream *stream;
@@ -4556,8 +4536,7 @@ void lttng_consumer_reset_stream_rotate_state(struct lttng_consumer_stream *stre
  * Perform the rotation a local stream file.
  */
 static
-int rotate_local_stream(struct lttng_consumer_local_data *ctx,
-               struct lttng_consumer_stream *stream)
+int rotate_local_stream(struct lttng_consumer_stream *stream)
 {
        int ret = 0;
 
@@ -4596,8 +4575,7 @@ end:
  *
  * Return 0 on success, a negative number of error.
  */
-int lttng_consumer_rotate_stream(struct lttng_consumer_local_data *ctx,
-               struct lttng_consumer_stream *stream)
+int lttng_consumer_rotate_stream(struct lttng_consumer_stream *stream)
 {
        int ret;
 
@@ -4632,7 +4610,7 @@ int lttng_consumer_rotate_stream(struct lttng_consumer_local_data *ctx,
        }
 
        if (stream->net_seq_idx == (uint64_t) -1ULL) {
-               ret = rotate_local_stream(ctx, stream);
+               ret = rotate_local_stream(stream);
                if (ret < 0) {
                        ERR("Failed to rotate stream, ret = %i", ret);
                        goto error;
@@ -4676,7 +4654,7 @@ error:
  * Returns 0 on success, < 0 on error
  */
 int lttng_consumer_rotate_ready_streams(struct lttng_consumer_channel *channel,
-               uint64_t key, struct lttng_consumer_local_data *ctx)
+               uint64_t key)
 {
        int ret;
        struct lttng_consumer_stream *stream;
@@ -4705,7 +4683,7 @@ int lttng_consumer_rotate_ready_streams(struct lttng_consumer_channel *channel,
                }
                DBG("Consumer rotate ready stream %" PRIu64, stream->key);
 
-               ret = lttng_consumer_rotate_stream(ctx, stream);
+               ret = lttng_consumer_rotate_stream(stream);
                pthread_mutex_unlock(&stream->lock);
                pthread_mutex_unlock(&stream->chan->lock);
                if (ret) {
This page took 0.026748 seconds and 4 git commands to generate.