From patchwork Tue Mar 4 12:08:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 3761661 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7FBD59F376 for ; Tue, 4 Mar 2014 12:08:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E30C203DA for ; Tue, 4 Mar 2014 12:08:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 07684203B5 for ; Tue, 4 Mar 2014 12:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932212AbaCDMIX (ORCPT ); Tue, 4 Mar 2014 07:08:23 -0500 Received: from mail-bk0-f45.google.com ([209.85.214.45]:50451 "EHLO mail-bk0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932209AbaCDMIW (ORCPT ); Tue, 4 Mar 2014 07:08:22 -0500 Received: by mail-bk0-f45.google.com with SMTP id na10so182069bkb.4 for ; Tue, 04 Mar 2014 04:08:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=mzwoce2uPwie8yLrLQv8prmrHi0BawjroeF4S8pO9Nw=; b=IfsNhfdTSTqAZk2HJjvmYP9k5j0w9A0vyFV5OVE+Y6hupm0M2wJa+nb74xQXGlDmNl hA6GLikXmEojC4WRsx2T8GK5iIMJT9mOj44jc/g3OATjlZYxy9o8eAsMgyHq2LL1p6hX Uqi4/tHzg6mxIknVGqlr7aSCAV+MnAd5vch8dK/pU0MyiSUp4ZvlQaYrdS7ycScfZOxH Kd3LvZtHQ4kGPYEh4xhhM2NnwcOdnRZ2CypGl1vCP4Nx8B2l5kk+F9oYsCBAZtH+g14P MPEvaXMUnHLZw/PLLnNyh3ZZU7UMu8e6Ve6+IS0lFCcEZbLvdmZei0QgszvlFvB1yAXz EYhg== X-Gm-Message-State: ALoCoQkTNAZLH/zs+8EnlhaoYBiRPpR8shvn6Ln6sKC/v7JXUGtQJ8pZyqyMF20RAqYXOv4J8wRD X-Received: by 10.205.41.9 with SMTP id ts9mr590857bkb.61.1393934901339; Tue, 04 Mar 2014 04:08:21 -0800 (PST) Received: from [192.168.1.102] (c-98-229-118-119.hsd1.ma.comcast.net. [98.229.118.119]) by mx.google.com with ESMTPSA id u14sm936950bkg.9.2014.03.04.04.08.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Mar 2014 04:08:20 -0800 (PST) Message-ID: <5315C233.1080503@dev.mellanox.co.il> Date: Tue, 04 Mar 2014 07:08:19 -0500 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "Hefty, Sean" CC: "linux-rdma (linux-rdma@vger.kernel.org)" Subject: [PATCH v2] examples/riostream.c: Add AF_IB support Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Allow the user to specify GID addresses (AF_IB) into riostream example. Signed-off-by: Hal Rosenstock --- Change since v1: Added brief description -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/examples/riostream.c b/examples/riostream.c index a1d3671..4c0d21f 100644 --- a/examples/riostream.c +++ b/examples/riostream.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2011-2012 Intel Corporation. All rights reserved. + * Copyright (c) 2014 Mellanox Technologies LTD. All rights reserved. * * This software is available to you under the OpenIB.org BSD license * below: @@ -75,6 +76,7 @@ static struct test_size_param test_size[] = { static int rs, lrs; static int use_async; +static int use_rgai; static int verify; static int flags = MSG_DONTWAIT; static int poll_timeout = 0; @@ -92,6 +94,8 @@ static char *src_addr; static struct timeval start, end; static void *buf; static volatile uint8_t *poll_byte; +static struct rdma_addrinfo rai_hints; +static struct addrinfo ai_hints; static void show_perf(void) { @@ -355,18 +359,24 @@ static void set_options(int rs) static int server_listen(void) { - struct addrinfo hints, *res; + struct rdma_addrinfo *rai = NULL; + struct addrinfo *ai; int val, ret; - memset(&hints, 0, sizeof hints); - hints.ai_flags = AI_PASSIVE; - ret = getaddrinfo(src_addr, port, &hints, &res); + if (use_rgai) { + 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 = rsocket(res->ai_family, res->ai_socktype, res->ai_protocol); + lrs = rai ? rsocket(rai->ai_family, SOCK_STREAM, 0) : + rsocket(ai->ai_family, SOCK_STREAM, 0); if (lrs < 0) { perror("rsocket"); ret = lrs; @@ -380,7 +390,8 @@ static int server_listen(void) goto close; } - ret = rbind(lrs, res->ai_addr, res->ai_addrlen); + ret = rai ? rbind(lrs, rai->ai_src_addr, rai->ai_src_len) : + rbind(lrs, ai->ai_addr, ai->ai_addrlen); if (ret) { perror("rbind"); goto close; @@ -394,7 +405,10 @@ close: if (ret) rclose(lrs); free: - freeaddrinfo(res); + if (rai) + rdma_freeaddrinfo(rai); + else + freeaddrinfo(ai); return ret; } @@ -429,18 +443,21 @@ static int server_connect(void) static int client_connect(void) { - struct addrinfo *res; + struct rdma_addrinfo *rai = NULL; + struct addrinfo *ai; struct pollfd fds; int ret, err; socklen_t len; - ret = getaddrinfo(dst_addr, port, NULL, &res); + ret = use_rgai ? rdma_getaddrinfo(dst_addr, port, &rai_hints, &rai) : + getaddrinfo(dst_addr, port, &ai_hints, &ai); if (ret) { perror("getaddrinfo"); return ret; } - rs = rsocket(res->ai_family, res->ai_socktype, res->ai_protocol); + rs = rai ? rsocket(rai->ai_family, SOCK_STREAM, 0) : + rsocket(ai->ai_family, SOCK_STREAM, 0); if (rs < 0) { perror("rsocket"); ret = rs; @@ -450,7 +467,8 @@ static int client_connect(void) set_options(rs); /* TODO: bind client to src_addr */ - ret = rconnect(rs, res->ai_addr, res->ai_addrlen); + ret = rai ? rconnect(rs, rai->ai_dst_addr, rai->ai_dst_len) : + rconnect(rs, ai->ai_addr, ai->ai_addrlen); if (ret && (errno != EINPROGRESS)) { perror("rconnect"); goto close; @@ -478,7 +496,10 @@ close: if (ret) rclose(rs); free: - freeaddrinfo(res); + if (rai) + rdma_freeaddrinfo(rai); + else + freeaddrinfo(ai); return ret; } @@ -579,7 +600,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; @@ -587,6 +610,17 @@ 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; + use_rgai = 1; + } else { + fprintf(stderr, "Warning: unknown address format\n"); + } + break; case 'B': buffer_size = atoi(optarg); break; @@ -617,6 +651,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");