From patchwork Fri Apr 4 00:51:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 3935231 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 D4564BFF02 for ; Fri, 4 Apr 2014 00:52:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1770420225 for ; Fri, 4 Apr 2014 00:52:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AA88202FE for ; Fri, 4 Apr 2014 00:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbaDDAwR (ORCPT ); Thu, 3 Apr 2014 20:52:17 -0400 Received: from mga11.intel.com ([192.55.52.93]:33514 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751634AbaDDAwQ (ORCPT ); Thu, 3 Apr 2014 20:52:16 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 03 Apr 2014 17:52:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,791,1389772800"; d="scan'208";a="506609517" Received: from sedona.ch.intel.com ([143.182.228.65]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2014 17:52:13 -0700 Received: from phlsvsles11.ph.intel.com (phlsvsles11.ph.intel.com [10.228.195.43]) by sedona.ch.intel.com (8.13.6/8.14.3/Standard MailSET/Hub) with ESMTP id s340qD2u008052; Thu, 3 Apr 2014 17:52:13 -0700 Received: from phlsvsles11.ph.intel.com (localhost [127.0.0.1]) by phlsvsles11.ph.intel.com with ESMTP id s340qCJm017480; Thu, 3 Apr 2014 20:52:12 -0400 Received: (from iweiny@localhost) by phlsvsles11.ph.intel.com with id s340qCJc017476; Thu, 3 Apr 2014 20:52:12 -0400 X-Authentication-Warning: phlsvsles11.ph.intel.com: iweiny set sender to ira.weiny@intel.com using -f From: ira.weiny@intel.com To: linux-rdma@vger.kernel.org Cc: sean.hefty@intel.com, Ira Weiny Subject: [PATCH 03/14] ibacm: use sysfs (in acm_if_is_ib) rather than ioctl(... SIOCGIFHWADDR ...) to read interface type Date: Thu, 3 Apr 2014 20:51:43 -0400 Message-Id: <1396572714-16498-4-git-send-email-ira.weiny@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1396572714-16498-1-git-send-email-ira.weiny@intel.com> References: <1396572714-16498-1-git-send-email-ira.weiny@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=-7.5 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: Ira Weiny Getting an interface type from sysfs is easier than using an ioctl when an interface name is readily available (as is the case with netlink.) In preparation for netlink support create a function which uses sysfs and use it instead of ioctls. Signed-off-by: Ira Weiny --- linux/acme_linux.c | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/linux/acme_linux.c b/linux/acme_linux.c index 201ff19..0bd1f75 100644 --- a/linux/acme_linux.c +++ b/linux/acme_linux.c @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -101,6 +102,31 @@ get_sgid(char *ifname, union ibv_gid *sgid) return ret; } +static int acm_if_is_ib(char *ifname) +{ + unsigned type; + char buf[128]; + FILE *f; + int ret; + + snprintf(buf, sizeof buf, "//sys//class//net//%s//type", ifname); + f = fopen(buf, "r"); + if (!f) { + printf("failed to open %s\n", buf); + return 0; + } + + if (fgets(buf, sizeof buf, f)) { + type = strtol(buf, NULL, 0); + ret = (type == ARPHRD_INFINIBAND); + } else { + ret = 0; + } + + fclose(f); + return ret; +} + static int get_devaddr(char *ifname, int *dev_index, uint8_t *port, uint16_t *pkey) { @@ -189,13 +215,7 @@ int gen_addr_ip(FILE *f) continue; } - ret = ioctl(s, SIOCGIFHWADDR, &ifr[i]); - if (ret) { - printf("failed to get hw address %d\n", ret); - continue; - } - - if (ifr[i].ifr_hwaddr.sa_family != ARPHRD_INFINIBAND) + if (!acm_if_is_ib(ifr[i].ifr_name)) continue; ret = get_devaddr(ifr[i].ifr_name, &dev_index, &port, &pkey);