From patchwork Fri Aug 2 22:20:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 2838200 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9980CBF535 for ; Fri, 2 Aug 2013 22:20:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A1E020345 for ; Fri, 2 Aug 2013 22:20:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71DEA20347 for ; Fri, 2 Aug 2013 22:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753962Ab3HBWUb (ORCPT ); Fri, 2 Aug 2013 18:20:31 -0400 Received: from mga01.intel.com ([192.55.52.88]:27933 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754090Ab3HBWU3 (ORCPT ); Fri, 2 Aug 2013 18:20:29 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 02 Aug 2013 15:20:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.89,804,1367996400"; d="scan'208";a="375385372" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga001.fm.intel.com with ESMTP; 02 Aug 2013 15:20:28 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org Cc: Sean Hefty Subject: [PATCH librdmacm 2/5] examples: Add support for native IB addressing to samples Date: Fri, 2 Aug 2013 15:20:19 -0700 Message-Id: <1375482022-5953-3-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1375482022-5953-1-git-send-email-sean.hefty@intel.com> References: <1375482022-5953-1-git-send-email-sean.hefty@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Hefty Allow the user to specify GID addresses (AF_IB) into udaddy and rstream. Signed-off-by: Sean Hefty --- examples/rstream.c | 62 +++++++++++++++++++++++++++++++++++++++++----------- examples/udaddy.c | 49 ++++++++++++++++++++++++++++------------ 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/examples/rstream.c b/examples/rstream.c index a408b9e..e27ddcd 100644 --- a/examples/rstream.c +++ b/examples/rstream.c @@ -93,6 +93,8 @@ static char *dst_addr; static char *src_addr; static struct timeval start, end; static void *buf; +static struct rdma_addrinfo rai_hints; +static struct addrinfo ai_hints; static void show_perf(void) { @@ -285,18 +287,25 @@ static void set_options(int rs) static int server_listen(void) { - struct addrinfo hints, *res; + struct rdma_addrinfo *rai; + struct addrinfo *ai; int val, ret; - memset(&hints, 0, sizeof hints); - hints.ai_flags = AI_PASSIVE; - ret = getaddrinfo(src_addr, port, &hints, &res); + if (rai_hints.ai_flags) { + rai_hints.ai_flags |= RAI_PASSIVE; + ret = rdma_getaddrinfo(src_addr, port, &rai_hints, &rai); + } else { + ai_hints.ai_flags |= AI_PASSIVE; + ret = getaddrinfo(src_addr, port, &ai_hints, &ai); + } if (ret) { perror("getaddrinfo"); return ret; } - lrs = rs_socket(res->ai_family, res->ai_socktype, res->ai_protocol); + lrs = rai_hints.ai_flags ? + rs_socket(rai->ai_family, SOCK_STREAM, 0) : + rs_socket(ai->ai_family, SOCK_STREAM, 0); if (lrs < 0) { perror("rsocket"); ret = lrs; @@ -310,7 +319,9 @@ static int server_listen(void) goto close; } - ret = rs_bind(lrs, res->ai_addr, res->ai_addrlen); + ret = rai_hints.ai_flags ? + rs_bind(lrs, rai->ai_src_addr, rai->ai_src_len) : + rs_bind(lrs, ai->ai_addr, ai->ai_addrlen); if (ret) { perror("rbind"); goto close; @@ -324,7 +335,10 @@ close: if (ret) rs_close(lrs); free: - freeaddrinfo(res); + if (rai_hints.ai_flags) + rdma_freeaddrinfo(rai); + else + freeaddrinfo(ai); return ret; } @@ -362,18 +376,23 @@ static int server_connect(void) static int client_connect(void) { - struct addrinfo *res; + struct rdma_addrinfo *rai; + struct addrinfo *ai; struct pollfd fds; int ret, err; socklen_t len; - ret = getaddrinfo(dst_addr, port, NULL, &res); + ret = rai_hints.ai_flags ? + rdma_getaddrinfo(dst_addr, port, &rai_hints, &rai) : + getaddrinfo(dst_addr, port, &ai_hints, &ai); if (ret) { perror("getaddrinfo"); return ret; } - rs = rs_socket(res->ai_family, res->ai_socktype, res->ai_protocol); + rs = rai_hints.ai_flags ? + rs_socket(rai->ai_family, SOCK_STREAM, 0) : + rs_socket(ai->ai_family, SOCK_STREAM, 0); if (rs < 0) { perror("rsocket"); ret = rs; @@ -383,7 +402,9 @@ static int client_connect(void) set_options(rs); /* TODO: bind client to src_addr */ - ret = rs_connect(rs, res->ai_addr, res->ai_addrlen); + ret = rai_hints.ai_flags ? + rs_connect(rs, rai->ai_dst_addr, rai->ai_dst_len) : + rs_connect(rs, ai->ai_addr, ai->ai_addrlen); if (ret && (errno != EINPROGRESS)) { perror("rconnect"); goto close; @@ -411,7 +432,10 @@ close: if (ret) rs_close(rs); free: - freeaddrinfo(res); + if (rai_hints.ai_flags) + rdma_freeaddrinfo(rai); + else + freeaddrinfo(ai); return ret; } @@ -534,7 +558,9 @@ int main(int argc, char **argv) { int op, ret; - while ((op = getopt(argc, argv, "s:b:B:I:C:S:p:T:")) != -1) { + ai_hints.ai_socktype = SOCK_STREAM; + rai_hints.ai_port_space = RDMA_PS_TCP; + while ((op = getopt(argc, argv, "s:b:f:B:I:C:S:p:T:")) != -1) { switch (op) { case 's': dst_addr = optarg; @@ -542,6 +568,14 @@ int main(int argc, char **argv) case 'b': src_addr = optarg; break; + case 'f': + if (!strncasecmp("ip", optarg, 2)) { + ai_hints.ai_flags = AI_NUMERICHOST; + } else if (!strncasecmp("gid", optarg, 3)) { + rai_hints.ai_flags = RAI_NUMERICHOST | RAI_FAMILY; + rai_hints.ai_family = AF_IB; + } + break; case 'B': buffer_size = atoi(optarg); break; @@ -572,6 +606,8 @@ int main(int argc, char **argv) printf("usage: %s\n", argv[0]); printf("\t[-s server_address]\n"); printf("\t[-b bind_address]\n"); + printf("\t[-f address_format]\n"); + printf("\t name, ip, ipv6, or gid\n"); printf("\t[-B buffer_size]\n"); printf("\t[-I iterations]\n"); printf("\t[-C transfer_count]\n"); diff --git a/examples/udaddy.c b/examples/udaddy.c index 7360d60..031b0b6 100644 --- a/examples/udaddy.c +++ b/examples/udaddy.c @@ -77,7 +77,7 @@ static uint8_t set_tos = 0; static uint8_t tos; static char *dst_addr; static char *src_addr; -static enum rdma_port_space port_space = RDMA_PS_UDP; +static struct rdma_addrinfo hints; static int create_message(struct cmatest_node *node) { @@ -429,7 +429,7 @@ static int alloc_nodes(void) if (dst_addr) { ret = rdma_create_id(test.channel, &test.nodes[i].cma_id, - &test.nodes[i], port_space); + &test.nodes[i], hints.ai_port_space); if (ret) goto err; } @@ -505,19 +505,15 @@ static int connect_events(void) static int run_server(void) { struct rdma_cm_id *listen_id; - struct rdma_addrinfo hints; int i, ret; printf("udaddy: starting server\n"); - ret = rdma_create_id(test.channel, &listen_id, &test, port_space); + ret = rdma_create_id(test.channel, &listen_id, &test, hints.ai_port_space); if (ret) { perror("udaddy: listen request failed"); return ret; } - memset(&hints, 0, sizeof hints); - hints.ai_flags = RAI_PASSIVE; - hints.ai_port_space = port_space; ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { perror("cmatose: getrdmaaddr error"); @@ -563,13 +559,10 @@ out: static int run_client(void) { - struct rdma_addrinfo hints; int i, ret; printf("udaddy: starting client\n"); - memset(&hints, 0, sizeof hints); - hints.ai_port_space = port_space; ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { perror("udaddy: getaddrinfo error"); @@ -613,7 +606,8 @@ int main(int argc, char **argv) { int op, ret; - while ((op = getopt(argc, argv, "s:b:c:C:S:t:p:")) != -1) { + hints.ai_port_space = RDMA_PS_UDP; + while ((op = getopt(argc, argv, "s:b:c:C:S:t:p:P:f:")) != -1) { switch (op) { case 's': dst_addr = optarg; @@ -634,13 +628,36 @@ int main(int argc, char **argv) set_tos = 1; tos = (uint8_t) strtoul(optarg, NULL, 0); break; - case 'p': - port_space = strtol(optarg, NULL, 0); + case 'p': /* for backwards compatibility - use -P */ + hints.ai_port_space = strtol(optarg, NULL, 0); + break; + case 'f': + if (!strncasecmp("ip", optarg, 2)) { + hints.ai_flags = RAI_NUMERICHOST; + } else if (!strncasecmp("gid", optarg, 3)) { + hints.ai_flags = RAI_NUMERICHOST | RAI_FAMILY; + hints.ai_family = AF_IB; + } else if (strncasecmp("name", optarg, 4)) { + fprintf(stderr, "Warning: unknown address format\n"); + } + break; + case 'P': + if (!strncasecmp("ib", optarg, 2)) { + hints.ai_port_space = RDMA_PS_IB; + } else if (!strncasecmp("ipoib", optarg, 5)) { + hints.ai_port_space = RDMA_PS_IPOIB; + } else if (strncasecmp("udp", optarg, 3)) { + fprintf(stderr, "Warning: unknown port space format\n"); + } break; default: printf("usage: %s\n", argv[0]); printf("\t[-s server_address]\n"); printf("\t[-b bind_address]\n"); + printf("\t[-f address_format]\n"); + printf("\t name, ip, ipv6, or gid\n"); + printf("\t[-P port_space]\n"); + printf("\t udp, ipoib, or ib\n"); printf("\t[-c connections]\n"); printf("\t[-C message_count]\n"); printf("\t[-S message_size]\n"); @@ -662,10 +679,12 @@ int main(int argc, char **argv) if (alloc_nodes()) exit(1); - if (dst_addr) + if (dst_addr) { ret = run_client(); - else + } else { + hints.ai_flags |= RAI_PASSIVE; ret = run_server(); + } printf("test complete\n"); destroy_nodes();