From 9235dedf92dbeca0a3069417265da5cc609d44da Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 15 Apr 2014 10:52:32 +0100 Subject: [PATCH] rxgen: Clean up the debugging in the AF_RXRPC driver a bit Signed-off-by: David Howells --- af_rxrpc.c | 77 ++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/af_rxrpc.c b/af_rxrpc.c index 4dce64b..859a9da 100644 --- a/af_rxrpc.c +++ b/af_rxrpc.c @@ -24,6 +24,8 @@ #define RXGEN_BUF_MAGIC (0x52420000U | __LINE__) #define RXGEN_BUF_DEAD (0x6b6bU | __LINE__) +#define debug(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0) + /* * dump the control messages */ @@ -269,7 +271,7 @@ struct rx_call *rxrpc_alloc_call(struct rx_connection *z_conn, return NULL; } - //printf("Alloc: buf=%p data=%p\n", buf, data); + debug("Alloc: buf=%p data=%p\n", buf, data); buf->magic = RXGEN_BUF_MAGIC; buf->buf = data; @@ -327,9 +329,9 @@ int rxrpc_send_data(struct rx_call *call) size_t ctrllen; unsigned char control[128]; struct iovec iov[16]; - int ioc, ret; + int ioc, ret, i; - //printf("-->rxrpc_send_data(%u,%u)\n", call->state, call->data_count); + debug("-->rxrpc_send_data(%u,0x%x)\n", call->state, call->data_count); rxrpc_check_call(call); @@ -383,6 +385,8 @@ int rxrpc_send_data(struct rx_call *call) if (cursor == call->buffer_tail) end = call->data_cursor - cursor->buf; + debug("BUF[%02u] %04x %04x\n", ioc, io_cursor, end); + iov[ioc].iov_base = cursor->buf + io_cursor; iov[ioc].iov_len = end - io_cursor; if (cursor == call->buffer_tail) { @@ -395,37 +399,12 @@ int rxrpc_send_data(struct rx_call *call) /* Send the data */ //dump_cmsg(&msg); - if (0) { - const uint8_t *p; - unsigned i, j; - - printf("NAME %02u [", msg.msg_namelen); - p = (const void *)msg.msg_name; - for (i = 0; i < msg.msg_namelen; i++) - printf("%02x", *p++); - printf("]\n"); - - for (j = 0; j < msg.msg_iovlen; j++) { - printf("IOV[%02u] %04zu [", j, msg.msg_iov[j].iov_len); - p = (const void *)msg.msg_iov[j].iov_base; - for (i = 0; i < msg.msg_iov[j].iov_len; i++) - printf("%02x", *p++); - printf("]\n"); - } - - printf("CTRL %02zu [", msg.msg_controllen); - p = (const void *)msg.msg_control; - for (i = 0; i < msg.msg_controllen; i++) - printf("%02x", *p++); - printf("]\n"); - - printf("FLAGS %x\n", msg.msg_flags); - } + for (i = 0; i < msg.msg_iovlen; i++) + debug("IOV[%02u] %04zu %p\n", + i, msg.msg_iov[i].iov_len, msg.msg_iov[i].iov_base); ret = sendmsg(call->conn->fd, &msg, call->more ? MSG_MORE : 0) == -1 ? -1 : 0; - if (0) { - printf("SENDMSG: %d\n", ret); - } + debug("SENDMSG: %d\n", ret); if (ret == -1) return -1; @@ -468,7 +447,7 @@ int rxrpc_send_data(struct rx_call *call) if (call->state == rx_call_cl_waiting_for_response) { /* Prepare to decode the response */ - //printf("Prep to decode\n"); + debug("Prep to decode\n"); call->data_stop = call->data_cursor = call->data_start = call->buffer_head->buf; call->buffer_head->io_cursor = 0; call->data_count = 0; @@ -506,9 +485,7 @@ int rxrpc_recv_data(struct rx_connection *z_conn) msg.msg_flags = 0; ret = recvmsg(z_conn->fd, &msg, MSG_PEEK); - if (0) { - printf("RECVMSG: %d\n", ret); - } + debug("RECVMSG: %d\n", ret); if (ret == -1) return -1; @@ -538,8 +515,8 @@ int rxrpc_recv_data(struct rx_connection *z_conn) msg.msg_controllen = sizeof(control); msg.msg_flags = 0; - //printf("Recv: buf[0]=%p data[0]=%p (io=%u)\n", - // call->buffer_tail, call->buffer_tail->buf, call->buffer_tail->io_cursor); + debug("Recv: buf[0]=%p data[0]=%p (io=%u)\n", + call->buffer_tail, call->buffer_tail->buf, call->buffer_tail->io_cursor); rxrpc_check_call(call); @@ -581,21 +558,19 @@ int rxrpc_recv_data(struct rx_connection *z_conn) msg.msg_iovlen = 4; ret = recvmsg(z_conn->fd, &msg, 0); - if (0) { - printf("RECVMSG: %d\n", ret); - } + debug("RECVMSG: %d\n", ret); if (ret == -1) return -1; - //printf("RECV: %d [fl:%d]\n", ret, msg.msg_flags); - //printf("CMSG: %zu\n", msg.msg_controllen); - //printf("IOV: %zu [0]=%zu\n", msg.msg_iovlen, iov[0].iov_len); + debug("RECV: %d [fl:%d]\n", ret, msg.msg_flags); + debug("CMSG: %zu\n", msg.msg_controllen); + debug("IOV: %zu [0]=%zu\n", msg.msg_iovlen, iov[0].iov_len); /* Attach any used buffers to the call and discard the rest */ if (ret > 0) { for (ioc = 0; ioc < 4 && ret > 0; ioc++) { unsigned added = RXGEN_BUFFER_SIZE - bufs[ioc]->io_cursor; - //printf("xfer[%d] space=%u rem=%d\n", ioc, added, ret); + debug("xfer[%d] space=%u rem=%d\n", ioc, added, ret); if (added > ret) added = ret; bufs[ioc]->io_cursor += added; @@ -620,11 +595,9 @@ int rxrpc_recv_data(struct rx_connection *z_conn) rxrpc_check_call(call); - if (0) { - for (cursor = call->buffer_head; cursor; cursor = cursor->next) - printf("Recv buf=%p data=%p ioc=%u\n", - cursor, cursor->buf, cursor->io_cursor); - } + for (cursor = call->buffer_head; cursor; cursor = cursor->next) + debug("Recv buf=%p data=%p ioc=%u\n", + cursor, cursor->buf, cursor->io_cursor); /* Process the metadata */ if (msg.msg_flags & MSG_EOR) @@ -845,10 +818,10 @@ int rxrpc_run_sync_call(struct rx_call *call) switch (call->state) { case rx_call_cl_complete: - //printf("Call complete\n"); + debug("Call complete\n"); return 0; case rx_call_remotely_aborted ... rx_call_rejected_busy: - //printf("Call failed\n"); + debug("Call failed\n"); errno = call->error_code; return -1; default: -- 2.49.0