From patchwork Thu Jun 29 14:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 9817071 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 368536020A for ; Thu, 29 Jun 2017 14:01:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A9C6284E3 for ; Thu, 29 Jun 2017 14:01:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F7432875A; Thu, 29 Jun 2017 14:01:16 +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=-6.9 required=2.0 tests=BAYES_00, 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 BDBEE28764 for ; Thu, 29 Jun 2017 14:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753260AbdF2OBO (ORCPT ); Thu, 29 Jun 2017 10:01:14 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48234 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753270AbdF2OBN (ORCPT ); Thu, 29 Jun 2017 10:01:13 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 29 Jun 2017 17:00:24 +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 v5TE0OuY009744; Thu, 29 Jun 2017 17:00:24 +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 v5TE0Oo1023409; Thu, 29 Jun 2017 17:00:24 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id v5TE0Og7023408; Thu, 29 Jun 2017 17:00:24 +0300 From: Yishai Hadas To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, yishaih@mellanox.com, maorg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 2/5] verbs: Split ibverbs_init functionality Date: Thu, 29 Jun 2017 17:00:13 +0300 Message-Id: <1498744816-23354-3-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1498744816-23354-1-git-send-email-yishaih@mellanox.com> References: <1498744816-23354-1-git-send-email-yishaih@mellanox.com> 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: Maor Gottlieb ibverbs_init is called only in the first time that ibv_get_device_list is called by the user. This function does two main things: 1) Initialization actions like fork init, memory check, etc. 2) Scan the sysfs device list and build the cached ibv_device list. This patch refactors the ibverbs_init and moves out the built device list code into new function - ibverbs_get_device_list. Motivation: In downstream patch, we refresh the ibv_device list according to the updated snapshot of the sysfs devices, so we want that the initialization action will continue to be singleton, but rescan the sysfs in each call to ibv_get_device_list. Signed-off-by: Maor Gottlieb Reviewed-by: Yishai Hadas --- libibverbs/init.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/libibverbs/init.c b/libibverbs/init.c index fdabe82..6e453ea 100644 --- a/libibverbs/init.c +++ b/libibverbs/init.c @@ -486,9 +486,8 @@ static void add_device(struct ibv_device *dev, (*dev_list)[(*num_devices)++] = dev; } -int ibverbs_init(struct ibv_device ***list) +int ibverbs_get_device_list(struct ibv_device ***list) { - const char *sysfs_path; struct ibv_sysfs_dev *sysfs_dev, *next_dev; struct ibv_device *device; int num_devices = 0; @@ -499,23 +498,6 @@ int ibverbs_init(struct ibv_device ***list) *list = NULL; - if (getenv("RDMAV_FORK_SAFE") || getenv("IBV_FORK_SAFE")) - if (ibv_fork_init()) - fprintf(stderr, PFX "Warning: fork()-safety requested " - "but init failed\n"); - - sysfs_path = ibv_get_sysfs_path(); - if (!sysfs_path) - return -ENOSYS; - - ret = check_abi_version(sysfs_path); - if (ret) - return -ret; - - check_memlock_limit(); - - read_config(); - ret = find_sysfs_devs(); if (ret) return -ret; @@ -582,3 +564,28 @@ out: return num_devices; } + +int ibverbs_init(struct ibv_device ***list) +{ + const char *sysfs_path; + int ret; + + if (getenv("RDMAV_FORK_SAFE") || getenv("IBV_FORK_SAFE")) + if (ibv_fork_init()) + fprintf(stderr, PFX "Warning: fork()-safety requested " + "but init failed\n"); + + sysfs_path = ibv_get_sysfs_path(); + if (!sysfs_path) + return -ENOSYS; + + ret = check_abi_version(sysfs_path); + if (ret) + return -ret; + + check_memlock_limit(); + + read_config(); + + return ibverbs_get_device_list(list); +}