[openib-general] [librmdacm] fix rping to return a value different than zero when there is a failure
Dotan Barak
dotanb at mellanox.co.il
Thu May 18 08:01:10 PDT 2006
Hi.
Here is a patch to fix this issue in the test.
I couldn't find the parameters for executing this test. can you please send me an a command line example which i can use?
thanks
Added checks to the return values of all of the functions that may fail
(in order to add this test to the regression system).
Signed-off-by: Dotan Barak <dotanb at mellanox.co.il>
Index: last_stable/src/userspace/librdmacm/examples/rping.c
===================================================================
--- last_stable.orig/src/userspace/librdmacm/examples/rping.c 2006-05-18 17:07:12.000000000 +0300
+++ last_stable/src/userspace/librdmacm/examples/rping.c 2006-05-18 17:44:47.000000000 +0300
@@ -148,10 +148,10 @@ struct rping_cb {
struct rdma_cm_id *child_cm_id; /* connection on server side */
};
-static void rping_cma_event_handler(struct rdma_cm_id *cma_id,
+static int rping_cma_event_handler(struct rdma_cm_id *cma_id,
struct rdma_cm_event *event)
{
- int ret;
+ int ret = 0;
struct rping_cb *cb = cma_id->context;
DEBUG_LOG("cma_event type %d cma_id %p (%s)\n", event->event, cma_id,
@@ -194,6 +194,7 @@ static void rping_cma_event_handler(stru
fprintf(stderr, "cma event %d, error %d\n", event->event,
event->status);
sem_post(&cb->sem);
+ ret = -1;
break;
case RDMA_CM_EVENT_DISCONNECTED:
@@ -203,13 +204,17 @@ static void rping_cma_event_handler(stru
case RDMA_CM_EVENT_DEVICE_REMOVAL:
fprintf(stderr, "cma detected device removal!!!!\n");
+ ret = -1;
break;
default:
fprintf(stderr, "oof bad type!\n");
sem_post(&cb->sem);
+ ret = -1;
break;
}
+
+ return ret;
}
static int server_recv(struct rping_cb *cb, struct ibv_wc *wc)
@@ -248,7 +253,7 @@ static int client_recv(struct rping_cb *
return 0;
}
-static void rping_cq_event_handler(struct rping_cb *cb)
+static int rping_cq_event_handler(struct rping_cb *cb)
{
struct ibv_wc wc;
struct ibv_recv_wr *bad_wr;
@@ -258,6 +263,7 @@ static void rping_cq_event_handler(struc
if (wc.status) {
fprintf(stderr, "cq completion failed status %d\n",
wc.status);
+ ret = -1;
goto error;
}
@@ -297,6 +303,7 @@ static void rping_cq_event_handler(struc
default:
DEBUG_LOG("unknown!!!!! completion\n");
+ ret = -1;
goto error;
}
}
@@ -304,11 +311,13 @@ static void rping_cq_event_handler(struc
fprintf(stderr, "poll error %d\n", ret);
goto error;
}
- return;
+ return 0;
error:
cb->state = ERROR;
sem_post(&cb->sem);
+
+ return ret;
}
static int rping_accept(struct rping_cb *cb)
@@ -545,7 +554,9 @@ static void *cm_thread(void *arg)
fprintf(stderr, "rdma_get_cm_event err %d\n", ret);
exit(ret);
}
- rping_cma_event_handler(event->id, event);
+ ret = rping_cma_event_handler(event->id, event);
+ if (ret)
+ exit(ret);
rdma_ack_cm_event(event);
}
}
@@ -559,7 +570,7 @@ static void *cq_thread(void *arg)
DEBUG_LOG("cq_thread started.\n");
- while (1) {
+ while (1) {
ret = ibv_get_cq_event(cb->channel, &ev_cq, &ev_ctx);
if (ret) {
fprintf(stderr, "Failed to get cq event!\n");
@@ -574,7 +585,9 @@ static void *cq_thread(void *arg)
fprintf(stderr, "Failed to set notify!\n");
exit(ret);
}
- rping_cq_event_handler(cb);
+ ret = rping_cq_event_handler(cb);
+ if (ret);
+ exit(ret);
ibv_ack_cq_events(cb->cq, 1);
}
}
@@ -591,10 +604,10 @@ static void rping_format_send(struct rpi
info->buf, info->rkey, info->size);
}
-static void rping_test_server(struct rping_cb *cb)
+static int rping_test_server(struct rping_cb *cb)
{
struct ibv_send_wr *bad_wr;
- int ret;
+ int ret = 0;
while (1) {
/* Wait for client's Start STAG/TO/Len */
@@ -602,6 +615,7 @@ static void rping_test_server(struct rpi
if (cb->state != RDMA_READ_ADV) {
fprintf(stderr, "wait for RDMA_READ_ADV state %d\n",
cb->state);
+ ret = -1;
break;
}
@@ -616,6 +630,7 @@ static void rping_test_server(struct rpi
ret = ibv_post_send(cb->qp, &cb->rdma_sq_wr, &bad_wr);
if (ret) {
fprintf(stderr, "post send error %d\n", ret);
+ ret = 1;
break;
}
DEBUG_LOG("server posted rdma read req \n");
@@ -625,6 +640,7 @@ static void rping_test_server(struct rpi
if (cb->state != RDMA_READ_COMPLETE) {
fprintf(stderr, "wait for RDMA_READ_COMPLETE state %d\n",
cb->state);
+ ret = -1;
break;
}
DEBUG_LOG("server received read complete\n");
@@ -646,6 +662,7 @@ static void rping_test_server(struct rpi
if (cb->state != RDMA_WRITE_ADV) {
fprintf(stderr, "wait for RDMA_WRITE_ADV state %d\n",
cb->state);
+ ret = -1;
break;
}
DEBUG_LOG("server received sink adv\n");
@@ -671,6 +688,7 @@ static void rping_test_server(struct rpi
if (cb->state != RDMA_WRITE_COMPLETE) {
fprintf(stderr, "wait for RDMA_WRITE_COMPLETE state %d\n",
cb->state);
+ ret = -1;
break;
}
DEBUG_LOG("server rdma write complete \n");
@@ -683,6 +701,8 @@ static void rping_test_server(struct rpi
}
DEBUG_LOG("server posted go ahead\n");
}
+
+ return ret;
}
static int rping_bind_server(struct rping_cb *cb)
@@ -719,19 +739,19 @@ static int rping_bind_server(struct rpin
return 0;
}
-static void rping_run_server(struct rping_cb *cb)
+static int rping_run_server(struct rping_cb *cb)
{
struct ibv_recv_wr *bad_wr;
int ret;
ret = rping_bind_server(cb);
if (ret)
- return;
+ return ret;
ret = rping_setup_qp(cb, cb->child_cm_id);
if (ret) {
fprintf(stderr, "setup_qp failed: %d\n", ret);
- return;
+ return ret;
}
ret = rping_setup_buffers(cb);
@@ -761,11 +781,13 @@ err2:
rping_free_buffers(cb);
err1:
rping_free_qp(cb);
+
+ return ret;
}
-static void rping_test_client(struct rping_cb *cb)
+static int rping_test_client(struct rping_cb *cb)
{
- int ping, start, cc, i, ret;
+ int ping, start, cc, i, ret = 0;
struct ibv_send_wr *bad_wr;
unsigned char c;
@@ -798,6 +820,7 @@ static void rping_test_client(struct rpi
if (cb->state != RDMA_WRITE_ADV) {
fprintf(stderr, "wait for RDMA_WRITE_ADV state %d\n",
cb->state);
+ ret = -1;
break;
}
@@ -813,18 +836,22 @@ static void rping_test_client(struct rpi
if (cb->state != RDMA_WRITE_COMPLETE) {
fprintf(stderr, "wait for RDMA_WRITE_COMPLETE state %d\n",
cb->state);
+ ret = -1;
break;
}
if (cb->validate)
if (memcmp(cb->start_buf, cb->rdma_buf, cb->size)) {
fprintf(stderr, "data mismatch!\n");
+ ret = -1;
break;
}
if (cb->verbose)
printf("ping data: %s\n", cb->rdma_buf);
}
+
+ return ret;
}
static int rping_connect_client(struct rping_cb *cb)
@@ -881,19 +908,19 @@ static int rping_bind_client(struct rpin
return 0;
}
-static void rping_run_client(struct rping_cb *cb)
+static int rping_run_client(struct rping_cb *cb)
{
struct ibv_recv_wr *bad_wr;
int ret;
ret = rping_bind_client(cb);
if (ret)
- return;
+ return ret;
ret = rping_setup_qp(cb, cb->cm_id);
if (ret) {
fprintf(stderr, "setup_qp failed: %d\n", ret);
- return;
+ return ret;
}
ret = rping_setup_buffers(cb);
@@ -922,6 +949,8 @@ err2:
rping_free_buffers(cb);
err1:
rping_free_qp(cb);
+
+ return ret;
}
static void usage(char *name)
@@ -1039,9 +1068,9 @@ int main(int argc, char *argv[])
pthread_create(&cb->cmthread, NULL, cm_thread, cb);
if (cb->server)
- rping_run_server(cb);
+ ret = rping_run_server(cb);
else
- rping_run_client(cb);
+ ret = rping_run_client(cb);
DEBUG_LOG("destroy cm_id %p\n", cb->cm_id);
rdma_destroy_id(cb->cm_id);
@@ -1049,5 +1078,7 @@ out2:
rdma_destroy_event_channel(cb->cm_channel);
out:
free(cb);
+
+ printf("return status %d\n", ret);
return ret;
}
More information about the general
mailing list