summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/kiro-client.c36
-rw-r--r--src/kiro-server.c68
-rw-r--r--test/test-server.c2
3 files changed, 54 insertions, 52 deletions
diff --git a/src/kiro-client.c b/src/kiro-client.c
index b930595..c4ef9ed 100644
--- a/src/kiro-client.c
+++ b/src/kiro-client.c
@@ -98,7 +98,7 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
if (priv->conn) {
- printf ("Already connected to server.\n");
+ g_warning ("Already connected to server");
return -1;
}
@@ -109,11 +109,11 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
hints.ai_port_space = RDMA_PS_IB;
if (rdma_getaddrinfo (address, port, &hints, &res_addrinfo)) {
- printf ("Failed to contruct address information for %s:%s\n", address, port);
+ g_critical ("Failed to get address information for %s:%s : %s", address, port, strerror (errno));
return -1;
}
- printf ("Address information created.\n");
+ g_debug ("Address information created");
struct ibv_qp_init_attr qp_attr;
memset (&qp_attr, 0, sizeof (qp_attr));
qp_attr.cap.max_send_wr = 10;
@@ -124,15 +124,15 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
qp_attr.sq_sig_all = 1;
if (rdma_create_ep (& (priv->conn), res_addrinfo, NULL, &qp_attr)) {
- printf ("Endpoint creation failed with error: %i\n", errno);
+ g_critical ("Endpoint creation failed: %s", strerror (errno));
return -1;
}
- printf ("Route to server resolved.\n");
+ g_debug ("Route to server resolved");
struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context));
if (!ctx) {
- printf ("Failed to create connection context.\n");
+ g_critical ("Failed to create connection context (Out of memory?)");
rdma_destroy_ep (priv->conn);
return -1;
}
@@ -141,7 +141,7 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
- printf ("Failed to allocate Control Flow Memory Container.\n");
+ g_critical ("Failed to allocate Control Flow Memory Container (Out of memory?)");
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
@@ -151,7 +151,7 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
ctx->cf_mr_send = kiro_create_rdma_memory (priv->conn->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
- printf ("Failed to register control message memory.\n");
+ g_critical ("Failed to register control message memory (Out of memory?)");
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
@@ -161,44 +161,44 @@ kiro_client_connect (KiroClient *self, char *address, char *port)
priv->conn->context = ctx;
if (rdma_post_recv (priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr)) {
- printf ("Posting preemtive receive for connection failed with error: %i\n", errno);
+ g_critical ("Posting preemtive receive for connection failed: %s", strerror (errno));
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
}
if (rdma_connect (priv->conn, NULL)) {
- printf ("Failed to establish connection to the server.\n");
+ g_critical ("Failed to establish connection to the server: %s", strerror (errno));
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
}
- printf ("Connected to server.\n");
+ g_message ("Connection to server established");
struct ibv_wc wc;
if (rdma_get_recv_comp (priv->conn, &wc) < 0) {
- printf ("Failure waiting for POST from server.\n");
+ g_critical ("Failure waiting for POST from server: %s", strerror (errno));
rdma_disconnect (priv->conn);
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
}
- printf ("Got Message from Server.\n");
+ g_debug ("Got RDMI Access information from Server");
ctx->peer_mr = (((struct kiro_ctrl_msg *) (ctx->cf_mr_recv->mem))->peer_mri);
- printf ("Expected Memory Size is: %u\n", ctx->peer_mr.length);
+ g_debug ("Expected Memory Size is: %u", ctx->peer_mr.length);
ctx->rdma_mr = kiro_create_rdma_memory (priv->conn->pd, ctx->peer_mr.length, IBV_ACCESS_LOCAL_WRITE);
if (!ctx->rdma_mr) {
- printf ("Failed to allocate memory for receive buffer.\n");
+ g_critical ("Failed to allocate memory for receive buffer (Out of memory?)");
rdma_disconnect (priv->conn);
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
return -1;
}
- printf ("Connection setup completed successfully!\n");
+ g_message ("Connected to %s:%s", address, port);
return 0;
}
@@ -211,7 +211,7 @@ kiro_client_sync (KiroClient *self)
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
if (rdma_post_read (priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, ctx->peer_mr.addr, ctx->peer_mr.rkey)) {
- printf ("Failed to read from server.\n");
+ g_critical ("Failed to RDMA_READ from server: %s", strerror (errno));
rdma_disconnect (priv->conn);
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
@@ -221,7 +221,7 @@ kiro_client_sync (KiroClient *self)
struct ibv_wc wc;
if (rdma_get_send_comp (priv->conn, &wc) < 0) {
- printf ("Failure reading from server.\n");
+ g_critical ("No send completion for RDMA_READ received: %s", strerror (errno));
rdma_disconnect (priv->conn);
kiro_destroy_connection_context (&ctx);
rdma_destroy_ep (priv->conn);
diff --git a/src/kiro-server.c b/src/kiro-server.c
index c69b6e7..3913006 100644
--- a/src/kiro-server.c
+++ b/src/kiro-server.c
@@ -105,7 +105,7 @@ connect_client (struct rdma_cm_id *client)
return -1;
if ( -1 == kiro_attach_qp (client)) {
- printf ("Could not create a QP for the new connection.\n");
+ g_critical ("Could not create a QP for the new connection");
rdma_destroy_id (client);
return -1;
}
@@ -113,7 +113,7 @@ connect_client (struct rdma_cm_id *client)
struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context));
if (!ctx) {
- printf ("Failed to create connection context.\n");
+ g_critical ("Failed to create connection context");
rdma_destroy_id (client);
return -1;
}
@@ -122,7 +122,7 @@ connect_client (struct rdma_cm_id *client)
ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
- printf ("Failed to allocate Control Flow Memory Container.\n");
+ g_critical ("Failed to allocate Control Flow Memory Container");
goto error;
}
@@ -130,7 +130,7 @@ connect_client (struct rdma_cm_id *client)
ctx->cf_mr_send = kiro_create_rdma_memory (client->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
- printf ("Failed to register control message memory.\n");
+ g_critical ("Failed to register control message memory");
goto error;
}
@@ -138,16 +138,16 @@ connect_client (struct rdma_cm_id *client)
client->context = ctx;
if (rdma_post_recv (client, client, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr)) {
- printf ("Posting preemtive receive for connection failed.\n");
+ g_critical ("Posting preemtive receive for connection failed: %s", strerror (errno));
goto error;
}
if (rdma_accept (client, NULL)) {
- printf ("Failed to establish connection to the client with error: %i.\n", errno);
+ g_warning ("Failed to establish connection to the client: %s", strerror (errno));
goto error;
}
- printf ("Client Connected.\n");
+ g_debug ("Client connection setup successfull");
return 0;
error:
rdma_reject (client, NULL, 0);
@@ -164,7 +164,7 @@ welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
ctx->rdma_mr = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
if (!ctx->rdma_mr) {
- printf ("Failed to allocate RDMA Memory Container.\n");
+ g_critical ("Failed to allocate RDMA Memory Container: %s", strerror (errno));
return -1;
}
@@ -173,7 +173,7 @@ welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
ctx->rdma_mr->mr = rdma_reg_read (client, ctx->rdma_mr->mem, ctx->rdma_mr->size);
if (!ctx->rdma_mr->mr) {
- printf ("Failed to register RDMA Memory Region.\n");
+ g_critical ("Failed to register RDMA Memory Region: %s", strerror (errno));
kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
@@ -185,7 +185,7 @@ welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
msg->peer_mri = * (ctx->rdma_mr->mr);
if (rdma_post_send (client, client, ctx->cf_mr_send->mem, ctx->cf_mr_send->size, ctx->cf_mr_send->mr, IBV_SEND_SIGNALED)) {
- printf ("Failure while trying to post SEND.\n");
+ g_warning ("Failure while trying to post SEND: %s", strerror (errno));
kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
@@ -193,17 +193,17 @@ welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
struct ibv_wc wc;
if (rdma_get_send_comp (client, &wc) < 0) {
- printf ("Failed to post RDMA MRI to client.\n");
+ g_warning ("Failed to post RDMA MRI to client: %s", strerror (errno));
kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
- printf ("RDMA MRI sent to client.\n");
+ g_debug ("RDMA MRI sent to client");
return 0;
}
-void *
+static void *
event_loop (void *self)
{
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE ((KiroServer *)self);
@@ -216,7 +216,7 @@ event_loop (void *self)
struct rdma_cm_event *ev = malloc (sizeof (*active_event));
if (!ev) {
- printf ("Unable to allocate memory for Event handling!\n");
+ g_critical ("Unable to allocate memory for Event handling!");
rdma_ack_cm_event (active_event);
continue;
}
@@ -232,6 +232,8 @@ event_loop (void *self)
rdma_reject (ev->id, NULL, 0);
}
+ g_debug ("Got connection request from client");
+
if (0 == connect_client (ev->id)) {
// Post a welcoming "Recieve" for handshaking
if (0 == welcome_client (ev->id, priv->mem, priv->mem_size)) {
@@ -239,8 +241,8 @@ event_loop (void *self)
struct kiro_connection_context *ctx = (struct kiro_connection_context *) (ev->id->context);
ctx->identifier = priv->next_client_id++;
priv->clients = g_list_append (priv->clients, (gpointer)ev->id);
- printf ("Client id %u connected\n", ctx->identifier);
- printf ("Currently %u clients in total are connected.\n", g_list_length (priv->clients));
+ g_debug ("Client connection assigned with ID %u", ctx->identifier);
+ g_debug ("Currently %u clients in total are connected", g_list_length (priv->clients));
}
}
}
@@ -249,14 +251,14 @@ event_loop (void *self)
if (client) {
struct kiro_connection_context *ctx = (struct kiro_connection_context *) (ev->id->context);
- printf ("Got disconnect request from client %u.\n", ctx->identifier);
+ g_debug ("Got disconnect request from client ID %u", ctx->identifier);
priv->clients = g_list_delete_link (priv->clients, client);
}
else
- printf ("Got disconnect request from unknown client.\n");
+ g_debug ("Got disconnect request from unknown client");
kiro_destroy_connection (& (ev->id));
- printf ("Connection closed successfully. %u connected clients remaining.\n", g_list_length (priv->clients));
+ g_debug ("Connection closed successfully. %u connected clients remaining", g_list_length (priv->clients));
}
free (ev);
@@ -265,7 +267,7 @@ event_loop (void *self)
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
}
- printf ("Closing Event Listener Thread\n");
+ g_debug ("Closing Event Listener Thread");
return NULL;
}
@@ -278,12 +280,12 @@ kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
if (priv->base) {
- printf ("Server already started.\n");
+ g_debug ("Server already started.");
return -1;
}
if (!mem || mem_size == 0) {
- printf ("Invalid memory given to provide.\n");
+ g_warning ("Invalid memory given to provide.");
return -1;
}
@@ -293,7 +295,7 @@ kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_
hints.ai_flags = RAI_PASSIVE;
if (rdma_getaddrinfo (address, port, &hints, &res_addrinfo)) {
- printf ("Failed to create address information.");
+ g_critical ("Failed to create address information: %s", strerror (errno));
return -1;
}
@@ -307,11 +309,11 @@ kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_
qp_attr.sq_sig_all = 1;
if (rdma_create_ep (& (priv->base), res_addrinfo, NULL, &qp_attr)) {
- printf ("Endpoint creation failed: %s.\n", strerror (errno));
+ g_critical ("Endpoint creation failed: %s", strerror (errno));
return -1;
}
- printf ("Endpoint created.\n");
+ g_debug ("Endpoint created");
char *addr_local = NULL;
struct sockaddr *src_addr = rdma_get_local_addr (priv->base);
@@ -328,10 +330,10 @@ kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_
*/
}
- printf ("Bound to address %s:%s\n", addr_local, port);
+ g_message ("Server bound to address %s:%s", addr_local, port);
if (rdma_listen (priv->base, 0)) {
- printf ("Failed to put server into listening state.\n");
+ g_critical ("Failed to put server into listening state: %s", strerror (errno));
rdma_destroy_ep (priv->base);
return -1;
}
@@ -341,25 +343,25 @@ kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_
priv->ec = rdma_create_event_channel();
if (rdma_migrate_id (priv->base, priv->ec)) {
- printf ("Was unable to migrate connection to new Event Channel.\n");
+ g_critical ("Was unable to migrate connection to new Event Channel: %s", strerror (errno));
rdma_destroy_ep (priv->base);
return -1;
}
pthread_create (& (priv->event_listener), NULL, event_loop, self);
- printf ("Enpoint listening.\n");
+ g_message ("Enpoint listening");
sleep (1);
return 0;
}
-void
+static void
disconnect_client (gpointer data, gpointer user_data)
{
if (data) {
struct rdma_cm_id *id = (struct rdma_cm_id *)data;
struct kiro_connection_context *ctx = (struct kiro_connection_context *) (id->context);
- printf ("Disconnecting client: %u.\n", ctx->identifier);
+ g_debug ("Disconnecting client: %u", ctx->identifier);
rdma_disconnect ((struct rdma_cm_id *) data);
}
}
@@ -380,7 +382,7 @@ kiro_server_stop (KiroServer *self)
priv->close_signal = 1;
pthread_cancel (priv->event_listener);
pthread_join (priv->event_listener, NULL);
- printf ("Event Listener Thread stopped.\n");
+ g_debug ("Event Listener Thread stopped");
priv->close_signal = 0;
g_list_foreach (priv->clients, disconnect_client, NULL);
@@ -390,7 +392,7 @@ kiro_server_stop (KiroServer *self)
priv->base = NULL;
rdma_destroy_event_channel (priv->ec);
priv->ec = NULL;
- printf ("Server stopped successfully.\n");
+ g_message ("Server stopped successfully");
}
diff --git a/test/test-server.c b/test/test-server.c
index 2ed895b..64a25c9 100644
--- a/test/test-server.c
+++ b/test/test-server.c
@@ -170,7 +170,7 @@ main (void)
GRand *rand = g_rand_new();
if (0 > kiro_server_start (server, NULL, "60010", kiro_trb_get_raw_buffer (rb), kiro_trb_get_raw_size (rb))) {
- printf ("Failed to start server properly.\n");
+ g_critical ("Failed to start server properly");
goto done;
}