From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B0698A046B for ; Wed, 24 Jul 2019 18:47:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 71E081C238; Wed, 24 Jul 2019 18:47:41 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 04DB11C1D4 for ; Wed, 24 Jul 2019 18:47:38 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2019 09:47:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,303,1559545200"; d="scan'208";a="189132491" Received: from aburakov-mobl1.ger.corp.intel.com (HELO [10.237.220.83]) ([10.237.220.83]) by fmsmga001.fm.intel.com with ESMTP; 24 Jul 2019 09:47:36 -0700 To: Stephen Hemminger Cc: dev@dpdk.org, john.mcnamara@intel.com, thomas@monjalon.net References: <1862ad94e15a61121aea75a2933dc8a44bb12623.1563982007.git.anatoly.burakov@intel.com> <20190724092812.069d9049@hermes.lan> From: "Burakov, Anatoly" Message-ID: Date: Wed, 24 Jul 2019 17:47:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190724092812.069d9049@hermes.lan> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 2/2] usertools/devbind: check if module is loaded before binding X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 24-Jul-19 5:28 PM, Stephen Hemminger wrote: > On Wed, 24 Jul 2019 16:34:44 +0100 > Anatoly Burakov wrote: > >> +# check if a specific kernel module is loaded >> +def module_is_loaded(module): >> + # Get list of sysfs modules (both built-in and dynamically loaded) >> + sysfs_path = '/sys/module/' >> + >> + # Get the list of directories in sysfs_path >> + sysfs_mods = [os.path.join(sysfs_path, o) for o >> + in os.listdir(sysfs_path) >> + if os.path.isdir(os.path.join(sysfs_path, o))] >> + >> + # get module names >> + sysfs_mods = [os.path.basename(a) for a in sysfs_mods] >> + >> + # special case for vfio_pci (module is named vfio-pci, >> + # but its .ko is named vfio_pci) >> + sysfs_mods = [a if a != 'vfio_pci' else 'vfio-pci' for a in sysfs_mods] >> + >> + return module in sysfs_mods >> + > > You could just check if the one module exist rather than getting full > list. I tried to reduce the amount of changes made, but i suppose i could fix this. > > Maybe vfio-pci should be renamed vfil_pci earlier in the code. > Good point. -- Thanks, Anatoly