From patchwork Mon Feb 22 14:45:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eran Ben Elisha X-Patchwork-Id: 8378011 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6D673C0553 for ; Mon, 22 Feb 2016 14:45:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6AFCE204D1 for ; Mon, 22 Feb 2016 14:45:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 400452047B for ; Mon, 22 Feb 2016 14:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751161AbcBVOpc (ORCPT ); Mon, 22 Feb 2016 09:45:32 -0500 Received: from [193.47.165.129] ([193.47.165.129]:57323 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751122AbcBVOpb (ORCPT ); Mon, 22 Feb 2016 09:45:31 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from eranbe@mellanox.com) with ESMTPS (AES256-SHA encrypted); 22 Feb 2016 16:45:14 +0200 Received: from dev-l-vrt-198-005.mtl.labs.mlnx (dev-l-vrt-198-005.mtl.labs.mlnx [10.134.198.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u1MEjEre023080; Mon, 22 Feb 2016 16:45:14 +0200 From: Eran Ben Elisha To: Doug Ledford Cc: linux-rdma@vger.kernel.org, Moshe Lazer , Eran Ben Elisha Subject: [libibverbs] libibverbs: Modify ibv_asyncwatch to accept the monitored device Date: Mon, 22 Feb 2016 16:45:04 +0200 Message-Id: <1456152304-16924-1-git-send-email-eranbe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 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 The current code always monitors the first device found. This patch allows to specify the monitored device by a command line argument. Signed-off-by: Eran Ben Elisha Reviewed-by: Moshe Lazer --- examples/asyncwatch.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++----- man/ibv_asyncwatch.1 | 14 +++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/examples/asyncwatch.c b/examples/asyncwatch.c index da7ebd4..a77c1c8 100644 --- a/examples/asyncwatch.c +++ b/examples/asyncwatch.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include @@ -76,35 +78,77 @@ static const char *event_name_str(enum ibv_event_type event_type) } } +static void usage(const char *argv0) +{ + printf("Usage:\n"); + printf(" %s start an asyncwatch process\n", argv0); + printf("\n"); + printf("Options:\n"); + printf(" -d, --ib-dev= use IB device (default first device found)\n"); + printf(" -h, --help print a help text and exit\n"); +} + int main(int argc, char *argv[]) { struct ibv_device **dev_list; struct ibv_context *context; struct ibv_async_event event; + char *ib_devname = NULL; + int i = 0; /* Force line-buffering in case stdout is redirected */ setvbuf(stdout, NULL, _IOLBF, 0); + while (1) { + int ret = 1; + int c; + static struct option long_options[] = { + { .name = "ib-dev", .has_arg = 1, .val = 'd' }, + { .name = "help", .has_arg = 0, .val = 'h' }, + { 0 } + }; + + c = getopt_long(argc, argv, "d:h", long_options, NULL); + if (c == -1) + break; + switch (c) { + case 'd': + ib_devname = strdupa(optarg); + break; + case 'h': + ret = 0; + default: + usage(argv[0]); + return ret; + } + } dev_list = ibv_get_device_list(NULL); if (!dev_list) { perror("Failed to get IB devices list"); return 1; } + if (ib_devname) { + for (; dev_list[i]; ++i) { + if (!strcmp(ibv_get_device_name(dev_list[i]), ib_devname)) + break; + } + } - if (!*dev_list) { - fprintf(stderr, "No IB devices found\n"); + if (!dev_list[i]) { + fprintf(stderr, "IB device %s not found\n", + ib_devname ? ib_devname : ""); return 1; } - context = ibv_open_device(*dev_list); + context = ibv_open_device(dev_list[i]); if (!context) { fprintf(stderr, "Couldn't get context for %s\n", - ibv_get_device_name(*dev_list)); + ibv_get_device_name(dev_list[i])); return 1; } printf("%s: async event FD %d\n", - ibv_get_device_name(*dev_list), context->async_fd); + ibv_get_device_name(dev_list[i]), context->async_fd); while (1) { if (ibv_get_async_event(context, &event)) diff --git a/man/ibv_asyncwatch.1 b/man/ibv_asyncwatch.1 index ece25f8..09f9f65 100644 --- a/man/ibv_asyncwatch.1 +++ b/man/ibv_asyncwatch.1 @@ -5,12 +5,26 @@ ibv_asyncwatch \- display asynchronous events .SH SYNOPSIS .B ibv_asyncwatch +[\-d device] [-h] .SH DESCRIPTION .PP Display asynchronous events forwarded to userspace for an RDMA device. +.SH OPTIONS + +.PP +.TP +\fB\-d\fR, \fB\-\-ib\-dev\fR=\fIDEVICE\fR +use IB device \fIDEVICE\fR (default first device found) +.TP +\fB\-h\fR, \fB\-\-help\fR=\fIDEVICE\fR +Print a help text and exit. + .SH AUTHORS .TP Roland Dreier .RI < rolandd@cisco.com > +.TP +Eran Ben Elisha +.RI < eranbe@mellanox.com >