From f9faa20d6498363cb7348d79efa1d8abc24fa715 Mon Sep 17 00:00:00 2001 From: Chien Tin Tung Date: Wed, 3 Apr 2024 13:37:30 -0700 Subject: [PATCH] util: Add source address to fi_pingpong In multi-adapter environment, fi_pingpong is failing with -61, No data available error when not using the first interface. Add source address parameter and use it with hints src_addr to get at the correct interface for data transfer. Signed-off-by: Chien Tin Tung --- man/fi_pingpong.1.md | 3 +++ util/pingpong.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/man/fi_pingpong.1.md b/man/fi_pingpong.1.md index e72c5631903..f39dae502c6 100644 --- a/man/fi_pingpong.1.md +++ b/man/fi_pingpong.1.md @@ -84,6 +84,9 @@ given domains cannot communicate, then the application will fail. *-d \* : The name of the specific domain to be used. +*-s \* +: Address to corresponding domain. Required in multi-adapter environment. + ## Test Options *-I \* diff --git a/util/pingpong.c b/util/pingpong.c index b38c23d39a3..9f1098c3792 100644 --- a/util/pingpong.c +++ b/util/pingpong.c @@ -87,6 +87,7 @@ enum { struct pp_opts { uint16_t src_port; uint16_t dst_port; + char *src_addr; char *dst_addr; int iterations; int transfer_size; @@ -280,6 +281,8 @@ static void pp_banner_options(struct ct_pingpong *ct) } PP_DEBUG(" * PingPong options:\n"); + PP_DEBUG(" - %-20s: [%s]\n", "src_addr", + (opts.src_addr)? opts.src_addr: "None"); PP_DEBUG(" - %-20s: [%" PRIu16 "]\n", "src_port", opts.src_port); PP_DEBUG(" - %-20s: [%s]\n", "dst_addr", opts.dst_addr); PP_DEBUG(" - %-20s: [%" PRIu16 "]\n", "dst_port", opts.dst_port); @@ -1999,6 +2002,8 @@ static void pp_pingpong_usage(struct ct_pingpong *ct, char *name, char *desc) "destination control port number (client: 47592)"); fprintf(stderr, " %-20s %s\n", "-d ", "domain name"); + fprintf(stderr, " %-20s %s\n", "-s ", + "source address associated with domain name"); fprintf(stderr, " %-20s %s\n", "-p ", "specific provider name eg sockets, verbs"); fprintf(stderr, " %-20s %s\n", "-e ", @@ -2071,6 +2076,11 @@ static void pp_parse_opts(struct ct_pingpong *ct, int op, char *optarg) } break; + /* Source address */ + case 's': + ct->opts.src_addr = optarg; + break; + /* Check data */ case 'c': ct->opts.options |= PP_OPT_VERIFY_DATA; @@ -2274,6 +2284,24 @@ static int run_pingpong_msg(struct ct_pingpong *ct) return ret; } +static void pp_set_src_hint(struct ct_pingpong *ct) +{ + struct addrinfo *results = NULL; + + if (getaddrinfo(ct->opts.src_addr, NULL, NULL, &results)) + return; + + ct->hints->src_addr = calloc(1, results->ai_addrlen); + if (!ct->hints->src_addr) + return; + + ct->hints->src_addrlen = results->ai_addrlen; + memcpy(ct->hints->src_addr, results->ai_addr, results->ai_addrlen); + ct->hints->addr_format = results->ai_family; + + freeaddrinfo(results); +} + int main(int argc, char **argv) { int op, ret = EXIT_SUCCESS; @@ -2298,7 +2326,7 @@ int main(int argc, char **argv) ofi_osd_init(); - while ((op = getopt(argc, argv, "hvd:p:e:I:S:B:P:cm:6")) != -1) { + while ((op = getopt(argc, argv, "hvd:p:e:I:S:s:B:P:cm:6")) != -1) { switch (op) { default: pp_parse_opts(&ct, op, optarg); @@ -2314,6 +2342,9 @@ int main(int argc, char **argv) if (optind < argc) ct.opts.dst_addr = argv[optind]; + if (ct.opts.src_addr) + pp_set_src_hint(&ct); + pp_banner_options(&ct); switch (ct.hints->ep_attr->type) {