From: Hal Rosenstock <hal-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
To: "Hefty, Sean" <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: "linux-rdma
(linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org)"
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH v2] examples/riostream.c: Add AF_IB support
Date: Tue, 04 Mar 2014 07:08:19 -0500 [thread overview]
Message-ID: <5315C233.1080503@dev.mellanox.co.il> (raw)
Allow the user to specify GID addresses (AF_IB) into riostream example.
Signed-off-by: Hal Rosenstock <hal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
Change since v1:
Added brief description
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");
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2014-03-04 12:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-04 12:08 Hal Rosenstock [this message]
[not found] ` <5315C233.1080503-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2014-03-05 20:54 ` [PATCH v2] examples/riostream.c: Add AF_IB support Hefty, Sean
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5315C233.1080503@dev.mellanox.co.il \
--to=hal-ldsdmyg8hgv8yrgs2mwiifqbs+8scbdb@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.