static int client_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *fi; ssize_t rd; int ret; if (src_addr) { ret = getaddr(src_addr, NULL, (struct sockaddr **) &hints.src_addr, (socklen_t *) &hints.src_addrlen); if (ret) printf("source address error %s\n", gai_strerror(ret)); } ret = fi_getinfo(FI_VERSION(1, 0), dst_addr, port, 0, &hints, &fi); if (ret) { printf("fi_getinfo %s\n", strerror(-ret)); goto err0; } ret = fi_fabric(fi->fabric_attr, &fab, NULL); if (ret) { printf("fi_fabric %s\n", fi_strerror(-ret)); goto err1; } ret = fi_domain(fab, fi, &dom, NULL); if (ret) { printf("fi_domain %s %s\n", fi_strerror(-ret), fi->domain_attr->name); goto err2; } ret = fi_endpoint(dom, fi, &ep, NULL); if (ret) { printf("fi_endpoint %s\n", fi_strerror(-ret)); goto err3; } ret = alloc_ep_res(fi); if (ret) goto err4; ret = bind_ep_res(); if (ret) goto err5; ret = fi_connect(ep, fi->dest_addr, NULL, 0); if (ret) { printf("fi_connect %s\n", fi_strerror(-ret)); goto err5; } 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_COMPLETE || entry.fid != &ep->fid) { printf("Unexpected CM event %d fid %p (ep %p)\n", event, entry.fid, ep); ret = -FI_EOTHER; goto err1; } if (hints.src_addr) free(hints.src_addr); fi_freeinfo(fi); return 0; err5: free_ep_res(); err4: fi_close(&ep->fid); err3: fi_close(&dom->fid); err2: fi_close(&fab->fid); err1: fi_freeinfo(fi); err0: if (hints.src_addr) free(hints.src_addr); return ret; }
static int client_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; struct fi_info *fi; ssize_t rd; int ret; ret = ft_getsrcaddr(opts.src_addr, opts.src_port, hints); if (ret) return ret; ret = fi_getinfo(FT_FIVERSION, opts.dst_addr, opts.dst_port, 0, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); goto err0; } ret = fi_fabric(fi->fabric_attr, &fab, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); goto err1; } ret = fi_domain(fab, fi, &dom, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err2; } ret = fi_endpoint(dom, fi, &ep, NULL); if (ret) { FT_PRINTERR("fi_endpoint", ret); goto err3; } ret = alloc_ep_res(fi); if (ret) goto err3; ret = bind_ep_res(); if (ret) goto err5; ret = fi_connect(ep, fi->dest_addr, NULL, 0); if (ret) { FT_PRINTERR("fi_connect", ret); goto err5; } rd = fi_eq_sread(cmeq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PRINTERR("fi_eq_sread", rd); return (int) rd; } 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 err1; } fi_freeinfo(fi); return 0; err5: free_ep_res(); err3: fi_close(&dom->fid); err2: fi_close(&fab->fid); err1: fi_freeinfo(fi); err0: 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(eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, eq, "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 err; } ret = fi_domain(fabric, info, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); goto err; } ret = alloc_ep_res(info); if (ret) goto err; ret = ft_init_ep(buf); 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; } 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; 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; }
static int pp_connect_ctx(struct pingpong_context *ctx) { struct fi_eq_cm_entry entry; uint32_t event; int rc = 0; ssize_t rd; /* Open domain */ rc = fi_domain(ctx->fabric, ctx->info, &ctx->dom, NULL); if (rc) { FT_PRINTERR("fi_fdomain", rc); return 1; } if (pp_eq_create(ctx)) { fprintf(stderr, "Unable to create event queue\n"); return 1; } rc = fi_mr_reg(ctx->dom, ctx->buf, ctx->size, FI_SEND | FI_RECV, 0, 0, 0, &ctx->mr, NULL); if (rc) { FT_PRINTERR("fi_mr_reg", rc); return 1; } /* Open endpoint */ rc = fi_endpoint(ctx->dom, ctx->info, &ctx->ep, NULL); if (rc) { FT_PRINTERR("fi_endpoint", rc); return 1; } /* Create event queue */ if (pp_cq_create(ctx)) { fprintf(stderr, "Unable to create event queue\n"); return 1; } /* Bind eq to ep */ rc = fi_ep_bind(ctx->ep, &ctx->cq->fid, FI_SEND | FI_RECV); if (rc) { FT_PRINTERR("fi_ep_bind", rc); return 1; } rc = fi_ep_bind(ctx->ep, &ctx->eq->fid, 0); if (rc) { FT_PRINTERR("fi_ep_bind", rc); return 1; } rc = fi_enable(ctx->ep); if (rc) { FT_PRINTERR("fi_enable", rc); return EXIT_FAILURE; } ctx->routs = pp_post_recv(ctx, ctx->rx_depth); if (ctx->routs < ctx->rx_depth) { FT_ERR("Couldn't post receive (%d)", ctx->routs); return 1; } printf("Connecting to server\n"); rc = fi_connect(ctx->ep, ctx->info->dest_addr, NULL, 0); if (rc) { FT_PRINTERR("fi_connect", rc); return 1; } rd = fi_eq_sread(ctx->eq, &event, &entry, sizeof entry, -1, 0); if (rd != sizeof entry) { FT_PROCESS_EQ_ERR(rd, ctx->eq, "fi_eq_sread", "connect"); return 1; } if (event != FI_CONNECTED) { fprintf(stderr, "Unexpected CM event %d\n", event); return 1; } printf("Connection successful\n"); return 0; }
static int client_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; ssize_t rd; int ret; ret = fi_getinfo(FT_FIVERSION, opts.dst_addr, opts.dst_port, 0, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); return ret; } ret = fi_domain(fabric, fi, &domain, NULL); if (ret) { FT_PRINTERR("fi_domain", ret); return ret; } ret = check_address(&pep->fid, "fi_endpoint (pep)"); if (ret) return ret; assert(fi->handle == &pep->fid); ret = ft_alloc_active_res(fi); if (ret) return ret; /* Close the passive endpoint that we "stole" the source address * from */ FT_CLOSE_FID(pep); ret = ft_init_ep(); if (ret) return ret; ret = check_address(&ep->fid, "fi_endpoint (ep)"); if (ret) return ret; /* Connect to server */ ret = fi_connect(ep, fi->dest_addr, NULL, 0); if (ret) { FT_PRINTERR("fi_connect", ret); return ret; } /* Wait for the connection to be established */ 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; } if (event != FI_CONNECTED || entry.fid != &ep->fid) { FT_ERR("Unexpected CM event %d fid %p (ep %p)", event, entry.fid, ep); return -FI_EOTHER; } ret = check_address(&ep->fid, "connect"); if (ret) { return ret; } return 0; }
static int server_connect(void) { struct fi_eq_cm_entry entry; uint32_t event; 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; } fi = entry.info; if (event != FI_CONNREQ) { FT_ERR("Unexpected CM event %d", 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; /* 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)", event, entry.fid, ep); ret = -FI_EOTHER; goto err; } ret = check_address(&ep->fid, "accept"); if (ret) { goto err; } return 0; err: fi_reject(pep, fi->handle, NULL, 0); return ret; }
/* * Tests: * - sread with event pending * - sread with no event pending */ static int eq_wait_fd_sread() { struct fi_eq_entry entry; uint32_t event; int64_t elapsed; int testret; int ret; testret = FAIL; ret = create_eq(32, FI_WRITE, FI_WAIT_FD); if (ret != 0) { sprintf(err_buf, "fi_eq_open ret=%d, %s", ret, fi_strerror(-ret)); goto fail; } /* timed sread on empty EQ, 2s timeout */ ft_start(); ret = fi_eq_sread(eq, &event, &entry, sizeof(entry), 2000, 0); if (ret != -FI_EAGAIN) { sprintf(err_buf, "fi_eq_read of empty EQ returned %d", ret); goto fail; } /* check timeout accuracy */ ft_stop(); elapsed = get_elapsed(&start, &end, MILLI); if (elapsed < 1500 || elapsed > 2500) { sprintf(err_buf, "fi_eq_sread slept %d ms, expected 2000", (int)elapsed); goto fail; } /* write an event */ entry.fid = &eq->fid; entry.context = eq; ret = fi_eq_write(eq, FI_NOTIFY, &entry, sizeof(entry), 0); if (ret != sizeof(entry)) { sprintf(err_buf, "fi_eq_write ret=%d, %s", ret, fi_strerror(-ret)); goto fail; } /* timed sread on EQ with event, 2s timeout */ ft_start(); event = ~0; memset(&entry, 0, sizeof(entry)); ret = fi_eq_sread(eq, &event, &entry, sizeof(entry), 2000, 0); if (ret != sizeof(entry)) { sprintf(err_buf, "fi_eq_read ret=%d, %s", ret, fi_strerror(-ret)); goto fail; } /* check that no undue waiting occurred */ ft_stop(); elapsed = get_elapsed(&start, &end, MILLI); if (elapsed > 5) { sprintf(err_buf, "fi_eq_sread slept %d ms, expected immediate return", (int)elapsed); goto fail; } if (event != FI_NOTIFY) { sprintf(err_buf, "fi_eq_sread: event = %d, should be %d\n", event, FI_NOTIFY); goto fail; } if (entry.fid != &eq->fid) { sprintf(err_buf, "fi_eq_sread: fid mismatch: %p should be %p\n", entry.fid, &eq->fid); goto fail; } if (entry.context != eq) { sprintf(err_buf, "fi_eq_sread: context mismatch: %p should be %p\n", entry.context, eq); goto fail; } testret = PASS; fail: FT_CLOSE_FID(eq); return TEST_RET_VAL(ret, testret); }
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_enable_ep_recv(); 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; }