relayd: add `lttcomm_relayd_command_str()`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 11 Nov 2021 15:48:31 +0000 (10:48 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 10 Jan 2022 23:50:32 +0000 (18:50 -0500)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Idfd708843d19ca1b2cfe458a3b2b37e55f9c3274

src/bin/lttng-relayd/main.cpp
src/common/relayd/relayd.cpp
src/common/sessiond-comm/sessiond-comm.h

index dbf69a0e6537f119992ca004ec34e8e25bd3b36f..d3f8b3c9e30234a98eed30f49831028a3f9a99bf 100644 (file)
@@ -3301,86 +3301,68 @@ end_no_reply:
        return ret;
 }
 
-#define DBG_CMD(cmd_name, conn) \
-               DBG3("Processing \"%s\" command for socket %i", cmd_name, conn->sock->fd);
-
 static int relay_process_control_command(struct relay_connection *conn,
                const struct lttcomm_relayd_hdr *header,
                const struct lttng_buffer_view *payload)
 {
        int ret = 0;
 
+       DBG3("Processing \"%s\" command for socket %i",
+                       lttcomm_relayd_command_str((lttcomm_relayd_command) header->cmd),
+                       conn->sock->fd);
        switch (header->cmd) {
        case RELAYD_CREATE_SESSION:
-               DBG_CMD("RELAYD_CREATE_SESSION", conn);
                ret = relay_create_session(header, conn, payload);
                break;
        case RELAYD_ADD_STREAM:
-               DBG_CMD("RELAYD_ADD_STREAM", conn);
                ret = relay_add_stream(header, conn, payload);
                break;
        case RELAYD_START_DATA:
-               DBG_CMD("RELAYD_START_DATA", conn);
                ret = relay_start(header, conn, payload);
                break;
        case RELAYD_SEND_METADATA:
-               DBG_CMD("RELAYD_SEND_METADATA", conn);
                ret = relay_recv_metadata(header, conn, payload);
                break;
        case RELAYD_VERSION:
-               DBG_CMD("RELAYD_VERSION", conn);
                ret = relay_send_version(header, conn, payload);
                break;
        case RELAYD_CLOSE_STREAM:
-               DBG_CMD("RELAYD_CLOSE_STREAM", conn);
                ret = relay_close_stream(header, conn, payload);
                break;
        case RELAYD_DATA_PENDING:
-               DBG_CMD("RELAYD_DATA_PENDING", conn);
                ret = relay_data_pending(header, conn, payload);
                break;
        case RELAYD_QUIESCENT_CONTROL:
-               DBG_CMD("RELAYD_QUIESCENT_CONTROL", conn);
                ret = relay_quiescent_control(header, conn, payload);
                break;
        case RELAYD_BEGIN_DATA_PENDING:
-               DBG_CMD("RELAYD_BEGIN_DATA_PENDING", conn);
                ret = relay_begin_data_pending(header, conn, payload);
                break;
        case RELAYD_END_DATA_PENDING:
-               DBG_CMD("RELAYD_END_DATA_PENDING", conn);
                ret = relay_end_data_pending(header, conn, payload);
                break;
        case RELAYD_SEND_INDEX:
-               DBG_CMD("RELAYD_SEND_INDEX", conn);
                ret = relay_recv_index(header, conn, payload);
                break;
        case RELAYD_STREAMS_SENT:
-               DBG_CMD("RELAYD_STREAMS_SENT", conn);
                ret = relay_streams_sent(header, conn, payload);
                break;
        case RELAYD_RESET_METADATA:
-               DBG_CMD("RELAYD_RESET_METADATA", conn);
                ret = relay_reset_metadata(header, conn, payload);
                break;
        case RELAYD_ROTATE_STREAMS:
-               DBG_CMD("RELAYD_ROTATE_STREAMS", conn);
                ret = relay_rotate_session_streams(header, conn, payload);
                break;
        case RELAYD_CREATE_TRACE_CHUNK:
-               DBG_CMD("RELAYD_CREATE_TRACE_CHUNK", conn);
                ret = relay_create_trace_chunk(header, conn, payload);
                break;
        case RELAYD_CLOSE_TRACE_CHUNK:
-               DBG_CMD("RELAYD_CLOSE_TRACE_CHUNK", conn);
                ret = relay_close_trace_chunk(header, conn, payload);
                break;
        case RELAYD_TRACE_CHUNK_EXISTS:
-               DBG_CMD("RELAYD_TRACE_CHUNK_EXISTS", conn);
                ret = relay_trace_chunk_exists(header, conn, payload);
                break;
        case RELAYD_GET_CONFIGURATION:
-               DBG_CMD("RELAYD_GET_CONFIGURATION", conn);
                ret = relay_get_configuration(header, conn, payload);
                break;
        case RELAYD_UPDATE_SYNC_INFO:
@@ -3528,9 +3510,9 @@ static enum relay_connection_status relay_process_control_receive_header(
        memcpy(&conn->protocol.ctrl.state.receive_payload.header,
                        &header, sizeof(header));
 
-       DBG("Done receiving control command header: fd = %i, cmd = %" PRIu32 ", cmd_version = %" PRIu32 ", payload size = %" PRIu64 " bytes",
-                       conn->sock->fd, header.cmd, header.cmd_version,
-                       header.data_size);
+       DBG("Done receiving control command header: fd = %i, cmd = %s, cmd_version = %" PRIu32 ", payload size = %" PRIu64 " bytes",
+                       conn->sock->fd, lttcomm_relayd_command_str((enum lttcomm_relayd_command) header.cmd),
+                       header.cmd_version, header.data_size);
 
        if (header.data_size > DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE) {
                ERR("Command header indicates a payload (%" PRIu64 " bytes) that exceeds the maximal payload size allowed on a control connection.",
index 5ca919f23c517ace58b8de3cf59f126a6766a4d9..6c2641ac03bec575f2c7ad469bac9ddd19bb7fe0 100644 (file)
@@ -86,11 +86,13 @@ static int send_command(struct lttcomm_relayd_sock *rsock,
                memcpy(buf + sizeof(header), data, size);
        }
 
-       DBG3("Relayd sending command %d of size %" PRIu64, (int) cmd, buf_size);
+       DBG3("Relayd sending command %s of size %" PRIu64,
+                       lttcomm_relayd_command_str(cmd), buf_size);
        ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags);
        if (ret < 0) {
-               PERROR("Failed to send command %d of size %" PRIu64,
-                               (int) cmd, buf_size);
+               PERROR("Failed to send command %s of size %" PRIu64,
+                               lttcomm_relayd_command_str(cmd), buf_size);
+       ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags);
                ret = -errno;
                goto error;
        }
index d81e0b8cf7bc12aa156d5159873b209c904f4737..ba756f8f197ce8fd4cea1ebf3dc5d36b5080a1c0 100644 (file)
@@ -235,6 +235,59 @@ enum lttcomm_relayd_command {
        /* Feature branch specific commands start at 10000. */
 };
 
+static inline
+const char *lttcomm_relayd_command_str(lttcomm_relayd_command cmd)
+{
+       switch (cmd) {
+       case RELAYD_ADD_STREAM:
+               return "RELAYD_ADD_STREAM";
+       case RELAYD_CREATE_SESSION:
+               return "RELAYD_CREATE_SESSION";
+       case RELAYD_START_DATA:
+               return "RELAYD_START_DATA";
+       case RELAYD_UPDATE_SYNC_INFO:
+               return "RELAYD_UPDATE_SYNC_INFO";
+       case RELAYD_VERSION:
+               return "RELAYD_VERSION";
+       case RELAYD_SEND_METADATA:
+               return "RELAYD_SEND_METADATA";
+       case RELAYD_CLOSE_STREAM:
+               return "RELAYD_CLOSE_STREAM";
+       case RELAYD_DATA_PENDING:
+               return "RELAYD_DATA_PENDING";
+       case RELAYD_QUIESCENT_CONTROL:
+               return "RELAYD_QUIESCENT_CONTROL";
+       case RELAYD_BEGIN_DATA_PENDING:
+               return "RELAYD_BEGIN_DATA_PENDING";
+       case RELAYD_END_DATA_PENDING:
+               return "RELAYD_END_DATA_PENDING";
+       case RELAYD_ADD_INDEX:
+               return "RELAYD_ADD_INDEX";
+       case RELAYD_SEND_INDEX:
+               return "RELAYD_SEND_INDEX";
+       case RELAYD_CLOSE_INDEX:
+               return "RELAYD_CLOSE_INDEX";
+       case RELAYD_LIST_SESSIONS:
+               return "RELAYD_LIST_SESSIONS";
+       case RELAYD_STREAMS_SENT:
+               return "RELAYD_STREAMS_SENT";
+       case RELAYD_RESET_METADATA:
+               return "RELAYD_RESET_METADATA";
+       case RELAYD_ROTATE_STREAMS:
+               return "RELAYD_ROTATE_STREAMS";
+       case RELAYD_CREATE_TRACE_CHUNK:
+               return "RELAYD_CREATE_TRACE_CHUNK";
+       case RELAYD_CLOSE_TRACE_CHUNK:
+               return "RELAYD_CLOSE_TRACE_CHUNK";
+       case RELAYD_TRACE_CHUNK_EXISTS:
+               return "RELAYD_TRACE_CHUNK_EXISTS";
+       case RELAYD_GET_CONFIGURATION:
+               return "RELAYD_GET_CONFIGURATION";
+       default:
+               abort();
+       }
+}
+
 /*
  * lttcomm error code.
  */
This page took 0.029537 seconds and 4 git commands to generate.