[dpdk-dev] [PATCH 2/2] usertools/devbind: check if module is loaded before binding

Burakov, Anatoly anatoly.burakov at intel.com
Wed Jul 24 18:47:35 CEST 2019


On 24-Jul-19 5:28 PM, Stephen Hemminger wrote:
> On Wed, 24 Jul 2019 16:34:44 +0100
> Anatoly Burakov <anatoly.burakov at intel.com> 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


More information about the dev mailing list