static int hook_reject(struct fid_pep *pep, fid_t handle, const void *param, size_t paramlen) { struct hook_pep *mypep = container_of(pep, struct hook_pep, pep); return fi_reject(mypep->hpep, handle, param, paramlen); }
static int connreq_handler(struct fi_info *info) { struct cma_node *node; int ret; if (conn_index == connections) { ret = -ENOMEM; goto err1; } node = &nodes[conn_index++]; ret = init_node(node, info); if (ret) goto err2; ret = fi_accept(node->ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err2; } return 0; err2: connects_left--; err1: printf("cmatose: failing connection request\n"); fi_reject(pep, info->handle, NULL, 0); return ret; }
int ft_server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; ssize_t rd; int ret; rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, eq, "fi_eq_sread", "listen"); return (int) rd; } fi = entry.info; if (event != FI_CONNREQ) { fprintf(stderr, "Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err; } ret = fi_domain(fabric, fi, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err; } ret = ft_alloc_active_res(fi); if (ret) goto err; ret = ft_init_ep(); if (ret) goto err; ret = fi_accept(ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err; } rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, eq, "fi_eq_sread", "accept"); ret = (int) rd; goto err; } if (event != FI_CONNECTED || entry.fid != &ep->fid) { fprintf(stderr, "Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err; } return 0; err: fi_reject(pep, fi->handle, NULL, 0); return ret; }
static int setup_server_ep(struct fid_ep **ep) { int ret; ret = ft_retrieve_conn_req(eq, &fi); if (ret) goto failed_accept; ret = fi_endpoint(domain, fi, ep, NULL); if (ret) { FT_PRINTERR("fi_endpoint", ret); goto failed_accept; } ret = ft_setup_ep(*ep, eq, av, txcq, rxcq, txcntr, rxcntr, false); if (ret) goto failed_accept; ret = ft_accept_connection(*ep, eq); if (ret) goto failed_accept; return 0; failed_accept: fi_reject(pep, fi->handle, NULL, 0); return ret; }
static int server_reject(size_t paramlen) { int ret; ret = server_listen(paramlen); if (ret) return ret; /* Data will appear in error event generated on remote end. */ ft_fill_buf(cm_data, paramlen); ret = fi_reject(pep, fi->handle, cm_data, paramlen); if (ret) FT_PRINTERR("fi_reject", ret); return ret; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *info = NULL; ssize_t rd; int ret; /* Wait for connection request from client */ rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PRINTERR("fi_eq_sread", rd); return (int) rd; } info = entry.info; if (event != FI_CONNREQ) { FT_ERR("Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err; } ret = fi_domain(fabric, info, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err; } ret = ft_alloc_active_res(info); if (ret) goto err; ret = ft_init_ep(); if (ret) goto err; /* Accept the incoming connection. Also transitions endpoint to active state */ ret = fi_accept(ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err; } /* Wait for the connection to be established */ rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PRINTERR("fi_eq_sread", rd); goto err; } if (event != FI_CONNECTED || entry.fid != &ep->fid) { FT_ERR("Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err; } ret = check_address(&ep->fid, "accept"); if (ret) { goto err; } fi_freeinfo(info); return 0; err: fi_reject(pep, info->handle, NULL, 0); fi_freeinfo(info); return ret; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *info = NULL; ssize_t rd; int ret; /* Wait for connection request from client */ rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, cmeq, "fi_eq_sread", "listen"); return (int) rd; } info = entry.info; if (event != FI_CONNREQ) { fprintf(stderr, "Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err1; } ret = fi_domain(fab, info, &dom, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err1; } ret = alloc_ep_res(info); if (ret) goto err1; ret = bind_ep_res(); if (ret) goto err3; /* Accept the incoming connection. Also transitions endpoint to active state */ ret = fi_accept(ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err3; } /* Wait for the connection to be established */ rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, cmeq, "fi_eq_sread", "accept"); ret = (int) rd; goto err3; } if (event != FI_CONNECTED || entry.fid != &ep->fid) { fprintf(stderr, "Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err3; } fi_freeinfo(info); return 0; err3: free_ep_res(); err1: fi_reject(pep, info->handle, NULL, 0); fi_freeinfo(info); return ret; }
static int server_accept(size_t paramlen) { uint32_t event; int ret; ret = server_listen(paramlen); if (ret) return ret; ret = fi_domain(fabric, fi, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err; } ret = ft_alloc_active_res(fi); if (ret) { FT_PRINTERR("alloc_active_res", ret); goto err; } ret = ft_init_ep(); if (ret) { FT_PRINTERR("init_ep", ret); goto err; } /* Data will apppear on accept event on remote end. */ ft_fill_buf(cm_data, paramlen); /* Accept the incoming connection. Also transitions endpoint to active * state. */ ret = fi_accept(ep, cm_data, paramlen); if (ret) { FT_PRINTERR("fi_accept", ret); goto err; } /* Local FI_CONNECTED event does not have data associated. */ memset(entry, 0, sizeof(*entry)); ret = fi_eq_sread(eq, &event, entry, sizeof(*entry), -1, 0); if (ret != sizeof(*entry)) { FT_PROCESS_EQ_ERR(ret, eq, "fi_eq_sread", "accept"); goto err; } if (event != FI_CONNECTED || entry->fid != &ep->fid) { FT_ERR("Unexpected CM event %d fid %p (ep %p)", event, entry->fid, ep); ret = -FI_EOTHER; goto err; } fi_shutdown(ep, 0); ret = read_shutdown_event(); if (ret) goto err; FT_CLOSE_FID(ep); FT_CLOSE_FID(rxcq); FT_CLOSE_FID(txcq); FT_CLOSE_FID(rxcntr); FT_CLOSE_FID(txcntr); FT_CLOSE_FID(av); FT_CLOSE_FID(domain); return 0; err: fi_reject(pep, fi->handle, NULL, 0); return ret; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; ssize_t rd; int ret, k; int num_conn_reqs = 0, num_connected = 0; struct ep_info *ep_state_array = NULL; ep_array = calloc(ep_cnt, sizeof(*ep_array)); if (!ep_array) return -FI_ENOMEM; ep_state_array = calloc(ep_cnt, sizeof(*ep_state_array)); if (!ep_state_array) return -FI_ENOMEM; while (num_connected != ep_cnt) { rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, eq, "fi_eq_sread", "cm-event"); ret = (int) rd; goto err; } switch(event) { case FI_CONNREQ: if (num_conn_reqs == ep_cnt) { fprintf(stderr, "Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err; } fi = ep_state_array[num_conn_reqs].fi = entry.info; ep_state_array[num_conn_reqs].state = FT_EP_CONNECT_RCVD; if (num_conn_reqs == 0) { ret = fi_domain(fabric, fi, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err; } ret = alloc_ep_res(fi); if (ret) goto err; } ret = fi_endpoint(domain, fi, &ep_array[num_conn_reqs], NULL); if (ret) { FT_PRINTERR("fi_endpoint", ret); goto err; } ep_state_array[num_conn_reqs].ep = ep_array[num_conn_reqs]; ret = bind_ep_res(ep_array[num_conn_reqs]); if (ret) goto err; ret = fi_accept(ep_array[num_conn_reqs], NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err; } ep_state_array[num_conn_reqs].state = FT_EP_CONNECTING; num_conn_reqs++; break; case FI_CONNECTED: if (num_conn_reqs <= num_connected) { ret = -FI_EOTHER; goto err; } for (k = 0; k < num_conn_reqs; k++) { if (ep_state_array[k].state != FT_EP_CONNECTING) continue; if (&ep_state_array[k].ep->fid == entry.fid) { ep_state_array[k].state = FT_EP_CONNECTED; num_connected++; if (num_connected != ep_cnt) fi_freeinfo(ep_state_array[k].fi); break; } } if (k == num_conn_reqs) { fprintf(stderr, "Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err; } break; default: ret = -FI_EOTHER; goto err; } } /* Post recv */ if (rx_shared_ctx) ret = ft_post_rx(srx_ctx, MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx); else ret = ft_post_rx(ep_array[0], MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx); if (ret) goto err; free(ep_state_array); return 0; err: for (k = 0; k < ep_cnt; k++) { switch(ep_state_array[k].state) { case FT_EP_CONNECT_RCVD: fi_reject(pep, ep_state_array[k].fi->handle, NULL, 0); break; case FT_EP_CONNECTING: case FT_EP_CONNECTED: fi_shutdown(ep_state_array[k].ep, 0); break; case FT_EP_STATE_INIT: default: break; } } free(ep_state_array); return ret; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *info = NULL; ssize_t rd; int ret; rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { printf("fi_eq_sread %zd %s\n", rd, fi_strerror((int) -rd)); return (int) rd; } if (event != FI_CONNREQ) { printf("Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err1; } info = entry.info; ret = fi_domain(fab, info, &dom, NULL); if (ret) { printf("fi_domain %s\n", fi_strerror(-ret)); goto err1; } ret = fi_endpoint(dom, info, &ep, NULL); if (ret) { printf("fi_endpoint for req %s\n", fi_strerror(-ret)); goto err1; } ret = alloc_ep_res(info); if (ret) goto err2; ret = bind_ep_res(); if (ret) goto err3; ret = fi_accept(ep, NULL, 0); if (ret) { printf("fi_accept %s\n", fi_strerror(-ret)); goto err3; } rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { printf("fi_eq_sread %zd %s\n", rd, fi_strerror((int) -rd)); goto err3; } if (event != FI_COMPLETE || entry.fid != &ep->fid) { printf("Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err3; } fi_freeinfo(info); return 0; err3: free_ep_res(); err2: fi_close(&ep->fid); err1: fi_reject(pep, info->connreq, NULL, 0); fi_freeinfo(info); return ret; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *info = NULL; ssize_t rd; int ret; rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PRINTERR("fi_eq_sread", rd); return (int) rd; } info = entry.info; if (event != FI_CONNREQ) { fprintf(stderr, "Unexpected CM event %d\n", event); ret = -FI_EOTHER; goto err1; } ret = fi_domain(fab, info, &dom, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err1; } ret = fi_endpoint(dom, info, &ep, NULL); if (ret) { FT_PRINTERR("fi_endpoint", -ret); goto err1; } ret = alloc_ep_res(info); if (ret) goto err1; ret = bind_ep_res(); if (ret) goto err3; ret = fi_accept(ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err3; } rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PRINTERR("fi_eq_sread", rd); goto err3; } if (event != FI_CONNECTED || entry.fid != &ep->fid) { fprintf(stderr, "Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err3; } fi_freeinfo(info); return 0; err3: free_ep_res(); err1: fi_reject(pep, info->connreq, NULL, 0); fi_freeinfo(info); return ret; }