Don't send the subbuffer padding for streaming
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 77e314d95771757bd97e14765247752d08242f9b..fdddcbe6efcf54309078b3ad67917b0f46b59bbf 100644 (file)
@@ -977,9 +977,9 @@ end:
        free(root_path);
        /* send the session id to the client or a negative return code on error */
        if (ret < 0) {
-               reply.ret_code = htobe32(LTTCOMM_ERR);
+               reply.ret_code = htobe32(LTTNG_ERR_UNK);
        } else {
-               reply.ret_code = htobe32(LTTCOMM_OK);
+               reply.ret_code = htobe32(LTTNG_OK);
        }
        reply.handle = htobe64(stream->stream_handle);
        send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
@@ -1058,9 +1058,9 @@ end_unlock:
        rcu_read_unlock();
 
        if (ret < 0) {
-               reply.ret_code = htobe32(LTTCOMM_ERR);
+               reply.ret_code = htobe32(LTTNG_ERR_UNK);
        } else {
-               reply.ret_code = htobe32(LTTCOMM_OK);
+               reply.ret_code = htobe32(LTTNG_OK);
        }
        send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
                        sizeof(struct lttcomm_relayd_generic_reply), 0);
@@ -1081,7 +1081,7 @@ void relay_unknown_command(struct relay_command *cmd)
        struct lttcomm_relayd_generic_reply reply;
        int ret;
 
-       reply.ret_code = htobe32(LTTCOMM_ERR);
+       reply.ret_code = htobe32(LTTNG_ERR_UNK);
        ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
                        sizeof(struct lttcomm_relayd_generic_reply), 0);
        if (ret < 0) {
@@ -1097,13 +1097,13 @@ static
 int relay_start(struct lttcomm_relayd_hdr *recv_hdr,
                struct relay_command *cmd)
 {
-       int ret = htobe32(LTTCOMM_OK);
+       int ret = htobe32(LTTNG_OK);
        struct lttcomm_relayd_generic_reply reply;
        struct relay_session *session = cmd->session;
 
        if (!session) {
                DBG("Trying to start the streaming without a session established");
-               ret = htobe32(LTTCOMM_ERR);
+               ret = htobe32(LTTNG_ERR_UNK);
        }
 
        reply.ret_code = ret;
@@ -1144,6 +1144,36 @@ end:
        return ret;
 }
 
+/*
+ * Append padding to the file pointed by the file descriptor fd.
+ */
+static int write_padding_to_file(int fd, uint32_t size)
+{
+       int ret = 0;
+       char *zeros;
+
+       if (size == 0) {
+               goto end;
+       }
+
+       zeros = zmalloc(size);
+       if (zeros == NULL) {
+               PERROR("zmalloc zeros for padding");
+               ret = -1;
+               goto end;
+       }
+
+       do {
+               ret = write(fd, zeros, size);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               PERROR("write padding to file");
+       }
+
+end:
+       return ret;
+}
+
 /*
  * relay_recv_metadata: receive the metada for the session.
  */
@@ -1151,7 +1181,7 @@ static
 int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr,
                struct relay_command *cmd, struct lttng_ht *streams_ht)
 {
-       int ret = htobe32(LTTCOMM_OK);
+       int ret = htobe32(LTTNG_OK);
        struct relay_session *session = cmd->session;
        struct lttcomm_relayd_metadata_payload *metadata_struct;
        struct relay_stream *metadata_stream;
@@ -1208,6 +1238,13 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr,
                ret = -1;
                goto end_unlock;
        }
+
+       ret = write_padding_to_file(metadata_stream->fd,
+                       be32toh(metadata_struct->padding_size));
+       if (ret < 0) {
+               goto end_unlock;
+       }
+
        DBG2("Relay metadata written");
 
 end_unlock:
@@ -1223,7 +1260,7 @@ static
 int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
                struct relay_command *cmd)
 {
-       int ret = htobe32(LTTCOMM_OK);
+       int ret = htobe32(LTTNG_OK);
        struct lttcomm_relayd_version reply;
        struct relay_session *session = NULL;
 
@@ -1248,7 +1285,8 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
        if (ret < 0) {
                ERR("Relay sending version");
        }
-       DBG("Version check done");
+       DBG("Version check done (%u.%u)", be32toh(reply.major),
+                       be32toh(reply.minor));
 
 end:
        return ret;
@@ -1356,6 +1394,12 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
                ret = -1;
                goto end_unlock;
        }
+
+       ret = write_padding_to_file(stream->fd, be32toh(data_hdr.padding_size));
+       if (ret < 0) {
+               goto end_unlock;
+       }
+
        DBG2("Relay wrote %d bytes to tracefile for stream id %" PRIu64,
                ret, stream->stream_handle);
 
@@ -1406,7 +1450,7 @@ int relay_add_connection(int fd, struct lttng_poll_event *events,
                goto error;
        }
        ret = read(fd, relay_connection, sizeof(struct relay_command));
-       if (ret < 0 || ret < sizeof(relay_connection)) {
+       if (ret < 0 || ret < sizeof(struct relay_command)) {
                PERROR("read relay cmd pipe");
                goto error_read;
        }
This page took 0.025515 seconds and 4 git commands to generate.