From: "Eli Dorfman (Voltaire)" <dorfman.eli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
Cc: linux-rdma <linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH] ibsim: parse width and speed from ibnetdiscover output
Date: Thu, 02 Sep 2010 10:37:40 +0300 [thread overview]
Message-ID: <4C7F5444.4030302@gmail.com> (raw)
Search for the pattern '[0-9]*x[SDQ]DR'
Validate that width value is valid.
Signed-off-by: Eli Dorfman <elid-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
ibsim/sim_net.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/ibsim/sim_net.c b/ibsim/sim_net.c
index 13c3b8c..278c065 100644
--- a/ibsim/sim_net.c
+++ b/ibsim/sim_net.c
@@ -611,6 +611,7 @@ static int parse_port(char *line, Node * node, int type, int maxports)
int portnum, isalias = 0;
Port *port;
char *s;
+ char *p;
if (line[0] == '@') {
isalias = 1;
@@ -671,6 +672,7 @@ static int parse_port(char *line, Node * node, int type, int maxports)
}
parse_opt:
line = s;
+ p = s;
while (s && (s = strchr(s + 1, '='))) {
char *opt = s;
while (opt && !isalpha(*opt))
@@ -685,6 +687,52 @@ static int parse_port(char *line, Node * node, int type, int maxports)
IBWARN("cannot parse lid, lmc");
return -1;
}
+
+ /* parse width speed from '[0-9]*x[SDQ]DR' pattern */
+ /* also checking for valid width value */
+ char wstr[3];
+ char sstr[3];
+ s = p;
+ while (s && (s = strchr(s + 1, 'x'))) {
+ int width;
+ p = s - 1;
+ while (p && !isdigit(*p))
+ p--;
+ width = atoi(p);
+ switch (width) {
+ case 1: strcpy(wstr, "1");
+ break;
+ case 4: strcpy(wstr, "2");
+ break;
+ case 8: strcpy(wstr, "4");
+ break;
+ case 12: strcpy(wstr, "8");
+ break;
+ default: wstr[0] = sstr[0] = 0;
+ continue;
+ }
+ p = p + 2;
+ if (!strncmp("SDR", p, 3))
+ strcpy(sstr, "1");
+ else if (!strncmp("DDR", p, 3))
+ strcpy(sstr, "2");
+ else if (!strncmp("QDR", p, 3))
+ strcpy(sstr, "4");
+ else {
+ wstr[0] = sstr[0] = 0;
+ continue;
+ }
+ }
+
+ if (parse_port_opt(port, "w", wstr) < 0) {
+ IBWARN("bad port option");
+ return -1;
+ }
+
+ if (parse_port_opt(port, "s", sstr) < 0) {
+ IBWARN("bad port option");
+ return -1;
+ }
return 1;
}
--
1.7.2.1
--
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:[~2010-09-02 7:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-02 7:37 Eli Dorfman (Voltaire) [this message]
[not found] ` <4C7F5444.4030302-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-09-02 10:33 ` [PATCH] ibsim: parse width and speed from ibnetdiscover output Hal Rosenstock
[not found] ` <AANLkTi=3R5=obzp=hXmsh9HDswMMV770AB4cZvpTkhZc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-02 20:19 ` Eli Dorfman
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=4C7F5444.4030302@gmail.com \
--to=dorfman.eli-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sashak-smomgflXvOZWk0Htik3J/w@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox