From patchwork Mon Jul 10 15:05:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 9833225 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 4008660318 for ; Mon, 10 Jul 2017 15:06:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3103D26E3E for ; Mon, 10 Jul 2017 15:06:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25E9828550; Mon, 10 Jul 2017 15:06:13 +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 B7D6026E3E for ; Mon, 10 Jul 2017 15:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753646AbdGJPGK (ORCPT ); Mon, 10 Jul 2017 11:06:10 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:40412 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753657AbdGJPGJ (ORCPT ); Mon, 10 Jul 2017 11:06:09 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2017 18:06:03 +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 v6AF5xbU015662; Mon, 10 Jul 2017 18:05:59 +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 v6AF5xr0029106; Mon, 10 Jul 2017 18:05:59 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id v6AF5xkx029105; Mon, 10 Jul 2017 18:05:59 +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 V1 rdma-core 2/5] verbs: Split ibverbs_init functionality Date: Mon, 10 Jul 2017 18:05:34 +0300 Message-Id: <1499699137-29037-3-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1499699137-29037-1-git-send-email-yishaih@mellanox.com> References: <1499699137-29037-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); +}