From patchwork Mon Jul 9 16:03:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10515147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EA9F76032A for ; Mon, 9 Jul 2018 16:03:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8F53287BD for ; Mon, 9 Jul 2018 16:03:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD51A28916; Mon, 9 Jul 2018 16:03:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEE2D287BD for ; Mon, 9 Jul 2018 16:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932875AbeGIQD4 (ORCPT ); Mon, 9 Jul 2018 12:03:56 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:43665 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933333AbeGIQDz (ORCPT ); Mon, 9 Jul 2018 12:03:55 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 Jul 2018 19:06:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w69G3rRW000480; Mon, 9 Jul 2018 19:03:53 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w69G3r62022115; Mon, 9 Jul 2018 19:03:53 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w69G3qhg022112; Mon, 9 Jul 2018 19:03:52 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, parav@mellanox.com, majd@mellanox.com, jgg@mellanox.com Subject: [PATCH rdma-core] verbs: Do not add device whose uverbs device is not accessible Date: Mon, 9 Jul 2018 19:03:38 +0300 Message-Id: <1531152218-22041-1-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Parav Pandit When RDMA devices are used in container environment, orchestration software may choose to not map a uverbs character device to container. Adding an RDMA device which is not accessible for any verbs operation, but only accessible via sysfs is not very useful to real world applications but it just creates confusion. Therefore, do not add RDMA devices to ib device list, if its respective character device is not accessible. Signed-off-by: Parav Pandit Signed-off-by: Yishai Hadas --- PR was sent: https://github.com/linux-rdma/rdma-core/pull/357 libibverbs/init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libibverbs/init.c b/libibverbs/init.c index cda628b..d925c0e 100644 --- a/libibverbs/init.c +++ b/libibverbs/init.c @@ -66,6 +66,20 @@ struct ibv_driver { static LIST_HEAD(driver_name_list); static LIST_HEAD(driver_list); +static int try_access_device(const struct verbs_sysfs_dev *sysfs_dev) +{ + struct stat cdev_stat; + char *devpath; + int ret; + + if (asprintf(&devpath, "/dev/infiniband/%s", sysfs_dev->sysfs_name) < 0) + return ENOMEM; + + ret = stat(devpath, &cdev_stat); + free(devpath); + return ret; +} + static int find_sysfs_devs(struct list_head *tmp_sysfs_dev_list) { char class_path[IBV_SYSFS_PATH_MAX]; @@ -133,6 +147,9 @@ static int find_sysfs_devs(struct list_head *tmp_sysfs_dev_list) continue; } + if (try_access_device(sysfs_dev)) + continue; + sysfs_dev->time_created = buf.st_mtim; if (ibv_read_sysfs_file(sysfs_dev->sysfs_path, "abi_version",