From patchwork Fri Mar 28 05:49:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 3900931 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 C434BBF540 for ; Fri, 28 Mar 2014 05:50:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 784D7202EC for ; Fri, 28 Mar 2014 05:50:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87CDB202E6 for ; Fri, 28 Mar 2014 05:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751179AbaC1Fu0 (ORCPT ); Fri, 28 Mar 2014 01:50:26 -0400 Received: from mga01.intel.com ([192.55.52.88]:35279 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751185AbaC1FuS (ORCPT ); Fri, 28 Mar 2014 01:50:18 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 27 Mar 2014 22:50:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,748,1389772800"; d="scan'208";a="501476348" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 22:50:16 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org Cc: Ira Weiny Subject: [PATCH 03/16] ibacm: use sysfs (in acm_if_is_ib) rather than ioctl(... SIOCGIFHWADDR ...) to read interface type Date: Thu, 27 Mar 2014 22:49:57 -0700 Message-Id: <1395985810-23822-4-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1395985810-23822-1-git-send-email-sean.hefty@intel.com> References: <1395985810-23822-1-git-send-email-sean.hefty@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.3 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);