static int rxd_ep_cm_setname(fid_t fid, void *addr, size_t addrlen) { struct rxd_ep *ep; ep = container_of(fid, struct rxd_ep, util_ep.ep_fid.fid); return fi_setname(&ep->dg_ep->fid, addr, addrlen); }
int rxm_setname(fid_t fid, void *addr, size_t addrlen) { struct rxm_ep *rxm_ep; rxm_ep = container_of(fid, struct rxm_ep, util_ep.ep_fid.fid); return fi_setname(&rxm_ep->msg_pep->fid, addr, addrlen); }
void do_setname_enosys(void) { int ret, i; for (i = 0; i < NUMEPS; i++) { ret = fi_setname(get_fid[ep_type](i), NULL, 0); cr_assert_eq(ret, -FI_ENOSYS, "Invalid return value: %s", fi_strerror(-ret)); } }
void do_setname(void) { int i, ret; void *addr; struct gnix_ep_name *src_addr = NULL, rebuilt; struct fi_info *info = NULL; ret = fi_setname(get_fid[ep_type](0), NULL, 0xbabbbcbd); cr_assert(ret == -FI_EINVAL, "fi_setname returned: %s", fi_strerror(-ret)); for (i = 0; i < NUMEPS; i++) { addr = malloc(ep_name_len[i]); ret = errno; cr_assert_not_null(addr, "malloc returned: %s", strerror(ret)); if (use_str_fmt) generate_rand_fas((char **) &addr); else init_bufs(&addr, 1, ep_name_len[i]); ret = fi_setname(get_fid[ep_type](i), addr, ep_name_len[i]); cr_assert(ret == FI_SUCCESS, "fi_setname returned: %s", fi_strerror(-ret)); get_fid_ep(i, (void **) &info, (void **) NULL, (void **) &src_addr); /* Ensure that the address was set properly. */ if (use_str_fmt) { fas_to_ep_name(addr, &rebuilt); check_ep_name(rebuilt, *src_addr); } else { check_ep_name(((struct gnix_ep_name *)addr)[0], *src_addr); } free(addr); } }
static int setup_handle(void) { static char buf[BUFSIZ]; struct addrinfo *ai, aihints; const char *bound_addr_str; int ret; memset(&aihints, 0, sizeof aihints); aihints.ai_flags = AI_PASSIVE; ret = getaddrinfo(opts.src_addr, opts.src_port, &aihints, &ai); if (ret == EAI_SYSTEM) { FT_ERR("getaddrinfo for %s:%s: %s\n", opts.src_addr, opts.src_port, strerror(errno)); return -ret; } else if (ret) { FT_ERR("getaddrinfo: %s\n", gai_strerror(ret)); return -FI_ENODATA; } switch (ai->ai_family) { case AF_INET: hints->addr_format = FI_SOCKADDR_IN; break; case AF_INET6: hints->addr_format = FI_SOCKADDR_IN6; break; } /* Get fabric info */ ret = fi_getinfo(FT_FIVERSION, opts.src_addr, NULL, FI_SOURCE, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); goto out; } free(fi->src_addr); fi->src_addr = NULL; fi->src_addrlen = 0; ret = fi_fabric(fi->fabric_attr, &fabric, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); goto out; } ret = fi_eq_open(fabric, &eq_attr, &eq, NULL); if (ret) { FT_PRINTERR("fi_eq_open", ret); goto out; } /* Open a passive endpoint */ ret = fi_passive_ep(fabric, fi, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); goto out; } ret = fi_setname(&pep->fid, ai->ai_addr, ai->ai_addrlen); if (ret) { FT_PRINTERR("fi_setname", ret); goto out; } ret = fi_getname(&pep->fid, &bound_addr, &bound_addr_len); if (ret) { FT_PRINTERR("fi_getname", ret); goto out; } /* Verify port number */ switch (ai->ai_family) { case AF_INET: if (bound_addr.sin.sin_port == 0) { FT_ERR("port number is 0 after fi_setname()\n"); ret = -FI_EINVAL; goto out; } break; case AF_INET6: if (bound_addr.sin6.sin6_port == 0) { FT_ERR("port number is 0 after fi_setname()\n"); ret = -FI_EINVAL; goto out; } break; } bound_addr_str = sockaddrstr(&bound_addr, bound_addr_len, buf, BUFSIZ); if (!bound_addr_str) { FT_ERR("Unable to get bound_addr as string!\n"); ret = -FI_EINVAL; goto out; } printf("bound_addr: \"%s\"\n", bound_addr_str); hints->handle = &pep->fid; out: freeaddrinfo(ai); return ret; }
static int hook_setname(fid_t fid, void *addr, size_t addrlen) { return fi_setname(hook_to_hfid(fid), addr, addrlen); }
static void test_connect_with_accept_blocking_on_eq_fq_SERVER(void) { int ret; printf("SERVER running\n"); setup_ofi(NULL, NULL, FI_SOURCE); #if WANT_FDS // Add the EQ FD to the epoll fd static struct epoll_event edt; memset(&edt, 0, sizeof(edt)); edt.events = EPOLLIN; edt.data.u32 = 2222; ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fidev.eq_fd, &edt); if (ret < 0) { error("server epoll_ctl failed"); } #endif // Make a PEP ret = fi_passive_ep(fidev.fabric, fidev.info, &fidev.pep, NULL); if (0 != ret) { error("fi_passive_ep failed"); } #if WANT_FIXED_PORT size_t ss = sizeof(sin); ret = fi_getname(&(fidev.pep->fid), &sin, &ss); if (0 != ret) { error("fi_setname failed"); } sin.sin_port = htons(listen_port); // Bind the PEP to listen on a specific port ret = fi_setname(&(fidev.pep->fid), &sin, sizeof(sin)); if (0 != ret) { error("fi_setname failed"); } #endif // Bind the EQ to the PEP ret = fi_pep_bind(fidev.pep, &fidev.eq->fid, 0); if (0 != ret) { error("fi_pep_bind failed"); } // Listen ret = fi_listen(fidev.pep); if (0 != ret) { error("fi_listen failed"); } // Get the actual address of this PEP struct sockaddr_in sinout; size_t s = sizeof(sinout); ret = fi_getname(&(fidev.pep->fid), &sinout, &s); if (0 != ret) { error("fi_setname failed"); } sin.sin_family = sinout.sin_family; sin.sin_addr = sinout.sin_addr; sin.sin_port = sinout.sin_port; // Print server addr printf("SERVER listening on %s\n", addrstr(&sin)); // Send our node (IP addr) and service (port) to the client snprintf(ofi_node, sizeof(ofi_node) - 1, "%s", inet_ntoa(sin.sin_addr)); snprintf(ofi_service, sizeof(ofi_service) - 1, "%d", ntohs(sin.sin_port)); MPI_Send(ofi_node, sizeof(ofi_node) - 1, MPI_CHAR, 1, 101, MPI_COMM_WORLD); MPI_Send(ofi_service, sizeof(ofi_service) - 1, MPI_CHAR, 1, 102, MPI_COMM_WORLD); printf("SERVER sent via MPI to client: %s / %s\n", ofi_node, ofi_service); #if WANT_FDS // Now wait for the listen to complete int nevents; #define NEVENTS 32 struct epoll_event events[NEVENTS]; int timeout = 10000; while (1) { printf("SERVER blocking on epoll\n"); nevents = epoll_wait(epoll_fd, events, NEVENTS, timeout); if (nevents < 0) { if (errno != EINTR) { error("server epoll wait failed"); } else { continue; } } else { printf("SERVER successfully woke up from epoll! %d events\n", nevents); for (int i = 0; i < nevents; ++i) { if (events[i].data.u32 != 2222) { error("server unexpected epoll return type"); } } // If we got the expected event, then go read from the EQ break; } } #endif // Wait for the FI_CONNREQ event uint32_t event; uint8_t *entry_buffer; size_t expected_len = sizeof(struct fi_eq_cm_entry) + sizeof(client_data); entry_buffer = (uint8_t*) calloc(1, expected_len); if (NULL == entry_buffer) { error("calloc failed"); } struct fi_eq_cm_entry *entry = (struct fi_eq_cm_entry*) entry_buffer; while (1) { printf("SERVER waiting for FI_CONNREQ\n"); #if WANT_FDS ret = fi_eq_read(fidev.eq, &event, entry, expected_len, 0); #else ret = fi_eq_sread(fidev.eq, &event, entry, expected_len, -1, 0); #endif if (-FI_EAVAIL == ret) { printf("server fi_eq_sread failed because there's something in the error queue\n"); char buffer[2048]; struct fi_eq_err_entry *err_entry = (struct fi_eq_err_entry*) buffer; ret = fi_eq_readerr(fidev.eq, err_entry, 0); printf("error code: %d (%s), prov err code: %d (%s)\n", err_entry->err, fi_strerror(err_entry->err), err_entry->prov_errno, fi_strerror(err_entry->prov_errno)); error("sad panda"); } else if (-EAGAIN == ret) { fprintf(stderr, "SERVER fi_eq_sread fail got -EAGAIN... trying again...\n"); sleep(1); continue; } else if (ret < 0) { fprintf(stderr, "SERVER fi_eq_sread fail: %s (FI_EAVAIL = %d, -ret = %d)\n", fi_strerror(-ret), FI_EAVAIL, -ret); error("SERVER fi_eq_sread failed for some random reason"); } else if (event != FI_CONNREQ) { error("SERVER got some unexpected event"); } else if (ret != expected_len) { error("SERVER got wrong length back from fi_eq_sread"); } uint32_t *d = (uint32_t*) entry->data; for (int i = 0; i < (sizeof(client_data) / sizeof(uint32_t)); ++i) { if (d[i] != client_data[i]) { printf("SERVER got wrong CM client data: d[%d]=%d, should be %d\n", i, d[i], client_data[i]); } } printf("SERVER got FI_CONNREQ, correct size, and correct data -- yay!\n"); break; } // Silly logistics: setup_ofi_active adds the fd to the epoll set. // But we already added it. So for simplicity, just remove it // here so that setup_ofi_active() can re-add it. #if WANT_FDS // Remove the EQ FD from the epoll fd ret = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fidev.eq_fd, &edt); if (ret < 0) { error("server epoll_ctl DEL failed"); } #endif // Make an active endpoint setup_ofi_active(entry->info, &ficonn.ep); // Accept the incoming connection ret = fi_accept(ficonn.ep, (void*) server_data, sizeof(server_data)); if (ret != 0) { printf("fi_accept: ret=%d, %s\n", ret, fi_strerror(-ret)); error("SERVER fi_accept failed\n"); } // Need to read and get a FI_CONNECTED event while (1) { printf("SERVER waiting for FI_CONNECTED\n"); #if WANT_FDS ret = fi_eq_read(fidev.eq, &event, entry, expected_len, 0); #else ret = fi_eq_sread(fidev.eq, &event, entry, expected_len, -1, 0); #endif if (-FI_EAVAIL == ret) { printf("server fi_eq_sread failed because there's something in the error queue\n"); char buffer[2048]; struct fi_eq_err_entry *err_entry = (struct fi_eq_err_entry*) buffer; ret = fi_eq_readerr(fidev.eq, err_entry, 0); printf("error code: %d (%s), prov err code: %d (%s)\n", err_entry->err, fi_strerror(err_entry->err), err_entry->prov_errno, fi_strerror(err_entry->prov_errno)); error("sad panda"); } else if (-EAGAIN == ret) { fprintf(stderr, "SERVER fi_eq_sread fail got -EAGAIN... trying again...\n"); sleep(1); continue; } else if (ret < 0) { fprintf(stderr, "SERVER fi_eq_sread fail: %s (FI_EAVAIL = %d, -ret = %d)\n", fi_strerror(-ret), FI_EAVAIL, -ret); error("SERVER fi_eq_sread failed for some random reason"); } else if (event != FI_CONNECTED) { error("SERVER got some unexpected event"); } printf("SERVER got FI_CONNECTED -- yay!\n"); break; } // Post a recv buffer for the client to send int msg[4] = { 0 }; int len = sizeof(msg); printf("SERVER receiving len of %d\n", len); struct fid_mr no_mr; struct fid_mr *mr; void *recv_context = (void*) 0x17; #if 0 fi_mr_reg(fidev.domain, msg, len, FI_SEND | FI_RECV, 0, (uint64_t)(uintptr_t) msg, 0, &mr, NULL); #else // Try using no mr, like fi_msg_pingpong... memset(&no_mr, 0, sizeof(no_mr)); mr = &no_mr; #endif ret = fi_recv(ficonn.ep, msg, len, fi_mr_desc(mr), 0, recv_context); if (ret < 0) { printf("fi_recv failed! %d, %s\n", ret, fi_strerror(-ret)); MPI_Abort(MPI_COMM_WORLD, 37); } sleep(1); printf("SERVER posted receive -- waiting for client to send\n"); MPI_Barrier(MPI_COMM_WORLD); // Wait for receive completion struct fi_cq_entry cqe; while (1) { ret = fi_cq_sread(ficonn.cq, &cqe, 1, 0, -1); if (cqe.op_context == recv_context) { printf("SERVER receive completed\n"); break; } else { printf("SERVER got some other completion... continuing\n"); } } printf("SERVER finished -- waiting for client before teardown\n"); MPI_Barrier(MPI_COMM_WORLD); printf("SERVER tearing down\n"); fi_close(&(mr->fid)); teardown_ofi(); }