void post_receive(boost::system::error_code &ec) { util::spinlock::scoped_lock lk(mtx_); if(!id_) { HPX_IBVERBS_THROWS_IF(ec, boost::asio::error::not_connected); return; } struct ibv_recv_wr wr, *bad_wr = NULL; struct ibv_sge sge; std::memset(&wr, 0, sizeof(ibv_recv_wr)); HPX_ASSERT(id_); wr.wr_id = (uintptr_t)id_; wr.sg_list = &sge; wr.num_sge = 1; sge.addr = (uintptr_t)client_msg_; sge.length = sizeof(message); sge.lkey = client_msg_mr_->lkey; int ret = 0; HPX_ASSERT(id_); ret = ibv_post_recv(id_->qp, &wr, &bad_wr); if(ret) { int verrno = errno; boost::system::error_code err(verrno, boost::system::system_category()); HPX_IBVERBS_THROWS_IF( ec , err ); } }
static void infini_post_recv(struct ibvif *m) { struct ibv_sge list; struct ibv_recv_wr wr; int i; struct ibv_recv_wr *bad_wr_recv; memset(&list, 0, sizeof(struct ibv_sge)); list.addr = (uintptr_t) m->recv_buf; list.length = m->send_size; list.lkey = m->recv_mr->lkey; memset(&wr, 0, sizeof(struct ibv_recv_wr)); wr.wr_id = list.addr; wr.sg_list = &list; wr.num_sge = 1; wr.next = NULL; for (i = 0; i < m->rx_depth ; ++i) { bad_wr_recv = NULL; wr.wr_id = list.addr; ibv_post_recv(m->qp, &wr, &bad_wr_recv); if (i+1 < m->rx_depth) list.addr += m->send_size; } }
static int post_recvs(struct cmatest_node *node) { struct ibv_recv_wr recv_wr, *recv_failure; struct ibv_sge sge; int i, ret = 0; if (!message_count) return 0; recv_wr.next = NULL; recv_wr.sg_list = &sge; recv_wr.num_sge = 1; recv_wr.wr_id = (uintptr_t) node; sge.length = message_size; sge.lkey = node->mr->lkey; sge.addr = (uintptr_t) node->mem; for (i = 0; i < message_count && !ret; i++ ) { ret = ibv_post_recv(node->cma_id->qp, &recv_wr, &recv_failure); if (ret) { printf("failed to post receives: %d\n", ret); break; } } return ret; }
static int __xfer_rdma_post_recv(struct xfer_context *ctx) { struct ibv_sge list; struct ibv_recv_wr wr, *bad_wr; int rc; memset(&wr, 0, sizeof(wr)); list.addr = (uintptr_t) ctx->recv_msg; list.length = sizeof(struct message); list.lkey = ctx->recv_mr->lkey; wr.next = NULL; wr.wr_id = 0xcafebabe; wr.sg_list = &list; wr.num_sge = 1; rc = ibv_post_recv(ctx->qp, &wr, &bad_wr); if (rc) { perror("ibv_post_recv"); fprintf(stderr, "%d:%s: ibv_post_recv failed %d\n", pid, __func__, rc); return -1; } return 0; }
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 ret; sem_wait(&cb->sem); if (cb->state != CONNECT_REQUEST) { fprintf(stderr, "wait for CONNECT_REQUEST state %d\n", cb->state); return -1; } ret = rping_setup_qp(cb, cb->child_cm_id); if (ret) { fprintf(stderr, "setup_qp failed: %d\n", ret); return ret; } ret = rping_setup_buffers(cb); if (ret) { fprintf(stderr, "rping_setup_buffers failed: %d\n", ret); goto err1; } ret = ibv_post_recv(cb->qp, &cb->rq_wr, &bad_wr); if (ret) { fprintf(stderr, "ibv_post_recv failed: %d\n", ret); goto err2; } pthread_create(&cb->cqthread, NULL, cq_thread, cb); ret = rping_accept(cb); if (ret) { fprintf(stderr, "connect error %d\n", ret); goto err2; } ret = rping_test_server(cb); if (ret) { fprintf(stderr, "rping server failed: %d\n", ret); goto err3; } ret = 0; err3: rdma_disconnect(cb->child_cm_id); pthread_join(cb->cqthread, NULL); rdma_destroy_id(cb->child_cm_id); err2: rping_free_buffers(cb); err1: rping_free_qp(cb); return ret; }
static int post_receive(struct resources *res) { struct ibv_recv_wr rr; struct ibv_sge sge; struct ibv_recv_wr *bad_wr; int rc; /* prepare the scatter/gather entry */ memset(&sge, 0, sizeof(sge)); sge.addr = (uintptr_t)res->buf; sge.length = MSG_SIZE; sge.lkey = res->mr->lkey; /* prepare the receive work request (RR) */ memset(&rr, 0, sizeof(rr)); rr.next = NULL; rr.wr_id = 0; rr.sg_list = &sge; rr.num_sge = 1; /* post the Receive Request to the RQ */ rc = ibv_post_recv(res->qp, &rr, &bad_wr); if (rc) { fprintf(stderr, "failed to post RR\n"); return 1; } fprintf(stdout, "Receive Request was posted\n"); return 0; }
void RDMAChannel::recv() { struct ibv_recv_wr wr; caffe_memset(sizeof(wr), 0, &wr); wr.wr_id = (uint64_t) this; struct ibv_recv_wr* bad_wr; CHECK(!ibv_post_recv(qp_, &wr, &bad_wr)) << "Failed to post recv"; }
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 ret; ret = rping_setup_qp(cb, cb->cm_id); if (ret) { fprintf(stderr, "setup_qp failed: %d\n", ret); return ret; } ret = rping_setup_buffers(cb); if (ret) { fprintf(stderr, "rping_setup_buffers failed: %d\n", ret); goto err1; } ret = ibv_post_recv(cb->qp, &cb->rq_wr, &bad_wr); if (ret) { fprintf(stderr, "ibv_post_recv failed: %d\n", ret); goto err2; } ret = pthread_create(&cb->cqthread, NULL, cq_thread, cb); if (ret) { perror("pthread_create"); goto err2; } ret = rping_connect_client(cb); if (ret) { fprintf(stderr, "connect error %d\n", ret); goto err3; } ret = rping_test_client(cb); if (ret) { fprintf(stderr, "rping client failed: %d\n", ret); goto err4; } ret = 0; err4: rdma_disconnect(cb->cm_id); err3: pthread_join(cb->cqthread, NULL); err2: rping_free_buffers(cb); err1: rping_free_qp(cb); return ret; }
void post_receive(struct connection *conn) { struct ibv_recv_wr wr, *bad_wr = NULL; memset(&wr, 0, sizeof(wr)); wr.wr_id = (uintptr_t)conn; wr.next = NULL; wr.num_sge = 0; TEST_NZ(ibv_post_recv(conn->qp, &wr, &bad_wr)); }
static void *rping_persistent_server_thread(void *arg) { struct rping_cb *cb = arg; struct ibv_recv_wr *bad_wr; int ret; ret = rping_setup_qp(cb, cb->child_cm_id); if (ret) { fprintf(stderr, "setup_qp failed: %d\n", ret); goto err0; } ret = rping_setup_buffers(cb); if (ret) { fprintf(stderr, "rping_setup_buffers failed: %d\n", ret); goto err1; } ret = ibv_post_recv(cb->qp, &cb->rq_wr, &bad_wr); if (ret) { fprintf(stderr, "ibv_post_recv failed: %d\n", ret); goto err2; } ret = pthread_create(&cb->cqthread, NULL, cq_thread, cb); if (ret) { perror("pthread_create"); goto err2; } ret = rping_accept(cb); if (ret) { fprintf(stderr, "connect error %d\n", ret); goto err3; } rping_test_server(cb); rdma_disconnect(cb->child_cm_id); pthread_join(cb->cqthread, NULL); rping_free_buffers(cb); rping_free_qp(cb); rdma_destroy_id(cb->child_cm_id); free_cb(cb); return NULL; err3: pthread_cancel(cb->cqthread); pthread_join(cb->cqthread, NULL); err2: rping_free_buffers(cb); err1: rping_free_qp(cb); err0: free_cb(cb); return NULL; }
void IBConnection::post_recv(struct ibv_recv_wr* wr) { struct ibv_recv_wr* bad_recv_wr; int err = ibv_post_recv(qp(), wr, &bad_recv_wr); if (err) { L_(fatal) << "ibv_post_recv failed: " << strerror(err); throw InfinibandException("ibv_post_recv failed"); } ++total_recv_requests_; }
void post_receive_data() { /* Post receive for data */ sge_data.addr = (uintptr_t)data; sge_data.length = BUFFER_SIZE; sge_data.lkey = mr_data->lkey; recv_wr.sg_list = &sge_data; recv_wr.num_sge = 1; err = ibv_post_recv(cm_id->qp, &recv_wr, &bad_recv_wr); assert(err == 0); }
static void post_receive(struct rdma_cm_id *id) { struct ibv_recv_wr wr, *bad_wr = NULL; memset(&wr, 0, sizeof(wr)); wr.wr_id = (uintptr_t)id; wr.sg_list = NULL; wr.num_sge = 0; TEST_NZ(ibv_post_recv(id->qp, &wr, &bad_wr)); }
static int fio_rdmaio_recv(struct thread_data *td, struct io_u **io_us, unsigned int nr) { struct rdmaio_data *rd = td->io_ops->data; struct ibv_recv_wr *bad_wr; struct rdma_io_u_data *r_io_u_d; int i; i = 0; if (rd->rdma_protocol == FIO_RDMA_CHA_RECV) { /* post io_u into recv queue */ for (i = 0; i < nr; i++) { r_io_u_d = io_us[i]->engine_data; if (ibv_post_recv(rd->qp, &r_io_u_d->rq_wr, &bad_wr) != 0) { log_err("fio: ibv_post_recv fail\n"); return 1; } } } else if ((rd->rdma_protocol == FIO_RDMA_MEM_READ) || (rd->rdma_protocol == FIO_RDMA_MEM_WRITE)) { /* re-post the rq_wr */ if (ibv_post_recv(rd->qp, &rd->rq_wr, &bad_wr) != 0) { log_err("fio: ibv_post_recv fail\n"); return 1; } rdma_poll_wait(td, IBV_WC_RECV); dprint(FD_IO, "fio: recv FINISH message\n"); td->done = 1; return 0; } return i; }
void PrepareToReceive(ArgStruct *p) { int ret; /* Return code */ struct ibv_recv_wr rr; /* Receive request */ struct ibv_recv_wr *bad_wr; /* Handle to any incomplete requests */ struct ibv_sge sg_entry; /* Scatter/Gather list - holds buff addr */ /* We don't need to post a receive if doing RDMA write with local polling */ if( p->prot.commtype == NP_COMM_RDMAWRITE && p->prot.comptype == NP_COMP_LOCALPOLL ) return; /* setup the receive request, specify which list to use and # entries */ rr.num_sge = 1; /* # of entries in this list */ rr.sg_list = &sg_entry; /* the list of entries */ rr.next = NULL; /* the next entry (if more than one */ sg_entry.lkey = r_mr_hndl->lkey; /* link the entries lkey to our remote mr */ sg_entry.length = p->bufflen; /* provide a buffer length */ sg_entry.addr = (uintptr_t)p->r_ptr; /* address/context of sg_entry */ /* technically if we have problems, the return is < 0, * but this works as well */ /* if we get a change in bad_wr value, it is because the Receive request * couldnt be posted to the command queue for some reason. * (This may be because the queue is full) * You should probably do something with the bad_wr if your request * needs to actuall get posted. */ ret = ibv_post_recv(qp_hndl, &rr, &bad_wr); if(ret) { fprintf(stderr, "Error posting recv request\n"); CleanUp(p); exit(-1); } else { LOGPRINTF(("Posted recv request")); } /* Set receive flag to zero and request event completion * notification for this receive so the event handler will * be triggered when the receive completes. */ if( p->prot.comptype == NP_COMP_EVENT ) { receive_complete = 0; } }
void post_receives(struct connection *conn) { struct ibv_recv_wr wr, *bad_wr = NULL; struct ibv_sge sge; wr.wr_id = (uintptr_t)conn; wr.next = NULL; wr.sg_list = &sge; wr.num_sge = 1; sge.addr = (uintptr_t)conn->recv_msg; sge.length = sizeof(struct message); sge.lkey = conn->recv_mr->lkey; TEST_NZ(ibv_post_recv(conn->qp, &wr, &bad_wr)); }
static int fio_rdmaio_setup_listen(struct thread_data *td, short port) { struct rdmaio_data *rd = td->io_ops->data; struct ibv_recv_wr *bad_wr; int state = td->runstate; td_set_runstate(td, TD_SETTING_UP); rd->addr.sin_family = AF_INET; rd->addr.sin_addr.s_addr = htonl(INADDR_ANY); rd->addr.sin_port = htons(port); /* rdma_listen */ if (rdma_bind_addr(rd->cm_id, (struct sockaddr *)&rd->addr) != 0) { log_err("fio: rdma_bind_addr fail\n"); return 1; } if (rdma_listen(rd->cm_id, 3) != 0) { log_err("fio: rdma_listen fail\n"); return 1; } log_info("fio: waiting for connection\n"); /* wait for CONNECT_REQUEST */ if (get_next_channel_event (td, rd->cm_channel, RDMA_CM_EVENT_CONNECT_REQUEST) != 0) { log_err("fio: wait for RDMA_CM_EVENT_CONNECT_REQUEST\n"); return 1; } if (fio_rdmaio_setup_qp(td) != 0) return 1; if (fio_rdmaio_setup_control_msg_buffers(td) != 0) return 1; /* post recv buf */ if (ibv_post_recv(rd->qp, &rd->rq_wr, &bad_wr) != 0) { log_err("fio: ibv_post_recv fail\n"); return 1; } td_set_runstate(td, state); return 0; }
void post_receives(rdma_conn_t *conn) { struct ibv_recv_wr wr, *bad_wr = NULL; struct ibv_sge sge; wr.wr_id = (uintptr_t)conn; wr.next = NULL; wr.sg_list = &sge; wr.num_sge = 1; sge.addr = (uintptr_t)conn->recv_msg; sge.length = sizeof(rdma_msg_t); sge.lkey = conn->recv_mr->lkey; ++ request_stack_size; TEST_NZ(ibv_post_recv(conn->qp, &wr, &bad_wr)); }
int mvdev_post_rq_buffers(mv_rpool * rp, mv_qp * qp, int num_bufs) { int i = 0, total = 1; mv_rbuf *v, *first_v, *last_v; struct ibv_recv_wr *bad_wr; D_PRINT("Attempting to post %d recv bufs\n", num_bufs); first_v = last_v = get_mv_rbuf(rp->buffer_size); switch(qp->type) { case MVDEV_CH_RC_RQ: prepare_rc_recv(first_v, rp); break; case MVDEV_CH_UD_RQ: prepare_ud_recv(first_v, rp); break; default: error_abort_all(IBV_RETURN_ERR,"Invalid QP Type: %d\n", qp->type); } for(i = 1; i < num_bufs; i++) { ++total; v = get_mv_rbuf(rp->buffer_size); switch(qp->type) { case MVDEV_CH_RC_RQ: prepare_rc_recv(v, rp); break; case MVDEV_CH_UD_RQ: prepare_ud_recv(v, rp); break; } last_v->desc.rr.next = &v->desc.rr; last_v = v; } if(ibv_post_recv(qp->qp, &first_v->desc.rr, &bad_wr)) { return 0; } D_PRINT("Posted %d recvs\n", i); return total; }
static void rdmasniff_post_recv(pcap_t *handle, uint64_t wr_id) { struct pcap_rdmasniff *priv = handle->priv; struct ibv_sge sg_entry; struct ibv_recv_wr wr, *bad_wr; sg_entry.length = RDMASNIFF_RECEIVE_SIZE; sg_entry.addr = (uintptr_t) handle->buffer + RDMASNIFF_RECEIVE_SIZE * wr_id; sg_entry.lkey = priv->mr->lkey; wr.wr_id = wr_id; wr.num_sge = 1; wr.sg_list = &sg_entry; wr.next = NULL; ibv_post_recv(priv->qp, &wr, &bad_wr); }
void post_receive_for_msg(void *con){ struct connection *conn = (struct connection *)con; struct ibv_recv_wr wr, *bad_wr = NULL; struct ibv_sge sge; memset(&wr, 0, sizeof(wr)); wr.wr_id = (uintptr_t)conn; wr.sg_list = &sge; wr.num_sge = 1; sge.addr = (uintptr_t)conn->recv_msg; sge.length = sizeof(*conn->recv_msg); sge.lkey = conn->recv_msg_mr->lkey; TEST_NZ(ibv_post_recv(conn->qp, &wr, &bad_wr)); }
static inline ssize_t fi_ibv_rdm_batch_repost_receives(struct fi_ibv_rdm_tagged_conn *conn, struct fi_ibv_rdm_ep *ep, int num_to_post) { const size_t idx = (conn->cm_role == FI_VERBS_CM_SELF) ? 1 : 0; struct ibv_recv_wr *bad_wr = NULL; struct ibv_recv_wr wr[num_to_post]; struct ibv_sge sge[num_to_post]; int last = num_to_post - 1; int i; /* IBV_WR_SEND opcode specific */ assert((num_to_post % ep->n_buffs) == 0); assert(ep->topcode == IBV_WR_SEND || ep->topcode == IBV_WR_RDMA_WRITE_WITH_IMM); if (ep->topcode == IBV_WR_SEND) { for (i = 0; i < num_to_post; i++) { sge[i].addr = (uint64_t)(void *) fi_ibv_rdm_get_rbuf(conn, ep, i % ep->n_buffs); sge[i].length = FI_IBV_RDM_DFLT_BUFFER_SIZE; sge[i].lkey = conn->r_mr->lkey; } } for (i = 0; i < num_to_post; i++) { wr[i].wr_id = (uintptr_t) conn; wr[i].next = &wr[i + 1]; wr[i].sg_list = &sge[i]; wr[i].num_sge = 1; } wr[last].next = NULL; if (ibv_post_recv(conn->qp[idx], wr, &bad_wr) == 0) { conn->recv_preposted += num_to_post; return num_to_post; } VERBS_INFO(FI_LOG_EP_DATA, "Failed to post recv\n"); return -FI_ENOMEM; }
static ssize_t fi_ibv_msg_ep_recvmsg(struct fid_ep *ep, const struct fi_msg *msg, uint64_t flags) { struct fi_ibv_msg_ep *_ep; struct ibv_recv_wr wr, *bad; struct ibv_sge *sge = NULL; ssize_t ret; size_t i; _ep = container_of(ep, struct fi_ibv_msg_ep, ep_fid); assert(_ep->rcq); wr.wr_id = (uintptr_t) msg->context; wr.next = NULL; if (msg->iov_count) { sge = alloca(sizeof(*sge) * msg->iov_count); for (i = 0; i < msg->iov_count; i++) { sge[i].addr = (uintptr_t) msg->msg_iov[i].iov_base; sge[i].length = (uint32_t) msg->msg_iov[i].iov_len; sge[i].lkey = (uint32_t) (uintptr_t) (msg->desc[i]); } } wr.sg_list = sge; wr.num_sge = msg->iov_count; ret = ibv_post_recv(_ep->id->qp, &wr, &bad); switch (ret) { case ENOMEM: return -FI_EAGAIN; case -1: /* Deal with non-compliant libibverbs drivers which set errno * instead of directly returning the error value */ return (errno == ENOMEM) ? -FI_EAGAIN : -errno; default: return -ret; } }
void RDMAChannel::RecvMR(int id) { memory_regions_[id] = new ibv_mr(); // Map the memory region itself so that it can be received ibv_mr* init = ibv_reg_mr(adapter_.pd_, memory_regions_[id], sizeof(ibv_mr), IBV_ACCESS_LOCAL_WRITE); region_regions_[id] = init; struct ibv_sge list; list.addr = (uint64_t) memory_regions_[id]; list.length = sizeof(ibv_mr); list.lkey = init->lkey; struct ibv_recv_wr wr; caffe_memset(sizeof(wr), 0, &wr); wr.wr_id = (uint64_t) this; wr.sg_list = &list; wr.num_sge = 1; struct ibv_recv_wr* bad_wr; CHECK(!ibv_post_recv(qp_, &wr, &bad_wr)); }
static int post_one_recv_wqe(struct pingpong_context *ctx) { struct ibv_recv_wr wr; struct ibv_recv_wr *bad_wr; struct ibv_sge list; list.addr = (uintptr_t)ctx->buf; list.length = sizeof(struct pingpong_dest); list.lkey = ctx->mr->lkey; wr.next = NULL; wr.wr_id = SYNC_SPEC_ID; wr.sg_list = &list; wr.num_sge = 1; if (ibv_post_recv(ctx->qp[0],&wr,&bad_wr)) { fprintf(stderr, "Function ibv_post_recv failed for RDMA_CM QP\n"); return FAILURE; } return SUCCESS; }
static void infini_post_recv_buf(struct tcpip_thread *t, struct pbuf *p) { struct ibv_sge list; struct ibv_recv_wr wr; struct ibv_recv_wr *bad_wr_recv; struct ibvif *m; m = (struct ibvif *)t->netif.state; memset(&list, 0, sizeof(struct ibv_sge)); list.addr = (uintptr_t) p->actual_payload; list.length = m->send_size; list.lkey = m->recv_mr->lkey; memset(&wr, 0, sizeof(struct ibv_recv_wr)); wr.wr_id = list.addr; wr.sg_list = &list; wr.num_sge = 1; wr.next = NULL; ibv_post_recv(m->qp, &wr, &bad_wr_recv); }
static UCS_F_NOINLINE void uct_ud_verbs_iface_post_recv_always(uct_ud_verbs_iface_t *iface, int max) { struct ibv_recv_wr *bad_wr; uct_ib_recv_wr_t *wrs; unsigned count; int ret; wrs = ucs_alloca(sizeof *wrs * max); count = uct_ib_iface_prepare_rx_wrs(&iface->super.super, &iface->super.rx.mp, wrs, max); if (count == 0) { return; } ret = ibv_post_recv(iface->super.qp, &wrs[0].ibwr, &bad_wr); if (ret != 0) { ucs_fatal("ibv_post_recv() returned %d: %m", ret); } iface->super.rx.available -= count; }
int m_pi_prep_rcv_q(struct mcm_qp *m_qp) { struct ibv_recv_wr recv_wr, *recv_err; struct ibv_qp *ib_qp; int i; /* MXS -> MSS or HST, PI service will be on QP1 */ if (MXS_EP(&m_qp->smd->md->addr) && (MSS_EP(&m_qp->cm->msg.daddr1) || HST_EP(&m_qp->cm->msg.daddr1))) ib_qp = m_qp->ib_qp1; else ib_qp = m_qp->ib_qp2; if (!ib_qp) { mlog(0, " ERR: m_qp %p ib_qp == 0, QP1 %p QP2 %p\n", m_qp, m_qp->ib_qp1, m_qp->ib_qp2); return -1; } mlog(4, " post %d 0-byte messages, m_qp %p qpn %x\n", mcm_rx_entries, m_qp, ib_qp->qp_num); recv_wr.next = NULL; recv_wr.sg_list = NULL; recv_wr.num_sge = 0; recv_wr.wr_id = (uint64_t)(uintptr_t) m_qp; /* pre-post zero byte messages for proxy-in service, inbound rdma_writes with immed data */ for (i=0; i< mcm_rx_entries; i++) { errno = 0; if (ibv_post_recv(ib_qp, &recv_wr, &recv_err)) { mlog(0, " ERR: qpn %x ibv_post_recv[%d] - %s\n", ib_qp->qp_num, i, strerror(errno)); return 1; } MCNTR(m_qp->smd->md, MCM_QP_RECV); } return 0; }
/** * \brief Post a new receive buffer to the RQ * * \param rdma Pointer to the rdma transport structure * \c RDMA buffer context */ static void rdma_post_recv(struct Rdmatrans *rdma, Rdmactx *rctx) { int n; struct ibv_sge sge; struct ibv_recv_wr wr, *bad_wr; rctx->wc_op = IBV_WC_RECV; rctx->rdma = rdma; rctx->next = NULL; rctx->used = 1; sge.addr = (uintptr_t)rctx->buf; sge.length = rdma->msize - sizeof(Rdmactx); sge.lkey = rdma->rcv_mr->lkey; wr.next = NULL; wr.wr_id = (u64)(unsigned long)rctx; wr.sg_list = &sge; wr.num_sge = 1; n = ibv_post_recv(rdma->qp, &wr, &bad_wr); if (n) { np_uerror(n); //fprintf(stderr, "Error %d posting recv\n", n); } }
static int rping_cq_event_handler(struct rping_cb *cb) { struct ibv_wc wc; struct ibv_recv_wr *bad_wr; int ret; int flushed = 0; while ((ret = ibv_poll_cq(cb->cq, 1, &wc)) == 1) { ret = 0; if (wc.status) { if (wc.status == IBV_WC_WR_FLUSH_ERR) { flushed = 1; continue; } fprintf(stderr, "cq completion failed status %d\n", wc.status); ret = -1; goto error; } switch (wc.opcode) { case IBV_WC_SEND: DEBUG_LOG("send completion\n"); break; case IBV_WC_RDMA_WRITE: DEBUG_LOG("rdma write completion\n"); cb->state = RDMA_WRITE_COMPLETE; sem_post(&cb->sem); break; case IBV_WC_RDMA_READ: DEBUG_LOG("rdma read completion\n"); cb->state = RDMA_READ_COMPLETE; sem_post(&cb->sem); break; case IBV_WC_RECV: DEBUG_LOG("recv completion\n"); ret = cb->server ? server_recv(cb, &wc) : client_recv(cb, &wc); if (ret) { fprintf(stderr, "recv wc error: %d\n", ret); goto error; } ret = ibv_post_recv(cb->qp, &cb->rq_wr, &bad_wr); if (ret) { fprintf(stderr, "post recv error: %d\n", ret); goto error; } sem_post(&cb->sem); break; default: DEBUG_LOG("unknown!!!!! completion\n"); ret = -1; goto error; } } if (ret) { fprintf(stderr, "poll error %d\n", ret); goto error; } return flushed; error: cb->state = ERROR; sem_post(&cb->sem); return ret; }