Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Update all examples to use new APIs #1271

Merged
merged 9 commits into from
Oct 1, 2021
10 changes: 8 additions & 2 deletions examples/02-read-to-volatile/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ main(int argc, char *argv[])
if (ret)
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_mr_remote_delete;

/* wait for the completion to be ready */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_mr_remote_delete;

/* wait for a completion of the RDMA read */
ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_mr_remote_delete;

Expand Down
10 changes: 8 additions & 2 deletions examples/03-read-to-persistent/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,18 @@ main(int argc, char *argv[])
if (ret)
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_mr_remote_delete;

/* wait for the completion to be ready */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_mr_remote_delete;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_mr_remote_delete;

Expand Down
10 changes: 8 additions & 2 deletions examples/04-write-to-persistent/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,18 @@ main(int argc, char *argv[])
if (ret)
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_mr_remote_delete;

/* wait for the completion to be ready */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_mr_remote_delete;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_mr_remote_delete;

Expand Down
10 changes: 8 additions & 2 deletions examples/05-flush-to-persistent/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,18 @@ main(int argc, char *argv[])
if (ret)
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_mr_remote_delete;

/* wait for the completion to be ready */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_mr_remote_delete;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_mr_remote_delete;

Expand Down
16 changes: 12 additions & 4 deletions examples/06-multiple-connections/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
struct client_res {
/* RPMA resources */
struct rpma_conn *conn;
struct rpma_cq *cq;

/* resources - memory regions */
size_t offset;
Expand Down Expand Up @@ -151,7 +152,7 @@ client_add_to_epoll(struct client_res *clnt, int epoll)
return ret;

/* get the connection's completion fd and add it to epoll */
ret = rpma_conn_get_completion_fd(clnt->conn, &fd);
ret = rpma_cq_get_fd(clnt->cq, &fd);
if (ret) {
epoll_delete(epoll, &clnt->ev_conn_event);
return ret;
Expand Down Expand Up @@ -206,8 +207,8 @@ client_handle_completion(struct custom_event *ce)
struct client_res *clnt = (struct client_res *)ce->arg;
const struct server_res *svr = clnt->svr;

/* prepare detected completions for processing */
int ret = rpma_conn_completion_wait(clnt->conn);
/* wait for the completion to be ready */
int ret = rpma_cq_wait(clnt->cq);
if (ret) {
/* no completion is ready - continue */
if (ret == RPMA_E_NO_COMPLETION)
Expand All @@ -220,7 +221,7 @@ client_handle_completion(struct custom_event *ce)

/* get next completion */
struct rpma_completion cmpl;
ret = rpma_conn_completion_get(clnt->conn, &cmpl);
ret = rpma_cq_get_completion(clnt->cq, &cmpl);
if (ret) {
/* no completion is ready - continue */
if (ret == RPMA_E_NO_COMPLETION)
Expand Down Expand Up @@ -383,6 +384,13 @@ server_handle_incoming_client(struct custom_event *ce)
return;
}

/* get the connection's main CQ */
if (rpma_conn_get_cq(clnt->conn, &clnt->cq)) {
/* an error occurred - disconnect */
(void) rpma_conn_disconnect(clnt->conn);
return;
}

if (client_add_to_epoll(clnt, svr->epoll))
(void) rpma_conn_disconnect(clnt->conn);
}
Expand Down
13 changes: 9 additions & 4 deletions examples/07-atomic-write/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ main(int argc, char *argv[])
sizeof(uint64_t), RPMA_F_COMPLETION_ALWAYS, NULL)))
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
if ((ret = rpma_conn_get_cq(conn, &cq)))
goto err_mr_remote_delete;

/* wait for the completion to be ready */
if ((ret = rpma_conn_completion_wait(conn)))
if ((ret = rpma_cq_wait(cq)))
goto err_mr_remote_delete;

if ((ret = rpma_conn_completion_get(conn, &cmpl)))
if ((ret = rpma_cq_get_completion(cq, &cmpl)))
goto err_mr_remote_delete;

if (cmpl.op_status != IBV_WC_SUCCESS) {
Expand Down Expand Up @@ -172,10 +177,10 @@ main(int argc, char *argv[])
break;

/* wait for the completion to be ready */
if ((ret = rpma_conn_completion_wait(conn)))
if ((ret = rpma_cq_wait(cq)))
break;

if ((ret = rpma_conn_completion_get(conn, &cmpl)))
if ((ret = rpma_cq_get_completion(cq, &cmpl)))
break;

if (cmpl.op_context != FLUSH_ID) {
Expand Down
12 changes: 9 additions & 3 deletions examples/08-messages-ping-pong/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ main(int argc, char *argv[])
if ((ret = client_connect(peer, addr, port, NULL, NULL, &conn)))
goto err_mr_dereg;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
if ((ret = rpma_conn_get_cq(conn, &cq)))
goto err_conn_disconnect;

while (--rounds) {
/* prepare a receive for the server's response */
if ((ret = rpma_recv(conn, recv_mr, 0, MSG_SIZE, recv)))
Expand All @@ -115,14 +120,14 @@ main(int argc, char *argv[])

do {
/* prepare completions, get one and validate it */
ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret && ret != RPMA_E_NO_COMPLETION)
break;

if (ret == RPMA_E_NO_COMPLETION) {
if ((ret = rpma_conn_completion_wait(conn))) {
if ((ret = rpma_cq_wait(cq))) {
break;
} else if ((ret = rpma_conn_completion_get(conn,
} else if ((ret = rpma_cq_get_completion(cq,
&cmpl))) {
if (ret == RPMA_E_NO_COMPLETION)
continue;
Expand Down Expand Up @@ -174,6 +179,7 @@ main(int argc, char *argv[])
ret |= rpma_send(conn, send_mr, 0, MSG_SIZE, RPMA_F_COMPLETION_ON_ERROR,
NULL);

err_conn_disconnect:
ret |= common_disconnect_and_wait_for_conn_close(&conn);

err_mr_dereg:
Expand Down
11 changes: 8 additions & 3 deletions examples/08-messages-ping-pong/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,26 @@ main(int argc, char *argv[])
goto err_conn_disconnect;
}

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
if ((ret = rpma_conn_get_cq(conn, &cq)))
goto err_conn_disconnect;

/* RPMA_OP_SEND completion in the first round is not present */
int send_cmpl = 1;
int recv_cmpl = 0;

while (1) {
do {
/* prepare completions, get one and validate it */
ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret && ret != RPMA_E_NO_COMPLETION)
break;

if (ret == RPMA_E_NO_COMPLETION) {
if ((ret = rpma_conn_completion_wait(conn))) {
if ((ret = rpma_cq_wait(cq))) {
break;
} else if ((ret = rpma_conn_completion_get(conn,
} else if ((ret = rpma_cq_get_completion(cq,
&cmpl))) {
if (ret == RPMA_E_NO_COMPLETION)
continue;
Expand Down
10 changes: 8 additions & 2 deletions examples/10-send-with-imm/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ main(int argc, char *argv[])
if (ret)
goto err_conn_disconnect;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_conn_disconnect;

/* prepare completions, get one and validate it */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_conn_disconnect;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_conn_disconnect;

Expand Down
10 changes: 8 additions & 2 deletions examples/10-send-with-imm/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ main(int argc, char *argv[])
}
uint32_t *exp_imm = pdata.ptr;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_conn_disconnect;

/* prepare completions, get one and validate it */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_conn_disconnect;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_conn_disconnect;

Expand Down
10 changes: 8 additions & 2 deletions examples/11-write-with-imm/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,18 @@ main(int argc, char *argv[])
if (ret)
goto err_mr_remote_delete;

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_mr_remote_delete;

/* prepare completions, get one and validate it */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_mr_remote_delete;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_mr_remote_delete;

Expand Down
10 changes: 8 additions & 2 deletions examples/11-write-with-imm/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ main(int argc, char *argv[])
goto err_conn_disconnect;
}

/* get the connection's main CQ */
struct rpma_cq *cq = NULL;
ret = rpma_conn_get_cq(conn, &cq);
if (ret)
goto err_conn_disconnect;

/* prepare completions, get one and validate it */
ret = rpma_conn_completion_wait(conn);
ret = rpma_cq_wait(cq);
if (ret)
goto err_conn_disconnect;

ret = rpma_conn_completion_get(conn, &cmpl);
ret = rpma_cq_get_completion(cq, &cmpl);
if (ret)
goto err_conn_disconnect;

Expand Down