From: Francis Deslauriers Date: Thu, 11 Nov 2021 15:48:31 +0000 (-0500) Subject: relayd: add `lttcomm_relayd_command_str()` X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=00e71031969e1cef925cd32f81de49ab7213dfec;p=lttng-tools.git relayd: add `lttcomm_relayd_command_str()` Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Idfd708843d19ca1b2cfe458a3b2b37e55f9c3274 --- diff --git a/src/bin/lttng-relayd/main.cpp b/src/bin/lttng-relayd/main.cpp index dbf69a0e6..d3f8b3c9e 100644 --- a/src/bin/lttng-relayd/main.cpp +++ b/src/bin/lttng-relayd/main.cpp @@ -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.", diff --git a/src/common/relayd/relayd.cpp b/src/common/relayd/relayd.cpp index 5ca919f23..6c2641ac0 100644 --- a/src/common/relayd/relayd.cpp +++ b/src/common/relayd/relayd.cpp @@ -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; } diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index d81e0b8cf..ba756f8f1 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -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. */